Added line_width to Graph.DrawRectangle. tk.PhotoImage can be passed in data parm to Image.update

This commit is contained in:
PySimpleGUI 2019-11-07 09:50:10 -05:00
parent 7e6069a16b
commit 37c8349b49
1 changed files with 24 additions and 16 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "4.5.0 Released version 04-Nov-2019" version = __version__ = "4.6.0.2 Unreleased - Added border to Graph.draw_rectangle, Image.Update data parm can be tk.PhotoImage obj"
# 888888ba .d88888b oo dP .88888. dP dP dP # 888888ba .d88888b oo dP .88888. dP dP dP
@ -1582,15 +1582,18 @@ class Spin(Element):
except: except:
pass pass
self.DefaultValue = value self.DefaultValue = value
if disabled == True: if disabled is not None:
self.TKSpinBox.configure(state='disabled') self.TKSpinBox.configure(state='disabled' if disabled else 'normal')
elif disabled == False: # if disabled == True:
self.TKSpinBox.configure(state='normal') # self.TKSpinBox.configure(state='disabled')
# elif disabled == False:
# self.TKSpinBox.configure(state='normal')
if visible is False: if visible is False:
self.TKSpinBox.pack_forget() self.TKSpinBox.pack_forget()
elif visible is True: elif visible is True:
self.TKSpinBox.pack() self.TKSpinBox.pack()
def _SpinChangedHandler(self, event): def _SpinChangedHandler(self, event):
""" """
Callback function. Used internally only. Called by tkinter when Spinbox Widget changes. Results in Window.Read() call returning Callback function. Used internally only. Called by tkinter when Spinbox Widget changes. Results in Window.Read() call returning
@ -2727,11 +2730,12 @@ class Image(Element):
Changes some of the settings for the Image Element. Must call `Window.Read` or `Window.Finalize` prior Changes some of the settings for the Image Element. Must call `Window.Read` or `Window.Finalize` prior
:param filename: (str) filename to the new image to display. :param filename: (str) filename to the new image to display.
:param data: (str) Base64 encoded string :param data: Union[str, tkPhotoImage] Base64 encoded string OR a tk.PhotoImage object
:param size: Tuple[int,int] size of a image (w,h) w=characters-wide, h=rows-high :param size: Tuple[int,int] size of a image (w,h) w=characters-wide, h=rows-high
:param visible: (bool) control visibility of element :param visible: (bool) control visibility of element
""" """
image = None
if self.Widget is None: if self.Widget is None:
warnings.warn('You cannot Update element with key = {} until the window has been Read or Finalized'.format(self.Key), UserWarning) warnings.warn('You cannot Update element with key = {} until the window has been Read or Finalized'.format(self.Key), UserWarning)
return return
@ -2741,10 +2745,12 @@ class Image(Element):
# if type(data) is bytes: # if type(data) is bytes:
try: try:
image = tk.PhotoImage(data=data) image = tk.PhotoImage(data=data)
except: except Exception as e:
return # an error likely means the window has closed so exit image = data
# return # an error likely means the window has closed so exit
else: else:
return return
if image is not None:
width, height = size[0] or image.width(), size[1] or image.height() width, height = size[0] or image.width(), size[1] or image.height()
try: # sometimes crashes if user closed with X try: # sometimes crashes if user closed with X
self.tktext_label.configure(image=image, width=width, height=height) self.tktext_label.configure(image=image, width=width, height=height)
@ -3067,7 +3073,7 @@ class Graph(Element):
id = None id = None
return id return id
def DrawRectangle(self, top_left, bottom_right, fill_color=None, line_color=None): def DrawRectangle(self, top_left, bottom_right, fill_color=None, line_color=None, line_width=None):
""" """
Draw a rectangle given 2 points. Can control the line and fill colors Draw a rectangle given 2 points. Can control the line and fill colors
@ -3084,10 +3090,12 @@ class Graph(Element):
print('*** WARNING - The Graph element has not been finalized and cannot be drawn upon ***') print('*** WARNING - The Graph element has not been finalized and cannot be drawn upon ***')
print('Call Window.Finalize() prior to this operation') print('Call Window.Finalize() prior to this operation')
return None return None
if line_width is None:
line_width = 1
try: # in case closed with X try: # in case closed with X
id = self._TKCanvas2.create_rectangle(converted_top_left[0], converted_top_left[1], id = self._TKCanvas2.create_rectangle(converted_top_left[0], converted_top_left[1],
converted_bottom_right[0], converted_bottom_right[0],
converted_bottom_right[1], fill=fill_color, outline=line_color) converted_bottom_right[1], fill=fill_color, outline=line_color, width=line_width)
except: except:
id = None id = None
return id return id