Skip to content

Commit

Permalink
Added a filepath datatype for parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad-Goff committed Mar 27, 2024
1 parent 0821de1 commit 484b962
Show file tree
Hide file tree
Showing 33 changed files with 288 additions and 102 deletions.
45 changes: 38 additions & 7 deletions MacroQueue/Dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ def GetValueType(Value):
if ValueType == bool:
return "Boolean"
if ValueType == str:
return "String"
if os.path.exists(Value):
return "File"
else:
return "String"
try:
FloatValue = float(Value)
return "Numerical"
Expand All @@ -186,7 +189,14 @@ def GetValueType(Value):
FunctionButton = wx.Button( m_FunctionButtonScrolledWindow, wx.ID_ANY, Name, wx.DefaultPosition, wx.DefaultSize, 0 )
FunctionButton.SetMinSize( wx.Size( 150,-1 ) )
AddFunctionButtonSizer.Add( FunctionButton, 0, wx.ALL, 5 )
Parameters = {Key:{"DefaultValue":Value,"Tooltip":"","Frozen":False,"ValueType":GetValueType(Value)} for Key,Value in zip(inspect.getfullargspec(Function)[0],inspect.getfullargspec(Function)[3])} if len(inspect.getfullargspec(Function)[0]) > 0 else {}
Parameters = {}
if len(inspect.getfullargspec(Function)[0]) > 0:
ParameterNames = inspect.getfullargspec(Function)[0]
ParameterDefaults = list(inspect.getfullargspec(Function)[3])
ParameterDefaults = ([''] * (len(ParameterNames) - len(ParameterDefaults))) + list(ParameterDefaults)
for Key,Value in zip(ParameterNames,ParameterDefaults):
Parameters[Key] = {"DefaultValue":Value,"Tooltip":"","Frozen":False,"ValueType":GetValueType(Value)}

for ParameterName in Parameters.keys():
Parameters[ParameterName]["InRange"] = True
if Parameters[ParameterName]["ValueType"] == "Choice":
Expand Down Expand Up @@ -456,7 +466,10 @@ def SetParameterPanels(self):

self.ParameterPanel = wx.Panel( FunctionPanel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
self.ParameterPanel.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INACTIVECAPTION ) )
self.ParameterPanel.SetMinSize( wx.Size( 250,60 ) )
if ParameterInfo['ValueType'] == 'File':
self.ParameterPanel.SetMinSize( wx.Size( 330,60 ) )
else:
self.ParameterPanel.SetMinSize( wx.Size( 250,60 ) )
self.ParameterPanel.SetToolTip(Tooltip)

ParameterSizer = wx.FlexGridSizer( 0, 1, 0, 0 )
Expand Down Expand Up @@ -487,6 +500,8 @@ def SetParameterPanels(self):
ParameterDefaultValueText.SetValue(ParameterInfo['DefaultValue'])
elif ParameterInfo['ValueType'] == 'String':
ParameterDefaultValueText = wx.TextCtrl( self.ParameterPanel, wx.ID_ANY, ParameterInfo['DefaultValue'], wx.DefaultPosition, wx.DefaultSize, 0 )
elif ParameterInfo['ValueType'] == 'File':
ParameterDefaultValueText = wx.FilePickerCtrl( self.ParameterPanel, wx.ID_ANY, ParameterInfo['DefaultValue'], pos=wx.DefaultPosition, size=wx.DefaultSize ,style=wx.FLP_USE_TEXTCTRL )
elif ParameterInfo['ValueType'] == 'Choice':
ParameterDefaultValueText = wx.Choice( self.ParameterPanel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, ParameterInfo['DefaultList'] )
ParameterDefaultValueText.SetStringSelection(ParameterInfo['DefaultValue'])
Expand Down Expand Up @@ -576,6 +591,8 @@ def UpdateTheMacro(self):
for ParameterName,ParameterInfo in Parameters.items():
if ParameterInfo['ValueType'] == "Choice":
Parameters[ParameterName]['DefaultValue'] = self.TheMacroCtrls[i][ParameterName][0].GetStringSelection()
elif ParameterInfo['ValueType'] == "File":
Parameters[ParameterName]['DefaultValue'] = self.TheMacroCtrls[i][ParameterName][0].GetPath()
else:
Parameters[ParameterName]['DefaultValue'] = self.TheMacroCtrls[i][ParameterName][0].GetValue()
Parameters[ParameterName]['Frozen'] = self.TheMacroCtrls[i][ParameterName][1].GetValue()
Expand Down Expand Up @@ -605,7 +622,10 @@ def GetValueType(Value):
if ValueType == bool:
return "Boolean"
if ValueType == str:
return "String"
if os.path.exists(Value):
return "File"
else:
return "String"
try:
FloatValue = float(Value)
return "Numerical"
Expand Down Expand Up @@ -795,7 +815,10 @@ def PanelTextCheckFunction(Name,ThisFunction,m_FunctionTextCheck,event):

