Skip to content

Commit

Permalink
New properties, updated testing #340
Browse files Browse the repository at this point in the history
Getters for:
* padding
* guiPadding
* inPadding
* transparency
* editMenu

Accessibility now use above getter #328

Refactored setSize - simplified

Updated testing
  • Loading branch information
jarvisteach committed Feb 16, 2018
1 parent a88cba3 commit c5f41d1
Show file tree
Hide file tree
Showing 4 changed files with 7,372 additions and 70 deletions.
71 changes: 40 additions & 31 deletions appJar/appjar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2158,33 +2158,27 @@ def setSize(self, geom, height=None, ignoreSettings=None):

if geom == "fullscreen":
self.setFullscreen()
else:
if geom is None:
size = None
else:
if height is not None:
geom = "%sx%s" % (geom, height)
else:
if isinstance(geom, list) or isinstance(geom, tuple):
geom = str(geom[0])+"x"+str(geom[1])

dims = gui.GET_DIMS(container)
elif geom is not None:
if height is not None:
geom=(geom, height)
elif not isinstance(geom, list) and not isinstance(geom, tuple):
geom, loc = gui.SPLIT_GEOM(geom)
size = str(geom[0]) + "x" + str(geom[1])

gui.trace("Setting size: %s", size)
# warn the user that their geom is not big enough
if geom[0] < dims["b_width"] or geom[1] < dims["b_height"]:
self.warn("Specified dimensions (%s, %s) less than requested dimensions (%s, %s)",
geom[0], geom[1], dims["b_width"], dims["b_height"])
size = "%sx%s" % (int(geom[0]), int(geom[1]))
gui.trace("Setting size: %s", size)

# warn the user that their geom is not big enough
dims = gui.GET_DIMS(container)
if geom[0] < dims["b_width"] or geom[1] < dims["b_height"]:
self.warn("Specified dimensions (%s, %s) less than requested dimensions (%s, %s)",
geom[0], geom[1], dims["b_width"], dims["b_height"])

# and set it as the minimum size
if not hasattr(container, 'ms'):
self.setMinSize(container, geom)
# and set it as the minimum size
if not hasattr(container, 'ms'):
self.setMinSize(container, geom)

self.exitFullscreen()
if size is not None:
container.geometry(size)
container.geometry(size)

def getSize(self):
container = self._getTopLevel()
Expand Down Expand Up @@ -2316,7 +2310,10 @@ def setPadding(self, x, y=None):
self.containerStack[-1]['padx'] = x
self.containerStack[-1]['pady'] = y

padding = property(fset=setPadding)
def getPadding(self):
return self.containerStack[-1]['padx'], self.containerStack[-1]['pady']

padding = property(getPadding, setPadding)

def config(self, **kwargs):
self.configure(**kwargs)
Expand Down Expand Up @@ -2397,7 +2394,10 @@ def setGuiPadding(self, x, y=None):
x, y = self._parseTwoParams(x, y)
self.containerStack[0]['container'].config(padx=x, pady=y)

guiPadding = property(fset=setGuiPadding)
def getGuiPadding(self):
return int(str(self.containerStack[0]['container'].cget('padx'))), int(str(self.containerStack[0]['container'].cget('pady')))

guiPadding = property(getGuiPadding, setGuiPadding)

# sets the current containers internal padding
def setIPadX(self, x=0):
Expand All @@ -2420,7 +2420,10 @@ def setInPadding(self, x, y=None):
self.containerStack[-1]['ipadx'] = x
self.containerStack[-1]['ipady'] = y

inPadding = property(fset=setInPadding)
def getInPadding(self):
return self.containerStack[-1]['ipadx'], self.containerStack[-1]['ipady']

inPadding = property(getInPadding, setInPadding)

# set an override sticky for this container
def setSticky(self, sticky):
Expand Down Expand Up @@ -2724,8 +2727,11 @@ def setTransparency(self, percentage):
percentage = float(percentage) / 100
self._getTopLevel().attributes("-alpha", percentage)

def getTransparency(self):
return self._getTopLevel().attributes("-alpha") * 100

# property for setTransparency
transparency = property(fset=setTransparency)
transparency = property(getTransparency, setTransparency)

##############################
# functions to deal with tabbing and right clicking
Expand Down Expand Up @@ -8211,9 +8217,9 @@ def _resetAccess(self):
def showAccess(self, location=None):
self._makeAccess()
# update current settings
self.accessFont = self._labelFont.actual()
self.accessBg = self.bgLabel.cget("bg")
self.accessFg = self.containerStack[0]["fg"]
self.accessFont = self.font
self.accessBg = self.bg
self.accessFg = self.fg
self._resetAccess()
self.showSubWindow("access_access_subwindow")

Expand Down Expand Up @@ -10140,13 +10146,16 @@ def addMenuEdit(self, inMenuBar=False):
self.addMenuItem("EDIT", 'Redo', lambda e: self._copyAndPasteHelper( "Redo"), shortcut="Shift-" + shortcut + "Z", createBinding=True)
self.disableMenu("EDIT")

def _editMenuWrapper(self, enabled=True):
def _editMenuSetter(self, enabled=True):
if enabled:
self.addMenuEdit()
else:
self.disableMenuEdit()

editMenu = property(fset=_editMenuWrapper)
def _editMenuGetter(self):
return self.copyAndPaste.inUse

editMenu = property(_editMenuGetter, _editMenuSetter)

def appJarAbout(self, menu=None):
self.infoBox("About appJar",
Expand Down
11 changes: 9 additions & 2 deletions examples/issues/issue340.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def logger(level):

def setts(btn):
if btn == 'SIZE':
app.size=(app.entry('x'), app.entry('y'))
if app.entry('y') is None:
app.size=str(app.entry('x'))+'x'+str(app.entry('x'))
else:
app.size=(app.entry('x'), app.entry('y'))
elif btn == 'LOCATION':
app.location=(app.entry('x'), app.entry('y'))
elif btn == 'FSIZE':
Expand All @@ -28,11 +31,14 @@ def setts(btn):
app.fullscreen = True
elif btn == 'NOFULL':
app.fullscreen = False
elif btn == "RESIZE":
app.resizable = app.check("RESIZE")
elif btn == 'GET':
app.label("t",
"SIZE: " + str(app.size) + "\n" +
"LOC: " + str(app.location) + "\n" +
"FULL: " + str(app.fullscreen)
"FULL: " + str(app.fullscreen) + '\n' +
"RES: " + str(app.resizable)
)
elif btn == "fonts":
app.label("fonts",
Expand All @@ -54,6 +60,7 @@ def setts(btn):
with app.tab("settings", bg="green", fg="red"):
app.entry("x", label=True, kind='numeric')
app.entry("y", label=True, kind='numeric', pos=(0,1))
app.check("RESIZE", label=True, change=setts)
app.buttons(["SIZE", "FSIZE", "LOCATION", "FULL", "NOFULL"], setts, colspan=2)
app.button('GET', setts, colspan=2)
app.label('t', colspan=2, font={'size':20})
Expand Down
Loading

0 comments on commit c5f41d1

Please sign in to comment.