Skip to content

Commit 6a4dd60

Browse files
committed
- additional lazy imports to speed up startup time
. internal: pid, piddialogs, large_lcds, simulator, scheduler . external: babel, scipy, mqtt, s7 - drop pyyaml and switch to JSON for logging configuration - prevent loading of large module cocoa if not strictly needed
1 parent aa79f38 commit 6a4dd60

22 files changed

Lines changed: 382 additions & 304 deletions

src/artisan-mac.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ DATA_FILES = [
122122
(r'includes/Machines', './Machines'),
123123
(r'includes/Themes', './Themes'),
124124
(r'includes/Icons', './Icons'),
125-
(r'includes/logging.yaml', '.')
125+
(r'includes/logging.json', '.')
126126
]
127127

128128
# add Artisan translations to DATA_FILES

src/artisan-win.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ for fn in [
313313
r'includes\mstile-150x150.png',
314314
r'includes\safari-pinned-tab.svg',
315315
r'includes\site.webmanifest',
316-
r'includes\logging.yaml',
316+
r'includes\logging.json',
317317
r'includes\artisan_public_key.pem',
318318
]:
319319
copy_file(fn, TARGET)

src/artisanlib/button_style.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
}}
148148
""",
149149
'ON': """
150-
QPushButton {
150+
QPushButton {{
151151
min-width: {min_width}px;
152152
border-style:solid;
153153
border-radius:20px;
@@ -157,22 +157,22 @@
157157
font-weight: bold;
158158
color: #cc0f50;
159159
background-color: white;
160-
}
161-
QPushButton:!enabled {
160+
}}
161+
QPushButton:!enabled {{
162162
color: darkgrey;
163163
background-color: #E0E0E0;
164-
}
165-
QPushButton:pressed {
164+
}}
165+
QPushButton:pressed {{
166166
color: #c70d49;
167167
background-color: #EEEEEE;
168-
}
169-
QPushButton:hover:!pressed {
168+
}}
169+
QPushButton:hover:!pressed {{
170170
color: #d4336a;
171171
background-color: #F5F5F5;
172-
}
172+
}}
173173
""",
174174
'STOP': """
175-
QPushButton {
175+
QPushButton {{
176176
min-width: {min_width}px;
177177
border-style:solid;
178178
border-radius:20px;
@@ -182,22 +182,22 @@
182182
font-weight: bold;
183183
color: #147bb3;
184184
background-color: white;
185-
}
186-
QPushButton:!enabled {
185+
}}
186+
QPushButton:!enabled {{
187187
color: #EFEFEF;
188188
background-color: darkgrey;
189-
}
190-
QPushButton:pressed {
189+
}}
190+
QPushButton:pressed {{
191191
color: #116999;
192192
background-color: #EEEEEE;
193-
}
194-
QPushButton:hover:!pressed {
193+
}}
194+
QPushButton:hover:!pressed {{
195195
color: #1985ba;
196196
background-color: #F5F5F5;
197-
}
197+
}}
198198
""",
199199
'START': """
200-
QPushButton {
200+
QPushButton {{
201201
min-width: {min_width}px;
202202
border-style:solid;
203203
border-radius:20px;
@@ -207,19 +207,19 @@
207207
font-weight: bold;
208208
color: yellow;
209209
background-color: #ff3d00;
210-
}
211-
QPushButton:!enabled {
210+
}}
211+
QPushButton:!enabled {{
212212
color: darkgrey;
213213
background-color: #E0E0E0;
214-
}
215-
QPushButton:pressed {
214+
}}
215+
QPushButton:pressed {{
216216
color: #EEEEEE;
217217
background-color: #116999;
218-
}
219-
QPushButton:hover:!pressed {
218+
}}
219+
QPushButton:hover:!pressed {{
220220
color: white;
221221
background-color: red;
222-
}
222+
}}
223223
""",
224224
}
225225

src/artisanlib/canvas.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import functools
4949
import psutil
5050
from psutil._common import bytes2human # pyright:ignore[reportPrivateImportUsage]
51-
from babel.units import get_unit_name
5251

5352
from collections.abc import Callable, Sequence
5453
from typing import override, Final, Literal, Any, cast, TYPE_CHECKING
@@ -9383,17 +9382,24 @@ def default_xlabel_text(self) -> str:
93839382
if self.flagstart or self.xgrid == 0:
93849383
return ''
93859384
if self.roastersize_setup == 0 and self.roastertype_setup == '':
9385+
93869386
if self.aw.qmc.xgrid < 3600:
9387+
res = 'mins'
9388+
if self.aw.locale_str != 'en':
9389+
try:
9390+
from babel.units import get_unit_name
9391+
res = get_unit_name('duration-minute', length='short', locale=self.aw.locale_str) or 'mins'
9392+
except Exception as e: # pylint: disable=broad-except # UnknownLocaleError
9393+
_log.exception(e)
9394+
return res
9395+
res = 'h'
9396+
if self.aw.locale_str != 'en':
93879397
try:
9388-
return get_unit_name('duration-minute', length='short', locale=self.aw.locale_str) or 'min'
9398+
from babel.units import get_unit_name
9399+
return get_unit_name('duration-hour', length='short', locale=self.aw.locale_str) or 'h'
93899400
except Exception as e: # pylint: disable=broad-except # UnknownLocaleError
93909401
_log.exception(e)
9391-
return get_unit_name('duration-minute', length='short', locale='en') or 'min'
9392-
try:
9393-
return get_unit_name('duration-hour', length='short', locale=self.aw.locale_str) or 'h'
9394-
except Exception as e: # pylint: disable=broad-except # UnknownLocaleError
9395-
_log.exception(e)
9396-
return get_unit_name('duration-hour', length='short', locale='en') or 'h'
9402+
return res
93979403
if right_to_left(self.locale_str):
93989404
return f"{(render_weight(self.roastersize_setup, 1, weight_units.index(self.weight[2]), right_to_left_lang=True) if self.roastersize_setup>=0 else '')} {self.__dijkstra_to_ascii(self.roastertype_setup)}"
93999405
return f"{self.__dijkstra_to_ascii(self.roastertype_setup)} {(render_weight(self.roastersize_setup, 1, weight_units.index(self.weight[2])) if self.roastersize_setup>0 else '')}"

src/artisanlib/comm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,8 @@ def piddutycycle(self) -> tuple[float,float,float]:
711711
self.aw.qmc.updateLargePIDLCDs(sv='', duty='')
712712
return self.aw.qmc.timeclock.elapsedMilli(),-1,-1
713713
lcdformat = ('%.1f' if self.aw.qmc.LCDdecimalplaces else '%.0f')
714-
if (self.aw.qmc.device == 19 and not self.aw.pidcontrol.externalPIDControl()) or \
715-
(self.aw.qmc.device in {29, 79} and not self.aw.pidcontrol.externalPIDControl()):
714+
if not self.aw.pidcontrol.externalPIDControl() and \
715+
(self.aw.qmc.device == 19 or self.aw.qmc.device in {29, 79}):
716716
# TC4 (19) or MODBUS/S7 (29/79) with Artisan Software PID
717717
duty = self.aw.qmc.pid.getDuty()
718718
duty = (-1.0 if duty is None else min(100.0, max(-100.0, duty)))

src/artisanlib/devices.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import platform
3333
import logging
3434
from PIL import ImageColor
35-
from babel.units import get_unit_name
3635
from typing import override, Final, cast, TYPE_CHECKING
3736

3837
if TYPE_CHECKING:
@@ -2012,7 +2011,10 @@ def __init__(self, parent:QWidget, aw:'ApplicationWindow', activeTab:int = 0) ->
20122011
self.automaticRegistrationPeriod.setToolTip(QApplication.translate('Tooltip','Register the weight of a roasted batch automatically\nafter the given time (if not set to zero) without removing the filled container,\nenabling the addition of more batches'))
20132012
self.automaticRegistrationPeriod.setRange(0, 30)
20142013
self.automaticRegistrationPeriod.setAlignment(Qt.AlignmentFlag.AlignRight)
2014+
2015+
from babel.units import get_unit_name
20152016
unit_name = get_unit_name('duration-minute', length='short', locale=self.aw.locale_str)
2017+
20162018
self.automaticRegistrationPeriod.setSuffix(f" {unit_name if unit_name is not None else 'min'}")
20172019
self.automaticRegistrationPeriod.setValue(int(round(self.aw.automatic_registration_period/60.)))
20182020

0 commit comments

Comments
 (0)