Merge pull request #822 from MikeTheWatchGuy/Dev-latest

set_to_index parm in ListBox, return values for MenuBar
This commit is contained in:
MikeTheWatchGuy 2018-11-30 12:27:23 -05:00 committed by GitHub
commit 9127d9fe58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -718,7 +718,7 @@ class Listbox(Element):
super().__init__(ELEM_TYPE_INPUT_LISTBOX, size=size, auto_size_text=auto_size_text, font=font, super().__init__(ELEM_TYPE_INPUT_LISTBOX, size=size, auto_size_text=auto_size_text, font=font,
background_color=bg, text_color=fg, key=key, pad=pad, tooltip=tooltip) background_color=bg, text_color=fg, key=key, pad=pad, tooltip=tooltip)
def Update(self, values=None, disabled=None): def Update(self, values=None, disabled=None, set_to_index=None):
if disabled == True: if disabled == True:
self.TKListbox.configure(state='disabled') self.TKListbox.configure(state='disabled')
elif disabled == False: elif disabled == False:
@ -729,6 +729,14 @@ class Listbox(Element):
self.TKListbox.insert(tk.END, item) self.TKListbox.insert(tk.END, item)
self.TKListbox.selection_set(0, 0) self.TKListbox.selection_set(0, 0)
self.Values = values self.Values = values
if set_to_index is not None:
self.TKListbox.selection_clear(0)
try:
self.TKListbox.selection_set(set_to_index, set_to_index)
except:
pass
def SetValue(self, values): def SetValue(self, values):
for index, item in enumerate(self.Values): for index, item in enumerate(self.Values):
@ -2574,12 +2582,14 @@ class Menu(Element):
self.MenuDefinition = menu_definition self.MenuDefinition = menu_definition
self.TKMenu = None self.TKMenu = None
self.Tearoff = tearoff self.Tearoff = tearoff
self.MenuItemChosen = None
super().__init__(ELEM_TYPE_MENUBAR, background_color=background_color, size=size, pad=pad, key=key) super().__init__(ELEM_TYPE_MENUBAR, background_color=background_color, size=size, pad=pad, key=key)
return return
def MenuItemChosenCallback(self, item_chosen): def MenuItemChosenCallback(self, item_chosen):
# print('IN MENU ITEM CALLBACK', item_chosen) # print('IN MENU ITEM CALLBACK', item_chosen)
self.MenuItemChosen = item_chosen
self.ParentForm.LastButtonClicked = item_chosen self.ParentForm.LastButtonClicked = item_chosen
self.ParentForm.FormRemainedOpen = True self.ParentForm.FormRemainedOpen = True
if self.ParentForm.CurrentlyRunningMainloop: if self.ParentForm.CurrentlyRunningMainloop:
@ -3841,6 +3851,12 @@ def BuildResultsForSubform(form, initialize_only, top_level_form):
value = element.SelectedRows value = element.SelectedRows
elif element.Type == ELEM_TYPE_GRAPH: elif element.Type == ELEM_TYPE_GRAPH:
value = element.ClickPosition value = element.ClickPosition
elif element.Type == ELEM_TYPE_MENUBAR:
if element.MenuItemChosen is not None:
top_level_form.LastButtonClicked = element.MenuItemChosen
button_pressed_text = top_level_form.LastButtonClicked
value = element.MenuItemChosen
element.MenuItemChosen = None
else: else:
value = None value = None