happyscript 0.0.42__tar.gz → 0.0.44__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.
- {happyscript-0.0.42 → happyscript-0.0.44}/PKG-INFO +1 -1
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/__init__.py +2 -1
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/forms/form_main.py +11 -1
- happyscript-0.0.44/happyscript/forms/form_settings.py +94 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/forms/formsbase.py +103 -2
- happyscript-0.0.44/happyscript/inifile.py +163 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/staticscriptmanager.py +27 -5
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript.egg-info/PKG-INFO +1 -1
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript.egg-info/SOURCES.txt +2 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/pyproject.toml +1 -1
- {happyscript-0.0.42 → happyscript-0.0.44}/README.md +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/__init__.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/chart.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/histogram_chart.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/histogram_series.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/matplotlib_chart.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/panel_charts.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/scatter_chart.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/scatter_series.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/time_chart.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/charts/time_series.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/forms/form_askchoice.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/forms/form_askimage.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/forms/form_ontestfailure.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/forms/form_serials.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/forms/form_stop.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/imglib.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/modulereader.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/panels/panel_log.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/panels/panel_messages.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/panels/panel_scripts2.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/panels/panel_tests.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/panels/panelsbase.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptartwork.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptcontrol.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptexceptions.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptgui.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptinfo.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptmanager.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptparams.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptreader.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/scriptrunner.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/splashmenu/exit.png +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/splashmenu/forms.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/splashmenu/splashmenuform.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/splashmenu/splashmenumain.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/testlog/global_log_handler.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/testlog/log_to_text.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/testlog/logtoxml.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/testlog/printredirect.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/testloghandler.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/userpanel/userpanel.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript/userpanel/userpanelvalue.py +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript.egg-info/dependency_links.txt +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript.egg-info/requires.txt +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/happyscript.egg-info/top_level.txt +0 -0
- {happyscript-0.0.42 → happyscript-0.0.44}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""HappyScript - handy script launcher"""
|
|
2
2
|
|
|
3
|
-
__version__ = "0.0.
|
|
3
|
+
__version__ = "0.0.44"
|
|
4
4
|
|
|
5
5
|
# With these statements, after doing 'import happyscript' you can do 'xxx = happyscript.ScriptManager()'
|
|
6
6
|
#from .scriptmanager import ScriptManager
|
|
@@ -8,6 +8,7 @@ __version__ = "0.0.42"
|
|
|
8
8
|
|
|
9
9
|
from .scriptmanager import ScriptManager
|
|
10
10
|
from .staticscriptmanager import StaticScriptManager
|
|
11
|
+
from .inifile import IniFile
|
|
11
12
|
from .splashmenu.splashmenumain import SplashMenu
|
|
12
13
|
|
|
13
14
|
from .scriptcontrol import ScriptControl as Ctrl
|
|
@@ -363,4 +363,14 @@ class FormMain(FormMain_Base):
|
|
|
363
363
|
''' Clears the logs in the message area and the log window.
|
|
364
364
|
'''
|
|
365
365
|
self.msgArea.clear()
|
|
366
|
-
self.logPane.clear()
|
|
366
|
+
self.logPane.clear()
|
|
367
|
+
|
|
368
|
+
def OnMnuSettingsClicked( self, event ):
|
|
369
|
+
self._script_manager.show_settings()
|
|
370
|
+
|
|
371
|
+
def DisableSettingsButton(self):
|
|
372
|
+
''' Disable the settings button in the toolbar.
|
|
373
|
+
This is used when no ini file is set.
|
|
374
|
+
'''
|
|
375
|
+
self.m_mnuToolbar.EnableTool(self.m_btnSettings.GetId(), False)
|
|
376
|
+
# self.m_btnSettings.Hide()
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
import re
|
|
3
|
+
import wx
|
|
4
|
+
from .formsbase import FormSettings_Base
|
|
5
|
+
|
|
6
|
+
class FormSettings( FormSettings_Base ):
|
|
7
|
+
|
|
8
|
+
@classmethod
|
|
9
|
+
def show_modal( cls, parent, iniclass ):
|
|
10
|
+
|
|
11
|
+
frm = cls(parent, iniclass)
|
|
12
|
+
result = frm.ShowModal()
|
|
13
|
+
|
|
14
|
+
frm.Destroy()
|
|
15
|
+
|
|
16
|
+
def __init__( self, parent, iniclass ):
|
|
17
|
+
''' @param parent Control to put this panel in. Typically a notebook.
|
|
18
|
+
@param iniclass Class that inherits from happyscript.IniFile, which contains the settings to display.
|
|
19
|
+
'''
|
|
20
|
+
super().__init__(parent)
|
|
21
|
+
|
|
22
|
+
self.iniclass = iniclass
|
|
23
|
+
self.field_info = list()
|
|
24
|
+
self.show_fields()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def show_fields(self):
|
|
28
|
+
|
|
29
|
+
self.Scroll.GetChildren()[0].Hide()
|
|
30
|
+
|
|
31
|
+
scrollsizer = self.Scroll.GetSizer()
|
|
32
|
+
|
|
33
|
+
count = 0
|
|
34
|
+
|
|
35
|
+
for section_name in self.iniclass.sections():
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
sbsizer = wx.StaticBoxSizer( wx.StaticBox( self.Scroll, wx.ID_ANY, section_name ), wx.VERTICAL )
|
|
39
|
+
box = sbsizer.GetStaticBox()
|
|
40
|
+
|
|
41
|
+
fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 )
|
|
42
|
+
fgSizer1.AddGrowableCol( 1 )
|
|
43
|
+
fgSizer1.SetFlexibleDirection( wx.BOTH )
|
|
44
|
+
fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
|
|
45
|
+
|
|
46
|
+
cfg = self.iniclass[section_name]
|
|
47
|
+
for key, value in cfg.items():
|
|
48
|
+
|
|
49
|
+
label = wx.StaticText( box, wx.ID_ANY, key, wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
50
|
+
label.Wrap( -1 )
|
|
51
|
+
fgSizer1.Add( label, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 5 )
|
|
52
|
+
|
|
53
|
+
txtCtrl = wx.TextCtrl( box, wx.ID_ANY, value, wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
54
|
+
fgSizer1.Add( txtCtrl, 5, wx.ALL|wx.EXPAND, 5 )
|
|
55
|
+
|
|
56
|
+
self.field_info.append( (section_name, key, txtCtrl) )
|
|
57
|
+
|
|
58
|
+
sbsizer.Add( fgSizer1, 1, wx.EXPAND, 5 )
|
|
59
|
+
scrollsizer.Insert( count, sbsizer, 0, wx.EXPAND, 5 )
|
|
60
|
+
count += 1
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def OnBtnApply( self, event ):
|
|
65
|
+
|
|
66
|
+
msg = "OK to apply settings ?\n\n" \
|
|
67
|
+
"They will be written to the following file:\n" \
|
|
68
|
+
f"{self.iniclass._get_filename()}\n\n" \
|
|
69
|
+
"You may have to restart the program for the changes to take effect."
|
|
70
|
+
|
|
71
|
+
dlg = wx.MessageDialog(self, msg, "Happyscript", wx.OK | wx.CANCEL | wx.ICON_QUESTION)
|
|
72
|
+
if dlg.ShowModal() == wx.ID_OK:
|
|
73
|
+
self.save_settings()
|
|
74
|
+
self.EndModal(wx.ID_OK)
|
|
75
|
+
|
|
76
|
+
dlg.Destroy()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def OnBtnCancel( self, event ):
|
|
80
|
+
self.EndModal(wx.ID_CANCEL)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def save_settings(self):
|
|
84
|
+
''' Save the settings to the ini file.
|
|
85
|
+
This is called when the user clicks the "Apply" button.
|
|
86
|
+
'''
|
|
87
|
+
cfg = self.iniclass._get_configparser()
|
|
88
|
+
for section, key, txtCtrl in self.field_info:
|
|
89
|
+
value = txtCtrl.GetValue()
|
|
90
|
+
|
|
91
|
+
cfg.set(section, key, value)
|
|
92
|
+
# print(f"Setting {section}.{key} = {value}")
|
|
93
|
+
|
|
94
|
+
self.iniclass.write()
|
|
@@ -41,6 +41,8 @@ class FormMain_Base ( wx.Frame ):
|
|
|
41
41
|
|
|
42
42
|
self.m_btnLayout = self.m_mnuToolbar.AddTool( wx.ID_ANY, u"User", wx.ArtProvider.GetBitmap( "layout_DD", ), wx.NullBitmap, wx.ITEM_NORMAL, wx.EmptyString, wx.EmptyString, None )
|
|
43
43
|
|
|
44
|
+
self.m_btnSettings = self.m_mnuToolbar.AddTool( wx.ID_ANY, u"Settings", wx.ArtProvider.GetBitmap( "settings", ), wx.NullBitmap, wx.ITEM_NORMAL, wx.EmptyString, wx.EmptyString, None )
|
|
45
|
+
|
|
44
46
|
self.m_mnuToolbar.AddSeparator()
|
|
45
47
|
|
|
46
48
|
self.m_btnTestList = self.m_mnuToolbar.AddTool( ID_BTN_TESTLIST, u"Tests", wx.ArtProvider.GetBitmap( "tests", ), wx.NullBitmap, wx.ITEM_NORMAL, wx.EmptyString, wx.EmptyString, None )
|
|
@@ -98,6 +100,7 @@ class FormMain_Base ( wx.Frame ):
|
|
|
98
100
|
self.Bind( wx.EVT_CLOSE, self.OnFormClose )
|
|
99
101
|
self.Bind( wx.EVT_TIMER, self.OnGuiTimer, id=self.m_guiTimer.GetId() )
|
|
100
102
|
self.Bind( wx.EVT_TOOL, self.OnMnuLayoutClicked, id = self.m_btnLayout.GetId() )
|
|
103
|
+
self.Bind( wx.EVT_TOOL, self.OnMnuSettingsClicked, id = self.m_btnSettings.GetId() )
|
|
101
104
|
self.Bind( wx.EVT_TOOL, self.OnBtnTestList, id = self.m_btnTestList.GetId() )
|
|
102
105
|
self.Bind( wx.EVT_TOOL, self.OnBtnMessages, id = self.m_btnMessages.GetId() )
|
|
103
106
|
self.Bind( wx.EVT_TOOL, self.OnBtnLogging, id = self.m_btnLogging.GetId() )
|
|
@@ -127,6 +130,9 @@ class FormMain_Base ( wx.Frame ):
|
|
|
127
130
|
def OnMnuLayoutClicked( self, event ):
|
|
128
131
|
event.Skip()
|
|
129
132
|
|
|
133
|
+
def OnMnuSettingsClicked( self, event ):
|
|
134
|
+
event.Skip()
|
|
135
|
+
|
|
130
136
|
def OnBtnTestList( self, event ):
|
|
131
137
|
event.Skip()
|
|
132
138
|
|
|
@@ -174,7 +180,7 @@ class FormMain_Base ( wx.Frame ):
|
|
|
174
180
|
class FormSerials_Base ( wx.Dialog ):
|
|
175
181
|
|
|
176
182
|
def __init__( self, parent ):
|
|
177
|
-
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Scan serial numbers", pos = wx.DefaultPosition, size = wx.Size( 400,431 ), style =
|
|
183
|
+
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Scan serial numbers", pos = wx.DefaultPosition, size = wx.Size( 400,431 ), style = 0 )
|
|
178
184
|
|
|
179
185
|
self.SetSizeHints( wx.DefaultSize, wx.Size( 400,500 ) )
|
|
180
186
|
|
|
@@ -562,7 +568,7 @@ class FormAskChoice_Base ( wx.Dialog ):
|
|
|
562
568
|
class FormOnTestFailure_Base ( wx.Dialog ):
|
|
563
569
|
|
|
564
570
|
def __init__( self, parent ):
|
|
565
|
-
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Error", pos = wx.DefaultPosition, size = wx.Size( 356,229 ), style = wx.CAPTION
|
|
571
|
+
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Error", pos = wx.DefaultPosition, size = wx.Size( 356,229 ), style = wx.CAPTION )
|
|
566
572
|
|
|
567
573
|
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
|
|
568
574
|
self.SetForegroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOW ) )
|
|
@@ -658,3 +664,98 @@ class FormStop_base ( wx.Dialog ):
|
|
|
658
664
|
event.Skip()
|
|
659
665
|
|
|
660
666
|
|
|
667
|
+
###########################################################################
|
|
668
|
+
## Class FormSettings_Base
|
|
669
|
+
###########################################################################
|
|
670
|
+
|
|
671
|
+
class FormSettings_Base ( wx.Dialog ):
|
|
672
|
+
|
|
673
|
+
def __init__( self, parent ):
|
|
674
|
+
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Settings", pos = wx.DefaultPosition, size = wx.Size( 543,623 ), style = wx.CAPTION|wx.RESIZE_BORDER )
|
|
675
|
+
|
|
676
|
+
self.SetSizeHints( wx.Size( 320,240 ), wx.DefaultSize )
|
|
677
|
+
|
|
678
|
+
bSizer9 = wx.BoxSizer( wx.HORIZONTAL )
|
|
679
|
+
|
|
680
|
+
self.Scroll = wx.ScrolledWindow( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.VSCROLL )
|
|
681
|
+
self.Scroll.SetScrollRate( 5, 5 )
|
|
682
|
+
ScrollSizer = wx.BoxSizer( wx.VERTICAL )
|
|
683
|
+
|
|
684
|
+
delete_me = wx.StaticBoxSizer( wx.StaticBox( self.Scroll, wx.ID_ANY, u"toy" ), wx.VERTICAL )
|
|
685
|
+
|
|
686
|
+
fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 )
|
|
687
|
+
fgSizer1.AddGrowableCol( 1 )
|
|
688
|
+
fgSizer1.SetFlexibleDirection( wx.BOTH )
|
|
689
|
+
fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
|
|
690
|
+
|
|
691
|
+
self.m_staticText21 = wx.StaticText( delete_me.GetStaticBox(), wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
692
|
+
self.m_staticText21.Wrap( -1 )
|
|
693
|
+
|
|
694
|
+
fgSizer1.Add( self.m_staticText21, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 5 )
|
|
695
|
+
|
|
696
|
+
self.m_textCtrl17 = wx.TextCtrl( delete_me.GetStaticBox(), wx.ID_ANY, u"Dit is een test", wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
697
|
+
fgSizer1.Add( self.m_textCtrl17, 5, wx.ALL|wx.EXPAND, 5 )
|
|
698
|
+
|
|
699
|
+
self.m_staticText22 = wx.StaticText( delete_me.GetStaticBox(), wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
700
|
+
self.m_staticText22.Wrap( -1 )
|
|
701
|
+
|
|
702
|
+
fgSizer1.Add( self.m_staticText22, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 5 )
|
|
703
|
+
|
|
704
|
+
self.m_textCtrl18 = wx.TextCtrl( delete_me.GetStaticBox(), wx.ID_ANY, u"Nog een test", wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
705
|
+
fgSizer1.Add( self.m_textCtrl18, 5, wx.ALL|wx.EXPAND, 5 )
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
delete_me.Add( fgSizer1, 1, wx.EXPAND, 5 )
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
ScrollSizer.Add( delete_me, 0, wx.EXPAND, 5 )
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
ScrollSizer.Add( ( 0, 0), 1, wx.EXPAND, 5 )
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
self.Scroll.SetSizer( ScrollSizer )
|
|
718
|
+
self.Scroll.Layout()
|
|
719
|
+
ScrollSizer.Fit( self.Scroll )
|
|
720
|
+
bSizer9.Add( self.Scroll, 1, wx.EXPAND |wx.ALL, 5 )
|
|
721
|
+
|
|
722
|
+
bSizer10 = wx.BoxSizer( wx.VERTICAL )
|
|
723
|
+
|
|
724
|
+
self.btnApply = wx.Button( self, wx.ID_ANY, u"Apply", wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
725
|
+
self.btnApply.SetMinSize( wx.Size( -1,40 ) )
|
|
726
|
+
|
|
727
|
+
bSizer10.Add( self.btnApply, 0, wx.ALL, 5 )
|
|
728
|
+
|
|
729
|
+
self.btnCancel = wx.Button( self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
730
|
+
self.btnCancel.SetMinSize( wx.Size( -1,40 ) )
|
|
731
|
+
|
|
732
|
+
bSizer10.Add( self.btnCancel, 0, wx.ALL, 5 )
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
bSizer10.Add( ( 0, 0), 1, wx.EXPAND, 5 )
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
bSizer9.Add( bSizer10, 0, wx.EXPAND, 5 )
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
self.SetSizer( bSizer9 )
|
|
742
|
+
self.Layout()
|
|
743
|
+
|
|
744
|
+
self.Centre( wx.BOTH )
|
|
745
|
+
|
|
746
|
+
# Connect Events
|
|
747
|
+
self.btnApply.Bind( wx.EVT_BUTTON, self.OnBtnApply )
|
|
748
|
+
self.btnCancel.Bind( wx.EVT_BUTTON, self.OnBtnCancel )
|
|
749
|
+
|
|
750
|
+
def __del__( self ):
|
|
751
|
+
pass
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
# Virtual event handlers, override them in your derived class
|
|
755
|
+
def OnBtnApply( self, event ):
|
|
756
|
+
event.Skip()
|
|
757
|
+
|
|
758
|
+
def OnBtnCancel( self, event ):
|
|
759
|
+
event.Skip()
|
|
760
|
+
|
|
761
|
+
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# ____ _ _
|
|
2
|
+
# | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Ini-file base class for happyscript
|
|
3
|
+
# | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2023 | Project : n/a
|
|
4
|
+
# | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
|
|
5
|
+
# |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 14/8/2025
|
|
6
|
+
#__________________________________________________|_________________________________________________________
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
import os, configparser
|
|
10
|
+
|
|
11
|
+
class IniFileMeta(type):
|
|
12
|
+
def __getitem__(self, arg):
|
|
13
|
+
''' This method is called when the class is indexed with square brackets, e.g. IniFile['section_name'].
|
|
14
|
+
'self' refers to the class itself, and 'arg' is the section name being requested.
|
|
15
|
+
'''
|
|
16
|
+
# print("__getitem__:", self, arg)
|
|
17
|
+
return self.get_section(arg)
|
|
18
|
+
|
|
19
|
+
def __contains__(self, arg):
|
|
20
|
+
# print("__contains__:", self, arg)
|
|
21
|
+
return self.has_section(arg)
|
|
22
|
+
|
|
23
|
+
class IniFile(metaclass=IniFileMeta):
|
|
24
|
+
|
|
25
|
+
__configparser_object = None
|
|
26
|
+
__filename = None
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def read(cls, filename: str, /, generate_default: bool = True):
|
|
30
|
+
''' Read values from the given ini-file.
|
|
31
|
+
Only sections and values that are present as inner classes of this class will be read.
|
|
32
|
+
If the file does not exist, it can be created with default values.
|
|
33
|
+
|
|
34
|
+
:param filename: The name of the ini-file to read.
|
|
35
|
+
:param generate_default: If True, the file will be created with default values if it does not exist.
|
|
36
|
+
'''
|
|
37
|
+
|
|
38
|
+
inifile = configparser.ConfigParser()
|
|
39
|
+
cls.__configparser_object = inifile # store the configparser object for later use
|
|
40
|
+
|
|
41
|
+
filename = os.path.normpath(os.path.abspath(filename)) # get the absolute, normalized path to the file
|
|
42
|
+
cls.__filename = filename # store the filename for later use
|
|
43
|
+
|
|
44
|
+
file_exists = os.path.exists(filename) # check if the file exists and read it if it does
|
|
45
|
+
if file_exists:
|
|
46
|
+
inifile.read(filename)
|
|
47
|
+
|
|
48
|
+
for section, attr in cls.dataclass_sections(): # go over all the sections defined in the class
|
|
49
|
+
|
|
50
|
+
if inifile.has_section(section): # if section exists in the config file
|
|
51
|
+
for field in attr.__dataclass_fields__:
|
|
52
|
+
if inifile.has_option(section, field): # read our class values from the inifile if present
|
|
53
|
+
value = inifile.get(section, field)
|
|
54
|
+
if value is not None:
|
|
55
|
+
setattr(attr, field, value)
|
|
56
|
+
else:
|
|
57
|
+
value = getattr(attr, field) # write our class value as default if not present in the inifile
|
|
58
|
+
inifile.set(section, field, str(value))
|
|
59
|
+
|
|
60
|
+
else: # if section does not exist, create it and copy the default values
|
|
61
|
+
inifile.add_section(section)
|
|
62
|
+
for field in attr.__dataclass_fields__:
|
|
63
|
+
value = getattr(attr, field)
|
|
64
|
+
if value is not None: # only write the field if it has a value
|
|
65
|
+
inifile.set(section, field, str(value))
|
|
66
|
+
|
|
67
|
+
if not file_exists and generate_default: # create the file with default values if it does not exist
|
|
68
|
+
with open(filename, 'w') as f:
|
|
69
|
+
inifile.write(f)
|
|
70
|
+
|
|
71
|
+
from .staticscriptmanager import StaticScriptManager
|
|
72
|
+
StaticScriptManager._set_ini(cls) # set the ini file class in the script manager
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def _get_configparser(cls):
|
|
76
|
+
''' Returns the configparser object that was created by the read() method. '''
|
|
77
|
+
return cls.__configparser_object
|
|
78
|
+
|
|
79
|
+
@classmethod
|
|
80
|
+
def _get_filename(cls):
|
|
81
|
+
''' Returns the filename of the ini file that was read by the read() method. '''
|
|
82
|
+
return cls.__filename
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def dataclass_sections(cls):
|
|
86
|
+
for attr_name in dir(cls):
|
|
87
|
+
attr = getattr(cls, attr_name)
|
|
88
|
+
if isinstance(attr, type) and hasattr(attr, "__dataclass_fields__"):
|
|
89
|
+
yield attr_name, attr
|
|
90
|
+
|
|
91
|
+
@classmethod
|
|
92
|
+
def print_dataclass(cls):
|
|
93
|
+
for section, attr in cls.dataclass_sections():
|
|
94
|
+
print(f"{section}:")
|
|
95
|
+
for field in attr.__dataclass_fields__:
|
|
96
|
+
value = getattr(attr, field)
|
|
97
|
+
print(f"* {field} = {value}")
|
|
98
|
+
|
|
99
|
+
@classmethod
|
|
100
|
+
def write(cls):
|
|
101
|
+
''' Write the current values to the ini-file.
|
|
102
|
+
Any changes to the file will be lost.
|
|
103
|
+
TODO:
|
|
104
|
+
'''
|
|
105
|
+
assert cls._get_filename() is not None, "You must first read the settings from a file before doing a write(). " \
|
|
106
|
+
"Note that you can do read() even if the file does not exist."
|
|
107
|
+
|
|
108
|
+
config = cls._get_configparser() or configparser.ConfigParser()
|
|
109
|
+
|
|
110
|
+
for section, attr in cls.dataclass_sections():
|
|
111
|
+
if not config.has_section(section):
|
|
112
|
+
config.add_section(section)
|
|
113
|
+
|
|
114
|
+
for field in attr.__dataclass_fields__:
|
|
115
|
+
if not config.has_option(section, field):
|
|
116
|
+
value = getattr(attr, field)
|
|
117
|
+
config.set(section, field, value)
|
|
118
|
+
|
|
119
|
+
with open(cls._get_filename(), 'w') as configfile:
|
|
120
|
+
config.write(configfile)
|
|
121
|
+
|
|
122
|
+
@classmethod
|
|
123
|
+
def get_section(cls, name:str):
|
|
124
|
+
''' returns a configparser section for the given name, or an empty section if the name is not found.
|
|
125
|
+
'''
|
|
126
|
+
|
|
127
|
+
if cls.__configparser_object is not None and name in cls.__configparser_object.sections():
|
|
128
|
+
ini = cls.__configparser_object
|
|
129
|
+
else:
|
|
130
|
+
ini = configparser.ConfigParser()
|
|
131
|
+
ini.read_string(f"[{name}]\n\n")
|
|
132
|
+
|
|
133
|
+
return ini[name]
|
|
134
|
+
|
|
135
|
+
@classmethod
|
|
136
|
+
def sections(cls):
|
|
137
|
+
''' Returns a list of all sections in the ini file. '''
|
|
138
|
+
if cls.__configparser_object is not None:
|
|
139
|
+
return cls.__configparser_object.sections()
|
|
140
|
+
else:
|
|
141
|
+
return []
|
|
142
|
+
|
|
143
|
+
@classmethod
|
|
144
|
+
def has_section(cls, section: str) -> bool:
|
|
145
|
+
''' Checks if the given section exists in the ini file. '''
|
|
146
|
+
if cls.__configparser_object is not None:
|
|
147
|
+
return cls.__configparser_object.has_section(section)
|
|
148
|
+
return False
|
|
149
|
+
|
|
150
|
+
@classmethod
|
|
151
|
+
def has_option(cls, section: str, option: str) -> bool:
|
|
152
|
+
''' Checks if the given option exists in the given section of the ini file. '''
|
|
153
|
+
if cls.__configparser_object is not None:
|
|
154
|
+
return cls.__configparser_object.has_option(section, option)
|
|
155
|
+
return False
|
|
156
|
+
|
|
157
|
+
@classmethod
|
|
158
|
+
def set(cls, section: str, option: str, value: str):
|
|
159
|
+
''' Sets the value of the given option in the given section of the ini file. '''
|
|
160
|
+
assert cls.__configparser_object is not None, "You must first read the settings from a file before doing a set()."
|
|
161
|
+
|
|
162
|
+
cls.__configparser_object.set(section, option, str(value) )
|
|
163
|
+
|
|
@@ -20,14 +20,16 @@ from .forms.form_serials import FormSerials
|
|
|
20
20
|
from .testlog.global_log_handler import GlobalLogHandler
|
|
21
21
|
from .testlog.log_to_text import LogToText
|
|
22
22
|
from .modulereader import ModuleReader
|
|
23
|
+
from .inifile import IniFile
|
|
24
|
+
from .forms.form_settings import FormSettings
|
|
23
25
|
|
|
24
26
|
class StaticScriptManager(object):
|
|
25
|
-
'''
|
|
26
|
-
classdocs
|
|
27
|
-
'''
|
|
28
27
|
dialog = None
|
|
29
28
|
logger = logging.getLogger("happyscript")
|
|
30
29
|
|
|
30
|
+
__the_one_and_only_instance = None
|
|
31
|
+
ini = IniFile
|
|
32
|
+
|
|
31
33
|
def __init__(self, title=None, colors = None, use_yaml=False):
|
|
32
34
|
'''
|
|
33
35
|
Constructor
|
|
@@ -36,6 +38,9 @@ class StaticScriptManager(object):
|
|
|
36
38
|
@param Optional color scheme for test list.
|
|
37
39
|
0=green, 1=blue, 2=yellow, 3=grey, 4=orange, 5=darker blue
|
|
38
40
|
'''
|
|
41
|
+
assert StaticScriptManager.__the_one_and_only_instance is None, "Only one instance of a ScriptManager can be created."
|
|
42
|
+
StaticScriptManager.__the_one_and_only_instance = self
|
|
43
|
+
|
|
39
44
|
fixedcolors = [ (226, 239, 217), (222, 235, 246), (255, 242, 204), (237, 237, 237),
|
|
40
45
|
(251, 229, 213), (217, 226, 243) ]
|
|
41
46
|
|
|
@@ -82,7 +87,7 @@ class StaticScriptManager(object):
|
|
|
82
87
|
self._script_runner = ScriptRunner(self._script_params, self._script_readers, self.ctrl)
|
|
83
88
|
self.ctrl.set_script_runner( self._script_runner )
|
|
84
89
|
|
|
85
|
-
self._script_params.add_objects( ctrl=self.ctrl, gui=self.gui, info=self.info )
|
|
90
|
+
self._script_params.add_objects( ctrl=self.ctrl, gui=self.gui, info=self.info, mngr=self )
|
|
86
91
|
|
|
87
92
|
self.dialog.pnlTests.on_sequence_start_callback = self.handle_batch_start
|
|
88
93
|
self.dialog.pnlTests.on_sequence_end_callback = self.handle_batch_end
|
|
@@ -168,6 +173,14 @@ class StaticScriptManager(object):
|
|
|
168
173
|
'''
|
|
169
174
|
self.dialog.ClearLogs()
|
|
170
175
|
|
|
176
|
+
@classmethod
|
|
177
|
+
def _set_ini(cls, ini):
|
|
178
|
+
''' Set the IniFile class for appication settings read from an ini file.
|
|
179
|
+
This method is called by the IniFile class when a .ini file is read.
|
|
180
|
+
'''
|
|
181
|
+
assert cls.__the_one_and_only_instance is not None, "ScriptManager must be instantiated before reading an ini file."
|
|
182
|
+
cls.ini = ini
|
|
183
|
+
|
|
171
184
|
#============================================================================================================
|
|
172
185
|
# P A R A M E T E R S
|
|
173
186
|
#============================================================================================================
|
|
@@ -189,7 +202,8 @@ class StaticScriptManager(object):
|
|
|
189
202
|
if obj_value is None:
|
|
190
203
|
self.logger.warning( f"Object with name {obj_name} is None." )
|
|
191
204
|
else:
|
|
192
|
-
|
|
205
|
+
if obj_name not in ['mgnr', 'ctrl', 'gui', 'info']:
|
|
206
|
+
self.logger.info("Added object %s" %obj_name)
|
|
193
207
|
self.dialog.PushShellCommand("%s = _mngr_._script_params.get_param('%s')" % (obj_name, obj_name))
|
|
194
208
|
|
|
195
209
|
#============================================================================================================
|
|
@@ -317,6 +331,11 @@ class StaticScriptManager(object):
|
|
|
317
331
|
'''
|
|
318
332
|
return self.dialog.AddCustomPanel(title, panelType, **args)
|
|
319
333
|
|
|
334
|
+
def show_settings(self):
|
|
335
|
+
|
|
336
|
+
FormSettings.show_modal(self.dialog, self.ini)
|
|
337
|
+
|
|
338
|
+
|
|
320
339
|
#============================================================================================================
|
|
321
340
|
# S T A R T A P P L I C A T I O N
|
|
322
341
|
#============================================================================================================
|
|
@@ -325,6 +344,9 @@ class StaticScriptManager(object):
|
|
|
325
344
|
''' Starts the application.
|
|
326
345
|
Not to be confused with ScriptPanelRunner.run(), which is used to run a script.
|
|
327
346
|
'''
|
|
347
|
+
if self.ini._get_configparser() is None: # if no ini file set, disable the settings button
|
|
348
|
+
self.dialog.DisableSettingsButton()
|
|
349
|
+
|
|
328
350
|
self.dialog.BeforeShow() # restores previous layout of dialog
|
|
329
351
|
# PrintRedirect.set_logfile("happyscript.log")
|
|
330
352
|
PrintRedirect.start_redirection(self.loghandler) # redirect print output to message area
|
|
@@ -2,6 +2,7 @@ README.md
|
|
|
2
2
|
pyproject.toml
|
|
3
3
|
happyscript/__init__.py
|
|
4
4
|
happyscript/imglib.py
|
|
5
|
+
happyscript/inifile.py
|
|
5
6
|
happyscript/modulereader.py
|
|
6
7
|
happyscript/scriptartwork.py
|
|
7
8
|
happyscript/scriptcontrol.py
|
|
@@ -34,6 +35,7 @@ happyscript/forms/form_askimage.py
|
|
|
34
35
|
happyscript/forms/form_main.py
|
|
35
36
|
happyscript/forms/form_ontestfailure.py
|
|
36
37
|
happyscript/forms/form_serials.py
|
|
38
|
+
happyscript/forms/form_settings.py
|
|
37
39
|
happyscript/forms/form_stop.py
|
|
38
40
|
happyscript/forms/formsbase.py
|
|
39
41
|
happyscript/panels/panel_log.py
|
|
@@ -17,7 +17,7 @@ build-backend = "setuptools.build_meta"
|
|
|
17
17
|
[project]
|
|
18
18
|
name = "happyscript"
|
|
19
19
|
description = "Framework for running scripts"
|
|
20
|
-
version = "0.0.
|
|
20
|
+
version = "0.0.44"
|
|
21
21
|
readme = "README.md"
|
|
22
22
|
requires-python = ">=3.5"
|
|
23
23
|
dependencies = [ "wxpython", "numpy" ]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|