New Image features - load from RAM, update with new image

This commit is contained in:
MikeTheWatchGuy 2018-08-18 23:19:11 -04:00
parent ea2b401801
commit a6d375f8a1
1 changed files with 32 additions and 10 deletions

View File

@ -747,7 +747,7 @@ class ProgressBar(Element):
# Image # # Image #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Image(Element): class Image(Element):
def __init__(self, filename, scale=(None, None), size=(None, None)): def __init__(self, filename=None, data=None,scale=(None, None), size=(None, None)):
''' '''
Image Element Image Element
:param filename: :param filename:
@ -755,9 +755,23 @@ class Image(Element):
:param size: Size of field in characters :param size: Size of field in characters
''' '''
self.Filename = filename self.Filename = filename
self.Data = data
self.tktext_label = None
if data is None and filename is None:
print('* Warning... no image specified in Image Element! *')
super().__init__(ELEM_TYPE_IMAGE, scale=scale, size=size) super().__init__(ELEM_TYPE_IMAGE, scale=scale, size=size)
return return
def Update(self, filename=None, data=None):
if filename is not None:
image = tk.PhotoImage(file=filename)
elif data is not None:
image = tk.PhotoImage(data=data)
else: return
self.tktext_label.configure(image=image)
self.tktext_label.image = image
def __del__(self): def __del__(self):
super().__del__() super().__del__()
@ -835,7 +849,7 @@ class Column(Element):
for element in row: for element in row:
element.__del__() element.__del__()
try: try:
del(self.TKroot) del(self.TKFrame)
except: except:
pass pass
super().__del__() super().__del__()
@ -1592,15 +1606,23 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKOut.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1]) element.TKOut.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])
# ------------------------- IMAGE Box element ------------------------- # # ------------------------- IMAGE Box element ------------------------- #
elif element_type == ELEM_TYPE_IMAGE: elif element_type == ELEM_TYPE_IMAGE:
if element.Filename is not None:
photo = tk.PhotoImage(file=element.Filename) photo = tk.PhotoImage(file=element.Filename)
elif element.Data is not None:
photo = tk.PhotoImage(data=element.Data)
else:
photo = None
print('*ERROR laying out form.... Image Element has no image specified*')
if photo is not None:
if element_size == (None, None) or element_size == None or element_size == toplevel_form.DefaultElementSize: if element_size == (None, None) or element_size == None or element_size == toplevel_form.DefaultElementSize:
width, height = photo.width(), photo.height() width, height = photo.width(), photo.height()
else: else:
width, height = element_size width, height = element_size
tktext_label = tk.Label(tk_row_frame, image=photo, width=width, height=height, bd=border_depth) element.tktext_label = tk.Label(tk_row_frame, image=photo, width=width, height=height, bd=border_depth)
tktext_label.image = photo element.tktext_label.image = photo
# tktext_label.configure(anchor=tk.NW, image=photo) # tktext_label.configure(anchor=tk.NW, image=photo)
tktext_label.pack(side=tk.LEFT, padx=element.Pad[0],pady=element.Pad[1]) element.tktext_label.pack(side=tk.LEFT, padx=element.Pad[0],pady=element.Pad[1])
# ------------------------- SLIDER Box element ------------------------- # # ------------------------- SLIDER Box element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_SLIDER: elif element_type == ELEM_TYPE_INPUT_SLIDER:
slider_length = element_size[0] * CharWidthInPixels() slider_length = element_size[0] * CharWidthInPixels()