func (g *GUI) mkMenuBar() *gtk.MenuBar { menubar := gtk.NewMenuBar() fileMenu := gtk.NewMenu() open := gtk.NewImageMenuItemFromStock(gtk.STOCK_OPEN, g.accel) open.Connect("activate", g.openWorldDlg) fileMenu.Append(open) if quickopen, ok := g.mkQuickOpen(); ok { quickopenItem := gtk.NewMenuItemWithLabel("Open Map") quickopenItem.SetSubmenu(quickopen) fileMenu.Append(quickopenItem) } g.menuitemSave = gtk.NewImageMenuItemFromStock(gtk.STOCK_SAVE, g.accel) g.menuitemSave.Connect("activate", g.save) g.menuitemSave.SetSensitive(false) fileMenu.Append(g.menuitemSave) quit := gtk.NewImageMenuItemFromStock(gtk.STOCK_QUIT, g.accel) quit.Connect("activate", g.exitApp) fileMenu.Append(quit) fileMenuItem := gtk.NewMenuItemWithLabel("File") fileMenuItem.SetSubmenu(fileMenu) menubar.Append(fileMenuItem) helpMenu := gtk.NewMenu() controls := gtk.NewMenuItemWithLabel("Controls") controls.Connect("activate", func() { dlg := gtk.NewMessageDialog(g.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Click to use selected tool.\nMiddle mouse button to move around.") dlg.Run() dlg.Destroy() }) helpMenu.Append(controls) about := gtk.NewImageMenuItemFromStock(gtk.STOCK_ABOUT, g.accel) about.Connect("activate", g.aboutDlg) helpMenu.Append(about) helpMenuItem := gtk.NewMenuItemWithLabel("Help") helpMenuItem.SetSubmenu(helpMenu) menubar.Append(helpMenuItem) return menubar }
func main() { gtk.Init(&os.Args) glib.SetApplicationName("go-gtk-statusicon-example") mi := gtk.NewMenuItemWithLabel("Popup!") mi.Connect("activate", func() { gtk.MainQuit() }) nm := gtk.NewMenu() nm.Append(mi) nm.ShowAll() si := gtk.NewStatusIconFromStock(gtk.STOCK_FILE) si.SetTitle("StatusIcon Example") si.SetTooltipMarkup("StatusIcon Example") si.Connect("popup-menu", func(cbx *glib.CallbackContext) { nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint(cbx.Args(1))) }) println(` Can you see statusicon in systray? If you don't see it and if you use 'unity', try following. # gsettings set com.canonical.Unity.Panel systray-whitelist \ "$(gsettings get com.canonical.Unity.Panel systray-whitelist \| sed -e "s/]$/, 'go-gtk-statusicon-example']/")" `) gtk.Main() }
func main() { FreeConsole() gtk.Init(nil) screenHeight := gdk.ScreenHeight() screenWidth := gdk.ScreenWidth() window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("mgc") window.SetIconName("gtk-about") window.Connect("destroy", func() { gtk.MainQuit() }) vbox := gtk.NewVBox(false, 0) menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) menu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(menu) submenu := gtk.NewMenu() menu.SetSubmenu(submenu) menuitem := gtk.NewMenuItemWithMnemonic("E_xit") menuitem.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menuitem) hpaned := gtk.NewHPaned() leftFrame := gtk.NewFrame("") rightFrame := gtk.NewFrame("") leftLabel := gtk.NewLabel("Left") rightLabel := gtk.NewLabel("Right") leftFrame.Add(leftLabel) rightFrame.Add(rightLabel) hpaned.Pack1(leftFrame, true, false) hpaned.Pack2(rightFrame, true, false) vbox.Add(hpaned) window.Add(vbox) window.SetSizeRequest(screenWidth/4*3, screenHeight/4*3) window.ShowAll() gtk.Main() }
func createMenu() *gtk.MenuBar { menubar := gtk.NewMenuBar() vpaned := gtk.NewVPaned() //-------------------------------------------------------- // GtkMenuItem //-------------------------------------------------------- cascademenu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(cascademenu) submenu := gtk.NewMenu() cascademenu.SetSubmenu(submenu) var menuitem *gtk.MenuItem menuitem = gtk.NewMenuItemWithMnemonic("E_xit") menuitem.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_View") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable") checkmenuitem.Connect("activate", func() { vpaned.SetSensitive(!checkmenuitem.GetActive()) }) submenu.Append(checkmenuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_Help") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) return menubar }
func (g *GUI) mkQuickOpen() (*gtk.Menu, bool) { maps := allMaps() if (maps == nil) || (len(maps) == 0) { return nil, false } menu := gtk.NewMenu() for name, p := range maps { mitem := gtk.NewMenuItemWithLabel(name) p2 := p mitem.Connect("activate", func() { g.openWorld(p2) }) menu.Append(mitem) } return menu, true }
// newMenuFromItems returns a GTK menu from a pathtree.Items map. This function // calls itself recursively and takes a relpath used to build the absolute path // needed by the pass command. func newMenuFromItems(items pathtree.Items, relpath string) *gtk.Menu { result := gtk.NewMenu() for k, v := range items { mi := gtk.NewMenuItemWithLabel(k) abspath := relpath + k if len(v) > 0 { mi.SetSubmenu(newMenuFromItems(v, abspath+"/")) } else { mi.Connect("activate", func() { exec.Command("pass", abspath, "-c").Run() }) } result.Append(mi) } return result }
func main() { gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("GoMADScan") window.SetIconName("GoMADScan-info") window.Connect("destroy", func(ctx *glib.CallbackContext) { // fmt.Println("got destroy!", ctx.Data().(string)) gtk.MainQuit() }, "") //-------------------------------------------------------- // GtkVBox //-------------------------------------------------------- vbox := gtk.NewVBox(false, 1) //-------------------------------------------------------- // GtkMenuBar //-------------------------------------------------------- menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) //-------------------------------------------------------- // GtkVPaned //-------------------------------------------------------- vpaned := gtk.NewVPaned() vbox.Add(vpaned) //-------------------------------------------------------- // GtkFrame //-------------------------------------------------------- frame1 := gtk.NewFrame("") framebox1 := gtk.NewVBox(false, 1) frame1.Add(framebox1) frame2 := gtk.NewFrame("Column index for search (0: all columns)") framebox2 := gtk.NewVBox(false, 1) frame2.Add(framebox2) vpaned.Pack1(frame1, false, false) vpaned.Pack2(frame2, false, false) //-------------------------------------------------------- // GtkImage //-------------------------------------------------------- dir := os.Getenv("GOPATH") if dir == "" { dir = filepath.Join(os.Getenv("HOME"), "/go") } imagefile := filepath.Join(dir, "/src/github.com/carushi/GoMADScan/image/logo.png") label := gtk.NewLabel("Go-based Modification associated database scanner") label.ModifyFontEasy("DejaVu Serif 15") framebox1.PackStart(label, false, true, 0) image := gtk.NewImageFromFile(imagefile) framebox1.Add(image) //-------------------------------------------------------- // Data input and output filename //-------------------------------------------------------- arg := arguments{ 0, filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/Sample_modification_site"), filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/Ras_gene_synonym.txt"), filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/output.txt"), false, true, "\t"} //-------------------------------------------------------- // GtkScale //-------------------------------------------------------- scale := gtk.NewHScaleWithRange(0, 20, 1) scale.Connect("value-changed", func() { arg.column = int(scale.GetValue()) // fmt.Println("scale:", int(scale.GetValue())) }) framebox2.Add(scale) //-------------------------------------------------------- // InputArea //-------------------------------------------------------- ientry := gtk.NewEntry() ientry.SetText(arg.inputPath) inputs := gtk.NewHBox(false, 1) button := gtk.NewButtonWithLabel("Choose input file") button.Clicked(func() { //-------------------------------------------------------- // GtkFileChooserDialog //-------------------------------------------------------- filechooserdialog := gtk.NewFileChooserDialog( "Choose File...", button.GetTopLevelAsWindow(), gtk.FILE_CHOOSER_ACTION_OPEN, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) filter := gtk.NewFileFilter() filter.AddPattern("*") filechooserdialog.AddFilter(filter) filechooserdialog.Response(func() { arg.inputPath = filechooserdialog.GetFilename() ientry.SetText(arg.inputPath) filechooserdialog.Destroy() }) filechooserdialog.Run() }) inputs.Add(button) inputs.Add(ientry) framebox2.PackStart(inputs, false, false, 0) fentry := gtk.NewEntry() fentry.SetText(arg.filterPath) inputs = gtk.NewHBox(false, 1) button = gtk.NewButtonWithLabel("Choose keyword file") button.Clicked(func() { //-------------------------------------------------------- // GtkFileChooserDialog //-------------------------------------------------------- filechooserdialog := gtk.NewFileChooserDialog( "Choose File...", button.GetTopLevelAsWindow(), gtk.FILE_CHOOSER_ACTION_OPEN, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) filter := gtk.NewFileFilter() filter.AddPattern("*") filechooserdialog.AddFilter(filter) filechooserdialog.Response(func() { arg.filterPath = filechooserdialog.GetFilename() fentry.SetText(arg.filterPath) filechooserdialog.Destroy() }) filechooserdialog.Run() }) inputs.Add(button) inputs.Add(fentry) framebox2.PackStart(inputs, false, false, 0) oentry := gtk.NewEntry() oentry.SetText(arg.outputPath) inputs = gtk.NewHBox(false, 1) button = gtk.NewButtonWithLabel("Choose output file") button.Clicked(func() { //-------------------------------------------------------- // GtkFileChooserDialog //-------------------------------------------------------- filechooserdialog := gtk.NewFileChooserDialog( "Choose File...", button.GetTopLevelAsWindow(), gtk.FILE_CHOOSER_ACTION_OPEN, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) filter := gtk.NewFileFilter() filter.AddPattern("*") filechooserdialog.AddFilter(filter) filechooserdialog.Response(func() { arg.outputPath = filechooserdialog.GetFilename() oentry.SetText(arg.outputPath) filechooserdialog.Destroy() }) filechooserdialog.Run() }) inputs.Add(button) inputs.Add(oentry) framebox2.PackStart(inputs, false, false, 0) buttons := gtk.NewHBox(false, 1) //-------------------------------------------------------- // GtkCheckButton //-------------------------------------------------------- checkbutton := gtk.NewCheckButtonWithLabel("Case-insensitive (lower/upper)") checkbutton.Connect("toggled", func() { if checkbutton.GetActive() { arg.ignoreCase = true } else { arg.ignoreCase = false } }) buttons.Add(checkbutton) checkMatchButton := gtk.NewCheckButtonWithLabel("Partial matching / Perfect matching") checkMatchButton.Connect("toggled", func() { if checkMatchButton.GetActive() { arg.perfectMatch = false } else { arg.perfectMatch = true } }) buttons.Add(checkMatchButton) combobox := gtk.NewComboBoxText() for _, delim := range delimName { combobox.AppendText(delim) } combobox.SetActive(0) combobox.Connect("changed", func() { fmt.Println("value:", combobox.GetActiveText()) arg.delim = combobox.GetActiveText() }) buttons.Add(combobox) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- swin := gtk.NewScrolledWindow(nil, nil) swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin.SetShadowType(gtk.SHADOW_IN) textview := gtk.NewTextView() // var start, end gtk.TextIter var end gtk.TextIter buffer := textview.GetBuffer() swin.Add(textview) //-------------------------------------------------------- // Run button //-------------------------------------------------------- runbutton := gtk.NewButtonWithLabel("Run") runbutton.Clicked(func() { arg.inputPath = ientry.GetText() arg.filterPath = fentry.GetText() arg.outputPath = oentry.GetText() num, err := getKeysearchWords(arg) buffer.GetStartIter(&end) if err != nil { log.Println(err) buffer.Insert(&end, err.Error()+"\n") } else { buffer.Insert(&end, "GoMADScan found "+strconv.Itoa(num)+ " modification sites.\nThe result is written into "+arg.outputPath+".\n") } }) buttons.Add(runbutton) framebox2.PackStart(buttons, false, false, 0) //-------------------------------------------------------- // GtkVSeparator //-------------------------------------------------------- vsep := gtk.NewVSeparator() framebox2.PackStart(vsep, false, false, 0) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- framebox2.Add(swin) // buffer.Connect("changed", func() { // // fmt.Println("changed") // }) //-------------------------------------------------------- // GtkMenuItem //-------------------------------------------------------- cascademenu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(cascademenu) submenu := gtk.NewMenu() cascademenu.SetSubmenu(submenu) var menuitem *gtk.MenuItem menuitem = gtk.NewMenuItemWithMnemonic("_Exit") menuitem.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_View") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable") checkmenuitem.Connect("activate", func() { vpaned.SetSensitive(!checkmenuitem.GetActive()) }) submenu.Append(checkmenuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_Help") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) menuitem = gtk.NewMenuItemWithMnemonic("_About") menuitem.Connect("activate", func() { dialog := gtk.NewAboutDialog() dialog.SetName("GoMADScan") dialog.SetProgramName("GoMADScan") dialog.SetAuthors(authors()) dialog.SetLicense("LGPL v3") dialog.SetWrapLicense(true) dialog.Run() dialog.Destroy() }) submenu.Append(menuitem) //-------------------------------------------------------- // GtkStatusbar //-------------------------------------------------------- statusbar := gtk.NewStatusbar() context_id := statusbar.GetContextId("GoMADScan v0") statusbar.Push(context_id, "Simple search GUI") framebox2.PackStart(statusbar, false, false, 0) //-------------------------------------------------------- // Event //-------------------------------------------------------- window.Add(vbox) window.SetSizeRequest(600, 600) window.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) display = gtk.NewEntry() window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("Simple Go Calculator") window.Connect("destroy", Quit, nil) // Vertical box containing all components vbox := gtk.NewVBox(false, 1) // Menu bar menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) // Add calculator display to vertical box display.SetCanFocus(false) // disable focus on calcuator display display.SetText("0") display.SetAlignment(1.0) //align text to right vbox.Add(display) // Menu items filemenu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(filemenu) filesubmenu := gtk.NewMenu() filemenu.SetSubmenu(filesubmenu) aboutmenuitem := gtk.NewMenuItemWithMnemonic("_About") aboutmenuitem.Connect("activate", func() { messagedialog := gtk.NewMessageDialog( window.GetTopLevelAsWindow(), gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Simple Go Calculator") messagedialog.Response(func() {}, nil) messagedialog.Run() messagedialog.Destroy() }, nil) filesubmenu.Append(aboutmenuitem) resetmenuitem := gtk.NewMenuItemWithMnemonic("_Reset") resetmenuitem.Connect("activate", func() { Reset(); display.SetText("0") }, nil) filesubmenu.Append(resetmenuitem) exitmenuitem := gtk.NewMenuItemWithMnemonic("E_xit") exitmenuitem.Connect("activate", Quit, nil) filesubmenu.Append(exitmenuitem) // Vertical box containing all buttons buttons := gtk.NewVBox(false, 5) for i := 0; i < 4; i++ { hbox := gtk.NewHBox(false, 5) // a horizontal box for each 4 buttons for j := 0; j < 4; j++ { b := gtk.NewButtonWithLabel(string(nums[i*4+j])) b.Clicked(Input(b), nil) //add click event hbox.Add(b) } buttons.Add(hbox) // add horizonatal box to vertical buttons' box } vbox.Add(buttons) window.Add(vbox) window.SetSizeRequest(250, 250) window.ShowAll() gtk.Main() }
// main reads the config file, connects to each IMAP server in a separate thread // and watches the notify channel for messages telling it to update the status // icon. func main() { conf, err := goconf.ReadConfigFile(os.Getenv("HOME") + "/.hasmailrc") if err != nil { fmt.Println("Failed to load configuration file, exiting...\n", err) return } // This channel will be used to tell us if we should exit the program quit := make(chan os.Signal, 1) signal.Notify(quit, os.Interrupt) // GTK engage! gtk.Init(&os.Args) glib.SetApplicationName("hasmail") defer gtk.MainQuit() // Set up the tray icon si := gtk.NewStatusIconFromStock(gtk.STOCK_DISCONNECT) si.SetTitle("hasmail") si.SetTooltipMarkup("Not connected") // Set up the tray icon right click menu mi := gtk.NewMenuItemWithLabel("Quit") mi.Connect("activate", func() { quit <- syscall.SIGINT }) nm := gtk.NewMenu() nm.Append(mi) nm.ShowAll() si.Connect("popup-menu", func(cbx *glib.CallbackContext) { nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint32(cbx.Args(1))) }) /* If the user clicks the tray icon, here's what happens: * - if only a single account has new emails, and a click command has been * specified for that account, execute it * - if the user has specified a default click handler, execute that * - otherwise, do nothing */ si.Connect("activate", func(cbx *glib.CallbackContext) { command, geterr := conf.GetString("default", "click") nonZero := 0 nonZeroAccount := "" for account, unseenList := range parts.Unseen { if len(unseenList) > 0 { nonZero++ nonZeroAccount = account } } // Can't just use HasOption here because that also checks "default" section, // even though Get* doesn't... if nonZero == 1 { acommand, ageterr := conf.GetString(nonZeroAccount, "click") if ageterr == nil { command = acommand geterr = ageterr } } if geterr == nil { fmt.Printf("Executing user command: %s\n", command) shell := os.Getenv("SHELL") if shell == "" { shell = "/bin/sh" } sh := exec.Command(shell, "-c", command) sh.Env = os.Environ() err = sh.Start() if err != nil { fmt.Printf("Failed to run command '%s' on click\n", command) fmt.Println(err) } } else { fmt.Println("No action defined for click\n", geterr) } }) go gtk.Main() // Connect to all accounts sections := conf.GetSections() notify := make(chan bool, len(sections)) for _, account := range sections { // default isn't really an account if account == "default" { continue } initConnection(notify, conf, account) } // Let the user know that we've now initiated all the connections si.SetFromStock(gtk.STOCK_CONNECT) si.SetTooltipText("Connecting") // Keep updating the status icon (or quit if the user wants us to) for { select { case <-quit: return case <-notify: totUnseen := 0 s := "" for account, e := range parts.Errs { if e == 0 { continue } s += account + ": " switch e { case 1: s += "Connection failed!" case 2: s += "IDLE not supported!" case 3: s += "No login credentials given!" case 4: s += "Login failed!" case 5: s += "Connection dropped!" } s += "\n" } for account, unseenList := range parts.Unseen { if parts.Errs[account] != 0 { continue } numUnseen := len(unseenList) if numUnseen >= 0 { totUnseen += numUnseen } s += account + ": " switch numUnseen { case 0: s += "No new messages" case 1: s += "One new message" default: s += fmt.Sprintf("%d new messages", numUnseen) } s += "\n" } // get rid of trailing newline s = strings.TrimRight(s, "\n") si.SetTooltipText(s) // http://developer.gnome.org/gtk3/3.0/gtk3-Stock-Items.html switch totUnseen { case 0: si.SetFromStock(gtk.STOCK_NEW) case 1: si.SetFromStock(gtk.STOCK_DND) default: si.SetFromStock(gtk.STOCK_DND_MULTIPLE) } } } }
func main() { if len(os.Args) < 2 { filename = "" } else { filename = os.Args[1] } gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle(filename) window.Connect("destroy", gtk.MainQuit) vbox := gtk.NewVBox(false, 1) menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) webview = webkit.NewWebView() vbox.Add(webview) filemenu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(filemenu) submenu := gtk.NewMenu() filemenu.SetSubmenu(submenu) menu_open := gtk.NewMenuItemWithMnemonic("_Open") menu_open.Connect("activate", func() { filechooserdialog := gtk.NewFileChooserDialog( "Choose file", window, gtk.FILE_CHOOSER_ACTION_OPEN, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) filter := gtk.NewFileFilter() filter.AddPattern("*.md") filter.AddPattern("*.markdown") filter.SetName("Markdown files") filechooserdialog.AddFilter(filter) filechooserdialog.Response(func() { filename = (filechooserdialog.GetFilename()) filechooserdialog.Destroy() }) filechooserdialog.Run() reload() }) submenu.Append(menu_open) menu_reload = gtk.NewMenuItemWithMnemonic("_Reload") menu_reload.Connect("activate", func() { reload() }) submenu.Append(menu_reload) menu_exit = gtk.NewMenuItemWithMnemonic("E_xit") menu_exit.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menu_exit) viewmenu := gtk.NewMenuItemWithMnemonic("_View") menubar.Append(viewmenu) viewsubmenu := gtk.NewMenu() viewmenu.SetSubmenu(viewsubmenu) menu_dark := gtk.NewCheckMenuItemWithMnemonic("D_ark Theme") menu_dark.Connect("activate", func() { if menu_dark.GetActive() { dark_theme = true } else { dark_theme = false } reload() }) viewsubmenu.Append(menu_dark) window.Add(vbox) window.SetSizeRequest(480, 600) bytesSlice := bytesFromXpmData(xpm_data) icon_file := "/tmp/hackdown-icon.xpm" ioutil.WriteFile(icon_file, bytesSlice, os.ModePerm) window.SetIconFromFile(icon_file) window.ShowAll() webview.LoadString(getContent(), "text/html", "utf-8", ".") gtk.Main() }
func init_tabby() { init_navigation() init_inotify() search_view.Init() source_buf = gtksourceview.NewSourceBuffer() source_buf.Connect("paste-done", paste_done_cb, nil) source_buf.Connect("mark-set", mark_set_cb, nil) source_buf.Connect("modified-changed", buf_changed_cb, nil) init_lang() source_buf.CreateTag("instance", map[string]string{"background": "#FF8080"}) tree_store = gtk.NewTreeStore(glib.G_TYPE_STRING) tree_view = file_tree.NewFileTree() tree_view.ModifyFontEasy("Regular 8") tree_model = tree_store.ToTreeModel() tree_view.SetModel(tree_model) tree_view.SetHeadersVisible(false) tree_view.Connect("cursor-changed", tree_view_select_cb, nil) error_view = gtk.NewTextView() error_view.ModifyFontEasy("Monospace Regular 8") error_view.SetEditable(false) error_buf = error_view.GetBuffer() source_view = gtksourceview.NewSourceViewWithBuffer(source_buf) source_view.ModifyFontEasy("Monospace Regular 10") source_view.SetAutoIndent(true) source_view.SetHighlightCurrentLine(true) source_view.SetShowLineNumbers(true) source_view.SetRightMarginPosition(80) source_view.SetShowRightMargin(true) source_view.SetIndentWidth(2) source_view.SetTabWidth(2) source_view.SetInsertSpacesInsteadOfTabs(opt.space_not_tab) source_view.SetDrawSpaces(gtksourceview.SOURCE_DRAW_SPACES_TAB) source_view.SetSmartHomeEnd(gtksourceview.SOURCE_SMART_HOME_END_ALWAYS) source_view.SetWrapMode(gtk.WRAP_WORD) vbox := gtk.NewVBox(false, 0) inner_hpaned := gtk.NewHPaned() view_vpaned := gtk.NewVPaned() outer_hpaned := gtk.NewHPaned() outer_hpaned.Add1(inner_hpaned) inner_hpaned.Add2(view_vpaned) menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) vbox.PackStart(outer_hpaned, true, true, 0) file_item := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(file_item) file_submenu := gtk.NewMenu() file_item.SetSubmenu(file_submenu) accel_group := gtk.NewAccelGroup() new_item := gtk.NewMenuItemWithMnemonic("_New") file_submenu.Append(new_item) new_item.Connect("activate", new_cb, nil) new_item.AddAccelerator("activate", accel_group, gdk.KEY_n, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) open_item := gtk.NewMenuItemWithMnemonic("_Open") file_submenu.Append(open_item) open_item.Connect("activate", open_cb, nil) open_item.AddAccelerator("activate", accel_group, gdk.KEY_o, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) open_rec_item := gtk.NewMenuItemWithMnemonic("Open _Recursively") file_submenu.Append(open_rec_item) open_rec_item.Connect("activate", open_rec_cb, nil) save_item := gtk.NewMenuItemWithMnemonic("_Save") file_submenu.Append(save_item) save_item.Connect("activate", save_cb, nil) save_item.AddAccelerator("activate", accel_group, gdk.KEY_s, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) save_as_item := gtk.NewMenuItemWithMnemonic("Save _as") file_submenu.Append(save_as_item) save_as_item.Connect("activate", save_as_cb, nil) close_item := gtk.NewMenuItemWithMnemonic("_Close") file_submenu.Append(close_item) close_item.Connect("activate", close_cb, nil) close_item.AddAccelerator("activate", accel_group, gdk.KEY_w, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) exit_item := gtk.NewMenuItemWithMnemonic("E_xit") file_submenu.Append(exit_item) exit_item.Connect("activate", exit_cb, nil) navigation_item := gtk.NewMenuItemWithMnemonic("_Navigation") menubar.Append(navigation_item) navigation_submenu := gtk.NewMenu() navigation_item.SetSubmenu(navigation_submenu) prev_instance_item := gtk.NewMenuItemWithMnemonic("_Previous Instance") navigation_submenu.Append(prev_instance_item) prev_instance_item.Connect("activate", prev_instance_cb, nil) prev_instance_item.AddAccelerator("activate", accel_group, gdk.KEY_F2, 0, gtk.ACCEL_VISIBLE) next_instance_item := gtk.NewMenuItemWithMnemonic("_Next Instance") navigation_submenu.Append(next_instance_item) next_instance_item.Connect("activate", next_instance_cb, nil) next_instance_item.AddAccelerator("activate", accel_group, gdk.KEY_F3, 0, gtk.ACCEL_VISIBLE) prev_result_item := gtk.NewMenuItemWithMnemonic("Prev search result") navigation_submenu.Append(prev_result_item) prev_result_item.Connect("activate", func() { search_view.PrevResult() }, nil) prev_result_item.AddAccelerator("activate", accel_group, gdk.KEY_F4, 0, gtk.ACCEL_VISIBLE) next_result_item := gtk.NewMenuItemWithMnemonic("Next search result") navigation_submenu.Append(next_result_item) next_result_item.Connect("activate", func() { search_view.NextResult() }, nil) next_result_item.AddAccelerator("activate", accel_group, gdk.KEY_F5, 0, gtk.ACCEL_VISIBLE) find_item := gtk.NewMenuItemWithMnemonic("_Find") navigation_submenu.Append(find_item) find_item.Connect("activate", find_cb, nil) find_item.AddAccelerator("activate", accel_group, gdk.KEY_f, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) find_file_item := gtk.NewMenuItemWithMnemonic("_Find file") navigation_submenu.Append(find_file_item) find_file_item.Connect("activate", find_file_cb, nil) find_file_item.AddAccelerator("activate", accel_group, gdk.KEY_d, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) fnr_item := gtk.NewMenuItemWithMnemonic("Find and Replace") navigation_submenu.Append(fnr_item) fnr_item.Connect("activate", fnr_cb, nil) fnr_item.AddAccelerator("activate", accel_group, gdk.KEY_r, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) prev_file_item := gtk.NewMenuItemWithMnemonic("Prev File") navigation_submenu.Append(prev_file_item) prev_file_item.Connect("activate", prev_file_cb, nil) prev_file_item.AddAccelerator("activate", accel_group, gdk.KEY_F7, 0, gtk.ACCEL_VISIBLE) next_file_item := gtk.NewMenuItemWithMnemonic("Next File") navigation_submenu.Append(next_file_item) next_file_item.Connect("activate", next_file_cb, nil) next_file_item.AddAccelerator("activate", accel_group, gdk.KEY_F8, 0, gtk.ACCEL_VISIBLE) tools_item := gtk.NewMenuItemWithMnemonic("_Tools") menubar.Append(tools_item) tools_submenu := gtk.NewMenu() tools_item.SetSubmenu(tools_submenu) gofmt_item := gtk.NewMenuItemWithMnemonic("_Gofmt") tools_submenu.Append(gofmt_item) gofmt_item.Connect("activate", gofmt_cb, nil) gofmt_item.AddAccelerator("activate", accel_group, gdk.KEY_F9, 0, gtk.ACCEL_VISIBLE) gofmtAll_item := gtk.NewMenuItemWithMnemonic("Gofmt _All") tools_submenu.Append(gofmtAll_item) gofmtAll_item.Connect("activate", gofmt_all, nil) gofmtAll_item.AddAccelerator("activate", accel_group, gdk.KEY_F9, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) options_item := gtk.NewMenuItemWithMnemonic("_Options") menubar.Append(options_item) options_submenu := gtk.NewMenu() options_item.SetSubmenu(options_submenu) search_chkitem := gtk.NewCheckMenuItemWithMnemonic("Show _Searchview") options_submenu.Append(search_chkitem) search_chkitem.SetActive(opt.show_search) search_chkitem.Connect("toggled", func() { search_chk_cb(search_chkitem.GetActive()) }, nil) error_chkitem := gtk.NewCheckMenuItemWithMnemonic("Show _Errorview") options_submenu.Append(error_chkitem) error_chkitem.SetActive(opt.show_error) error_chkitem.Connect("toggled", func() { error_chk_cb(error_chkitem.GetActive()) }, nil) notab_chkitem := gtk.NewCheckMenuItemWithMnemonic("Spaces for _Tabs") options_submenu.Append(notab_chkitem) notab_chkitem.SetActive(opt.space_not_tab) notab_chkitem.Connect("toggled", func() { notab_chk_cb(notab_chkitem.GetActive()) }, nil) font_item := gtk.NewMenuItemWithMnemonic("_Font") options_submenu.Append(font_item) font_item.Connect("activate", font_cb, nil) tabsize_item := gtk.NewMenuItemWithMnemonic("_Tab size") options_submenu.Append(tabsize_item) tabsize_submenu := gtk.NewMenu() tabsize_item.SetSubmenu(tabsize_submenu) const tabsize_cnt = 8 tabsize_chk := make([]*gtk.CheckMenuItem, tabsize_cnt) for y := 0; y < tabsize_cnt; y++ { tabsize_chk[y] = gtk.NewCheckMenuItemWithMnemonic(strconv.Itoa(y + 1)) tabsize_submenu.Append(tabsize_chk[y]) cur_ind := y tabsize_chk[y].Connect("activate", func() { if false == tabsize_chk[cur_ind].GetActive() { active_cnt := 0 for j := 0; j < tabsize_cnt; j++ { if tabsize_chk[j].GetActive() { active_cnt++ } } if 0 == active_cnt { tabsize_chk[cur_ind].SetActive(true) } return } for j := 0; j < tabsize_cnt; j++ { if j != cur_ind { tabsize_chk[j].SetActive(false) } } options_set_tabsize(cur_ind + 1) }, nil) } tree_window := gtk.NewScrolledWindow(nil, nil) tree_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) inner_hpaned.Add1(tree_window) tree_window.Add(tree_view) outer_hpaned.Add2(search_view.window) text_window := gtk.NewScrolledWindow(nil, nil) text_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) view_vpaned.Add1(text_window) text_window.Add(source_view) error_window = gtk.NewScrolledWindow(nil, nil) error_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) view_vpaned.Add2(error_window) error_window.Add(error_view) inner_hpaned.Connect("size_request", func() { ohp_cb(outer_hpaned.GetPosition()) }, nil) view_vpaned.Connect("size_request", func() { ihp_cb(inner_hpaned.GetPosition()) }, nil) source_view.Connect("size_request", func() { vvp_cb(view_vpaned.GetPosition()) }, nil) outer_hpaned.SetPosition(opt.ohp_position) inner_hpaned.SetPosition(opt.ihp_position) view_vpaned.SetPosition(opt.vvp_position) main_window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL) main_window.AddAccelGroup(accel_group) main_window.SetSizeRequest(400, 200) //minimum size main_window.Resize(opt.window_width, opt.window_height) main_window.Move(opt.window_x, opt.window_y) main_window.Connect("destroy", exit_cb, "") main_window.Connect("configure-event", window_event_cb, "") main_window.Add(vbox) // init_tabby blocks for some reason when is called after ShowAll. init_vars() main_window.ShowAll() error_window.SetVisible(opt.show_error) // Cannot be called before ShowAll. This is also not clear. file_switch_to(file_stack_pop()) stack_prev(&file_stack_max) if "" == cur_file { new_cb() } source_view.GrabFocus() }
func main() { gtk.Init(&os.Args) display = gtk.NewEntry() display.SetAlignment(1.0) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("Simple Go Calculator") window.Connect("destroy", Quit) // Vertical box containing all components vbox := gtk.NewVBox(false, 1) // Menu bar menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) // Add calculator display to vertical box display.SetCanFocus(false) // disable focus on calcuator display vbox.Add(display) // Menu items filemenu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(filemenu) filesubmenu := gtk.NewMenu() filemenu.SetSubmenu(filesubmenu) aboutmenuitem := gtk.NewMenuItemWithMnemonic("_About") aboutmenuitem.Connect("activate", func() { messagedialog := gtk.NewMessageDialog( window.GetTopLevelAsWindow(), gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Simple Go Calculator") messagedialog.Response(func() {}) messagedialog.Run() messagedialog.Destroy() }, nil) filesubmenu.Append(aboutmenuitem) resetmenuitem := gtk.NewMenuItemWithMnemonic("_Reset") resetmenuitem.Connect("activate", func() { Reset(); display.SetText("0") }) filesubmenu.Append(resetmenuitem) exitmenuitem := gtk.NewMenuItemWithMnemonic("E_xit") exitmenuitem.Connect("activate", Quit) filesubmenu.Append(exitmenuitem) // Vertical box containing all buttons buttons := gtk.NewVBox(false, 5) bmap := map[string]*gtk.Button{} for i := 0; i < 4; i++ { hbox := gtk.NewHBox(false, 5) // a horizontal box for each 4 buttons for j := 0; j < 4; j++ { b := gtk.NewButtonWithLabel(string(nums[i*4+j])) b.Clicked(Input(b)) //add click event hbox.Add(b) bmap[string(nums[i*4+j])] = b } buttons.Add(hbox) // add horizonatal box to vertical buttons' box } vbox.Add(buttons) window.Connect("key-press-event", func(ctx *glib.CallbackContext) bool { arg := ctx.Args(0) kev := *(**gdk.EventKey)(unsafe.Pointer(&arg)) c := (string(uint8(kev.Keyval % 0xff))) if kev.Keyval == gdk.KEY_Return { c = "=" return true } if b, ok := bmap[c]; ok { Input(b)() b.GrabFocus() } else if kev.Keyval == gdk.KEY_Delete { Reset() display.SetText("0") return true } return false }) window.Add(vbox) window.SetSizeRequest(250, 250) window.ShowAll() gtk.Main() }
func main() { flag.Parse() usr, err := user.Current() if err != nil { fmt.Println("Couldn't get home directory:", err) return } file, err := ioutil.ReadFile(usr.HomeDir + "/.gpuush") if err != nil { fmt.Println("Config file error:", err) return } err = json.Unmarshal(file, &conf) if err != nil { fmt.Println("Config file error:", err) return } success := login(conf.Email, conf.Pass) if !success { return } if background { quit := make(chan os.Signal, 1) signal.Notify(quit, os.Interrupt) gtk.Init(&os.Args) glib.SetApplicationName("gpuush") defer gtk.MainQuit() si := gtk.NewStatusIconFromFile("/usr/local/share/gpuush/icon.png") si.SetTitle("gpuush") si.SetTooltipMarkup("gpuush") nm := gtk.NewMenu() mi := gtk.NewMenuItemWithLabel("Take Screenshot") mi.Connect("activate", func() { go takeScreenshot() }) nm.Append(mi) nm.ShowAll() mi = gtk.NewMenuItemWithLabel("Quit") mi.Connect("activate", func() { quit <- syscall.SIGINT }) nm.Append(mi) nm.ShowAll() si.Connect("popup-menu", func(cbx *glib.CallbackContext) { nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint32(cbx.Args(1))) }) go gtk.Main() for { select { case <-quit: return } } } else if screenshot { takeScreenshot() } else { result := uploadFile(flag.Arg(0)) if len(result) > 0 { notify(result) copy(result) } else { notify("Upload failed") } } }
func main() { flag.Parse() runtime.GOMAXPROCS(runtime.NumCPU()) common.SetDefaultGtkTheme() machinePassword = uuid.New()[:4] clremoton = newClient(&remoton.Client{Prefix: "/remoton", TLSConfig: &tls.Config{}}) sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGABRT, syscall.SIGKILL, syscall.SIGTERM) go func() { <-sigs clremoton.Terminate() }() gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("REMOTON CLIENT") window.Connect("destroy", func(ctx *glib.CallbackContext) { gtk.MainQuit() clremoton.Terminate() }, "quit") window.SetIcon(common.GetIconGdkPixbuf()) appLayout := gtk.NewVBox(false, 1) menu := gtk.NewMenuBar() appLayout.Add(menu) cascademenu := gtk.NewMenuItemWithMnemonic("_Help") menu.Append(cascademenu) submenu := gtk.NewMenu() cascademenu.SetSubmenu(submenu) menuitem := gtk.NewMenuItemWithMnemonic("_About") menuitem.Connect("activate", func() { dialog := common.GtkAboutDialog() dialog.SetProgramName("Client Desktop") dialog.SetComments("Share your desktop secure") dialog.Run() dialog.Destroy() }) submenu.Append(menuitem) hpaned := gtk.NewHPaned() appLayout.Add(hpaned) statusbar := gtk.NewStatusbar() contextID := statusbar.GetContextId("remoton-desktop-client") //--- //CONTROL //--- frameControl := gtk.NewFrame("Controls") controlBox := gtk.NewVBox(false, 1) frameControl.Add(controlBox) controlBox.Add(gtk.NewLabel("MACHINE ID")) machineIDEntry := gtk.NewEntry() machineIDEntry.SetEditable(false) controlBox.Add(machineIDEntry) machineAuthEntry := gtk.NewEntry() machineAuthEntry.SetEditable(false) controlBox.Add(machineAuthEntry) controlBox.Add(gtk.NewLabel("Server")) serverEntry := gtk.NewEntry() serverEntry.SetText("127.0.0.1:9934") if os.Getenv("REMOTON_SERVER") != "" { serverEntry.SetText(os.Getenv("REMOTON_SERVER")) serverEntry.SetEditable(false) } controlBox.Add(serverEntry) controlBox.Add(gtk.NewLabel("Auth Server")) authServerEntry := gtk.NewEntry() authServerEntry.SetText("public") controlBox.Add(authServerEntry) var getCertFilename func() string localCert := filepath.Join(filepath.Dir(os.Args[0]), "cert.pem") if _, err := os.Stat(localCert); err == nil || os.IsExist(err) { controlBox.Add(gtk.NewLabel("Cert local")) getCertFilename = func() string { return localCert } } else if os.Getenv("REMOTON_CERT_FILE") != "" { controlBox.Add(gtk.NewLabel("Cert enviroment")) getCertFilename = func() string { return os.Getenv("REMOTON_CERT_FILE") } } else { btnCert := gtk.NewFileChooserButton("Cert", gtk.FILE_CHOOSER_ACTION_OPEN) getCertFilename = btnCert.GetFilename controlBox.Add(btnCert) } btnSrv := gtk.NewButtonWithLabel("Start") clremoton.VNC.OnConnection(func(addr net.Addr) { statusbar.Push(contextID, "Someone connected") log.Println("New connection from:" + addr.String()) }) btnSrv.Clicked(func() { if *insecure { clremoton.SetInsecure() } else { certPool, err := common.GetRootCAFromFile(getCertFilename()) if err != nil { dialogError(window, err) return } clremoton.SetCertPool(certPool) } if !clremoton.Started() { log.Println("starting remoton") machinePassword = uuid.New()[:4] err := clremoton.Start(serverEntry.GetText(), authServerEntry.GetText(), machinePassword) if err != nil { dialogError(btnSrv.GetTopLevelAsWindow(), err) statusbar.Push(contextID, "Failed") } else { btnSrv.SetLabel("Stop") machineIDEntry.SetText(clremoton.MachineID()) machineAuthEntry.SetText(machinePassword) statusbar.Push(contextID, "Connected") } } else { clremoton.Stop() btnSrv.SetLabel("Start") machineIDEntry.SetText("") machineAuthEntry.SetText("") statusbar.Push(contextID, "Stopped") } }) controlBox.Add(btnSrv) //--- // CHAT //--- frameChat := gtk.NewFrame("Chat") chatBox := gtk.NewVBox(false, 1) frameChat.Add(chatBox) swinChat := gtk.NewScrolledWindow(nil, nil) chatHistory := gtk.NewTextView() clremoton.Chat.OnRecv(func(msg string) { chatHistoryRecv(chatHistory, msg) }) swinChat.Add(chatHistory) chatEntry := gtk.NewEntry() chatEntry.Connect("key-press-event", func(ctx *glib.CallbackContext) { arg := ctx.Args(0) event := *(**gdk.EventKey)(unsafe.Pointer(&arg)) if event.Keyval == gdk.KEY_Return { msgToSend := chatEntry.GetText() clremoton.Chat.Send(msgToSend) chatHistorySend(chatHistory, msgToSend) chatEntry.SetText("") } }) chatBox.Add(chatEntry) chatBox.Add(swinChat) hpaned.Pack1(frameControl, false, false) hpaned.Pack2(frameChat, false, true) appLayout.Add(statusbar) window.Add(appLayout) window.ShowAll() gtk.Main() }
func main() { flag.Parse() common.SetDefaultGtkTheme() runtime.GOMAXPROCS(runtime.NumCPU()) rclient = &remoton.Client{Prefix: "/remoton", TLSConfig: &tls.Config{}} sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGABRT, syscall.SIGKILL, syscall.SIGTERM) go func() { <-sigs chatSrv.Terminate() tunnelSrv.Terminate() }() gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("REMOTON SUPPORT") window.Connect("destroy", func() { gtk.MainQuit() chatSrv.Terminate() tunnelSrv.Terminate() }) window.SetIcon(common.GetIconGdkPixbuf()) appLayout := gtk.NewVBox(false, 1) menu := gtk.NewMenuBar() appLayout.Add(menu) cascademenu := gtk.NewMenuItemWithMnemonic("_Help") menu.Append(cascademenu) submenu := gtk.NewMenu() cascademenu.SetSubmenu(submenu) menuitem := gtk.NewMenuItemWithMnemonic("_About") menuitem.Connect("activate", func() { dialog := common.GtkAboutDialog() dialog.SetProgramName("Support Desktop") dialog.Run() dialog.Destroy() }) submenu.Append(menuitem) hpaned := gtk.NewHPaned() appLayout.Add(hpaned) //--- //CHAT //--- frameChat := gtk.NewFrame("Chat") chatBox := gtk.NewVBox(false, 1) frameChat.Add(chatBox) swinChat := gtk.NewScrolledWindow(nil, nil) chatHistory := gtk.NewTextView() swinChat.Add(chatHistory) chatEntry := gtk.NewEntry() chatEntry.Connect("key-press-event", func(ctx *glib.CallbackContext) { arg := ctx.Args(0) event := *(**gdk.EventKey)(unsafe.Pointer(&arg)) if event.Keyval == gdk.KEY_Return { msgToSend := chatEntry.GetText() chatSrv.Send(msgToSend) chatHistorySend(chatHistory, msgToSend) chatEntry.SetText("") } }) chatSrv.OnRecv(func(msg string) { log.Println(msg) chatHistoryRecv(chatHistory, msg) }) chatBox.Add(chatEntry) chatBox.Add(swinChat) //--- //CONTROL //--- frameControl := gtk.NewFrame("Control") controlBox := gtk.NewVBox(false, 1) frameControl.Add(controlBox) controlBox.Add(gtk.NewLabel("Machine ID")) machineIDEntry := gtk.NewEntry() controlBox.Add(machineIDEntry) controlBox.Add(gtk.NewLabel("Machine AUTH")) machineAuthEntry := gtk.NewEntry() controlBox.Add(machineAuthEntry) controlBox.Add(gtk.NewLabel("Server")) serverEntry := gtk.NewEntry() serverEntry.SetText("localhost:9934") if os.Getenv("REMOTON_SERVER") != "" { serverEntry.SetText(os.Getenv("REMOTON_SERVER")) serverEntry.SetEditable(false) } controlBox.Add(serverEntry) btnCert := gtk.NewFileChooserButton("Cert", gtk.FILE_CHOOSER_ACTION_OPEN) controlBox.Add(btnCert) btn := gtk.NewButtonWithLabel("Connect") started := false btn.Clicked(func() { if *insecure { rclient.TLSConfig.InsecureSkipVerify = true } else { certPool, err := common.GetRootCAFromFile(btnCert.GetFilename()) if err != nil { dialogError(window, err) return } rclient.TLSConfig.RootCAs = certPool } session := &remoton.SessionClient{Client: rclient, ID: machineIDEntry.GetText(), APIURL: "https://" + serverEntry.GetText()} if !started { err := chatSrv.Start(session) if err != nil { dialogError(btn.GetTopLevelAsWindow(), err) return } err = tunnelSrv.Start(session, machineAuthEntry.GetText()) if err != nil { dialogError(btn.GetTopLevelAsWindow(), err) return } btn.SetLabel("Disconnect") started = true } else { chatSrv.Terminate() tunnelSrv.Terminate() btn.SetLabel("Connect") started = false } }) controlBox.Add(btn) hpaned.Pack1(frameControl, false, false) hpaned.Pack2(frameChat, false, false) window.Add(appLayout) window.ShowAll() gtk.Main() }
func main() { var menuitem *gtk.MenuItem gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("GoBox a0.1") window.SetIconName("gtk-dialog-info") window.Connect("destroy", func(ctx *glib.CallbackContext) { println("got destroy!", ctx.Data().(string)) gtk.MainQuit() }, "foo") //-------------------------------------------------------- // GtkVBox //-------------------------------------------------------- vbox := gtk.NewVBox(false, 1) //-------------------------------------------------------- // GtkMenuBar //-------------------------------------------------------- menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) //-------------------------------------------------------- // GtkVPaned //-------------------------------------------------------- vpaned := gtk.NewVPaned() vbox.Add(vpaned) //-------------------------------------------------------- // GtkFrame //-------------------------------------------------------- frame1 := gtk.NewFrame("Dossier et Paramètres") framebox1 := gtk.NewVBox(false, 1) frame1.Add(framebox1) frame2 := gtk.NewFrame("Fonctions") framebox2 := gtk.NewVBox(false, 1) frame2.Add(framebox2) vpaned.Pack1(frame1, false, false) vpaned.Pack2(frame2, false, false) //-------------------------------------------------------- // GtkImage //-------------------------------------------------------- /*dir, _ := path.Split(os.Args[0]) //imagefile := path.Join(dir, "../../mattn/go-gtk/data/go-gtk-logo.png") imagefile := path.Join(dir, "./go-gtk-logo.png") println(dir)*/ label := gtk.NewLabel("GoBox a0.1") label.ModifyFontEasy("DejaVu Serif 15") framebox1.PackStart(label, false, true, 0) //-------------------------------------------------------- // GtkEntry //-------------------------------------------------------- champIp := gtk.NewEntry() champIp.SetText("10.0.0.1") framebox1.Add(champIp) champPort := gtk.NewEntry() champPort.SetText("80") framebox1.Add(champPort) folder := "./" /*image := gtk.NewImageFromFile(imagefile) framebox1.Add(image)*/ buttons := gtk.NewHBox(false, 1) //-------------------------------------------------------- // GtkButton //-------------------------------------------------------- button := gtk.NewButtonWithLabel("Choisir le dossier") button.Clicked(func() { //-------------------------------------------------------- // GtkFileChooserDialog //-------------------------------------------------------- filechooserdialog := gtk.NewFileChooserDialog( "Sélectionnez le dossier ...", button.GetTopLevelAsWindow(), gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) /*filter := gtk.NewFileFilter() filter.AddPattern("*.go") filechooserdialog.AddFilter(filter)*/ filechooserdialog.Response(func() { println(filechooserdialog.GetFilename()) folder = filechooserdialog.GetFilename() + "/" filechooserdialog.Destroy() }) filechooserdialog.Run() }) buttons.Add(button) //-------------------------------------------------------- // GtkToggleButton //-------------------------------------------------------- togglebutton := gtk.NewToggleButtonWithLabel("Lancer la synchronisation") togglebutton.Connect("toggled", func() { if togglebutton.GetActive() { togglebutton.SetLabel("Synchronisation ON") //Appel fonction synchro avec paramètres println(folder, champIp.GetText(), champPort.GetText()) sync(folder, champIp.GetText(), champPort.GetText()) } else { togglebutton.SetLabel("Synchronisation OFF") } }) buttons.Add(togglebutton) framebox2.PackStart(buttons, false, false, 0) //-------------------------------------------------------- // GtkVSeparator //-------------------------------------------------------- vsep := gtk.NewVSeparator() framebox2.PackStart(vsep, false, false, 0) //-------------------------------------------------------- // GtkMenuItem //-------------------------------------------------------- cascademenu := gtk.NewMenuItemWithMnemonic("_Fichier") menubar.Append(cascademenu) submenu := gtk.NewMenu() cascademenu.SetSubmenu(submenu) menuitem = gtk.NewMenuItemWithMnemonic("Q_uitter") menuitem.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_Aide") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) auteurs := gtk.NewEntry() auteurs.SetText("Application crée en MCS par Olivier CANO et Adrien CHAPELET") menuitem = gtk.NewMenuItemWithMnemonic("À_ propos") menuitem.Connect("activate", func() { messagedialog := gtk.NewMessageDialog( button.GetTopLevelAsWindow(), gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, auteurs.GetText()) messagedialog.Response(func() { messagedialog.Destroy() }) messagedialog.Run() }) submenu.Append(menuitem) //-------------------------------------------------------- // GtkStatusbar //-------------------------------------------------------- statusbar := gtk.NewStatusbar() context_id := statusbar.GetContextId("go-gtk") statusbar.Push(context_id, "En attente de synchronisation") framebox2.PackStart(statusbar, false, false, 0) //-------------------------------------------------------- // Event //-------------------------------------------------------- window.Add(vbox) window.SetSizeRequest(500, 300) window.ShowAll() gtk.Main() }
func main() { gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("GTK Go!") window.Connect("destroy", func(ctx *glib.CallbackContext) { gtk.MainQuit() }, "") vbox := gtk.NewVBox(false, 0) toolbar := gtk.NewToolbar() toolbar.SetStyle(gtk.TOOLBAR_ICONS) vbox.PackStart(toolbar, false, false, 5) btnnew := gtk.NewToolButtonFromStock(gtk.STOCK_NEW) btnclose := gtk.NewToolButtonFromStock(gtk.STOCK_CLOSE) separator := gtk.NewSeparatorToolItem() btncustom := gtk.NewToolButton(nil, "Custom") btnmenu := gtk.NewMenuToolButtonFromStock("gtk.STOCK_CLOSE") btnmenu.SetArrowTooltipText("This is a tool tip") btnnew.OnClicked(onToolButtonClicked) btnclose.OnClicked(onToolButtonClicked) btncustom.OnClicked(onToolButtonClicked) toolmenu := gtk.NewMenu() menuitem := gtk.NewMenuItemWithMnemonic("8") menuitem.Show() toolmenu.Append(menuitem) menuitem = gtk.NewMenuItemWithMnemonic("16") menuitem.Show() toolmenu.Append(menuitem) menuitem = gtk.NewMenuItemWithMnemonic("32") menuitem.Show() toolmenu.Append(menuitem) btnmenu.SetMenu(toolmenu) toolbar.Insert(btnnew, -1) toolbar.Insert(btnclose, -1) toolbar.Insert(separator, -1) toolbar.Insert(btncustom, -1) toolbar.Insert(btnmenu, -1) hbox := gtk.NewHBox(false, 0) vbox.PackStart(hbox, true, true, 0) toolbar2 := gtk.NewToolbar() toolbar2.SetOrientation(gtk.ORIENTATION_VERTICAL) hbox.PackStart(toolbar2, false, false, 5) btnhelp := gtk.NewToolButtonFromStock(gtk.STOCK_HELP) btnhelp.OnClicked(onToolButtonClicked) toolbar2.Insert(btnhelp, -1) btntoggle := gtk.NewToggleToolButton() btntoggle2 := gtk.NewToggleToolButtonFromStock(gtk.STOCK_ITALIC) toolbar2.Insert(btntoggle, -1) toolbar2.Insert(btntoggle2, -1) for i := 0; i < toolbar.GetNItems(); i++ { gti := toolbar.GetNthItem(i) switch gti.(type) { case *gtk.ToolButton: fmt.Printf("toolbar[%d] is a *gtk.ToolButton\n", i) w := gti.(*gtk.ToolButton).GetIconWidget() gti.(*gtk.ToolButton).SetIconWidget(w) case *gtk.ToggleToolButton: fmt.Printf("toolbar[%d] is a *gtk.ToggleToolButton\n", i) gti.(*gtk.ToggleToolButton).SetActive(true) case *gtk.SeparatorToolItem: fmt.Printf("toolbar[%d] is a *gtk.SeparatorToolItem\n", i) default: fmt.Printf("toolbar: Item is of unknown type\n") } } for i := 0; i < toolbar2.GetNItems(); i++ { gti := toolbar2.GetNthItem(i) switch gti.(type) { case *gtk.ToolButton: fmt.Printf("toolbar2[%d] is a *gtk.ToolButton\n", i) case *gtk.ToggleToolButton: fmt.Printf("toolbar2[%d] is a *gtk.ToggleToolButton\n", i) gti.(*gtk.ToggleToolButton).SetActive(true) case *gtk.SeparatorToolItem: fmt.Printf("toolbar2[%d] is a *gtk.SeparatorToolItem\n", i) default: fmt.Printf("toolbar2: Item is of unknown type\n") } } window.Add(vbox) window.SetSizeRequest(600, 600) window.ShowAll() gtk.Main() }
//InitializeGUI es la funcion que inicializa y ejecuta todo el entorno gráfico de la aplicacion func (p *Gui) InitializeGUI(errorstr string, file *os.File) { gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.Maximize() window.SetTitle("Go-SIC ASM/SIM!") window.SetIconName("gtk-dialog-info") window.Connect("destroy", func(ctx *glib.CallbackContext) { fmt.Println("got destroy!", ctx.Data().(string)) gtk.MainQuit() }, "foo") //-------------------------------------------------------- // GTK statusbar //-------------------------------------------------------- statusbar := gtk.NewStatusbar() context_id := statusbar.GetContextId("hola") //-------------------------------------------------------- // GtkVBox //-------------------------------------------------------- vbox := gtk.NewVBox(false, 1) //-------------------------------------------------------- // GtkMenuBar //-------------------------------------------------------- menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) //-------------------------------------------------------- // GtkVPaned //-------------------------------------------------------- vpaned := gtk.NewVPaned() vbox.Add(vpaned) //-------------------------------------------------------- // GtkFrame //-------------------------------------------------------- frame1 := gtk.NewFrame("Código Fuente/Archivo intermedio/TABSIM") framebox1 := gtk.NewVBox(false, 1) frame1.Add(framebox1) frame1.SetSizeRequest(300, 300) frame2 := gtk.NewFrame("Debug/Código Objeto") framebox2 := gtk.NewVBox(false, 1) frame2.Add(framebox2) vpaned.Pack1(frame1, false, false) vpaned.Pack2(frame2, false, false) //-------------------------------------------------------- // GtkHBox //-------------------------------------------------------- ventanasPrincipales := gtk.NewHBox(false, 1) //---------------------------------------------- label := gtk.NewLabel("Ensamblador SIC SIC/XE") label.ModifyFontEasy("DejaVu Serif 15") framebox1.PackStart(label, false, true, 0) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- swin := gtk.NewScrolledWindow(nil, nil) swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin.SetShadowType(gtk.SHADOW_IN) textview := gtk.NewTextView() textview.ModifyFontEasy("Sans 10") var start, end gtk.TextIter buffer := textview.GetBuffer() buffer.GetStartIter(&start) swin.Add(textview) ventanasPrincipales.Add(swin) //framebox1.Add(swin) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- swin4 := gtk.NewScrolledWindow(nil, nil) swin4.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin4.SetShadowType(gtk.SHADOW_IN) textview4 := gtk.NewTextView() textview4.ModifyFontEasy("Sans 10") var start4, end4 gtk.TextIter buffer4 := textview4.GetBuffer() buffer4.GetStartIter(&start4) swin4.Add(textview4) ventanasPrincipales.Add(swin4) //framebox1.Add(swin) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- swin5 := gtk.NewScrolledWindow(nil, nil) swin5.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin5.SetShadowType(gtk.SHADOW_IN) textview5 := gtk.NewTextView() textview5.ModifyFontEasy("Sans 10") var start5, end5 gtk.TextIter buffer5 := textview5.GetBuffer() buffer5.GetStartIter(&start5) swin5.Add(textview5) ventanasPrincipales.Add(swin5) framebox1.PackStart(ventanasPrincipales, true, true, 1) //framebox1.Add(swin) //-------------------------------------------------------- // GtkHBox //-------------------------------------------------------- ventanas := gtk.NewHBox(false, 1) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- swin2 := gtk.NewScrolledWindow(nil, nil) swin2.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin2.SetShadowType(gtk.SHADOW_IN) textview2 := gtk.NewTextView() textview2.SetEditable(false) var start2, end2 gtk.TextIter buffer2 := textview2.GetBuffer() buffer2.GetStartIter(&start2) swin2.Add(textview2) //framebox2.Add(swin2) ventanas.Add(swin2) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- swin3 := gtk.NewScrolledWindow(nil, nil) swin3.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin3.SetShadowType(gtk.SHADOW_IN) textview3 := gtk.NewTextView() textview3.SetEditable(false) var start3, end3 gtk.TextIter buffer3 := textview3.GetBuffer() buffer3.GetStartIter(&start3) swin3.Add(textview3) //framebox2.Add(swin2) ventanas.Add(swin3) framebox2.PackStart(ventanas, true, true, 1) //-------------------------------------------------------- // GtkEntry //-------------------------------------------------------- entry := gtk.NewEntry() entry.SetText("Para comenzar, favor de escoger un archivo del directorio....") //entry.SetSensitive(false) entry.SetEditable(false) framebox2.Add(entry) //-------------------------------------------------------- // GtkHBox //-------------------------------------------------------- buttons := gtk.NewHBox(false, 1) //-------------------------------------------------------- // GtkButton //**OPEN FILE****// //-------------------------------------------------------- button := gtk.NewButtonWithLabel("Elegir archivo...") var filename string var isXE bool button.Clicked(func() { fmt.Println("button clicked:", button.GetLabel()) messagedialog := gtk.NewMessageDialog( button.GetTopLevelAsWindow(), gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Escoja un archivo .*s o *.x de su directorio") messagedialog.Response(func() { fmt.Println("Dialog OK!") //-------------------------------------------------------- // GtkFileChooserDialog //-------------------------------------------------------- filechooserdialog := gtk.NewFileChooserDialog( "Choose File...", button.GetTopLevelAsWindow(), gtk.FILE_CHOOSER_ACTION_OPEN, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) filter := gtk.NewFileFilter() filter.AddPattern("*.s") filter.AddPattern("*.x") filechooserdialog.AddFilter(filter) filechooserdialog.Response(func() { /*aqui va el dialogo */ filename = filechooserdialog.GetFilename() var extension = filepath.Ext(filename) if extension == ".x" { isXE = true } else { isXE = false } fmt.Println(filechooserdialog.GetFilename()) statusbar.Push(context_id, filename) dat, err := ioutil.ReadFile(filechooserdialog.GetFilename()) if err == nil { buffer.GetStartIter(&start) buffer.GetEndIter(&end) buffer.Delete(&start, &end) buffer.Insert(&start, string(dat)) entry.SetText("Ahora haz click en el boton '¡Analizar!'") //fmt.Print(string(dat)) } filechooserdialog.Destroy() }) filechooserdialog.Run() messagedialog.Destroy() }) messagedialog.Run() }) buttons.Add(button) //-------------------------------------------------------- // GtkButton //-------------------------------------------------------- button2 := gtk.NewButtonWithLabel("Ensamblar!") button2.Clicked(func() { fmt.Println("button clicked:", button2.GetLabel()) messagedialog2 := gtk.NewMessageDialog( button.GetTopLevelAsWindow(), gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Analisis lexico y sintactico presiona OK para continuar...") messagedialog2.Response(func() { fmt.Println(filename) statusbar.Push(context_id, filename) file, err := os.Open(filename) if err != nil { log.Fatalf("Error al cargar el archivo: %s", err.Error()) } else { //********************************************************* util.GetTabSim().Allocate() if isXE == false { fmt.Println("IS SIC") errorstr = parser.New().Parse(file, true, false) file, err = os.Open(filename) util.GetAssembler().CreateOpCodeTable() errorstr = parser.New().Parse(file, false, false) file.Close() //util.GetAssembler().PrintCode() util.GetAssembler().FormatCodeToHEX() buffer2.GetStartIter(&start2) buffer2.GetEndIter(&end2) buffer2.Delete(&start2, &end2) if len(errorstr) > 0 { buffer2.Insert(&start2, string(errorstr+util.GetTabSim().Errores)) strArray := strings.Split(filename, ".s") f, err := os.OpenFile(strArray[0]+".ts", os.O_WRONLY|os.O_CREATE, 0600) if err != nil { panic(err) } defer f.Close() if _, err = f.WriteString(errorstr); err != nil { panic(err) } } else { buffer2.Insert(&start2, "Correcto!"+util.GetTabSim().Errores) } ///******************************************************* ///******************************************************* tabsimlines := util.GetTabSim().ReturnTable() buffer5.GetStartIter(&start5) buffer5.GetEndIter(&end5) buffer5.Delete(&start5, &end5) if len(tabsimlines) > 0 { buffer5.Insert(&start5, string(tabsimlines)) } ///******************************************************* ///******************************************************* util.GetTabSim().DecToHex() objectCode := util.GetAssembler().ObjCode() var obj string for i := 0; i < len(objectCode); i++ { if len(objectCode[i]) > 10 { obj += objectCode[i] } if i == len(objectCode)-1 { obj += objectCode[i] } } buffer3.GetStartIter(&start3) buffer3.GetEndIter(&end3) buffer3.Delete(&start3, &end3) if len(obj) > 0 { buffer3.Insert(&start3, string(obj)) } f2 := newFile(strings.Split(filename, ".s")[0], ".os") if _, err = f2.WriteString(obj); err != nil { panic(err) } ///******************************************************* ///******************************************************* var todostr string lines, err := readLines(filename) if err == nil { addrsstr := util.GetTabSim().GetProgPcStr() //fmt.Println(addrsstr) for i := 0; i < len(lines); i++ { if addrsstr[i+1] == "" { addrsstr[i+1] = addrsstr[i] todostr += addrsstr[i] + "\t" + lines[i] + "\n" } else { todostr += addrsstr[i] + "\t" + lines[i] + "\t" + util.GetTabSim().Progobjstr[i] + "\n" } } //util.GetTabSim().PrintProgpc() //fmt.Print(todostr) addrsstr = nil } buffer4.GetStartIter(&start4) buffer4.GetEndIter(&end4) buffer4.Delete(&start4, &end4) if len(obj) > 0 { buffer4.Insert(&start4, string(todostr)) } } else { fmt.Println("IS SIC XE") errorstr = parser.New().Parse(file, true, true) file, err = os.Open(filename) util.GetAssembler().CreateOpCodeTable() parser.New().Parse(file, false, true) file.Close() //util.GetAssembler().PrintCode() //util.GetAssembler().FormatCodeToHEX() buffer2.GetStartIter(&start2) buffer2.GetEndIter(&end2) buffer2.Delete(&start2, &end2) if len(errorstr) > 0 { buffer2.Insert(&start2, string(errorstr+util.GetTabSim().Errores)) strArray := strings.Split(filename, ".x") f, err := os.OpenFile(strArray[0]+".tx", os.O_WRONLY|os.O_CREATE, 0600) if err != nil { panic(err) } defer f.Close() if _, err = f.WriteString(errorstr); err != nil { panic(err) } } else { buffer2.Insert(&start2, "Correcto!"+util.GetTabSim().Errores) } ///******************************************************* ///******************************************************* tabsimlines := util.GetTabSim().ReturnTable() buffer5.GetStartIter(&start5) buffer5.GetEndIter(&end5) buffer5.Delete(&start5, &end5) if len(tabsimlines) > 0 { buffer5.Insert(&start5, string(tabsimlines)) } ///******************************************************* ///******************************************************* objectCode := util.GetAssembler().ObjCodeXE() util.GetTabSim().PcToHex() var obj string for i := 0; i < len(objectCode); i++ { if len(objectCode[i]) > 10 { obj += objectCode[i] } if i == len(objectCode)-1 { obj += objectCode[i] } } buffer3.GetStartIter(&start3) buffer3.GetEndIter(&end3) buffer3.Delete(&start3, &end3) if len(obj) > 0 { buffer3.Insert(&start3, string(obj)) } f2 := newFile(strings.Split(filename, ".x")[0], ".ox") if _, err = f2.WriteString(obj); err != nil { panic(err) } ///******************************************************* ///******************************************************* var todostr string lines, err := readLines(filename) if err == nil { addrsstr := util.GetTabSim().GetProgPcStr() //fmt.Println(addrsstr) for i := 0; i < len(lines); i++ { if addrsstr[i+1] == "" { addrsstr[i+1] = addrsstr[i] todostr += addrsstr[i] + "\t" + lines[i] + "\tError" + "\n" } else { todostr += addrsstr[i] + "\t" + lines[i] + "\t \t" if i != 0 && i < len(lines)-1 { todostr += util.GetAssembler().Hexcode[i-1] + "\n" } else { todostr += "\n" } } } //util.GetTabSim().PrintProgpc() //fmt.Print(todostr) addrsstr = nil } buffer4.GetStartIter(&start4) buffer4.GetEndIter(&end4) buffer4.Delete(&start4, &end4) if len(obj) > 0 { buffer4.Insert(&start4, string(todostr)) } } } entry.SetText("En la ventana debug se encuentran los errores lexicos y sintacticos del programa") fmt.Println("Dialog OK!") messagedialog2.Destroy() }) messagedialog2.Run() }) buttons.Add(button2) framebox2.PackStart(buttons, false, false, 0) ///////////////////////////////////////////// button3 := gtk.NewButtonWithLabel("Cargador...") button3.Clicked(func() { strArray2 := strings.Split(filename, ".s") f2, err := os.OpenFile(strArray2[0]+".o", os.O_WRONLY|os.O_CREATE, 0600) var obj string objectCode := util.GetAssembler().ObjCode() for i := 0; i < len(objectCode); i++ { if len(objectCode[i]) > 10 { obj += objectCode[i] } if i == len(objectCode)-1 { obj += objectCode[i] } } if _, err = f2.WriteString(obj); err != nil { panic(err) } //nombre := strings.Split(strArray2[0], "work") cmd := exec.Command("script.sh", strArray2[0]+".o") err = cmd.Start() if err != nil { log.Fatal(err) } log.Printf("Waiting for command to finish...") //err = cmd.Wait() log.Printf("Command finished with error: %v", err) }) buttons.Add(button3) //////////////////////////// buttons = gtk.NewHBox(false, 1) //-------------------------------------------------------- // GtkMenuItem ///***********SAVE FILE*****************/// //-------------------------------------------------------- cascademenu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(cascademenu) submenu := gtk.NewMenu() cascademenu.SetSubmenu(submenu) var menuitem2 *gtk.MenuItem menuitem2 = gtk.NewMenuItemWithMnemonic("G_uardar") menuitem2.Connect("activate", func() { strArray := strings.Split(filename, ".s") if len(strArray) <= 1 { strArray = strings.Split(filename, ".x") } if len(strArray) > 1 && len(filename) > 0 { statusbar.Push(context_id, filename) var s string buffer.GetStartIter(&start) buffer.GetEndIter(&end) s = buffer.GetText(&start, &end, true) fmt.Println(filename) err := ioutil.WriteFile(filename, []byte(s), 0644) if err != nil { panic(err) } } else { filechooserdialog := gtk.NewFileChooserDialog( "Choose File...", button.GetTopLevelAsWindow(), gtk.FILE_CHOOSER_ACTION_SAVE, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) filter := gtk.NewFileFilter() ///***ALLOWS SIC AND SIC-XE EXTENSION***/// filter.AddPattern("*.s") filter.AddPattern("*.x") filechooserdialog.AddFilter(filter) filechooserdialog.Response(func() { /*aqui va el dialogo */ statusbar.Push(context_id, filename) filename = filechooserdialog.GetFilename() if len(filename) > 0 { fmt.Println(filechooserdialog.GetFilename()) var s string buffer.GetStartIter(&start) buffer.GetEndIter(&end) s = buffer.GetText(&start, &end, true) err := ioutil.WriteFile(filename, []byte(s), 0644) if err != nil { panic(err) } entry.SetText("Haz click en el boton analizar") } filechooserdialog.Destroy() }) filechooserdialog.Run() } }) submenu.Append(menuitem2) var menuitem *gtk.MenuItem menuitem = gtk.NewMenuItemWithMnemonic("S_alir") menuitem.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_View") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable") checkmenuitem.Connect("activate", func() { textview.SetSensitive(!checkmenuitem.GetActive()) textview2.SetSensitive(!checkmenuitem.GetActive()) }) submenu.Append(checkmenuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_Help") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) menuitem = gtk.NewMenuItemWithMnemonic("_About") menuitem.Connect("activate", func() { dialog := gtk.NewAboutDialog() dialog.SetName("Go-SIC sim!") dialog.SetProgramName("Go-SIC sim") dialog.SetLicense("The library is available under the same terms and conditions as the Go, the BSD style license, and the LGPL (Lesser GNU Public License). The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.") dialog.SetWrapLicense(true) dialog.Run() dialog.Destroy() }) submenu.Append(menuitem) //-------------------------------------------------------- // GtkStatusbar //-------------------------------------------------------- statusbar.Push(context_id, "No hay archivo seleccionado") framebox2.PackStart(statusbar, false, false, 0) //-------------------------------------------------------- // Event //-------------------------------------------------------- window.Add(vbox) window.SetSizeRequest(600, 600) window.ShowAll() gtk.Main() }
func main() { var menuitem *gtk.MenuItem gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("GTK Go!") window.SetIconName("gtk-dialog-info") window.Connect("destroy", func(ctx *glib.CallbackContext) { println("got destroy!", ctx.Data().(string)) gtk.MainQuit() }, "foo") //-------------------------------------------------------- // GtkVBox //-------------------------------------------------------- vbox := gtk.NewVBox(false, 1) //-------------------------------------------------------- // GtkMenuBar //-------------------------------------------------------- menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) //-------------------------------------------------------- // GtkVPaned //-------------------------------------------------------- vpaned := gtk.NewVPaned() vbox.Add(vpaned) //-------------------------------------------------------- // GtkFrame //-------------------------------------------------------- frame1 := gtk.NewFrame("Demo") framebox1 := gtk.NewVBox(false, 1) frame1.Add(framebox1) frame2 := gtk.NewFrame("Demo") framebox2 := gtk.NewVBox(false, 1) frame2.Add(framebox2) vpaned.Pack1(frame1, false, false) vpaned.Pack2(frame2, false, false) //-------------------------------------------------------- // GtkImage //-------------------------------------------------------- dir, _ := path.Split(os.Args[0]) imagefile := path.Join(dir, "../../data/go-gtk-logo.png") label := gtk.NewLabel("Go Binding for GTK") label.ModifyFontEasy("DejaVu Serif 15") framebox1.PackStart(label, false, true, 0) //-------------------------------------------------------- // GtkEntry //-------------------------------------------------------- entry := gtk.NewEntry() entry.SetText("Hello world") framebox1.Add(entry) image := gtk.NewImageFromFile(imagefile) framebox1.Add(image) //-------------------------------------------------------- // GtkScale //-------------------------------------------------------- scale := gtk.NewHScaleWithRange(0, 100, 1) scale.Connect("value-changed", func() { println("scale:", int(scale.GetValue())) }) framebox2.Add(scale) //-------------------------------------------------------- // GtkHBox //-------------------------------------------------------- buttons := gtk.NewHBox(false, 1) //-------------------------------------------------------- // GtkButton //-------------------------------------------------------- button := gtk.NewButtonWithLabel("Button with label") button.Clicked(func() { println("button clicked:", button.GetLabel()) messagedialog := gtk.NewMessageDialog( button.GetTopLevelAsWindow(), gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, entry.GetText()) messagedialog.Response(func() { println("Dialog OK!") //-------------------------------------------------------- // GtkFileChooserDialog //-------------------------------------------------------- filechooserdialog := gtk.NewFileChooserDialog( "Choose File...", button.GetTopLevelAsWindow(), gtk.FILE_CHOOSER_ACTION_OPEN, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) filter := gtk.NewFileFilter() filter.AddPattern("*.go") filechooserdialog.AddFilter(filter) filechooserdialog.Response(func() { println(filechooserdialog.GetFilename()) filechooserdialog.Destroy() }) filechooserdialog.Run() messagedialog.Destroy() }) messagedialog.Run() }) buttons.Add(button) //-------------------------------------------------------- // GtkFontButton //-------------------------------------------------------- fontbutton := gtk.NewFontButton() fontbutton.Connect("font-set", func() { println("title:", fontbutton.GetTitle()) println("fontname:", fontbutton.GetFontName()) println("use_size:", fontbutton.GetUseSize()) println("show_size:", fontbutton.GetShowSize()) }) buttons.Add(fontbutton) framebox2.PackStart(buttons, false, false, 0) buttons = gtk.NewHBox(false, 1) //-------------------------------------------------------- // GtkToggleButton //-------------------------------------------------------- togglebutton := gtk.NewToggleButtonWithLabel("ToggleButton with label") togglebutton.Connect("toggled", func() { if togglebutton.GetActive() { togglebutton.SetLabel("ToggleButton ON!") } else { togglebutton.SetLabel("ToggleButton OFF!") } }) buttons.Add(togglebutton) //-------------------------------------------------------- // GtkCheckButton //-------------------------------------------------------- checkbutton := gtk.NewCheckButtonWithLabel("CheckButton with label") checkbutton.Connect("toggled", func() { if checkbutton.GetActive() { checkbutton.SetLabel("CheckButton CHECKED!") } else { checkbutton.SetLabel("CheckButton UNCHECKED!") } }) buttons.Add(checkbutton) //-------------------------------------------------------- // GtkRadioButton //-------------------------------------------------------- buttonbox := gtk.NewVBox(false, 1) radiofirst := gtk.NewRadioButtonWithLabel(nil, "Radio1") buttonbox.Add(radiofirst) buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio2")) buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio3")) buttons.Add(buttonbox) //radiobutton.SetMode(false); radiofirst.SetActive(true) framebox2.PackStart(buttons, false, false, 0) //-------------------------------------------------------- // GtkVSeparator //-------------------------------------------------------- vsep := gtk.NewVSeparator() framebox2.PackStart(vsep, false, false, 0) //-------------------------------------------------------- // GtkComboBoxEntry //-------------------------------------------------------- combos := gtk.NewHBox(false, 1) comboboxentry := gtk.NewComboBoxEntryNewText() comboboxentry.AppendText("Monkey") comboboxentry.AppendText("Tiger") comboboxentry.AppendText("Elephant") comboboxentry.Connect("changed", func() { println("value:", comboboxentry.GetActiveText()) }) combos.Add(comboboxentry) //-------------------------------------------------------- // GtkComboBox //-------------------------------------------------------- combobox := gtk.NewComboBoxNewText() combobox.AppendText("Peach") combobox.AppendText("Banana") combobox.AppendText("Apple") combobox.SetActive(1) combobox.Connect("changed", func() { println("value:", combobox.GetActiveText()) }) combos.Add(combobox) framebox2.PackStart(combos, false, false, 0) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- swin := gtk.NewScrolledWindow(nil, nil) swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin.SetShadowType(gtk.SHADOW_IN) textview := gtk.NewTextView() var start, end gtk.TextIter buffer := textview.GetBuffer() buffer.GetStartIter(&start) buffer.Insert(&start, "Hello ") buffer.GetEndIter(&end) buffer.Insert(&end, "World!") tag := buffer.CreateTag("bold", map[string]string{ "background": "#FF0000", "weight": "700"}) buffer.GetStartIter(&start) buffer.GetEndIter(&end) buffer.ApplyTag(tag, &start, &end) swin.Add(textview) framebox2.Add(swin) buffer.Connect("changed", func() { println("changed") }) //-------------------------------------------------------- // GtkMenuItem //-------------------------------------------------------- cascademenu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(cascademenu) submenu := gtk.NewMenu() cascademenu.SetSubmenu(submenu) menuitem = gtk.NewMenuItemWithMnemonic("E_xit") menuitem.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_View") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable") checkmenuitem.Connect("activate", func() { vpaned.SetSensitive(!checkmenuitem.GetActive()) }) submenu.Append(checkmenuitem) menuitem = gtk.NewMenuItemWithMnemonic("_Font") menuitem.Connect("activate", func() { fsd := gtk.NewFontSelectionDialog("Font") fsd.SetFontName(fontbutton.GetFontName()) fsd.Response(func() { println(fsd.GetFontName()) fontbutton.SetFontName(fsd.GetFontName()) fsd.Destroy() }) fsd.SetTransientFor(window) fsd.Run() }) submenu.Append(menuitem) cascademenu = gtk.NewMenuItemWithMnemonic("_Help") menubar.Append(cascademenu) submenu = gtk.NewMenu() cascademenu.SetSubmenu(submenu) menuitem = gtk.NewMenuItemWithMnemonic("_About") menuitem.Connect("activate", func() { dialog := gtk.NewAboutDialog() dialog.SetName("Go-Gtk Demo!") dialog.SetProgramName("demo") dialog.SetAuthors(authors()) dir, _ := path.Split(os.Args[0]) imagefile := path.Join(dir, "../../data/mattn-logo.png") pixbuf, _ := gdkpixbuf.NewFromFile(imagefile) dialog.SetLogo(pixbuf) dialog.SetLicense("The library is available under the same terms and conditions as the Go, the BSD style license, and the LGPL (Lesser GNU Public License). The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.") dialog.SetWrapLicense(true) dialog.Run() dialog.Destroy() }) submenu.Append(menuitem) //-------------------------------------------------------- // GtkStatusbar //-------------------------------------------------------- statusbar := gtk.NewStatusbar() context_id := statusbar.GetContextId("go-gtk") statusbar.Push(context_id, "GTK binding for Go!") framebox2.PackStart(statusbar, false, false, 0) //-------------------------------------------------------- // Event //-------------------------------------------------------- window.Add(vbox) window.SetSizeRequest(600, 600) window.ShowAll() gtk.Main() }
func menu_bar(vbox *gtk.VBox) { menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) buttons := gtk.NewAlignment(0, 0, 0, 0) checkbox := gtk.NewAlignment(1, 0, 0, 0) newPlayerGameButton := gtk.NewButtonWithLabel("Player vs Player") newIaGameButton := gtk.NewButtonWithLabel("Player vs AI") info = gtk.NewLabel("Hint: Not yet") threeCheckBox := gtk.NewCheckButtonWithLabel("Three and three") endCheckBox := gtk.NewCheckButtonWithLabel("Unbreakable end") hintCheckBox := gtk.NewCheckButtonWithLabel("Hint") hbox := gtk.NewHBox(false, 1) hbox0 := gtk.NewHBox(false, 1) hbox1 := gtk.NewHBox(false, 1) hbox0.Add(newPlayerGameButton) hbox0.Add(newIaGameButton) hbox1.Add(hintCheckBox) hbox1.Add(threeCheckBox) hbox1.Add(endCheckBox) buttons.Add(hbox0) checkbox.Add(hbox1) hbox.Add(buttons) hbox.Add(info) hbox.Add(checkbox) vbox.PackStart(hbox, false, true, 0) cascademenu := gtk.NewMenuItemWithMnemonic("_Game") menubar.Append(cascademenu) submenu := gtk.NewMenu() cascademenu.SetSubmenu(submenu) playermenuitem := gtk.NewMenuItemWithMnemonic("_Player Vs Player") playermenuitem.Connect("activate", func() { gc.SetRgbFgColor(gdk.NewColor("grey")) pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1) game = Gomoku{make([]int, 361), true, game.endgameTake, game.doubleThree, 1, [2]int{10, 10}, 0} player = 1 countTake = 0 iamode = false display_init_grid(gc, pixmap) drawingarea.Hide() drawingarea.Show() stopGame = false stopClick = false context_id := statusbar.GetContextId("go-gtk") statusbar.Push(context_id, "(not so) Proudly propulsed by the inglorious Gomoku Project, with love, and Golang!") }) submenu.Append(playermenuitem) newPlayerGameButton.Clicked(func() { playermenuitem.Activate() }) iamenuitem := gtk.NewMenuItemWithMnemonic("_Player Vs AI") iamenuitem.Connect("activate", func() { gc.SetRgbFgColor(gdk.NewColor("grey")) pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1) game = Gomoku{make([]int, 361), true, game.endgameTake, game.doubleThree, 1, [2]int{10, 10}, 0} player = 1 countTake = 0 iamode = true display_init_grid(gc, pixmap) drawingarea.Hide() drawingarea.Show() stopGame = false stopClick = false context_id := statusbar.GetContextId("go-gtk") statusbar.Push(context_id, "(not so) Proudly propulsed by the inglorious Gomoku Project, with love, and Golang!") }) submenu.Append(iamenuitem) newIaGameButton.Clicked(func() { iamenuitem.Activate() }) menuitem = gtk.NewMenuItemWithMnemonic("E_xit") menuitem.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menuitem) threeCheckBox.Connect("toggled", func() { if game.doubleThree == false { game.doubleThree = true } else { game.doubleThree = false } }) endCheckBox.Connect("toggled", func() { if game.endgameTake == false { game.endgameTake = true } else { game.endgameTake = false } }) hintCheckBox.Connect("toggled", func() { if hint == false { hint = true calcHint <- true } else { hint = false } }) }