func NewFooModel() *FooModel { m := new(FooModel) m.evenBitmap, _ = walk.NewBitmapFromFile("../img/open.png") m.oddIcon, _ = walk.NewIconFromFile("../img/x.ico") m.ResetRows() return m }
func NewClipsModel() *ClipsModel { m := new(ClipsModel) m.output = new(walk.TextEdit) m.evenBitmap, _ = walk.NewBitmapFromFile("../img/open.png") m.oddIcon, _ = walk.NewIconFromFile("../img/x.ico") m.ResetRows() return m }
func main() { hWindow = xcgui.XWnd_Create(0, 0, 0, 0, "炫彩界面库窗口", 0, xcgui.XC_WINDOW_STYLE_NOTHING) // We load our icon from a file. icon, err := walk.NewIconFromFile("../../img/x.ico") if err != nil { log.Fatal(err) } // Create the notify icon and make sure we clean it up on exit. ni, err = walk.NewNotifyIcon() if err != nil { log.Fatal(err) } defer ni.Dispose() // Set the icon and a tool tip text. if err := ni.SetIcon(icon); err != nil { log.Fatal(err) } if err := ni.SetToolTip("托盘"); err != nil { log.Fatal(err) } // When the left mouse button is pressed, bring up our balloon. ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) { if button == walk.LeftButton { if err := ni.ShowCustom( "自定义消息", "这是一个带图标的自定义消息."); err != nil { log.Fatal(err) } } else { RunXCMenu() } }) // 托盘图标默认为隐藏状态,需设置为显示。 if err := ni.SetVisible(true); err != nil { log.Fatal(err) } // Now that the icon is visible, we can bring up an info balloon. if err := ni.ShowInfo("托盘", "正在运行中."); err != nil { log.Fatal(err) } // 注册菜单选择事件 xcgui.XWnd_RegEventC(hWindow, xcgui.XWM_MENU_SELECT, xcgui.CallBack(OnWndMenuSelect)) // Run the message loop. xcgui.XRunXCGUI() }
func (this *SignUpMainWindow) SetIcon(filepath string) (ic *walk.Icon, err error) { ic, err = walk.NewIconFromFile(filepath) if err != nil { log.Print(err) return } this.mw.SetIcon(ic) if ic != nil { ic.Dispose() } return }
func newNotify() { var err error context.notifyIcon, err = walk.NewNotifyIcon() if err != nil { common.Error("Error invoking NewNotifyIcon: %v", err) } icon, _ := walk.NewIconFromFile("res/lily.ico") if err := context.notifyIcon.SetIcon(icon); err != nil { common.Error("Error setting notify icon: %v", err) } if err := context.notifyIcon.SetToolTip("Click for info or use the context menu to exit."); err != nil { common.Error("Fail to set tooltip: %v", err) } f := func() { if !context.mw.Visible() { context.mw.Show() } else { context.mw.SwitchToThisWindow() } } go core.Triggered(f) context.notifyIcon.MouseUp().Attach(func(x, y int, button walk.MouseButton) { if button == walk.LeftButton { f() } // if err := context.notifyIcon.ShowCustom( // "Walk NotifyIcon Example", // "There are multiple ShowX methods sporting different icons."); err != nil { // common.Error("Fail to show custom notify: %v", err) // } }) exitAction := walk.NewAction() if err := exitAction.SetText("退出"); err != nil { common.Error("Error setting exitAction text: %v", err) } exitAction.Triggered().Attach(func() { context.notifyIcon.Dispose() // os.Exit(-1) walk.App().Exit(0) }) if err := context.notifyIcon.ContextMenu().Actions().Add(exitAction); err != nil { common.Error("Error Adding exitAction: %v", err) } if err := context.notifyIcon.SetVisible(true); err != nil { common.Error("Error setting notify visible: %v", err) } // if err := context.notifyIcon.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again."); err != nil { // common.Error("Error showing info: %v", err) // } }
func main() { // Initialize walk and specify that we want errors to be panics. walk.Initialize(walk.InitParams{PanicOnError: true}) defer walk.Shutdown() // We need either a walk.MainWindow or a walk.Dialog for their message loop. // We will not make it visible in this example, though. mw, _ := walk.NewMainWindow() // We load our icon from a file. icon, _ := walk.NewIconFromFile("../img/x.ico") // Create the notify icon and make sure we clean it up on exit. ni, _ := walk.NewNotifyIcon() defer ni.Dispose() // Set the icon and a tool tip text. ni.SetIcon(icon) ni.SetToolTip("Click for info or use the context menu to exit.") // When the left mouse button is pressed, bring up our balloon. ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) { if button != walk.LeftButton { return } ni.ShowCustom( "Walk NotifyIcon Example", "There are multiple ShowX methods sporting different icons.") }) // We put an exit action into the context menu. exitAction := walk.NewAction() exitAction.SetText("E&xit") exitAction.Triggered().Attach(func() { walk.App().Exit(0) }) ni.ContextMenu().Actions().Add(exitAction) // The notify icon is hidden initially, so we have to make it visible. ni.SetVisible(true) // Now that the icon is visible, we can bring up an info balloon. ni.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again.") // Run the message loop. mw.Run() }
func runNotify() { // We need either a walk.MainWindow or a walk.Dialog for their message loop. // We will not make it visible in this example, though. mw, err := walk.NewMainWindow() if err != nil { log.Fatal(err) } // We load our icon from a file. iconPlay, err = walk.NewIconFromFile("play.ico") if err != nil { log.Fatal(err) } // We load our icon from a file. iconStop, err = walk.NewIconFromFile("stop.ico") if err != nil { log.Fatal(err) } // Create the notify icon and make sure we clean it up on exit. notifyIcon, err = walk.NewNotifyIcon() if err != nil { log.Fatal(err) } defer notifyIcon.Dispose() if err := notifyIcon.SetToolTip("Direct Print Server"); err != nil { log.Fatal(err) } // We put an exit action into the context menu. startAction = walk.NewAction() startAction.Triggered().Attach(func() { if stoped { start() } else { stop() } }) if err := notifyIcon.ContextMenu().Actions().Add(startAction); err != nil { log.Fatal(err) } // We put an exit action into the context menu. exitAction := walk.NewAction() if err := exitAction.SetText("E&xit"); err != nil { log.Fatal(err) } exitAction.Triggered().Attach(func() { //stop() walk.App().Exit(0) }) if err := notifyIcon.ContextMenu().Actions().Add(exitAction); err != nil { log.Fatal(err) } // The notify icon is hidden initially, so we have to make it visible. if err := notifyIcon.SetVisible(true); err != nil { log.Fatal(err) } start() // Run the message loop. mw.Run() }
func InterfaceStart(server ZakupkiProxyServer, config ServerConfig) (err error) { if server == nil { panic("InterfaceStart: passed nil server") } if config == nil { panic("InterfaceStart: passed nil config") } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * INITIALIZATION * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ startServer := func() { if !server.IsRunning() { go func() { // start server if err := server.Start(); err != nil { log.Println("Cannot start server:", err) } }() time.Sleep(_START_SERVER_TIMEOUT) } } stopServer := func() { if server.IsRunning() { // shutdown server if err = server.ShutDown(); err != nil { log.Println("Cannot shutdown server", err) } } } if _RUN_SERVER_ON_STARTING && !server.IsRunning() { startServer() } defer func() { if server.IsRunning() { stopServer() } }() defer func() { if err = config.Save(); err != nil { log.Println("Cannot save configures:", err) } }() /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * END INITIALIZATION * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ mw, err := walk.NewMainWindow() if err != nil { return } defer mw.Dispose() ni, err := walk.NewNotifyIcon() if err != nil { return } defer ni.Dispose() if err = ni.SetVisible(true); err != nil { return } if err = ni.SetToolTip(_PROG_TITLE); err != nil { return } ni.ShowMessage(_PROG_TITLE, _NOTICE_APP_START) // create image icon if icon, err := walk.NewIconFromFile(_PROG_ICON_FILE_NAME); err != nil { log.Println("Cannot load icon from file:", err) } else { defer icon.Dispose() if err = ni.SetIcon(icon); err != nil { log.Println("Cannot bind img with notify icon:", err) } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ACTIONS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ startServerAction := walk.NewAction() err = startServerAction.SetText(_ACTION_TITLE_START_SERVER) if err != nil { return } err = startServerAction.SetVisible(!server.IsRunning()) if err != nil { return } err = ni.ContextMenu().Actions().Add(startServerAction) if err != nil { return } stopServerAction := walk.NewAction() err = stopServerAction.SetText(_ACTION_TITLE_STOP_SERVER) if err != nil { return } err = stopServerAction.SetVisible(server.IsRunning()) if err != nil { return } err = ni.ContextMenu().Actions().Add(stopServerAction) if err != nil { return } filterEnableAction := walk.NewAction() err = filterEnableAction.SetText(_ACTION_TITLE_FILTER_ENABLED) if err != nil { return } err = filterEnableAction.SetVisible(!config.IsFilterEnabled()) if err != nil { return } err = ni.ContextMenu().Actions().Add(filterEnableAction) if err != nil { return } filterDisabledAction := walk.NewAction() err = filterDisabledAction.SetText(_ACTION_TITLE_FILTER_DISABLED) if err != nil { return } err = filterDisabledAction.SetVisible(config.IsFilterEnabled()) if err != nil { return } err = ni.ContextMenu().Actions().Add(filterDisabledAction) if err != nil { return } removeCacheAction := walk.NewAction() err = removeCacheAction.SetText(_ACTION_TITLE_REMOVE_CACHE) if err != nil { return } err = ni.ContextMenu().Actions().Add(removeCacheAction) if err != nil { return } err = ni.ContextMenu().Actions().Add(walk.NewSeparatorAction()) if err != nil { return } openURLGenAction := walk.NewAction() err = openURLGenAction.SetText(_ACTION_TITLE_OPEN_URL_GEN) if err != nil { return } err = ni.ContextMenu().Actions().Add(openURLGenAction) if err != nil { return } openDirAction := walk.NewAction() err = openDirAction.SetText(_ACTION_TITLE_OPEN_DIR) if err != nil { return } err = ni.ContextMenu().Actions().Add(openDirAction) if err != nil { return } openReadMeAction := walk.NewAction() err = openReadMeAction.SetText(_ACTION_TITLE_OPEN_README) if err != nil { return } err = ni.ContextMenu().Actions().Add(openReadMeAction) if err != nil { return } err = ni.ContextMenu().Actions().Add(walk.NewSeparatorAction()) if err != nil { return } exitAction := walk.NewAction() err = exitAction.SetText(_ACTION_TITLE_EXIT) if err != nil { return } err = ni.ContextMenu().Actions().Add(exitAction) if err != nil { return } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * EVENT HANDLERS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ updateServerButtons := func() { if server.IsRunning() { if err = startServerAction.SetVisible(false); err != nil { log.Println(err) } if err = stopServerAction.SetVisible(true); err != nil { log.Println(err) } } else { if err = stopServerAction.SetVisible(false); err != nil { log.Println(err) } if err = startServerAction.SetVisible(true); err != nil { log.Println(err) } } } startServerAction.Triggered().Attach(func() { if !server.IsRunning() { if err = startServerAction.SetEnabled(false); err != nil { log.Println(err) } startServer() if server.IsRunning() { ni.ShowMessage(_PROG_TITLE, _NOTICE_PROXY_ENABLED) } if err = startServerAction.SetEnabled(true); err != nil { log.Println(err) } } updateServerButtons() }) stopServerAction.Triggered().Attach(func() { if server.IsRunning() { stopServer() ni.ShowMessage(_PROG_TITLE, _NOTICE_PROXY_DISABLED) } updateServerButtons() }) updateFilterButtons := func() { if config.IsFilterEnabled() { err = filterEnableAction.SetVisible(false) if err != nil { log.Println(err) } err = filterDisabledAction.SetVisible(true) if err != nil { log.Println(err) } } else { err = filterDisabledAction.SetVisible(false) if err != nil { log.Println(err) } err = filterEnableAction.SetVisible(true) if err != nil { log.Println(err) } } } filterEnableAction.Triggered().Attach(func() { if !config.IsFilterEnabled() { config.SetFilterEnabled(true) ni.ShowInfo(_PROG_TITLE, _NOTICE_ENABLED_FILTERS) } updateFilterButtons() }) filterDisabledAction.Triggered().Attach(func() { if config.IsFilterEnabled() { config.SetFilterEnabled(false) ni.ShowInfo(_PROG_TITLE, _NOTICE_DISABLED_FILTERS) } updateFilterButtons() }) removeCacheAction.Triggered().Attach(func() { if err = server.RemoveCache(); err != nil { log.Println("Cannot remove cache:", err) } else { ni.ShowInfo(_PROG_TITLE, _NOTICE_CACHE_REMOVED) } }) openURLGenAction.Triggered().Attach(func() { err = exec.Command(_PROG_URL_GENER_FILE_NAME).Start() if err != nil { log.Println("Cannot open url generator:", err) } }) openDirAction.Triggered().Attach(func() { err = exec.Command("cmd", "/C", "start", ".").Start() if err != nil { log.Println("Cannot open program directory:", err) } else { ni.ShowInfo(_PROG_TITLE, _NOTICE_CONFIGS) } }) openReadMeAction.Triggered().Attach(func() { err = exec.Command( "cmd", "/C", "start", _PROG_DESCRIPTION_FILE_NAME, ).Start() if err != nil { log.Println("Cannot open README:", err) } }) exitAction.Triggered().Attach(func() { walk.App().Exit(0) }) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * END EVENT HANDLERS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ mw.Run() return }
func main() { defer func() { if e := recover(); e != nil { walk.MsgBox(mw, "Error", fmt.Sprintf("%v", e), walk.MsgBoxIconInformation) } }() MainWindow{ AssignTo: &mw, Title: "阻垢剂加药量计算器", MinSize: Size{600, 450}, Layout: VBox{}, Children: []Widget{ Composite{ Layout: HBox{}, Children: []Widget{ Label{Text: "用*标注的为必填项,用#标注的二者选填其一。"}, HSpacer{}, }, }, Composite{ Layout: Grid{Columns: 3}, Children: []Widget{ Label{Text: "*设备进水流量(T/h):"}, LineEdit{AssignTo: &warter_inputTE}, Label{Text: ""}, Label{Text: "*推荐加药剂量(g/T):"}, LineEdit{AssignTo: &potion_ppmTE}, Label{Text: ""}, Label{Text: "药剂注入量(g/h):"}, LineEdit{AssignTo: &potion_inputTE, ReadOnly: true}, Label{Text: ""}, Label{Text: "#药剂标准液用量(kg):"}, LineEdit{AssignTo: &potion_doseTE}, Label{Text: "", AssignTo: &potion_doseLB}, Label{Text: "*所需配制的药液体积(L):"}, LineEdit{AssignTo: &potion_volumnTE}, Label{Text: ""}, Label{Text: "药液浓度(g/L):"}, LineEdit{AssignTo: &potion_concentrationTE, ReadOnly: true}, Label{Text: ""}, Label{Text: "计量泵实际流量(L/h):"}, LineEdit{AssignTo: &pump_flowTE, ReadOnly: true}, Label{Text: ""}, Label{Text: "*计量泵最大流量(L/h):"}, LineEdit{AssignTo: &pump_max_flowTE}, Label{Text: ""}, Label{Text: "#计量泵刻度(%):"}, LineEdit{AssignTo: &pump_scaleTE}, Label{Text: ""}, }, }, Composite{ Layout: HBox{}, Children: []Widget{ HSpacer{}, PushButton{ Text: "计算", MaxSize: Size{120, 23}, OnClicked: calculateDose, }, HSpacer{}, }, }, Composite{ Layout: HBox{}, Children: []Widget{ Label{Text: "上海丰信环保科技有限公司 http://www.pnt-ro.com/", AssignTo: &companyLB, //OnClicked: openWebsite }, HSpacer{}, }, }, }, }.Create() if ic, err := walk.NewIconFromFile("icon.ico"); err == nil { mw.SetIcon(ic) } else { //walk.MsgBox(mw, "Error", err.Error(), walk.MsgBoxIconInformation) } //font := companyLB.Font() //newFont, _ := walk.NewFont(font.Family(), font.PointSize(), walk.FontUnderline) //companyLB.SetFont(newFont) mw.Run() }
func main() { xcgui.XWnd_Create(0, 0, 0, 0, "炫彩界面库窗口", 0, xcgui.XC_WINDOW_STYLE_NOTHING) // We load our icon from a file. icon, err := walk.NewIconFromFile("../../img/x.ico") if err != nil { log.Fatal(err) } // Create the notify icon and make sure we clean it up on exit. ni, err := walk.NewNotifyIcon() if err != nil { log.Fatal(err) } defer ni.Dispose() // Set the icon and a tool tip text. if err := ni.SetIcon(icon); err != nil { log.Fatal(err) } if err := ni.SetToolTip("托盘"); err != nil { log.Fatal(err) } // When the left mouse button is pressed, bring up our balloon. ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) { if button != walk.LeftButton { return } if err := ni.ShowCustom( "自定义消息", "这是一个带图标的自定义消息."); err != nil { log.Fatal(err) } }) // 菜单使用walk的,主程序为xcgui. exitAction := walk.NewAction() if err := exitAction.SetText("退出"); err != nil { log.Fatal(err) } exitAction.Triggered().Attach(func() { ni.Dispose() walk.App().Exit(0) xcgui.XExitXCGUI() }) if err := ni.ContextMenu().Actions().Add(exitAction); err != nil { log.Fatal(err) } // 托盘图标默认为隐藏状态,需设置为显示。 if err := ni.SetVisible(true); err != nil { log.Fatal(err) } // Now that the icon is visible, we can bring up an info balloon. if err := ni.ShowInfo("托盘", "正在运行中."); err != nil { log.Fatal(err) } // Run the message loop. xcgui.XRunXCGUI() }