diff --git a/appJar/appjar.py b/appJar/appjar.py index e8dff83..9c90658 100755 --- a/appJar/appjar.py +++ b/appJar/appjar.py @@ -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("", 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) @@ -5534,8 +5564,16 @@ def setToolbarPinned(self, pinned=True): self.tbm.bind("", 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) diff --git a/appJar/resources/icons/pin.gif b/appJar/resources/icons/pin.gif new file mode 100644 index 0000000..a90f25b Binary files /dev/null and b/appJar/resources/icons/pin.gif differ diff --git a/appJar/resources/icons/unpin.gif b/appJar/resources/icons/unpin.gif new file mode 100644 index 0000000..e65a86d Binary files /dev/null and b/appJar/resources/icons/unpin.gif differ diff --git a/examples/toolbar2.py b/examples/toolbar2.py index a3df284..dc99913 100644 --- a/examples/toolbar2.py +++ b/examples/toolbar2.py @@ -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()