From 91798a842534322450448d6a33face258ca721f5 Mon Sep 17 00:00:00 2001 From: Richard Jarvis Date: Sat, 18 Mar 2017 06:14:56 +0000 Subject: [PATCH] Ability to hide/show main window (#112) Functions to hide/show main window Extra parameter on go(), to declare which window to start with --- appJar/appjar.py | 19 +++++++++++--- docs/mkdocs/docs/pythonGuiOptions.md | 6 +++++ docs/mkdocs/docs/pythonWidgetGrouping.md | 5 ++++ examples/issues/issue112.py | 32 ++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 examples/issues/issue112.py diff --git a/appJar/appjar.py b/appJar/appjar.py index a1425f3..34631f8 100755 --- a/appJar/appjar.py +++ b/appJar/appjar.py @@ -997,7 +997,7 @@ def showSplash(self, text="appJar", fill="red", stripe="black", fg="white", font ##################################### # Event Loop - must always be called at end ##################################### - def go(self, language=None): + def go(self, language=None, startWindow=None): """ Most important function! Start the GUI """ if self.splashConfig is not None: @@ -1050,8 +1050,13 @@ def go(self, language=None): splash.destroy() # bring to front - self.__bringToFront() - self.topLevel.deiconify() + if startWindow is None: + self.__bringToFront() + self.topLevel.deiconify() + else: + self.hide() + sw = self.showSubWindow(startWindow) + self.__bringToFront(sw) # required to make the gui reopen after minimising if self.GET_PLATFORM() == self.MAC: @@ -3150,10 +3155,18 @@ def showSubWindow(self, title): tl.focus_set() self.topLevel.wait_window(tl.killLab) + return tl + def setSubWindowLocation(self, title, x, y): tl = self.__verifyItem(self.n_subWindows, title) tl.geometry("+%d+%d" % (x, y)) + def hide(self): + self.topLevel.withdraw() + + def show(self): + self.topLevel.deiconify() + def hideSubWindow(self, title): tl = self.__verifyItem(self.n_subWindows, title) theFunc = tl.stopFunction diff --git a/docs/mkdocs/docs/pythonGuiOptions.md b/docs/mkdocs/docs/pythonGuiOptions.md index c476240..6e6c2db 100644 --- a/docs/mkdocs/docs/pythonGuiOptions.md +++ b/docs/mkdocs/docs/pythonGuiOptions.md @@ -20,6 +20,12 @@ Some basic configuration for the size, position, transparency, etc. of the GUI. ###Size & Locaiton +* `.hide()` & `.show()` + Used to hide and show the main window. + Useful in conjunction with [SubWindows](/pythonWidgetGrouping/#sub-window) + You can have a menu or logon SubWindow that hides/shows the main window as necessary. + NB. hiding the window, effectively minimizes it, it is still there... + * `.setGeometry(geom)` & `.setGeometry(width, height)` Sets the height & width of the GUI: * Either as a single String `.setGeometry("200x100")` (widthxheight) diff --git a/docs/mkdocs/docs/pythonWidgetGrouping.md b/docs/mkdocs/docs/pythonWidgetGrouping.md index 73d1655..daeda93 100644 --- a/docs/mkdocs/docs/pythonWidgetGrouping.md +++ b/docs/mkdocs/docs/pythonWidgetGrouping.md @@ -423,6 +423,11 @@ app.go() Used to reopen the named *SubWindow*. ####Show/Hide Sub Windows + +* `.go(startWindow=None)` + If you set a *SubWindow* as the ```startWindow``` appJar will start-up showing the named *SubWindow*. + The main window will be minimized. + * `.showSubWindow(title)` Will cause the specified *SubWindow* to be shown. If it is set as *modal* the parent window will become uninteractive until the *SubWindow* is closed. diff --git a/examples/issues/issue112.py b/examples/issues/issue112.py new file mode 100644 index 0000000..ee24557 --- /dev/null +++ b/examples/issues/issue112.py @@ -0,0 +1,32 @@ +import sys +sys.path.append("../../") +from appJar import gui + +def press(btn): + if btn == "Hide": app.hide() + elif btn == "Show": app.show() + else: app.showSubWindow(btn) + +app=gui("Window") + +app.startSubWindow("Menu") +app.addButton("Hide", press) +app.addButton("Show", press) +app.stopSubWindow() + +for loop in range(5): + label = "PopUp" + str(loop) + app.startSubWindow(label) + app.setLocation(100+loop*100, 100) + app.addLabel(label, label) + app.openSubWindow("Menu") + app.addButton(label, press) + app.stopSubWindow() + app.addGrip() + app.stopSubWindow() + + +app.addLabel("l1", "mmmmmmmmmm") +app.addButton("Menu", press) +#app.go(startWindow="Menu") +app.go()