Added ability to change button image size in Button.Update when filename is specified

This commit is contained in:
MikeTheWatchGuy 2019-01-03 12:54:33 -05:00
parent b16473759a
commit 59f866e858
1 changed files with 14 additions and 29 deletions

View File

@ -1639,10 +1639,15 @@ class Button(Element):
self.TKButton.image = image self.TKButton.image = image
if image_filename is not None: if image_filename is not None:
self.TKButton.config(highlightthickness=0) self.TKButton.config(highlightthickness=0)
photo = tk.PhotoImage(file=image_filename) image = tk.PhotoImage(file=image_filename)
width, height = photo.width(), photo.height() if image_size is not None:
self.TKButton.config(image=photo, width=width, height=height) width, height = image_size
self.TKButton.image = photo else:
width, height = image.width(), image.height()
if image_subsample:
image = image.subsample(image_subsample)
self.TKButton.config(image=image, width=width, height=height)
self.TKButton.image = image
if visible is False: if visible is False:
self.TKButton.pack_forget() self.TKButton.pack_forget()
elif visible is True: elif visible is True:
@ -1711,6 +1716,7 @@ class ButtonMenu(Element):
self.MenuItemChosen = None self.MenuItemChosen = None
self.Tearoff = tearoff self.Tearoff = tearoff
self.TKButtonMenu = None self.TKButtonMenu = None
self.TKMenu = None
# self.temp_size = size if size != (NONE, NONE) else # self.temp_size = size if size != (NONE, NONE) else
super().__init__(ELEM_TYPE_BUTTONMENU, size=size, font=font, pad=pad, key=key, tooltip=tooltip, text_color=self.TextColor, background_color=self.BackgroundColor, visible=visible) super().__init__(ELEM_TYPE_BUTTONMENU, size=size, font=font, pad=pad, key=key, tooltip=tooltip, text_color=self.TextColor, background_color=self.BackgroundColor, visible=visible)
@ -1731,32 +1737,11 @@ class ButtonMenu(Element):
if menu_definition is not None: if menu_definition is not None:
self.TKMenu = tk.Menu(self.TKButtonMenu, tearoff=self.Tearoff) # create the menubar self.TKMenu = tk.Menu(self.TKButtonMenu, tearoff=self.Tearoff) # create the menubar
AddMenuItem(self.TKMenu, menu_definition[1], self) AddMenuItem(self.TKMenu, menu_definition[1], self)
# for menu_entry in menu_definition:
# # print(f'Adding a Menubar ENTRY {menu_entry}')
# baritem = tk.Menu(menubar, tearoff=self.Tearoff)
# pos = menu_entry[0].find('&')
# # print(pos)
# if pos != -1:
# if pos == 0 or menu_entry[0][pos - 1] != "\\":
# menu_entry[0] = menu_entry[0][:pos] + menu_entry[0][pos + 1:]
# if menu_entry[0][0] == MENU_DISABLED_CHARACTER:
# menubar.add_cascade(label=menu_entry[0][len(MENU_DISABLED_CHARACTER):], menu=baritem, underline=pos)
# menubar.entryconfig(menu_entry[0][len(MENU_DISABLED_CHARACTER):], state='disabled')
# else:
# menubar.add_cascade(label=menu_entry[0], menu=baritem, underline=pos)
#
# if len(menu_entry) > 1:
# AddMenuItem(baritem, menu_entry[1], self)
self.TKButtonMenu.configure(menu=self.TKMenu) self.TKButtonMenu.configure(menu=self.TKMenu)
if visible is False:
def UpdateQt(self, menu_definition=None, text=None, button_color=(None, None), font=None, visible=None): self.TKButtonMenu.pack_forget()
if menu_definition is not None: elif visible is True:
menu_def = menu_definition self.TKButtonMenu.pack()
qmenu = QMenu(self.QT_QPushButton)
qmenu.setTitle(menu_def[0])
AddMenuItem(qmenu, menu_def[1], self)
self.QT_QPushButton.setMenu(qmenu)
super().Update(self.QT_QPushButton, background_color=button_color[1], text_color=button_color[0], font=font, visible=visible)