SwiftGUI 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {swiftgui-0.2.2 → swiftgui-0.2.3}/PKG-INFO +1 -1
  2. {swiftgui-0.2.2 → swiftgui-0.2.3}/pyproject.toml +1 -1
  3. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Base.py +12 -4
  4. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/ElementFlags.py +1 -0
  5. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/GlobalOptions.py +14 -3
  6. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/KeyFunctions.py +26 -0
  7. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Widgets/Checkbox.py +10 -0
  8. swiftgui-0.2.3/src/SwiftGUI/Widgets/Frame.py +88 -0
  9. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Widgets/Spacer.py +8 -1
  10. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Widgets/Text.py +10 -0
  11. swiftgui-0.2.3/src/SwiftGUI/WidgetsAdvanced/ColorChooserButton.py +192 -0
  12. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/WidgetsAdvanced/FileBrowseButton.py +1 -3
  13. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Windows.py +2 -0
  14. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/__init__.py +2 -1
  15. swiftgui-0.2.2/src/SwiftGUI/Widgets/Frame.py +0 -61
  16. {swiftgui-0.2.2 → swiftgui-0.2.3}/LICENSE +0 -0
  17. {swiftgui-0.2.2 → swiftgui-0.2.3}/README.md +0 -0
  18. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Colors.py +0 -0
  19. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Events.py +0 -0
  20. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Examples.py +0 -0
  21. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Fonts.py +0 -0
  22. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/KeyManager.py +0 -0
  23. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Literals.py +0 -0
  24. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Popups.py +0 -0
  25. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Themes.py +0 -0
  26. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Tools.py +0 -0
  27. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Widgets/Button.py +0 -0
  28. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Widgets/Input.py +0 -0
  29. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Widgets/Listbox.py +0 -0
  30. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/Widgets/Separator.py +0 -0
  31. {swiftgui-0.2.2 → swiftgui-0.2.3}/src/SwiftGUI/WidgetsAdvanced/Form.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: SwiftGUI
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: An easy-to-use package for creating and using simple GUIs
5
5
  License: Apache-2.0
6
6
  Author: Eric aka LeButch
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "SwiftGUI"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  packages = [
5
5
  { include = "SwiftGUI", from = "src" }
6
6
  ]
@@ -2,7 +2,7 @@ from collections.abc import Iterable, Callable
2
2
  from typing import Literal, Self, Union
3
3
  import tkinter as tk
4
4
 
5
- from SwiftGUI import Event,GlobalOptions
5
+ from SwiftGUI import Event, GlobalOptions, Color
6
6
  from SwiftGUI.ElementFlags import ElementFlag
7
7
 
8
8
 
@@ -227,7 +227,7 @@ class BaseWidget(BaseElement):
227
227
  _insert_kwargs_rows:dict # kwargs for the grid-rows
228
228
 
229
229
  #_is_container:bool = False # True, if this widget contains other widgets
230
- _contains:Iterable[Iterable[Self]] = []
230
+ _contains:Iterable[Iterable["BaseElement"]] = []
231
231
 
232
232
  _transfer_keys: dict[str:str] = dict() # Rename a key from the update-function. from -> to; from_user -> to_widget
233
233
 
@@ -376,6 +376,8 @@ class BaseWidget(BaseElement):
376
376
  if self.has_flag(ElementFlag.IS_CONTAINER):
377
377
  self._init_containing()
378
378
 
379
+ _containing_row_frame_widgets: list[tk.Frame]
380
+ _background_color: str | Color
379
381
  def _init_containing(self):
380
382
  """
381
383
  Initialize all containing widgets
@@ -387,8 +389,9 @@ class BaseWidget(BaseElement):
387
389
  # line = tk.Frame(self._tk_widget,background="orange",relief="raised",borderwidth="3",border=3)
388
390
  # actual_line = tk.Frame(line,background="lightBlue")
389
391
 
390
- line = tk.Frame(self._tk_widget,relief="flat",background="") # This is the row
391
- actual_line = tk.Frame(line,background="") # This is where the actual elements are put in
392
+ line = tk.Frame(self._tk_widget,relief="flat",background=self._background_color) # This is the row
393
+ actual_line = tk.Frame(line,background=self._background_color) # This is where the actual elements are put in
394
+ self._containing_row_frame_widgets.extend((line,actual_line))
392
395
 
393
396
  line_elem = BaseElement()
394
397
  line_elem._fake_tk_element = actual_line
@@ -457,6 +460,11 @@ class BaseWidgetContainer(BaseWidget):
457
460
  """
