Skip to content

Commit

Permalink
Ability to hide/show main window (#112)
Browse files Browse the repository at this point in the history
Functions to hide/show main window
Extra parameter on go(), to declare which window to start with
  • Loading branch information
jarvisteach committed Mar 18, 2017
1 parent dc8b337 commit 91798a8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
19 changes: 16 additions & 3 deletions appJar/appjar.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/mkdocs/docs/pythonGuiOptions.md
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions docs/mkdocs/docs/pythonWidgetGrouping.md
Expand Up @@ -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.
Expand Down
32 changes: 32 additions & 0 deletions 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()

0 comments on commit 91798a8

Please sign in to comment.