Пример #1
0
func main() {
	gtk.Init(&os.Args)

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

	vbox := dialog.GetVBox()

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

	input := gtk.Entry()
	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.ButtonWithLabel("OK")
	button.Connect("clicked", func() {
		println(input.GetText())
		gtk.MainQuit()
	})
	vbox.Add(button)

	dialog.ShowAll()
	gtk.Main()
}
Пример #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.AccelGroup()
	}
	inotify_dlg := gtk.Dialog()
	defer inotify_dlg.Destroy()
	inotify_dlg.SetTitle("Some files have beed modified outside of tabby")
	inotify_dlg.AddButton("_Reload all", int(gtk.GTK_RESPONSE_ACCEPT))
	inotify_dlg.AddButton("_Keep all as is", int(gtk.GTK_RESPONSE_CANCEL))
	w := inotify_dlg.GetWidgetForResponse(int(gtk.GTK_RESPONSE_ACCEPT))
	inotify_dlg.AddAccelGroup(accel_group)
	w.AddAccelerator("clicked", accel_group, gdk.GDK_KEY_Return,
		0, gtk.GTK_ACCEL_VISIBLE)
	inotify_dlg.SetSizeRequest(800, 350)
	inotify_store := gtk.TreeStore(gtk.GTK_TYPE_STRING)
	inotify_view := gtk.TreeView()
	inotify_view.AppendColumn(
		gtk.TreeViewColumnWithAttributes("text", gtk.CellRendererText(), "text", 0))
	inotify_view.ModifyFontEasy("Regular 8")
	inotify_model := inotify_store.ToTreeModel()
	inotify_view.SetModel(inotify_model)
	inotify_view.SetHeadersVisible(false)
	var iter gtk.GtkTreeIter
	for name, _ := range s {
		inotify_store.Append(&iter, nil)
		inotify_store.Set(&iter, name)
	}
	inotify_view.SetVisible(true)
	view_window := gtk.ScrolledWindow(nil, nil)
	view_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
	view_window.SetVisible(true)
	view_window.Add(inotify_view)
	vbox := inotify_dlg.GetVBox()
	vbox.Add(view_window)
	if int(gtk.GTK_RESPONSE_ACCEPT) == inotify_dlg.Run() {
		return true
	}
	return false
}
Пример #3
0
func find_dialog(find_file bool) (bool, string, bool, bool) {
	dialog := gtk.Dialog()
	defer dialog.Destroy()
	dialog.SetTitle("Find")
	dialog.AddButton("_Find", int(gtk.GTK_RESPONSE_ACCEPT))
	dialog.AddButton("_Cancel", int(gtk.GTK_RESPONSE_CANCEL))
	w := dialog.GetWidgetForResponse(int(gtk.GTK_RESPONSE_ACCEPT))
	dialog.AddAccelGroup(accel_group)
	w.AddAccelerator("clicked", accel_group, gdk.GDK_KEY_Return,
		0, gtk.GTK_ACCEL_VISIBLE)
	entry := find_entry_with_history()
	global_button := gtk.CheckButtonWithLabel("Global")
	global_button.SetVisible(true)
	global_button.SetActive(prev_global)
	file_button := gtk.CheckButtonWithLabel("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 int(gtk.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
}
Пример #4
0
func main() {
	gtk.Init(&os.Args)

	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GoTalk")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})
	vbox := gtk.VBox(false, 1)
	scrolledwin := gtk.ScrolledWindow(nil, nil)
	textview := gtk.TextView()
	textview.SetEditable(false)
	textview.SetCursorVisible(false)
	scrolledwin.Add(textview)
	vbox.Add(scrolledwin)

	buffer := textview.GetBuffer()

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

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

	dialog := gtk.Dialog()
	dialog.SetTitle(window.GetTitle())
	sgroup := gtk.SizeGroup(gtk.GTK_SIZE_GROUP_HORIZONTAL)

	hbox := gtk.HBox(false, 1)
	dialog.GetVBox().Add(hbox)
	label := gtk.Label("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.GtkTextIter
				buffer.GetStartIter(&iter)
				buffer.Insert(&iter, chat.Remote+": "+chat.Text+"\n")
			}()
		}
	}()

	gtk.Main()
}
Пример #5
0
func fnr_dialog() {
	var fnr_cnt int = 0
	var scope_be, scope_en gtk.GtkTextIter
	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.Dialog()
	dialog.SetTitle("Find and Replace")
	dialog.AddButton("_Find Next", int(gtk.GTK_RESPONSE_OK))
	dialog.AddButton("_Replace", int(gtk.GTK_RESPONSE_YES))
	dialog.AddButton("Replace _All", int(gtk.GTK_RESPONSE_APPLY))
	dialog.AddButton("_Close", int(gtk.GTK_RESPONSE_CLOSE))
	dialog.AddAccelGroup(accel_group)

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

	global_button := gtk.CheckButtonWithLabel("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.GTK_RESPONSE_OK))
	replace_button := dialog.GetWidgetForResponse(int(gtk.GTK_RESPONSE_YES))
	replace_all_button := dialog.GetWidgetForResponse(int(gtk.GTK_RESPONSE_APPLY))
	close_button := dialog.GetWidgetForResponse(int(gtk.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.GDK_KEY_Return,
		0, gtk.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()
}