458
461
  Base for Widgets that contain other widgets
459
462
  """
463
+ def __init__(self,key:any=None,tk_kwargs:dict[str:any]=None,expand:bool = False,**kwargs):
464
+ super().__init__(key,tk_kwargs,expand,**kwargs)
465
+
466
+ self._containing_row_frame_widgets = list()
467
+ self._background_color: str | Color = self.defaults.single("background_color",None)
460
468
 
461
469
  def _flag_init(self):
462
470
  super()._flag_init()
@@ -7,6 +7,7 @@ class ElementFlag(Enum):
7
7
  UPDATE_FONT = 3 # Font has to be updated
8
8
  IS_CREATED = 4 # Element was created by _init
9
9
  EXPAND_ROW = 5 # The row this element is in should be expanded
10
+ APPLY_PARENT_BACKGROUND_COLOR = 6 # Set, if the element should apply whatever background-color the parent has
10
11
 
11
12
  # Flags 100-200 will never be used, so they are available for you to create custom flags
12
13
  # It's important to set an actual value for each flag so it can be saved/loaded correctly
@@ -1,6 +1,7 @@
1
1
  #import tkinter as tk # Not needed, but helpful to figure out default vals
2
2
  #from tkinter import ttk
3
3
  from collections.abc import Iterable
4
+ from os import PathLike
4
5
  from typing import Literal, Union
5
6
 
6
7
  from SwiftGUI import Literals, Color, font_windows, Font
@@ -166,6 +167,7 @@ class Text(Common,Common_Textual):
166
167
  underline:int = None
167
168
  justify:Literal["left","right","center"] = "left"
168
169
  #borderwidth:int = "5c" # Does not work
170
+ apply_parent_background_color:bool = True
169
171
 
170
172
  padding:Literals.padding = 0
171
173
  width:int = None
@@ -227,15 +229,17 @@ class Button(Common,Common_Textual):
227
229
 
228
230
  class Frame(Common):
229
231
  takefocus = False
230
- padding:Literals.padding = 3
231
- relief:Literals.relief = "flat"
232
+ padding: Literals.padding = 3
233
+ relief: Literals.relief = "flat"
232
234
  #background = "blue"
233
- alignment:Literals.alignment = None
235
+ alignment: Literals.alignment = None
236
+ apply_parent_background_color: bool = True
234
237
 
235
238
  class Checkbox(Common,Common_Textual):
236
239
  key: any = None
237
240
  default_value: bool = False
238
241
  readonly: bool = None
242
+ apply_parent_background_color: bool = True
239
243
  # borderwidth:int = None
240
244
  #
241
245
  text_color_disabled: str | Color = None
@@ -295,6 +299,13 @@ class FileBrowseButton(Button):
295
299
  file_browse_type: Literals.file_browse_types = "open_single"
296
300
  file_browse_filetypes: Literals.file_browse_filetypes = (("All files","*"),)
297
301
  dont_change_on_abort: bool = False
302
+ file_browse_initial_dir: PathLike | str = None, # initialdir
303
+ file_browse_initial_file: str = None, # initialfile
304
+ file_browse_title: str = None, # title
305
+ file_browse_save_defaultextension: str = None, # defaultextension
306
+
307
+ class ColorChooserButton(Button):
308
+ color_chooser_title: str = None
298
309
 
299
310
  def reset_all_options():
300
311
  """
@@ -1,4 +1,6 @@
1
1
  from collections.abc import Callable
2
+ from typing import Any
3
+
2
4
 
3
5
  ### HOW TO CREATE KEY-FUNCTION ###
4
6
  #
@@ -59,3 +61,27 @@ def set_value_to(new_value:any = "", elem_key:str = None) -> Callable:
59
61
 
