Skip to content

Commit

Permalink
Containers (through context manager) now take parameters #340
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisteach committed Feb 14, 2018
1 parent f53d2ba commit 1dbe7e6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
18 changes: 12 additions & 6 deletions appJar/appjar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4041,11 +4041,12 @@ def startContainer(self, fType, title, row=None, column=0, colspan=0, rowspan=0,
#####################################

@contextmanager
def notebook(self, title, row=None, column=0, colspan=0, rowspan=0, sticky="NSEW"):
def notebook(self, title, row=None, column=0, colspan=0, rowspan=0, sticky="NSEW", **kwargs):
try:
note = self.startNotebook(title, row, column, colspan, rowspan, sticky)
except ItemLookupError:
note = self.openNotebook(title)
self.configure(**kwargs)
try: yield note
finally: self.stopNotebook()

Expand All @@ -4060,11 +4061,12 @@ def stopNotebook(self):
self.stopContainer()

@contextmanager
def note(self, title, tabTitle=None):
def note(self, title, tabTitle=None, **kwargs):
if tabTitle is None:
note = self.startNote(title)
else:
self.openNote(title, tabTitle)
self.configure(**kwargs)
try: yield note
finally: self.stopNote()

Expand Down Expand Up @@ -4416,11 +4418,12 @@ def _colourTabs(self, swap=True):
return TabbedFrame(master, **kwargs)

@contextmanager
def tabbedFrame(self, title, row=None, column=0, colspan=0, rowspan=0, sticky="NSEW"):
def tabbedFrame(self, title, row=None, column=0, colspan=0, rowspan=0, sticky="NSEW", **kwargs):
try:
tabs = self.startTabbedFrame(title, row, column, colspan, rowspan, sticky)
except ItemLookupError:
tabs = self.openTabbedFrame(title)
self.configure(**kwargs)
try: yield tabs
finally: self.stopTabbedFrame()

Expand Down Expand Up @@ -4774,13 +4777,14 @@ def stopPanedFrame(self):
self.stopContainer()

@contextmanager
def panedFrameVertical(self, title, row=None, column=0, colspan=0, rowspan=0, sticky="NSEW"):
def panedFrameVertical(self, title, row=None, column=0, colspan=0, rowspan=0, sticky="NSEW", **kwargs):
reOpen = False
try:
pane = self.startPanedFrameVertical(title, row, column, colspan, rowspan, sticky)
except ItemLookupError:
reOpen = True
pane = self.openPane(title)
self.configure(**kwargs)
try: yield pane
finally:
if reOpen:
Expand Down Expand Up @@ -4874,11 +4878,12 @@ def getToggleFrameState(self, title):
#####################################

@contextmanager
def pagedWindow(self, title, row=None, column=0, colspan=0, rowspan=0):
def pagedWindow(self, title, row=None, column=0, colspan=0, rowspan=0, **kwargs):
try:
pw = self.startPagedWindow(title, row, column, colspan, rowspan)
except ItemLookupError:
pw = self.openPagedWindow(title)
self.configure(**kwargs)
try: yield pw
finally: self.stopPagedWindow()

Expand Down Expand Up @@ -4924,11 +4929,12 @@ def setPagedWindowTitle(self, title, pageTitle):
pager.setTitle(pageTitle)

@contextmanager
def page(self, windowTitle=None, pageNumber=None, sticky="nw"):
def page(self, windowTitle=None, pageNumber=None, sticky="nw", **kwargs):
if windowTitle is None:
pg = self.startPage(sticky)
else:
pg = self.openPage(windowTitle, pageNumber)
self.configure(**kwargs)
try: yield pg
finally: self.stopPage()

Expand Down
41 changes: 41 additions & 0 deletions examples/issues/issue340.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys
sys.path.append("../../")

from appJar import gui

with gui("KWARGS TEST", bg="green") as app:
with app.tabbedFrame("nb1", bg="blue"):
with app.tab("LabelFrame", bg="yellow"):
with app.labelFrame("LabelFrame", bg="green", fg="blue"):
app.label("YELLOW NOTE")
with app.tab("ToggleFrame", bg="black", fg="white"):
with app.toggleFrame("ToggleFrame", bg="pink", fg="red"):
app.label("BLACK NOTE")
with app.tab("PanedFrame", bg="orange"):
app.label("ORANGE NOTE")
with app.panedFrame("PanedFrame2", bg="orange", fg="white"):
app.label("ORANGE NOTE2")
with app.panedFrame("PanedFrame3", bg="green", fg="blue"):
app.label("ORANGE NOTE3")
with app.tab("PagedWindow", bg="purple"):
with app.pagedWindow("PagedWindow", bg="red", fg="yellow"):
with app.page(bg="white", fg="pink"):
app.label("PINK ON WHITE")
with app.page(bg="black", fg="red"):
app.label("RED ON BLACK")
with app.page():
app.label("PURPLE3 NOTE")
with app.tab("Frame", bg="red"):
with app.frame("Frame", bg="purple", fg="white"):
app.label("RED NOTE")
with app.tab("ScrollPane", bg="grey"):
with app.scrollPane("ScrollPane", sticky="SE", bg="pink"):
app.label("GREY NOTE", bg="orange")
with app.tab("NoteBook", bg="yellow"):
with app.notebook("nb1"):
with app.note("note1", bg="green"):
app.label("N_GREEN NOTE")
with app.note("note2", bg="pink"):
app.label("N_PINK NOTE2")
with app.note("note3", bg="blue"):
app.label("N_BLUE NOTE3")

0 comments on commit 1dbe7e6

Please sign in to comment.