Exemple #1
0
func main() {
	gtk.Init(&os.Args)

	dialog := gtk.NewDialog()
	dialog.SetTitle("number input")

	vbox := dialog.GetVBox()

	label := gtk.NewLabel("Numnber:")
	vbox.Add(label)

	input := gtk.NewEntry()
	input.SetEditable(true)
	vbox.Add(input)

	input.Connect("insert-text", func(ctx *glib.CallbackContext) {
		a := (*[2000]uint8)(unsafe.Pointer(ctx.Args(0)))
		p := (*int)(unsafe.Pointer(ctx.Args(2)))
		i := 0
		for a[i] != 0 {
			i++
		}
		s := string(a[0:i])
		if s == "." {
			if *p == 0 {
				input.StopEmission("insert-text")
			}
		} else {
			_, err := strconv.ParseFloat(s, 64)
			if err != nil {
				input.StopEmission("insert-text")
			}
		}
	})

	button := gtk.NewButtonWithLabel("OK")
	button.Connect("clicked", func() {
		println(input.GetText())
		gtk.MainQuit()
	})
	vbox.Add(button)

	dialog.ShowAll()
	gtk.Main()
}
Exemple #2
0
// Returns true in case of reloading files, and false in case of keeping as is.
func inotify_dialog(s map[string]int) bool {
	if nil == accel_group {
		accel_group = gtk.NewAccelGroup()
	}
	inotify_dlg := gtk.NewDialog()
	defer inotify_dlg.Destroy()
	inotify_dlg.SetTitle("Some files have beed modified outside of tabby")
	inotify_dlg.AddButton("_Reload all", gtk.RESPONSE_ACCEPT)
	inotify_dlg.AddButton("_Keep all as is", gtk.RESPONSE_CANCEL)
	w := inotify_dlg.GetWidgetForResponse(int(gtk.RESPONSE_ACCEPT))
	inotify_dlg.AddAccelGroup(accel_group)
	w.AddAccelerator("clicked", accel_group, gdk.KEY_Return,
		0, gtk.ACCEL_VISIBLE)
	inotify_dlg.SetSizeRequest(800, 350)
	inotify_store := gtk.NewTreeStore(gtk.TYPE_STRING)
	inotify_view := gtk.NewTreeView()
	inotify_view.AppendColumn(
		gtk.NewTreeViewColumnWithAttributes("text", gtk.NewCellRendererText(), "text", 0))
	inotify_view.ModifyFontEasy("Regular 8")
	inotify_model := inotify_store.ToTreeModel()
	inotify_view.SetModel(inotify_model)
	inotify_view.SetHeadersVisible(false)
	var iter gtk.TreeIter
	for name, _ := range s {
		inotify_store.Append(&iter, nil)
		inotify_store.Set(&iter, name)
	}
	inotify_view.SetVisible(true)
	view_window := gtk.NewScrolledWindow(nil, nil)
	view_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	view_window.SetVisible(true)
	view_window.Add(inotify_view)
	vbox := inotify_dlg.GetVBox()
	vbox.Add(view_window)
	if gtk.RESPONSE_ACCEPT == inotify_dlg.Run() {
		return true
	}
	return false
}
Exemple #3
0
func find_dialog(find_file bool) (bool, string, bool, bool) {
	dialog := gtk.NewDialog()
	defer dialog.Destroy()
	dialog.SetTitle("Find")
	dialog.AddButton("_Find", gtk.RESPONSE_ACCEPT)
	dialog.AddButton("_Cancel", gtk.RESPONSE_CANCEL)
	w := dialog.GetWidgetForResponse(int(gtk.RESPONSE_ACCEPT))
	dialog.AddAccelGroup(accel_group)
	w.AddAccelerator("clicked", accel_group, gdk.KEY_Return,
		0, gtk.ACCEL_VISIBLE)
	entry := find_entry_with_history()
	global_button := gtk.NewCheckButtonWithLabel("Global")
	global_button.SetVisible(true)
	global_button.SetActive(prev_global)
	file_button := gtk.NewCheckButtonWithLabel("Find file by name pattern")
	file_button.SetVisible(true)
	file_button.SetActive(find_file)
	vbox := dialog.GetVBox()
	vbox.Add(entry)
	vbox.Add(global_button)
	vbox.Add(file_button)
	if gtk.RESPONSE_ACCEPT == dialog.Run() {
		entry_text := entry.GetActiveText()
		if nil == search_history {
			search_history = make([]string, 1)
			search_history[0] = entry_text
		} else {
			be := 0
			if 10 <= len(search_history) {
				be = 1
			}
			search_history = append(search_history[be:], entry_text)
		}
		prev_global = global_button.GetActive()
		return true, entry_text, prev_global, file_button.GetActive()
	}
	return false, "", false, false
}
Exemple #4
0
func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor {
	ed := &BiomeInfoEditor{
		Dialog:  gtk.NewDialog(),
		biolist: newBiomeList(),
	}

	ed.SetModal(true)

	vbox := ed.GetVBox()

	btnHBox := gtk.NewHBox(true, 0)

	resetBtn := gtk.NewButtonWithLabel("Reset to defaults")
	resetBtn.Connect("clicked", ed.reset)
	loadBtn := gtk.NewButtonWithLabel("Load from file ...")
	loadBtn.Connect("clicked", ed.load)
	saveBtn := gtk.NewButtonWithLabel("Save to file ...")
	saveBtn.Connect("clicked", ed.save)

	btnHBox.PackStart(resetBtn, true, true, 3)
	btnHBox.PackStart(loadBtn, true, true, 3)
	btnHBox.PackStart(saveBtn, true, true, 3)
	vbox.PackStart(btnHBox, false, false, 3)

	ed.biolist.SetBiomes(biomes)
	vbox.PackStart(ed.biolist, true, true, 3)

	editFrame := newBiomeEditFrame()
	connectBiomeListEditFrame(ed.biolist, editFrame)
	vbox.PackStart(editFrame, false, false, 3)

	ed.AddButton("Cancel", gtk.RESPONSE_CANCEL)
	ed.AddButton("OK", gtk.RESPONSE_OK)
	ed.ShowAll()
	return ed
}
Exemple #5
0
func fnr_dialog() {
	var fnr_cnt int = 0
	var scope_be, scope_en gtk.TextIter
	if MAX_SEL_LEN < len(source_selection()) {
		source_buf.GetSelectionBounds(&scope_be, &scope_en)
	} else {
		source_buf.GetStartIter(&scope_be)
		source_buf.GetEndIter(&scope_en)
	}
	source_buf.CreateMark("fnr_be", &scope_be, true)
	source_buf.CreateMark("fnr_en", &scope_en, false)
	var map_filled bool = false
	var global_map map[string]int
	var insert_set bool = false

	dialog := gtk.NewDialog()
	dialog.SetTitle("Find and Replace")
	dialog.AddButton("_Find Next", gtk.RESPONSE_OK)
	dialog.AddButton("_Replace", gtk.RESPONSE_YES)
	dialog.AddButton("Replace _All", gtk.RESPONSE_APPLY)
	dialog.AddButton("_Close", gtk.RESPONSE_CLOSE)
	dialog.AddAccelGroup(accel_group)

	entry := find_entry_with_history()
	replacement := find_entry_with_history()

	global_button := gtk.NewCheckButtonWithLabel("Global")
	global_button.SetVisible(true)
	global_button.SetActive(prev_global)

	vbox := dialog.GetVBox()
	vbox.Add(entry)
	vbox.Add(replacement)
	vbox.Add(global_button)

	find_next_button := dialog.GetWidgetForResponse(int(gtk.RESPONSE_OK))
	replace_button := dialog.GetWidgetForResponse(int(gtk.RESPONSE_YES))
	replace_all_button := dialog.GetWidgetForResponse(int(gtk.RESPONSE_APPLY))
	close_button := dialog.GetWidgetForResponse(int(gtk.RESPONSE_CLOSE))

	find_next_button.Connect("clicked", func() {
		fnr_pre_cb(global_button, &insert_set)
		if !fnr_find_next(entry.GetActiveText(), prev_global, &map_filled, &global_map) {
			fnr_close_and_report(dialog, fnr_cnt)
		}
	},
		nil)
	find_next_button.AddAccelerator("clicked", accel_group, gdk.KEY_Return,
		0, gtk.ACCEL_VISIBLE)

	replace_button.Connect("clicked", func() {
		fnr_pre_cb(global_button, &insert_set)
		done, next_found := fnr_replace(entry.GetActiveText(), replacement.GetActiveText(),
			prev_global, &map_filled, &global_map)
		fnr_cnt += done
		if !next_found {
			fnr_close_and_report(dialog, fnr_cnt)
		}
	},
		nil)

	replace_all_button.Connect("clicked", func() {
		insert_set = false
		fnr_pre_cb(global_button, &insert_set)
		fnr_cnt += fnr_replace_all_local(entry.GetActiveText(), replacement.GetActiveText())
		if prev_global {
			fnr_cnt += fnr_replace_all_global(entry.GetActiveText(), replacement.GetActiveText())
			file_tree_store()
		}
		fnr_close_and_report(dialog, fnr_cnt)
	},
		nil)

	close_button.Connect("clicked", func() { dialog.Destroy() }, nil)

	dialog.Run()
}
Exemple #6
0
func main() {
	gtk.Init(&os.Args)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("GoTalk")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})
	vbox := gtk.NewVBox(false, 1)
	scrolledwin := gtk.NewScrolledWindow(nil, nil)
	textview := gtk.NewTextView()
	textview.SetEditable(false)
	textview.SetCursorVisible(false)
	scrolledwin.Add(textview)
	vbox.Add(scrolledwin)

	buffer := textview.GetBuffer()

	entry := gtk.NewEntry()
	vbox.PackEnd(entry, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(300, 400)
	window.ShowAll()

	dialog := gtk.NewDialog()
	dialog.SetTitle(window.GetTitle())
	sgroup := gtk.NewSizeGroup(gtk.SIZE_GROUP_HORIZONTAL)

	hbox := gtk.NewHBox(false, 1)
	dialog.GetVBox().Add(hbox)
	label := gtk.NewLabel("username:"******"password:"******"talk.google.com:443", username_, password_)
	if err != nil {
		log.Fatal(err)
	}

	entry.Connect("activate", func() {
		text := entry.GetText()
		tokens := strings.SplitN(text, " ", 2)
		if len(tokens) == 2 {
			func() {
				defer recover()
				talk.Send(xmpp.Chat{Remote: tokens[0], Type: "chat", Text: tokens[1]})
				entry.SetText("")
			}()
		}
	})

	go func() {
		for {
			func() {
				defer recover()
				chat, err := talk.Recv()
				if err != nil {
					log.Fatal(err)
				}

				var iter gtk.TextIter
				buffer.GetStartIter(&iter)
				if msg, ok := chat.(xmpp.Chat); ok {
					buffer.Insert(&iter, msg.Remote+": "+msg.Text+"\n")
				}
			}()
		}
	}()

	gtk.Main()
}