Skip to content

Commit

Permalink
fix to modal settings #108
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisteach committed Apr 12, 2017
1 parent 5058984 commit a92292c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
19 changes: 14 additions & 5 deletions appJar/appjar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion docs/mkdocs/docs/pythonWidgetGrouping.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*.
Expand Down
32 changes: 18 additions & 14 deletions examples/issues/issue108.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit a92292c

Please sign in to comment.