Skip to content

Commit

Permalink
Added icon to toggle/reflect pin status (#83)
Browse files Browse the repository at this point in the history
Added icons (50% size of originals, and show them in toolbar
Clicking the icon will toggle the pin state, and  in turn change the
icon
  • Loading branch information
jarvisteach committed Apr 29, 2017
1 parent 53fb7a8 commit 34ec498
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions appJar/appjar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5520,12 +5520,42 @@ def addToolbar(self, names, funcs, findIcon=False, pinned=True):
but.pack(side=LEFT, padx=2, pady=2)
but.tt_var = self.__addTooltip(but, t.title(), True)


# add the pinned image
self.pinBut = Label(self.tb)
# 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)
except:
self.pinBut = None

# if image found, then et up the label
if self.pinBut is not None:
if gui.GET_PLATFORM() == gui.MAC:
self.pinBut.config(cursor="pointinghand")
elif gui.GET_PLATFORM() in [gui.WINDOWS, gui.LINUX]:
self.pinBut.config(cursor="hand2")

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.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
if not self.tbPinned:
if self.pinBut is not None:
try:
self.pinBut.image = self.__getImage(os.path.join(self.icon_path, "unpin.gif"))
except:
pass
if not self.tbMinMade:
self.tbMinMade = True
self.tbm = Frame(self.appWindow, bd=1, relief=RAISED)
Expand All @@ -5534,8 +5564,16 @@ def setToolbarPinned(self, pinned=True):
self.tbm.bind("<Enter>", self.__maxToolbar)
self.__minToolbar()
else:
if self.pinBut is not None:
try:
self.pinBut.image = self.__getImage(os.path.join(self.icon_path, "pin.gif"))
except:
pass
self.__maxToolbar()

if self.pinBut is not None:
self.pinBut.config(image=self.pinBut.image)

def setToolbarIcon(self, name, icon):
if (name not in self.n_tbButts):
raise Exception("Unknown toolbar name: " + name)
Expand Down
Binary file added appJar/resources/icons/pin.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added appJar/resources/icons/unpin.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/toolbar2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def tbIn(btn): app.showToolbar()

app = gui()

app.addToolbar(["Save", "Open", "Close"], tbFunc, True)
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.setToolbarPinned(False)

app.go()

0 comments on commit 34ec498

Please sign in to comment.