From a92292c611a1bed5d528dd08046e6ad16e704dce Mon Sep 17 00:00:00 2001 From: jarvisteach Date: Wed, 12 Apr 2017 06:02:39 +0000 Subject: [PATCH] fix to modal settings #108 --- appJar/appjar.py | 19 ++++++++++---- docs/mkdocs/docs/pythonWidgetGrouping.md | 4 ++- examples/issues/issue108.py | 32 +++++++++++++----------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/appJar/appjar.py b/appJar/appjar.py index b0f65da..372e265 100755 --- a/appJar/appjar.py +++ b/appJar/appjar.py @@ -3235,12 +3235,13 @@ def startFrame( ### SUB WINDOWS ### - def startSubWindow(self, name, title=None, modal=False, grouped=False): + def startSubWindow(self, name, title=None, modal=False, blocking=False, transient=False, grouped=False): self.__verifyItem(self.n_subWindows, name, True) if title is None: title = name top = SubWindow() top.modal = modal + top.blocking = blocking top.title(title) top.protocol( "WM_DELETE_WINDOW", @@ -3249,6 +3250,8 @@ def startSubWindow(self, name, title=None, modal=False, grouped=False): name)) top.withdraw() top.win = self + if transient: + top.transient(self.topLevel) if not grouped: top.group(self.topLevel.group()) self.n_subWindows[name] = top @@ -3270,10 +3273,14 @@ def showSubWindow(self, title): tl.config(takefocus=True) tl.killLab = Label(tl) + # stop other windows receiving events if tl.modal: - tl.transient(self.topLevel) tl.grab_set() - tl.focus_set() + + tl.focus_set() + + # block here - wait for the subwindow to close + if tl.blocking: self.topLevel.wait_window(tl.killLab) return tl @@ -3282,10 +3289,10 @@ def setSubWindowLocation(self, title, x, y): tl = self.__verifyItem(self.n_subWindows, title) tl.geometry("+%d+%d" % (x, y)) - def hide(self): + def hide(self, btn=None): self.topLevel.withdraw() - def show(self): + def show(self, btn=None): self.topLevel.deiconify() def hideSubWindow(self, title): @@ -8925,6 +8932,8 @@ def __init__(self): self.escapeBindId = None # used to exit fullscreen self.stopFunction = None # used to stop self.geometry("+%d+%d" % (100, 100)) + self.modal = False + self.blocking = False # removed for python2.7 # def __getattr__(self, name): diff --git a/docs/mkdocs/docs/pythonWidgetGrouping.md b/docs/mkdocs/docs/pythonWidgetGrouping.md index daeda93..465689d 100644 --- a/docs/mkdocs/docs/pythonWidgetGrouping.md +++ b/docs/mkdocs/docs/pythonWidgetGrouping.md @@ -414,10 +414,12 @@ app.go() ``` ####Start/Stop Sub Windows -* `.startSubwindow(name, title=None, modal=False)` & `.stopSubwindow()` +* `.startSubwindow(name, title=None, modal=False, transient=False, blocking=False)` & `.stopSubwindow()` Used to start and stop defining a *SubWindow* Setting a `title` will override the `name` as a title for the *SubWindow*. Setting `modal` to True, will prevent the user from interacting with the parent window until the *SubWindow* is closed. + Setting `transient` to True, will cause the *SubWindow* to respond to parent window events such as hide & show. + Setting `blocking` to True, will stop execution of your code once the *SubWindow* is shown, until the user closes it. * `.openSubWindow(title)` Used to reopen the named *SubWindow*. diff --git a/examples/issues/issue108.py b/examples/issues/issue108.py index 155a3c7..8eeb3ad 100644 --- a/examples/issues/issue108.py +++ b/examples/issues/issue108.py @@ -2,24 +2,28 @@ sys.path.append("../../") from appJar import gui -def login(btn): print(btn) +def launch(win): + app.showSubWindow(win) -def openLogin(): - app.showSubWindow('L') +app=gui() +app.startSubWindow("Modal", modal=True, transient=True) +app.addLabel("l1", "SubWindow One") +app.addEntry("e1") +app.addButtons(["HIDE", "SHOW"], [app.hide, app.show]) +app.stopSubWindow() -app = gui('SLA Sendback Entry') - -# Login # -app.startSubWindow("L")#, modal=True) -app.addLabelEntry('Username') -app.setFocus('Username') -app.addLabelSecretEntry('Password') -app.addButton('Login', login) +app.startSubWindow("unModal") +app.addLabel("l2", "SubWindow Two") +app.addEntry("e2") +app.addButtons(["HIDE2", "SHOW2"], [app.hide, app.show]) app.stopSubWindow() -app.addLabelEntry('Entry') -app.setFocus('Entry') +app.addLabel("mt", "Modal Testing") +app.addButtons(["Modal", "unModal"], launch) + +print("show popup") +launch("Modal") +print("moving on") -openLogin() app.go()