summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/dotdict.py24
-rw-r--r--lib/utils/icons.py29
-rw-r--r--lib/utils/settings.py4
3 files changed, 49 insertions, 8 deletions
diff --git a/lib/utils/dotdict.py b/lib/utils/dotdict.py
index 12cf6e79..47f56623 100644
--- a/lib/utils/dotdict.py
+++ b/lib/utils/dotdict.py
@@ -3,6 +3,7 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+
class DotDict(dict):
"""A dict subclass that allows accessing methods using dot notation.
@@ -10,24 +11,33 @@ class DotDict(dict):
"""
def __init__(self, *args, **kwargs):
- super(DotDict, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self._dotdictify()
def update(self, *args, **kwargs):
- super(DotDict, self).update(*args, **kwargs)
+ super().update(*args, **kwargs)
self._dotdictify()
def _dotdictify(self):
for k, v in self.items():
- if isinstance(v, dict):
+ if isinstance(v, dict) and not isinstance(v, DotDict):
self[k] = DotDict(v)
- __setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
+ def __setattr__(self, name, value):
+ if name.startswith('_'):
+ super().__setattr__(name, value)
+ else:
+ if isinstance(value, dict) and not isinstance(value, DotDict):
+ value = DotDict(value)
+
+ super().__setitem__(name, value)
+
def __getattr__(self, name):
if name.startswith('_'):
- raise AttributeError("'DotDict' object has no attribute '%s'" % name)
+ raise AttributeError(
+ f"'{self.__class__.__name__}' object has no attribute '{name}'")
if name in self:
return self.__getitem__(name)
@@ -37,5 +47,5 @@ class DotDict(dict):
return new_dict
def __repr__(self):
- super_repr = super(DotDict, self).__repr__()
- return "DotDict(%s)" % super_repr
+ super_repr = super().__repr__()
+ return f"{self.__class__.__name__}({super_repr})"
diff --git a/lib/utils/icons.py b/lib/utils/icons.py
new file mode 100644
index 00000000..492d88ce
--- /dev/null
+++ b/lib/utils/icons.py
@@ -0,0 +1,29 @@
+import os
+
+import wx
+
+from .paths import get_resource_dir
+
+
+def is_dark_theme():
+ return wx.SystemSettings().GetAppearance().IsDark()
+
+
+def load_icon(icon_name, window=None, width=None, height=None):
+ if window is None and not (width and height):
+ raise ValueError("load_icon(): must pass a window or width and height")
+
+ icon = wx.Image(os.path.join(get_resource_dir("icons"), f"{icon_name}.png"))
+
+ if not (width and height):
+ render = wx.RendererNative.Get()
+ width = height = render.GetHeaderButtonHeight(window)
+ icon.Rescale(width, height, wx.IMAGE_QUALITY_HIGH)
+
+ if is_dark_theme():
+ # only way I've found to get a negative image
+ data = icon.GetDataBuffer()
+ for i in range(len(data)):
+ data[i] = 255 - data[i]
+
+ return icon.ConvertToBitmap()
diff --git a/lib/utils/settings.py b/lib/utils/settings.py
index e2287862..23e22b61 100644
--- a/lib/utils/settings.py
+++ b/lib/utils/settings.py
@@ -27,7 +27,9 @@ DEFAULT_SETTINGS = {
"color_change_button_status": False,
"toggle_page_button_status": True,
# apply palette
- "last_applied_palette": ""
+ "last_applied_palette": "",
+ # sew stack editor
+ "stitch_layer_editor_sash_position": -200,
}