60
62
  return temp
61
63
 
64
+ def cycle_values(key:Any, *values:Any) -> Callable:
65
+ """
66
+ Every time this gets called, the next value is written to key
67
+ IT WILL START AT THE SECOND VALUE, so it's a good idea to set the initial element-value as the first value.
68
+
69
+ :param key: Element to change
70
+ :param values: values you want to cycle
71
+ :return:
72
+ """
73
+ n = 0
74
+ val_len = len(values)
75
+
76
+ assert val_len > 1, "You did not provide enough values for your cycle_values key-function"
77
+
78
+ def temp(w):
79
+ nonlocal n
80
+ n += 1
81
+
82
+ if n == val_len:
83
+ n = 0
84
+
85
+ w[key].value = values[n]
86
+
87
+ return temp
@@ -64,6 +64,7 @@ class Checkbox(BaseWidget):
64
64
  anchor: Literals.anchor = None,
65
65
  justify: Literal["left", "right", "center"] = None,
66
66
  background_color: str | Color = None,
67
+ apply_parent_background_color: bool = None,
67
68
  overrelief: Literals.relief = None,
68
69
  offrelief: Literals.relief = None,
69
70
  text_color: str | Color = None,
@@ -80,6 +81,9 @@ class Checkbox(BaseWidget):
80
81
  if tk_kwargs is None:
81
82
  tk_kwargs = dict()
82
83
 
