Merge pull request #1692 from PySimpleGUI/Dev-latest

More doc strings. Added check for background color and made optional …
This commit is contained in:
MikeTheWatchGuy 2019-07-16 17:42:02 -04:00 committed by GitHub
commit 874d79d1c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 35 deletions

View File

@ -2868,14 +2868,16 @@ class Graph(Element):
def DrawArc(self, top_left, bottom_right, extent, start_angle, style=None, arc_color='black'): def DrawArc(self, top_left, bottom_right, extent, start_angle, style=None, arc_color='black'):
""" """
Draws different types of arcs. Uses a "bounding box" to define location
:param top_left: :param top_left: Union[Tuple[int, int], Tuple[float, float]] the top left point of bounding rectangle
:param bottom_right: :param bottom_right: Union[Tuple[int, int], Tuple[float, float]] the bottom right point of bounding rectangle
:param extent: :param extent: (float) Andle to end drawing. Used in conjunction with start_angle
:param start_angle: :param start_angle: (float) Angle to begin drawing. Used in conjunction with extent
:param style: :param style: (str) Valid choices are One of these Style strings- 'pieslice', 'chord', 'arc', 'first', 'last',
:param arc_color: (Default value = 'black') 'butt', 'projecting', 'round', 'bevel', 'miter'
:param arc_color: (str) color to draw arc with
:return: Union[int, None] id returned from tkinter that you'll need if you want to manipulate the arc
""" """
converted_top_left = self._convert_xy_to_canvas_xy(top_left[0], top_left[1]) converted_top_left = self._convert_xy_to_canvas_xy(top_left[0], top_left[1])
converted_bottom_right = self._convert_xy_to_canvas_xy(bottom_right[0], bottom_right[1]) converted_bottom_right = self._convert_xy_to_canvas_xy(bottom_right[0], bottom_right[1])
@ -2894,13 +2896,15 @@ class Graph(Element):
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):
""" """
Draw a rectangle given 2 points. Can control the line and fill colors
:param top_left: :param top_left: Union[Tuple[int, int], Tuple[float, float]] the top left point of rectangle
:param bottom_right: :param bottom_right: Union[Tuple[int, int], Tuple[float, float]] the bottom right point of rectangle
:param fill_color: :param fill_color: (str) color of the interior
:param line_color: :param line_color: (str) color of outline
:return: Union[int, None] id returned from tkinter that you'll need if you want to manipulate the point :return: Union[int, None] id returned from tkinter that you'll need if you want to manipulate the rectangle
""" """
converted_top_left = self._convert_xy_to_canvas_xy(top_left[0], top_left[1]) converted_top_left = self._convert_xy_to_canvas_xy(top_left[0], top_left[1])
converted_bottom_right = self._convert_xy_to_canvas_xy(bottom_right[0], bottom_right[1]) converted_bottom_right = self._convert_xy_to_canvas_xy(bottom_right[0], bottom_right[1])
if self._TKCanvas2 is None: if self._TKCanvas2 is None:
@ -2917,13 +2921,14 @@ class Graph(Element):
def DrawText(self, text, location, color='black', font=None, angle=0): def DrawText(self, text, location, color='black', font=None, angle=0):
""" """
Draw some text on your graph. This is how you label graph number lines for example
:param text: :param text: (str) text to display
:param location: :param location: Union[Tuple[int, int], Tuple[float, float]] location to place first letter
:param color: (Default value = 'black') :param color: (str) text color
:param font: specifies the font family, size, etc :param font: Union[str, tuple] specifies the font family, size, etc
:param angle: (Default value = 0) :param angle: (float) Angle 0 to 360 to draw the text. Zero represents horizontal text
:return: Union[int, None] id returned from tkinter that you'll need if you want to manipulate the point :return: Union[int, None] id returned from tkinter that you'll need if you want to manipulate the text
""" """
if location == (None, None): if location == (None, None):
return return
@ -2941,14 +2946,15 @@ class Graph(Element):
def DrawImage(self, filename=None, data=None, location=(None, None), color='black', font=None, angle=0): def DrawImage(self, filename=None, data=None, location=(None, None), color='black', font=None, angle=0):
""" """
Places an image onto your canvas. It's a really important method for this element as it enables so much
:param filename: :param filename: (str) if image is in a file, path and filename for the image. (GIF and PNG only!)
:param data: :param data: Union[str, bytes] if image is in Base64 format or raw? format then use instead of filename
:param location: :param location: Union[Tuple[int, int], Tuple[float, float]] the (x,y) location to place image's top left corner
:param color: (Default value = 'black') :param color: (str) text color
:param font: specifies the font family, size, etc :param font: Union[str, tuple] specifies the font family, size, etc
:param angle: (Default value = 0) :param angle: (float) Angle 0 to 360 to draw the text. Zero represents horizontal text
:return: Union[int, None] id returned from tkinter that you'll need if you want to manipulate the point :return: Union[int, None] id returned from tkinter that you'll need if you want to manipulate the image
""" """
if location == (None, None): if location == (None, None):
return return
@ -2972,8 +2978,11 @@ class Graph(Element):
id = None id = None
return id return id
def Erase(self): def Erase(self):
""" """ """
Erase the Graph - Removes all figures previously "drawn" using the Graph methods (e.g. DrawText)
"""
if self._TKCanvas2 is None: if self._TKCanvas2 is None:
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')
@ -2984,11 +2993,12 @@ class Graph(Element):
except: except:
pass pass
def DeleteFigure(self, id): def DeleteFigure(self, id):
""" """
Remove from the Graph the figure represented by id. The id is given to you anytime you call a drawing primitive
:param id: :param id: (int) the id returned to you when calling one of the drawing methods
""" """
try: try:
self._TKCanvas2.delete(id) self._TKCanvas2.delete(id)
@ -2998,7 +3008,8 @@ class Graph(Element):
del self.Images[id] # in case was an image. If wasn't an image, then will get exception del self.Images[id] # in case was an image. If wasn't an image, then will get exception
except: pass except: pass
def Update(self, background_color, visible=None):
def Update(self, background_color=None, visible=None):
""" """
Changes some of the settings for the Graph Element. Must call `Window.Read` or `Window.Finalize` prior Changes some of the settings for the Graph Element. Must call `Window.Read` or `Window.Finalize` prior
@ -3008,19 +3019,21 @@ class Graph(Element):
if self._TKCanvas2 is None: if self._TKCanvas2 is None:
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
self._TKCanvas2.configure(background=background_color) if background_color is not None and background_color != COLOR_SYSTEM_DEFAULT:
self._TKCanvas2.configure(background=background_color)
if visible is False: if visible is False:
self._TKCanvas2.pack_forget() self._TKCanvas2.pack_forget()
elif visible is True: elif visible is True:
self._TKCanvas2.pack() self._TKCanvas2.pack()
def Move(self, x_direction, y_direction): def Move(self, x_direction, y_direction):
""" """
Moves the entire drawing area (the canvas) by indicated number of ticks in your coordinate system
:param x_direction: :param x_direction: Union[int, float] how far to move in the "X" direction in your coordinates
:param y_direction: :param y_direction: Union[int, float] how far to move in the "Y" direction in your coordinates
""" """
zero_converted = self._convert_xy_to_canvas_xy(0, 0) zero_converted = self._convert_xy_to_canvas_xy(0, 0)
shift_converted = self._convert_xy_to_canvas_xy(x_direction, y_direction) shift_converted = self._convert_xy_to_canvas_xy(x_direction, y_direction)
@ -4341,7 +4354,7 @@ class Table(Element):
self.DisplayRowNumbers = display_row_numbers self.DisplayRowNumbers = display_row_numbers
self.NumRows = num_rows if num_rows is not None else size[1] self.NumRows = num_rows if num_rows is not None else size[1]
self.RowHeight = row_height self.RowHeight = row_height
self.TKTreeview = None # type: ttk.Treeview self.Widget = self.TKTreeview = None # type: ttk.Treeview
self.AlternatingRowColor = alternating_row_color self.AlternatingRowColor = alternating_row_color
self.VerticalScrollOnly = vertical_scroll_only self.VerticalScrollOnly = vertical_scroll_only
self.HideVerticalScroll = hide_vertical_scroll self.HideVerticalScroll = hide_vertical_scroll