ParameterPanel = wx.Panel( FunctionPanel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
ParameterPanel.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INACTIVECAPTION ) )
ParameterPanel.SetMinSize( wx.Size( 250,-1 ) )
if ParameterInfo['ValueType'] == 'File':
ParameterPanel.SetMinSize( wx.Size( 330,-1 ) )
else:
ParameterPanel.SetMinSize( wx.Size( 250,-1 ) )
ParameterPanel.Bind(wx.EVT_LEFT_DOWN,ThisPanelTextCheckFunction)
ParameterPanel.Bind(wx.EVT_LEFT_DCLICK,ThisPanelTextCheckFunction)

Expand Down Expand Up @@ -889,10 +912,13 @@ def block_non_numbers(event):
# Block everything else
return
def UpdateParameters(Name,ThisFunction,ParameterName,FunctionTextCheck,event):
Value = event.GetEventObject().GetValue()
if ThisFunction['Parameters'][ParameterName]['ValueType'] == 'File':
Value = event.GetEventObject().GetPath()
else:
Value = event.GetEventObject().GetValue()
ThisPanel = event.GetEventObject().GetParent()

OldToolTip = event.GetEventObject().GetToolTip().GetTip()
OldToolTip = event.GetEventObject().GetParent().GetToolTip().GetTip()
if '\n' in OldToolTip:
FirstLine = OldToolTip[:OldToolTip.find("\n")]
FirstLine += "\n"
Expand Down Expand Up @@ -955,6 +981,11 @@ def UpdateChoiceParameters(Name,ThisFunction,ParameterName,FunctionTextCheck,eve
ParameterValueText.SetValue(ParameterInfo['DefaultValue'])
ThisUpdateParameters = partial(UpdateParameters,Name,Function,ParameterName,m_FunctionTextCheck)
ParameterValueText.Bind( wx.EVT_TEXT, ThisUpdateParameters)
elif ParameterInfo['ValueType'] == 'File':
ParameterValueText = wx.FilePickerCtrl( ParameterPanel, wx.ID_ANY, ParameterInfo['DefaultValue'], pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.FLP_DEFAULT_STYLE )
ParameterValueText.SetPath(ParameterInfo['DefaultValue'])
ThisUpdateParameters = partial(UpdateParameters,Name,Function,ParameterName,m_FunctionTextCheck)
ParameterValueText.Bind( wx.EVT_FILEPICKER_CHANGED, ThisUpdateParameters)
DefaultValueSizer.Add( ParameterValueText, 1, wx.ALL, 5 )


Expand Down
17 changes: 9 additions & 8 deletions MacroQueue/Functions/General.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
MacroQueueSelf = None


def Bare_Function(SomeParameter=""):
def Bare_Function(SomeParameter,SomeParameter2="a"):
print(SomeParameter)

print("Hehehe")

# {"Name":"SomeNumber","Units":"V","Min":-10,"Max":10,"Tooltip":"An example function which only takes numbers"}
def Numerical_Function(SomeNumber=5):
print(SomeNumber)

# {"Name":"Boolean","Tooltip":"A Boolean parameter produces a checkbox"}
# {"Name":"String","Tooltip":"A String parameter produces a textbox"}
# {"Name":"Choice","Tooltip":"A Choice parameter produces a dropdown menu"}
def Complex_Function(Boolean=True,String="String",Choice=['Choice','Combo','3rd','4th']):
if Boolean:
print(String, Choice)
# {"Name":"SomeBoolean","Tooltip":"A Boolean parameter produces a checkbox"}
# {"Name":"SomeString","Tooltip":"A String parameter produces a textbox"}
# {"Name":"SomeFilePath","Tooltip":"A filepath parameter produces a 'browse' button"}
# {"Name":"SomeChoice","Tooltip":"A Choice parameter produces a dropdown menu"}
def Complex_Function(SomeBoolean=True,SomeString="String",SomeFilePath="C:\\",SomeChoice=['Choice','Combo','3rd','4th']):
if SomeBoolean:
print(SomeString, SomeChoice)


# {"Name":"WaitTime","Units":"s","Tooltip":"The time to wait"}
Expand Down
2 changes: 2 additions & 0 deletions MacroQueue/Functions/RF.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pyvisa
import CreaTec

CurrentMacro = None
OutgoingQueue = None
Expand All @@ -7,6 +8,7 @@

def Connect_To_RF_Generator():
global RFGenerator

rm = pyvisa.ResourceManager()
# ResourceList = rm.list_resources()
RFGenerator = rm.open_resource('USB0::0x03EB::0xAFFF::481-34B6D0608-2368::INSTR')
Expand Down
13 changes: 8 additions & 5 deletions MacroQueue/GUIDesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ def __init__( self, parent ):
self.m_OptionsMenu.Append( self.m_PauseAfterCancel )
self.m_PauseAfterCancel.Check( True )

self.m_menuItem17 = wx.MenuItem( self.m_OptionsMenu, wx.ID_ANY, u"Reload Functions"+ u"\t" + u"CTRL+R", wx.EmptyString, wx.ITEM_NORMAL )
self.m_OptionsMenu.Append( self.m_menuItem17 )

self.m_menubar1.Append( self.m_OptionsMenu, u"Options" )

self.m_MacroMenu = wx.Menu()
self.m_MakeMacroMenuItem = wx.MenuItem( self.m_MacroMenu, wx.ID_ANY, u"Make New Macro", wx.EmptyString, wx.ITEM_NORMAL )
self.m_MakeMacroMenuItem = wx.MenuItem( self.m_MacroMenu, wx.ID_ANY, u"Make New Macro"+ u"\t" + u"CRTL+M", wx.EmptyString, wx.ITEM_NORMAL )
self.m_MacroMenu.Append( self.m_MakeMacroMenuItem )

self.m_OpenMacroMenuItem = wx.MenuItem( self.m_MacroMenu, wx.ID_ANY, u"Open Macro Folder", wx.EmptyString, wx.ITEM_NORMAL )
Expand All @@ -49,10 +52,10 @@ def __init__( self, parent ):
self.m_menubar1.Append( self.m_MacroMenu, u"Macro" )

self.m_Connectmenu = wx.Menu()
self.m_menuItem7 = wx.MenuItem( self.m_Connectmenu, wx.ID_ANY, u"Connect", wx.EmptyString, wx.ITEM_NORMAL )
self.m_menuItem7 = wx.MenuItem( self.m_Connectmenu, wx.ID_ANY, u"Connect"+ u"\t" + u"CRTL+C", wx.EmptyString, wx.ITEM_NORMAL )
self.m_Connectmenu.Append( self.m_menuItem7 )

self.m_menuItem8 = wx.MenuItem( self.m_Connectmenu, wx.ID_ANY, u"Disconnect", wx.EmptyString, wx.ITEM_NORMAL )
self.m_menuItem8 = wx.MenuItem( self.m_Connectmenu, wx.ID_ANY, u"Disconnect"+ u"\t" + u"CTRL+D", wx.EmptyString, wx.ITEM_NORMAL )
self.m_Connectmenu.Append( self.m_menuItem8 )

self.m_menubar1.Append( self.m_Connectmenu, u"Connect" )
Expand Down Expand Up @@ -153,7 +156,7 @@ def __init__( self, parent ):
self.Bind( wx.EVT_SIZE, self.OnSize )
self.Bind( wx.EVT_MENU, self.OpenSourceFolder, id = self.m_SourceMenuItem.GetId() )
self.Bind( wx.EVT_MENU, self.OnClose, id = self.m_ExitMenuItem.GetId() )
self.Bind( wx.EVT_MENU, self.PauseAfterCancel, id = self.m_PauseAfterCancel.GetId() )
self.Bind( wx.EVT_MENU, self.ReloadFunctions, id = self.m_menuItem17.GetId() )
self.Bind( wx.EVT_MENU, self.StartMakeNewMacro, id = self.m_MakeMacroMenuItem.GetId() )
self.Bind( wx.EVT_MENU, self.OpenMacroFile, id = self.m_OpenMacroMenuItem.GetId() )
self.Bind( wx.EVT_MENU, self.AddConnectToQueue, id = self.m_menuItem7.GetId() )
Expand Down Expand Up @@ -189,7 +192,7 @@ def OpenSourceFolder( self, event ):
event.Skip()


def PauseAfterCancel( self, event ):
def ReloadFunctions( self, event ):
event.Skip()

def StartMakeNewMacro( self, event ):
Expand Down
43 changes: 19 additions & 24 deletions MacroQueue/MacroQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,6 @@
# They all go in try/except just in case the required packages aren't installed for one of them
# (e.g. you can still use RHK's functions even without win32com which you need for CreaTec)
sys.path.append(os.path.dirname(__file__)+"\\Functions")
try:
import RHK as RHKFunctions
except:
pass

try:
import CreaTec as CreaTecFunctions
except:
pass

try:
import SXM as SXMFunctions
except:
pass

try:
import General as GeneralFunctions
except:
pass

import json

Expand Down Expand Up @@ -99,7 +80,7 @@
# In the createc Scan, when I get the Y pixels, it crashes if I haven't set it? There's no default value?
# On close, I cancel the scan. Should I try to prevent that?

VersionNumber = "v0.1.18"
VersionNumber = "v0.2.0"
class MacroQueue(MyFrame):
MacroPaths = {"RHK":"Macros//RHKMacro.json","CreaTec":"Macros//CreaTecMacro.json","SXM":"Macros//SXMMacro.json"}

Expand All @@ -118,6 +99,7 @@ def __init__(self,test=False):
self.test = test
application_path = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname(__file__)
os.chdir(os.path.realpath(application_path))

self.SavedSettingsFile = 'MacroQueueSettings.csv'


Expand Down Expand Up @@ -276,15 +258,15 @@ def OnClose(self,event=None):
self.Process.join(timeout=0.5)
if self.Closing:
self.Destroy()
def LoadFunctions(self):
def LoadFunctions(self,Reloading=False):
FunctionNames = [file for file in os.listdir('Functions') if file[-3:] == ".py"]
self.Functions = {}
for FunctionName in FunctionNames:
try:
self.Functions[f"{FunctionName[:-3]}"] = import_source_file(os.path.abspath(f'Functions\\{FunctionName}'),os.path.abspath(f'Functions\\{FunctionName}'))
except:
pass
for file in ["CreaTec.py","RHK.py","SXM.py"]:
for file in ["CreaTec.py","RHK.py","SXM.py","SXMRemote.py"]:
try:
FunctionNames.remove(file)
except:
Expand All @@ -294,8 +276,16 @@ def LoadFunctions(self):
except:
pass
for file in FunctionNames:
CheckFunction = self.m_NotSTMMenu.AppendCheckItem(wx.ID_ANY,file[:-3])
self.Bind(wx.EVT_MENU,self.EditLoadedFunctionFiles,CheckFunction)

if not Reloading:
CheckFunction = self.m_NotSTMMenu.AppendCheckItem(wx.ID_ANY,file[:-3])
self.Bind(wx.EVT_MENU,self.EditLoadedFunctionFiles,CheckFunction)
else:
MenuItems = self.m_NotSTMMenu.GetMenuItems()
MenuLabels = [MenuItem.GetItemLabel() for MenuItem in MenuItems ]
if not file[:-3] in MenuLabels:
CheckFunction = self.m_NotSTMMenu.AppendCheckItem(wx.ID_ANY,file[:-3])
self.Bind(wx.EVT_MENU,self.EditLoadedFunctionFiles,CheckFunction)
def EditLoadedFunctionFiles(self,event=None):
self.FunctionsLoaded = []
for item in self.m_NotSTMMenu.GetMenuItems():
Expand Down Expand Up @@ -805,6 +795,10 @@ def PauseAfterCancel(self,event):
ThisChooseSoftwareDialog = MyChooseSoftwareDialog(self,self.FunctionsLoaded)
ThisChooseSoftwareDialog.SetSoftware(self.Software)
pass
def ReloadFunctions(self,event):
self.LoadFunctions(Reloading=True)
self.IncomingQueue.put(["SoftwareChange",[self.Software,self.FunctionsLoaded]])
pass
def BasicUseageHelp(self, event):
HelpMessage = "Left click on your choosen macro from the list on the main page.\n"
HelpMessage += "Each function in the macro has a checkbox on the left side of the function's panel. You may check/uncheck it. If it is checked it will be run. If it is unchecked it will not run.\n"
Expand Down Expand Up @@ -998,6 +992,7 @@ def Thread(self,IncomingQueue,OutgoingQueue):
while True:
Message = IncomingQueue.get() # Blocks until there's a message
if Message[0] == "SoftwareChange":
Functions = self.Functions
# Changes the global parameters that are assessable to the new software's functions (e.g. RHK -> CreaTec)
Software,FunctionsToLoad = Message[1]
Functions[Software].MacroQueueSelf = self
Expand Down
63 changes: 63 additions & 0 deletions MacroQueue/Macros/CreaTecMacro.json
Original file line number Diff line number Diff line change
Expand Up @@ -696,5 +696,68 @@
{},
true
]
],
"Test": [
[
"Numerical Function",
{
"SomeNumber": {
"DefaultValue": "5",
"Tooltip": "An example function which only takes numbers\nAcceptable range: (-10,10)",
"Frozen": false,
"ValueType": "Numerical",
"InRange": true,
"Name": "SomeNumber",
"Units": "V",
"Min": -10,
"Max": 10
}
},
true
],
[
"Complex Function",
{
"SomeBoolean": {
"DefaultValue": true,
"Tooltip": "A Boolean parameter produces a checkbox",
"Frozen": false,
"ValueType": "Boolean",
"InRange": true,
"Name": "SomeBoolean"
},
"SomeString": {
"DefaultValue": "String",
"Tooltip": "A String parameter produces a textbox",
"Frozen": false,
"ValueType": "String",
"InRange": true,
"Name": "SomeString"
},
"SomeFilePath": {
"DefaultValue": "C:\\",
"Tooltip": "A filepath parameter produces a 'browse' button",
"Frozen": false,
"ValueType": "File",
"InRange": true,
"Name": "SomeFilePath"
},
"SomeChoice": {
"DefaultValue": "Choice",
"Tooltip": "A Choice parameter produces a dropdown menu",
"Frozen": false,
"ValueType": "Choice",
"InRange": true,
"DefaultList": [
"Choice",
"Combo",
"3rd",
"4th"
],
"Name": "SomeChoice"
}
},
true
]
]
}
4 changes: 2 additions & 2 deletions docs/Install.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ <h2>System requirements<a class="headerlink" href="#system-requirements" title="
<h2>Installation from pip (recommended)<a class="headerlink" href="#installation-from-pip-recommended" title="Link to this heading"></a></h2>
<ol class="arabic">
<li><p>Update pip:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="o">--</span><span class="n">upgrade</span> <span class="n">pip</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">pip</span> <span class="n">install</span> <span class="o">--</span><span class="n">upgrade</span> <span class="n">pip</span>
</pre></div>
</div>
</li>
<li><p>Install MacroQueue by pip:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="n">MacroQueue</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">pip</span> <span class="n">install</span> <span class="n">MacroQueue</span>
</pre></div>
</div>
</li>
Expand Down
Loading

0 comments on commit 484b962

Please sign in to comment.