Skip to content

Commit

Permalink
final updates to tb (#83)
Browse files Browse the repository at this point in the history
* added basic tooltip - need to merge into next_release so we can
change it easily on toggle
* changed way it functions - tbs default to no pin, user has to call
`.setToolbarPinned()` to turn it on and give the top an initial pinned
status
* changed `.__dimensionWindow()` it now makes sure the toolbar is
showing before setting minimum size

A couple of things to think about:
* should be possible to remove the pin, after it’s added
* hiding the toolbar causes the window to shrink - maybe not ideal…
  • Loading branch information
jarvisteach committed Apr 30, 2017
1 parent 34ec498 commit 1acbc23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 24 additions & 6 deletions appJar/appjar.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,12 @@ def __dimensionWindow(self):
# on MAC & LINUX, w_width/w_height always 1
# on WIN, w_height is bigger then r_height - leaving empty space

# show the tb if needed
toggleTb = False
if self.hasTb and not self.tbPinned:
self.__toggletb()
toggleTb = True

# get the apps requested width & height
r_width = self.__getTopLevel().winfo_reqwidth()
r_height = self.__getTopLevel().winfo_reqheight()
Expand Down Expand Up @@ -988,6 +994,10 @@ def __dimensionWindow(self):
# and set it as the minimum size
self.__getTopLevel().minsize(width, height)

# remove the tb again if needed
if toggleTb:
self.__toggletb()

# if the window hasn't been positioned by the user, put it in the
# middle
if not self.locationSet:
Expand Down Expand Up @@ -5477,7 +5487,7 @@ def setPieChart(self, title, name, value):
# FUNCTIONS for tool bar
#####################################
# adds a list of buttons along the top - like a tool bar...
def addToolbar(self, names, funcs, findIcon=False, pinned=True):
def addToolbar(self, names, funcs, findIcon=False):
if not self.hasTb:
self.hasTb = True

Expand Down Expand Up @@ -5522,15 +5532,23 @@ def addToolbar(self, names, funcs, findIcon=False, pinned=True):


# add the pinned image
self.pinBut = Label(self.tb)
self.pinBut = None

def __setPinBut(self):

# only call this once
if self.pinBut is not None:
return

# try to get the icon, if none - then set but to None, and ignore from now on
imgFile = os.path.join(self.icon_path, "pin.gif")
try:
imgObj = self.__getImage(imgFile)
self.pinBut = Label(self.tb)
except:
self.pinBut = None
return

# if image found, then et up the label
# if image found, then set up the label
if self.pinBut is not None:
if gui.GET_PLATFORM() == gui.MAC:
self.pinBut.config(cursor="pointinghand")
Expand All @@ -5540,16 +5558,16 @@ def addToolbar(self, names, funcs, findIcon=False, pinned=True):
self.pinBut.bind("<Button-1>", self.__toggletb)
self.pinBut.config(image=imgObj)#, compound=TOP, text="", justify=LEFT)
self.pinBut.image = imgObj # keep a reference!
self.__addTooltip(self.pinBut, "Click here to pin/unpin the toolbar.", True)
self.pinBut.pack(side=RIGHT, anchor=NE, padx=0, pady=0)

self.setToolbarPinned(pinned)

# called by pinBut, to toggle the pin status of the toolbar
def __toggletb(self, event=None):
self.setToolbarPinned(not self.tbPinned)

def setToolbarPinned(self, pinned=True):
self.tbPinned = pinned
self.__setPinBut()
if not self.tbPinned:
if self.pinBut is not None:
try:
Expand Down
2 changes: 0 additions & 2 deletions examples/toolbar2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def tbIn(btn): app.showToolbar()
app.addToolbar(["Save", "Open", "Close", "a", "b", "c", "d", "e", "f", "g"], tbFunc, True)

app.addButtons(["Pin", "Unpin", "Hide", "Show"], [pin, unpin, tbOut, tbIn])
app.addLabel("l1", "", colspan=2)
#app.setLabelOverFunction("l1", [tbIn, tbOut])
#app.setToolbarPinned(False)

app.go()

0 comments on commit 1acbc23

Please sign in to comment.