84
+ if background_color and not apply_parent_background_color:
85
+ apply_parent_background_color = False
86
+
83
87
  _tk_kwargs = {
84
88
  **tk_kwargs,
85
89
  "default_value": default_value,
@@ -99,6 +103,7 @@ class Checkbox(BaseWidget):
99
103
  "underline": underline,
100
104
  "justify": justify,
101
105
  "background_color": background_color,
106
+ "apply_parent_background_color": apply_parent_background_color,
102
107
  "highlightthickness": 5,
103
108
  "highlightcolor": "purple",
104
109
  "relief": relief,
@@ -174,6 +179,11 @@ class Checkbox(BaseWidget):
174
179
  self._tk_kwargs["state"] = "disabled" if new_val else "normal"
175
180
  case "check_type":
176
181
  self._tk_kwargs["indicatoron"] = int(new_val == "check")
182
+ case "apply_parent_background_color":
183
+ if new_val:
184
+ self.add_flags(ElementFlag.APPLY_PARENT_BACKGROUND_COLOR)
185
+ else:
186
+ self.remove_flags(ElementFlag.APPLY_PARENT_BACKGROUND_COLOR)
177
187
  case _: # Not a match
178
188
  return False
179
189
 
@@ -0,0 +1,88 @@
1
+ import tkinter as tk
2
+ import tkinter.ttk as ttk
3
+ from collections.abc import Iterable
4
+
5
+ from SwiftGUI import BaseElement, ElementFlag, BaseWidgetContainer, GlobalOptions, Literals, Color
6
+
7
+ class Frame(BaseWidgetContainer):
8
+ """
9
+ Copy this class ot create your own Widget
10
+ """
11
+ _tk_widget_class:type[ttk.Frame] = tk.Frame # Class of the connected widget
12
+ defaults = GlobalOptions.Frame
13
+
14
+ _transfer_keys = {
15
+ "background_color":"background"
16
+ }
17
+
18
+ def __init__(
19
+ self,
20
+ layout: Iterable[Iterable[BaseElement]],
21
+ /,
22
+ alignment: Literals.alignment = None,
23
+ expand: bool = False,
24
+ background_color: str | Color = None,
25
+ apply_parent_background_color: bool = None,
26
+ # Add here
27
+ tk_kwargs: dict[str:any]=None,
28
+ ):
29
+ super().__init__(tk_kwargs=tk_kwargs)
30
+
31
+ self._contains = layout
32
+
33
+ if background_color and not apply_parent_background_color:
34
+ apply_parent_background_color = False
35
+
36
+ if tk_kwargs is None:
37
+ tk_kwargs = dict()
38
+
39
+ _tk_kwargs = {
40
+ **tk_kwargs,
41
+ # Insert named arguments for the widget here
42
+ "background_color":background_color,
43
+ "apply_parent_background_color": apply_parent_background_color,
44
+ }
45
+ self.update(**_tk_kwargs)
46
+
47
+ self._insert_kwargs["expand"] = self.defaults.single("expand",expand)
48
+
49
+ self._insert_kwargs_rows.update({
50
+ "side":self.defaults.single("alignment",alignment),
51
+ })
52
+
53
+ def window_entry_point(self,root:tk.Tk|tk.Widget,window:BaseElement):
54
+ """
55
+ Starting point for the whole window, or part of the layout.
56
+ Don't use this unless you overwrite the sg.Window class
57
+ :param window: Window Element
58
+ :param root: Window to put every element
59
+ :return:
60
+ """
61
+ self.window = window
62
+ self.window.add_flags(ElementFlag.IS_CREATED)
63
+ self.add_flags(ElementFlag.IS_CONTAINER)
64
+ self._init_widget(root)
65
+
66
+ def _update_special_key(self,key:str,new_val:any) -> bool|None:
67
+
68
+ match key:
69
+ case "apply_parent_background_color":
70
+ if new_val:
71
+ self.add_flags(ElementFlag.APPLY_PARENT_BACKGROUND_COLOR)
72
+ else:
73
+ self.remove_flags(ElementFlag.APPLY_PARENT_BACKGROUND_COLOR)
74
+
75
+ case "background_color":
76
+ for row in self._containing_row_frame_widgets:
77
+ row.configure(background=new_val)
78
+
79
+ for i in self._contains:
80
+ for elem in i:
81
+ if elem.has_flag(ElementFlag.APPLY_PARENT_BACKGROUND_COLOR):
82
+ elem.update(background_color = new_val)
83
+
84
+ return True
85
+ case _:
86
+ return False
87
+
88
+ return True
@@ -1,5 +1,6 @@
1
1
  import tkinter as tk
2
- from SwiftGUI import BaseWidget
2
+ from SwiftGUI import BaseWidget, ElementFlag
3
+
3
4
 
4
5
  class Spacer(BaseWidget):
5
6
  """
@@ -7,6 +8,10 @@ class Spacer(BaseWidget):
7
8
  """
8
9
  _tk_widget_class = tk.Frame
9
10
 
11
+ _transfer_keys = {
12
+ "background_color":"bg"
13
+ }
14
+
10
15
  def __init__(
11
16
  self,
12
17
  width:int = None,
@@ -14,6 +19,8 @@ class Spacer(BaseWidget):
14
19
  ):
15
20
  super().__init__()
16
21
 
22
+ self.add_flags(ElementFlag.APPLY_PARENT_BACKGROUND_COLOR)
23
+
17
24
  self._tk_kwargs = {
18
25
  "width":width,
19
26
  "height":height,
@@ -30,6 +30,7 @@ class Text(BaseWidget):
30
30
  anchor:Literals.anchor = None,
31
31
  justify:Literal["left","right","center"] = None,
32
32
  background_color:str|Color = None,
33
+ apply_parent_background_color:bool = None,
33
34
  text_color:str|Color = None,
34
35
  relief:Literals.relief = None,
35
36
  padding:Literals.padding = None,
@@ -62,6 +63,9 @@ class Text(BaseWidget):
62
63
  if tk_kwargs is None:
63
64
  tk_kwargs = dict()
64
65
 
66
+ if background_color and not apply_parent_background_color:
67
+ apply_parent_background_color = False
68
+
65
69
  _tk_kwargs = {
66
70
  **tk_kwargs,
67
71
  "cursor":cursor,
@@ -82,6 +86,7 @@ class Text(BaseWidget):
82
86
  "font_underline":font_underline,
83
87
  "font_overstrike":font_overstrike,
84
88
  "anchor":anchor,
89
+ "apply_parent_background_color": apply_parent_background_color,
85
90
  }
86
91
  self.update(**_tk_kwargs)
87
92
 
@@ -124,6 +129,11 @@ class Text(BaseWidget):
124
129
  self._tk_kwargs["background"] = self.defaults.single(key,new_val)
125
130
  case "text_color":
126
131
  self._tk_kwargs["foreground"] = self.defaults.single(key,new_val)
132
+ case "apply_parent_background_color":
133
+ if new_val:
134
+ self.add_flags(ElementFlag.APPLY_PARENT_BACKGROUND_COLOR)
135
+ else:
136
+ self.remove_flags(ElementFlag.APPLY_PARENT_BACKGROUND_COLOR)
127
137
  case _: # Not a match
128
138
  return False
129
139
 
@@ -0,0 +1,192 @@
1
+ import tkinter as tk
2
+ from tkinter import colorchooser
3
+ from collections.abc import Iterable, Callable
4
+ from typing import Literal
5
+
6
+ from SwiftGUI import GlobalOptions, Literals, Color
7
+ from SwiftGUI.Widgets.Button import Button
8
+
9
+
10
+ class ColorChooserButton(Button):
11
+ """
12
+ Small Element to create a button that lets you chose a color
13
+ """
14
+ tk_widget:tk.Button
15
+ _tk_widget_class:type = tk.Button # Class of the connected widget
16
+ defaults = GlobalOptions.ColorChooserButton
17
+
18
+ def __init__(
19
+ # https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/button.html
20
+
21
+ self,
22
+ # Add here
23
+ text:str = "",
24
+ /,
25
+ key:any = None,
26
+ key_function:Callable|Iterable[Callable] = None,
27
+
28
+ initial_color: str | Color = None,
29
+ color_chooser_title: str = None,
30
+
31
+ borderwidth:int = None,
32
+
33
+ bitmap:Literals.bitmap = None,
34
+ disabled:bool = None,
35
+ text_color_disabled: str | Color = None,
36
+ background_color_active: str | Color = None,
37
+ text_color_active: str | Color = None,
38
+
39
+ width: int = None,
40
+ height: int = None,
41
+ padx:int = None,
42
+ pady:int = None,
43
+
44
+ cursor: Literals.cursor = None,
45
+ takefocus: bool = None,
46
+
47
+ underline: int = None,
48
+ anchor: Literals.anchor = None,
49
+ justify: Literal["left", "right", "center"] = None,
50
+ #background_color: str | Color = None,
51
+ overrelief: Literals.relief = None,
52
+ text_color: str | Color = None,
53
+ relief: Literals.relief = None,
54
+
55
+ repeatdelay:int = None,
56
+ repeatinterval:int = None,
57
+
58
+ # # Mixed options
59
+ fonttype: str = None,
60
+ fontsize: int = None,
61
+ font_bold: bool = None,
62
+ font_italic: bool = None,
63
+ font_underline: bool = None,
64
+ font_overstrike: bool = None,
65
+
66
+ expand: bool = None,
67
+ tk_kwargs: dict[str:any] = None
68
+ ):
69
+ """
70
+ A button that throws an event every time it is pushed
71
+
72
+ :param text: Text the button displays
73
+ :param key: (See docs for more details)
74
+ :param key_function: (See docs for more details)
75
+
76
+ :param initial_color: Color that should be displayed in the beginning
77
+
78
+
79
+ :param borderwidth: Border-Thickness in pixels. Default is 2
80
+ :param bitmap: The are a couple of icons builtin. If you are using PyCharm, they should be suggested when pressing "ctrl+space"
81
+ :param disabled: True, if this button should not be pressable
82
+ :param text_color_disabled: Text color, if disabled = True
83
+ :param background_color_active: Background color shown only when the button is held down
84
+ :param text_color_active: Text color only shown when the button is held down
85
+ :param width: Button-size in x-direction in text-characters
86
+ :param height: Button-height in text-rows
87
+ :param padx: Adds space to both sides not filled with text. Should not be combined with "width". The value is given in characters
88
+ :param pady: Adds space to the top and bottom not filled with text. Should not be combined with "height". The value is given in rows
89
+ :param cursor: How the cursor should look when hovering over this element.
90
+ :param takefocus: True, if this element should be able to get focus (e.g. by pressing tab)
91
+ :param underline: Underlines the single character at this index
92
+ :param anchor: Specifies, where the text in this element should be placed (See docs for more details)
93
+ :param justify: When the text is multiple rows long, this will specify where the new rows begin.
94
+ :param overrelief: Relief when the mouse hovers over the element
95
+ :param text_color: Text-color in non-pressed state
96
+ :param relief: Relief in non-pressed state
97
+ :param repeatdelay: How long to hold the button until repeation starts (doesn't work without "repeatinterval")
98
+ :param repeatinterval: How long to wait between repetitions (doesn't work without "repeatdelay")
99
+ :param fonttype: Use sg.font_windows. ... to select some fancy font. Personally, I like sg.font_windows.Small_Fonts
100
+ :param fontsize: Size (height) of the font in pixels
101
+ :param font_bold: True, if thicc text
102
+ :param font_italic: True, if italic text
103
+ :param font_underline: True, if the text should be underlined
104
+ :param font_overstrike: True, if the text should be overstruck
105
+ :param tk_kwargs: (Only if you know tkinter) Pass more kwargs directly to the tk-widget
106
+ """
107
+ if callable(key_function):
108
+ key_function = (self._button_callback,key_function)
109
+ elif key_function:
110
+ key_function = (self._button_callback,*tuple(key_function))
111
+ else:
112
+ key_function = self._button_callback
113
+
114
+ super().__init__(
115
+ text,
116
+ key=key,
117
+ key_function=key_function,
118
+ borderwidth=borderwidth,
119
+ bitmap=bitmap,
120
+ disabled=disabled,
121
+ text_color_disabled=text_color_disabled,
122
+ background_color_active=background_color_active,
123
+ text_color_active=text_color_active,
124
+ width=width,
125
+ height=height,
126
+ padx=padx,
127
+ pady=pady,
128
+ cursor=cursor,
129
+ takefocus=takefocus,
130
+ underline=underline,
131
+ anchor=anchor,
132
+ justify=justify,
133
+ #background_color=background_color,
134
+ overrelief=overrelief,
135
+ text_color=text_color,
136
+ relief=relief,
137
+ repeatdelay=repeatdelay,
138
+ repeatinterval=repeatinterval,
139
+ fonttype=fonttype,
140
+ fontsize=fontsize,
141
+ font_bold=font_bold,
142
+ font_italic=font_italic,
143
+ font_underline=font_underline,
144
+ font_overstrike=font_overstrike,
145
+ expand=expand,
146
+ tk_kwargs=tk_kwargs,
147
+ )
148
+
149
+ self._file_function_kwargs = dict()
150
+
151
+ self.update(
152
+ initial_color = initial_color,
153
+ color_chooser_title = color_chooser_title,
154
+ )
155
+
156
+ _prev_val:str = None
157
+ def _button_callback(self):
158
+ # Call the file-dialogue
159
+ _,temp = colorchooser.askcolor(initialcolor=self._prev_val,title=self._title)
160
+
161
+ if temp is None:
162
+ return
163
+
164
+ self.value = str(temp)
165
+
166
+ return True # Refresh values for coming key_functions
167
+
168
+ def _get_value(self) -> any:
169
+ return self._prev_val
170
+
171
+ def set_value(self,val:any):
172
+ self._prev_val = val
173
+ self.update(background_color = val)
174
+
175
+ _title:str = None
176
+ def _update_special_key(self,key:str,new_val:any) -> bool|None:
177
+ if super()._update_special_key(key,new_val):
178
+ return True
179
+
180
+ match key:
181
+ case "initial_color":
182
+ self.value = new_val
183
+ case "color_chooser_title":
184
+ self._title = new_val
185
+ case _:
186
+ return False
187
+
188
+ return True
189
+
190
+ def _personal_init_inherit(self):
191
+ pass # Avoid creating a target variable for this button, so the text can be changed with .update(text="...")
192
+
@@ -1,12 +1,10 @@
1
- import inspect
2
1
  import tkinter as tk
3
2
  from os import PathLike
4
3
  from tkinter import filedialog as fd
5
- import tkinter.font as font
6
4
  from collections.abc import Iterable, Callable
7
5
  from typing import Literal
8
6
 
9
- from SwiftGUI import BaseElement, ElementFlag, BaseWidget, BaseWidgetContainer, GlobalOptions, Literals, Color
7
+ from SwiftGUI import GlobalOptions, Literals, Color
10
8
  from SwiftGUI.Widgets.Button import Button
11
9
 
12
10
 
@@ -127,6 +127,8 @@ class Window(BaseElement):
127
127
  background_color = GlobalOptions.Window.single("background_color",background_color)
128
128
 
129
129
  if background_color is not None:
130
+ if _first_update:
131
+ print("Warning! It is not possible to change background_color on an already created window (yet)...")
130
132
  self._sg_widget.update(background_color=background_color)
131
133
 
132
134
  if title is not None:
@@ -19,6 +19,7 @@ from .Widgets.Listbox import Listbox
19
19
 
20
20
  from .WidgetsAdvanced.Form import Form
21
21
  from .WidgetsAdvanced.FileBrowseButton import FileBrowseButton
22
+ from .WidgetsAdvanced.ColorChooserButton import ColorChooserButton
22
23
 
23
24
  T = Text
24
25
 
@@ -32,7 +33,7 @@ Check = Checkbox
32
33
 
33
34
  Column = Frame
34
35
 
35
- AnyElement = BaseElement | BaseWidget | Text | Button | Checkbox | Frame | Input | VerticalSeparator | HorizontalSeparator | Spacer | Form | Listbox | FileBrowseButton
36
+ AnyElement = BaseElement | BaseWidget | Text | Button | Checkbox | Frame | Input | VerticalSeparator | HorizontalSeparator | Spacer | Form | Listbox | FileBrowseButton | ColorChooserButton
36
37
 
37
38
  from .Windows import Window
38
39
 
@@ -1,61 +0,0 @@
1
- import tkinter as tk
2
- import tkinter.font as font
3
- import tkinter.ttk as ttk
4
- from collections.abc import Iterable, Callable
5
- from typing import Literal
6
-
7
- from SwiftGUI import BaseElement, ElementFlag, BaseWidget, BaseWidgetContainer, GlobalOptions, Literals, Color
8
-
9
- class Frame(BaseWidgetContainer):
10
- """
11
- Copy this class ot create your own Widget
12
- """
13
- _tk_widget_class:type[ttk.Frame] = tk.Frame # Class of the connected widget
14
- defaults = GlobalOptions.Frame
15
-
16
- _transfer_keys = {
17
- "background_color":"background"
18
- }
19
-
20
- def __init__(
21
- self,
22
- layout:Iterable[Iterable[BaseElement]],
23
- /,
24
- alignment:Literals.alignment = None,
25
- expand:bool = False,
26
- background_color:Color = None,
27
- # Add here
28
- tk_kwargs:dict[str:any]=None,
29
- ):
30
- super().__init__(tk_kwargs=tk_kwargs)
31
-
32
- self._contains = layout
33
-
34
- if tk_kwargs is None:
35
- tk_kwargs = dict()
36
-
37
- _tk_kwargs = {
38
- **tk_kwargs,
39
- # Insert named arguments for the widget here
40
- "background_color":background_color,
41
- }
42
- self.update(**_tk_kwargs)
43
-
44
- self._insert_kwargs["expand"] = self.defaults.single("expand",expand)
45
-
46
- self._insert_kwargs_rows.update({
47
- "side":self.defaults.single("alignment",alignment),
48
- })
49
-
50
- def window_entry_point(self,root:tk.Tk|tk.Widget,window:BaseElement):
51
- """
52
- Starting point for the whole window, or part of the layout.
53
- Don't use this unless you overwrite the sg.Window class
54
- :param window: Window Element
55
- :param root: Window to put every element
56
- :return:
57
- """
58
- self.window = window
59
- self.window.add_flags(ElementFlag.IS_CREATED)
60
- self.add_flags(ElementFlag.IS_CONTAINER)
61
- self._init_widget(root)
File without changes
File without changes
File without changes
File without changes