Skip to content

Commit

Permalink
Update tick box optionmenu (#42)
Browse files Browse the repository at this point in the history
Cleaned up tick box optionmenu:
* Now only shows tick boxes in drop-down
* get function now returns dictionary of options with boolean
  • Loading branch information
Richard Jarvis committed Aug 9, 2016
1 parent d1d5905 commit 20bddd0
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions appjar.py
Expand Up @@ -1920,8 +1920,9 @@ def __buildOptionBox(self, frame, title, options, kind="normal"):
option.kind="normal"
elif kind == "ticks":
## http://stackoverflow.com/questions/29019760/how-to-create-a-combobox-that-includes-checkbox-for-each-item
option = OptionMenu(frame,variable=var,value="- options -")
option["menu"].entryconfigure(0, state="disabled")
option = OptionMenu(frame,variable=var,value="")
# delete the empty value we just added
option['menu'].delete(0, 'end')
var.set(title)
vals = []
for o in options:
Expand Down Expand Up @@ -1977,18 +1978,25 @@ def addLabelOptionBox(self, title, options, row=None, column=0, colspan=0, rowsp
def getOptionBox(self, title):
self.__verifyItem(self.n_optionVars, title)
val=self.n_optionVars[title]

if type(val) == list:
vals=[]
for v in val:
if v.get(): vals.append(True)
else: vals.append(False)
## get list of values ##
menu = self.n_options[title]["menu"]
last = menu.index("end")
items = []
for index in range(last+1):
items.append(menu.entrycget(index, "label"))
########################
vals={}
for pos, v in enumerate(val):
if v.get(): vals[items[pos]] = True
else: vals[items[pos]] = False
return vals

val = val.get().strip()
# set to None if it's a divider
if val.startswith("-") or len(val) == 0: val = None

return val
else:
val = val.get().strip()
# set to None if it's a divider
if val.startswith("-") or len(val) == 0: val = None
return val

def __disableOptionBoxSeparators(self, box):
# disable any separators
Expand Down

0 comments on commit 20bddd0

Please sign in to comment.