summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gui/simulator/drawing_panel.py11
-rw-r--r--lib/gui/simulator/simulator_panel.py1
-rw-r--r--lib/utils/__init__.py1
-rwxr-xr-xlib/utils/paths.py4
-rw-r--r--lib/utils/settings.py32
5 files changed, 30 insertions, 19 deletions
diff --git a/lib/gui/simulator/drawing_panel.py b/lib/gui/simulator/drawing_panel.py
index abe6fa0f..d6546c47 100644
--- a/lib/gui/simulator/drawing_panel.py
+++ b/lib/gui/simulator/drawing_panel.py
@@ -66,6 +66,11 @@ class DrawingPanel(wx.Panel):
self.show_page = global_settings['toggle_page_button_status']
self.background_color = None
+ # Set initial values as they may be accessed before a stitch plan is available
+ # for example through a focus action on the stitch box
+ self.num_stitches = 1
+ self.commands = [None]
+
# desired simulation speed in stitches per second
self.speed = global_settings['simulator_speed']
@@ -435,7 +440,11 @@ class DrawingPanel(wx.Panel):
def set_current_stitch(self, stitch):
self.current_stitch = stitch
self.clamp_current_stitch()
- command = self.commands[int(self.current_stitch)]
+ try:
+ command = self.commands[int(self.current_stitch)]
+ except IndexError:
+ # no stitch plan loaded yet, do nothing for now
+ return
self.control_panel.on_current_stitch(int(self.current_stitch), command)
statusbar = self.GetTopLevelParent().statusbar
statusbar.SetStatusText(_("Command: %s") % COMMAND_NAMES[command], 2)
diff --git a/lib/gui/simulator/simulator_panel.py b/lib/gui/simulator/simulator_panel.py
index 1cea9214..efbb2a62 100644
--- a/lib/gui/simulator/simulator_panel.py
+++ b/lib/gui/simulator/simulator_panel.py
@@ -58,7 +58,6 @@ class SimulatorPanel(wx.Panel):
(wx.ACCEL_SHIFT, ord('='), self.cp.animation_one_stitch_forward),
(wx.ACCEL_NORMAL, wx.WXK_ADD, self.cp.animation_one_stitch_forward),
(wx.ACCEL_NORMAL, wx.WXK_NUMPAD_ADD, self.cp.animation_one_stitch_forward),
- (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_UP, self.cp.animation_one_stitch_forward),
(wx.ACCEL_NORMAL, ord('-'), self.cp.animation_one_stitch_backward),
(wx.ACCEL_NORMAL, ord('_'), self.cp.animation_one_stitch_backward),
(wx.ACCEL_NORMAL, wx.WXK_SUBTRACT, self.cp.animation_one_stitch_backward),
diff --git a/lib/utils/__init__.py b/lib/utils/__init__.py
index 60a0bd36..b24257be 100644
--- a/lib/utils/__init__.py
+++ b/lib/utils/__init__.py
@@ -3,7 +3,6 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-from . import cache as cache_module # Slight hack to allow cache to be imported for monkeypatching
from .cache import cache
from .dotdict import DotDict
from .geometry import *
diff --git a/lib/utils/paths.py b/lib/utils/paths.py
index 3bc12c2a..542a0f2d 100755
--- a/lib/utils/paths.py
+++ b/lib/utils/paths.py
@@ -41,12 +41,12 @@ def get_resource_dir(name):
return realpath(os.path.join(dirname(realpath(__file__)), '..', '..', name))
-def get_user_dir(name=None):
+def get_user_dir(name=None, create=True):
try:
path = platformdirs.user_config_dir('inkstitch')
except ImportError:
path = os.path.expanduser('~/.inkstitch')
- if not os.path.exists(path):
+ if create and not os.path.exists(path):
os.makedirs(path)
if name is not None:
diff --git a/lib/utils/settings.py b/lib/utils/settings.py
index 42e6b233..501798ac 100644
--- a/lib/utils/settings.py
+++ b/lib/utils/settings.py
@@ -45,40 +45,44 @@ DEFAULT_SETTINGS = {
class GlobalSettings(MutableMapping):
def __init__(self):
super().__init__()
- self.__settings_file = os.path.join(get_user_dir(), "settings.json")
- self.__settings = {}
+ # We set create=False here because this code is executed on module load
+ # and via imports also runs on generate-inx-files, which with the Nix
+ # package manager is executed with a non-writable home directory.
+ user_dir = get_user_dir(create=False)
+ self._settings_file = os.path.join(user_dir, "settings.json")
+ self._settings = {}
for name, value in DEFAULT_METADATA.items():
- self.__settings[f"default_{name}"] = value
+ self._settings[f"default_{name}"] = value
- self.__settings.update(DEFAULT_SETTINGS)
+ self._settings.update(DEFAULT_SETTINGS)
try:
- with open(self.__settings_file, 'r') as settings_file:
- self.__settings.update(json.load(settings_file))
+ with open(self._settings_file, 'r') as settings_file:
+ self._settings.update(json.load(settings_file))
except (OSError, json.JSONDecodeError, ValueError):
pass
def __setitem__(self, item, value):
- self.__settings[item] = value
+ self._settings[item] = value
- with open(self.__settings_file, 'w') as settings_file:
- json.dump(self.__settings, settings_file)
+ with open(self._settings_file, 'w') as settings_file:
+ json.dump(self._settings, settings_file)
def __getitem__(self, item):
- return self.__settings[item]
+ return self._settings[item]
def __delitem__(self, item):
- del self.__settings[item]
+ del self._settings[item]
def __iter__(self):
- return iter(self.__settings)
+ return iter(self._settings)
def __len__(self):
- return len(self.__settings)
+ return len(self._settings)
def __json__(self):
- return self.__settings
+ return self._settings
global_settings = GlobalSettings()