Skip to content

Commit

Permalink
Hide/Show Toolbar (#83)
Browse files Browse the repository at this point in the history
Start on work to allow toolbar to be hidden/shown when mouse goes over.

Involves having a second label - just a few pixels tall. When the mouse
goes over it - hide it & show the toolbar.

When the mouse leaves the toolbar - hide it & show the label.

Includes a function to ```setToolbarPinned()``` to turn it on/off.

Now needs an icon (drawing pin) to place in toolbar to call the pin
function/show pin status.
  • Loading branch information
jarvisteach committed Mar 11, 2017
1 parent 2ebd6c7 commit 53fb7a8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
36 changes: 35 additions & 1 deletion appJar/appjar.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def __init__(self, title=None, geom=None, warn=True, debug=False):
# won't pack, if don't pack it here
self.tb = Frame(self.appWindow, bd=1, relief=RAISED)
self.tb.pack(side=TOP, fill=X)
self.tbMinMade = False

# create the main container for this GUI
container = Frame(self.appWindow)
Expand Down Expand Up @@ -4435,6 +4436,7 @@ def selectListItemPos(self, title, pos):
lb.see(pos)
lb.activate(pos)
lb.selection_set(pos)
self.topLevel.update_idletasks()

# replace the list items in the list box
def updateListItems(self, title, items):
Expand Down Expand Up @@ -5475,7 +5477,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):
def addToolbar(self, names, funcs, findIcon=False, pinned=True):
if not self.hasTb:
self.hasTb = True

Expand Down Expand Up @@ -5518,6 +5520,22 @@ def addToolbar(self, names, funcs, findIcon=False):
but.pack(side=LEFT, padx=2, pady=2)
but.tt_var = self.__addTooltip(but, t.title(), True)

self.setToolbarPinned(pinned)


def setToolbarPinned(self, pinned=True):
self.tbPinned = pinned
if not self.tbPinned:
if not self.tbMinMade:
self.tbMinMade = True
self.tbm = Frame(self.appWindow, bd=1, relief=RAISED)
self.tbm.config(bg="gray", height=3)
self.tb.bind("<Leave>", self.__minToolbar)
self.tbm.bind("<Enter>", self.__maxToolbar)
self.__minToolbar()
else:
self.__maxToolbar()

def setToolbarIcon(self, name, icon):
if (name not in self.n_tbButts):
raise Exception("Unknown toolbar name: " + name)
Expand Down Expand Up @@ -5555,15 +5573,31 @@ def setToolbarDisabled(self, disabled=True):
else:
self.n_tbButts[but].config(state=NORMAL)

def __minToolbar(self, e=None):
if not self.tbPinned:
if self.tbMinMade:
self.tbm.config(width=self.tb.winfo_reqwidth())
self.tbm.pack(before=self.containerStack[0]['container'], side=TOP, fill=X)
self.tb.pack_forget()

def __maxToolbar(self, e=None):
self.tb.pack(before=self.containerStack[0]['container'], side=TOP, fill=X)
if self.tbMinMade:
self.tbm.pack_forget()

# functions to hide & show the toolbar
def hideToolbar(self):
if self.hasTb:
self.tb.pack_forget()
if self.tbMinMade:
self.tbm.pack_forget()

def showToolbar(self):
if self.hasTb:
self.tb.pack(before=self.containerStack[0][
'container'], side=TOP, fill=X)
if self.tbMinMade:
self.tbm.pack_forget()

#####################################
# FUNCTIONS for menu bar
Expand Down
25 changes: 25 additions & 0 deletions examples/toolbar2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
sys.path.append("../")
from appJar import gui

pin = True

def tbFunc(btn):
print(btn)

def pin(btn): app.setToolbarPinned(True)
def unpin(btn): app.setToolbarPinned(False)

def tbOut(btn): app.hideToolbar()
def tbIn(btn): app.showToolbar()

app = gui()

app.addToolbar(["Save", "Open", "Close"], 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()
10 changes: 6 additions & 4 deletions examples/toolbarDemo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
sys.path.append("../")
from appJar import gui
showing = True

Expand Down Expand Up @@ -35,7 +37,7 @@ def bar(btn):

app=gui("Toolbar Demo")

app.startPanedWindow("mainPane")
app.startPanedFrame("mainPane")

app.setExpand("column")
app.setSticky("new")
Expand All @@ -51,15 +53,15 @@ def bar(btn):

app.setTextAreaWidth("t1", 50)
app.setTextAreaHeight("t1", 25)
app.startPanedWindow("toolPane")
app.startPanedFrame("toolPane")
app.setSticky("new")
app.addProperties("Settings", settings)
app.setSticky("new")
app.setExpand("column")
app.addButtons(["HIDE", "SHOW"], bar)
app.stopAllPanedWindows()
app.stopAllPanedFrames()

app.addToolbar(tools, tbFunc, True)
app.addToolbar(tools, tbFunc, True, False)
app.addStatusbar(fields=3, side="RIGHT")
app.setStatusbarBg("red", 2)
app.setStatusbarFg("white", 2)
Expand Down

0 comments on commit 53fb7a8

Please sign in to comment.