Skip to content

Commit

Permalink
Can edit which files are under Systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad-Goff committed Apr 8, 2024
1 parent f8af78a commit 0fd709a
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 607 deletions.
67 changes: 46 additions & 21 deletions MacroQueue/Dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
from MacroQueue.GUIDesign import MacroDialog
from MacroQueue.GUIDesign import MacroSettingsDialog
from MacroQueue.GUIDesign import StartMacroDialog
from MacroQueue.GUIDesign import ChooseSoftware
except ModuleNotFoundError:
from GUIDesign import MacroDialog
from GUIDesign import MacroSettingsDialog
from GUIDesign import StartMacroDialog
from GUIDesign import ChooseSoftware

import pandas as pd
class SettingsDialog(wx.Dialog):
Expand Down Expand Up @@ -1153,28 +1151,55 @@ def OnCancel(self, event):
self.Destroy()


class MyChooseSoftwareDialog(ChooseSoftware):
class MyChooseSoftwareDialog(wx.Dialog):
def __init__(self, parent,FunctionsToLoad=None):
super().__init__(parent)
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Choose the STM Software", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )

self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INACTIVECAPTION ) )

fgSizer12 = wx.FlexGridSizer( 0, 1, 0, 0 )
fgSizer12.SetFlexibleDirection( wx.BOTH )
fgSizer12.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

self.m_ChooseSoftwareText = wx.StaticText( self, wx.ID_ANY, u"Please select the STM Software you wish to use", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_ChooseSoftwareText.Wrap( -1 )

fgSizer12.Add( self.m_ChooseSoftwareText, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5 )

self.m_panel11 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
self.m_panel11.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVECAPTION ) )

bSizer6 = wx.BoxSizer( wx.HORIZONTAL )
for i,system in enumerate(parent.Systems):
self.m_button = wx.Button( self.m_panel11, wx.ID_ANY, system, wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer6.Add( self.m_button, 0, wx.ALL, 5 )
SetTHISSoftware = partial(self.SetSoftware,i)
self.m_button.Bind( wx.EVT_BUTTON, SetTHISSoftware)



self.m_panel11.SetSizer( bSizer6 )
self.m_panel11.Layout()
bSizer6.Fit( self.m_panel11 )
fgSizer12.Add( self.m_panel11, 1, wx.EXPAND |wx.ALL, 5 )


self.SetSizer( fgSizer12 )
self.Layout()
fgSizer12.Fit( self )

self.Centre( wx.BOTH )


self.SavedSettingsFile = self.Parent.SavedSettingsFile
self.FunctionsToLoad = FunctionsToLoad
def OnRHK(self, event=None):
self.SetSoftware("RHK")
def OnCreaTec(self, event=None):
self.SetSoftware("CreaTec")
def OnSXM(self, event=None):
self.SetSoftware("SXM")
def SetSoftware(self,software=None):
self.Parent.m_RHKmenuItem.Check(False)
self.Parent.m_CreaTecmenuItem.Check(False)
self.Parent.m_SXMmenuItem.Check(False)
if software is not None:
if software == "RHK":
self.Parent.m_RHKmenuItem.Check(True)
if software == "CreaTec":
self.Parent.m_CreaTecmenuItem.Check(True)
if software == "SXM":
self.Parent.m_SXMmenuItem.Check(True)
def SetSoftware(self,softwareIndex=None,event=None):
for MenuItem in self.Parent.SystemMenuItems:
MenuItem.Check(False)
if softwareIndex is not None:
self.Parent.SystemMenuItems[softwareIndex].Check(True)
software = self.Parent.Systems[softwareIndex]
self.Parent.Software = software
self.Parent.MacroPath = self.Parent.MacroPaths[software]
if self.FunctionsToLoad is None:
Expand Down
5 changes: 4 additions & 1 deletion MacroQueue/Functions/General.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from time import sleep

Systems =['RHK','CreaTec','SXM',"Testing"]


Cancel = False
MacroQueueSelf = None

Expand All @@ -11,7 +14,7 @@
# {"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']):
def Complex_Function2(SomeBoolean=True,SomeString="String",SomeFilePath="C:\\",SomeChoice=['Choice','Combo','3rd','4th']):
if SomeBoolean:
print(SomeString, SomeChoice)

Expand Down
24 changes: 24 additions & 0 deletions MacroQueue/Functions/Testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

from time import sleep

CurrentMacro = None
OutgoingQueue = None
Cancel = False
MacroQueueSelf = None

def Initialize():
pass


# {"Name":"WaitTime","Units":"s","Tooltip":"The time to wait"}
def Wait(WaitTime=1):
while WaitTime > 1 and not Cancel:
WaitTime-=1
sleep(1)
if not Cancel:
sleep(WaitTime)


# Index=This has no impact. It's solely used to repeat the functions.
def Null(Index=0):
pass
89 changes: 0 additions & 89 deletions MacroQueue/GUIDesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ def __init__( self, parent ):
self.m_menubar1.Append( self.m_Connectmenu, u"Connect" )

self.m_SystemMenu = wx.Menu()
self.m_RHKmenuItem = wx.MenuItem( self.m_SystemMenu, wx.ID_ANY, u"RHK", wx.EmptyString, wx.ITEM_CHECK )
self.m_SystemMenu.Append( self.m_RHKmenuItem )

self.m_CreaTecmenuItem = wx.MenuItem( self.m_SystemMenu, wx.ID_ANY, u"CreaTec", wx.EmptyString, wx.ITEM_CHECK )
self.m_SystemMenu.Append( self.m_CreaTecmenuItem )

self.m_SXMmenuItem = wx.MenuItem( self.m_SystemMenu, wx.ID_ANY, u"SXM", wx.EmptyString, wx.ITEM_CHECK )
self.m_SystemMenu.Append( self.m_SXMmenuItem )

self.m_menubar1.Append( self.m_SystemMenu, u"System" )

self.m_NotSTMMenu = wx.Menu()
Expand Down Expand Up @@ -157,9 +148,6 @@ def __init__( self, parent ):
self.Bind( wx.EVT_MENU, self.OpenMacroFile, id = self.m_OpenMacroMenuItem.GetId() )
self.Bind( wx.EVT_MENU, self.AddConnectToQueue, id = self.m_menuItem7.GetId() )
self.Bind( wx.EVT_MENU, self.AddDisconnectToQueue, id = self.m_menuItem8.GetId() )
self.Bind( wx.EVT_MENU, self.OnRHKSoftware, id = self.m_RHKmenuItem.GetId() )
self.Bind( wx.EVT_MENU, self.OnCreaTecSoftware, id = self.m_CreaTecmenuItem.GetId() )
self.Bind( wx.EVT_MENU, self.OnSXMSoftware, id = self.m_SXMmenuItem.GetId() )
self.Bind( wx.EVT_MENU, self.BasicUseageHelp, id = self.m_menuItem10.GetId() )
self.Bind( wx.EVT_MENU, self.ExpandNumericalParameters, id = self.m_menuItem102.GetId() )
self.Bind( wx.EVT_MENU, self.MakeAMacroHelp, id = self.m_menuItem11.GetId() )
Expand Down Expand Up @@ -202,15 +190,6 @@ def AddConnectToQueue( self, event ):
def AddDisconnectToQueue( self, event ):
event.Skip()

def OnRHKSoftware( self, event ):
event.Skip()

def OnCreaTecSoftware( self, event ):
event.Skip()

def OnSXMSoftware( self, event ):
event.Skip()

def BasicUseageHelp( self, event ):
event.Skip()

Expand Down Expand Up @@ -239,74 +218,6 @@ def ClearQueue( self, event ):
event.Skip()


###########################################################################
## Class ChooseSoftware
###########################################################################

class ChooseSoftware ( wx.Dialog ):

def __init__( self, parent ):
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Choose the STM Software", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )

self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INACTIVECAPTION ) )

fgSizer12 = wx.FlexGridSizer( 0, 1, 0, 0 )
fgSizer12.SetFlexibleDirection( wx.BOTH )
fgSizer12.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

self.m_ChooseSoftwareText = wx.StaticText( self, wx.ID_ANY, u"Please select the STM Software you wish to use", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_ChooseSoftwareText.Wrap( -1 )

fgSizer12.Add( self.m_ChooseSoftwareText, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5 )

self.m_panel11 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
self.m_panel11.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVECAPTION ) )

bSizer6 = wx.BoxSizer( wx.HORIZONTAL )

self.m_RHKbutton = wx.Button( self.m_panel11, wx.ID_ANY, u"RHK", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer6.Add( self.m_RHKbutton, 0, wx.ALL, 5 )

self.m_CreaTecbutton = wx.Button( self.m_panel11, wx.ID_ANY, u"CreaTec", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer6.Add( self.m_CreaTecbutton, 0, wx.ALL, 5 )

self.m_SXMbutton = wx.Button( self.m_panel11, wx.ID_ANY, u"SXM", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer6.Add( self.m_SXMbutton, 0, wx.ALL, 5 )


self.m_panel11.SetSizer( bSizer6 )
self.m_panel11.Layout()
bSizer6.Fit( self.m_panel11 )
fgSizer12.Add( self.m_panel11, 1, wx.EXPAND |wx.ALL, 5 )


self.SetSizer( fgSizer12 )
self.Layout()
fgSizer12.Fit( self )

self.Centre( wx.BOTH )

# Connect Events
self.m_RHKbutton.Bind( wx.EVT_BUTTON, self.OnRHK )
self.m_CreaTecbutton.Bind( wx.EVT_BUTTON, self.OnCreaTec )
self.m_SXMbutton.Bind( wx.EVT_BUTTON, self.OnSXM )

def __del__( self ):
pass


# Virtual event handlers, override them in your derived class
def OnRHK( self, event ):
event.Skip()

def OnCreaTec( self, event ):
event.Skip()

def OnSXM( self, event ):
event.Skip()


###########################################################################
## Class MacroDialog
###########################################################################
Expand Down
54 changes: 29 additions & 25 deletions MacroQueue/MacroQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,12 @@
# from GUIDesign import MacroDialog
from inspect import getmembers, isfunction

# 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)
if getattr(sys, 'frozen', False):
sys.path.append(os.path.dirname(sys.executable)+"\\Functions")
else:
sys.path.append(os.path.dirname(__file__)+"\\Functions")
sys.path.append(os.path.dirname(sys.executable if getattr(sys, 'frozen', False) else __file__)+"\\Functions")

import json

from PyInstaller.__main__ import run as PyInstall
from functools import partial


IconFileName = "MacroQueueIcon.ico"
Expand All @@ -57,13 +53,20 @@
# TODO:
# Show number of items in queue in status bar

VersionNumber = "v0.2.5"
VersionNumber = "v0.3.0"
# VersionNumber also in conf.py & setup.py
Date = "4/2024"


class MacroQueue(MyFrame):
MacroPaths = {"RHK":"Macros//RHKMacro.json","CreaTec":"Macros//CreaTecMacro.json","SXM":"Macros//SXMMacro.json"}
try:
import General
Systems = General.Systems
except:
Systems =['RHK','CreaTec','SXM',"Testing"]
NotAuxFiles = [f"{system}.py" for system in Systems]
NotAuxFiles.append("SXMRemote.py")
MacroPaths = {system:f"Macros//{system}Macro.json" for system in Systems}

# Scanning, fine motion, course motion, dI/dV scans, point spectra, tip form,
TheQueue = []
Expand All @@ -75,6 +78,7 @@ class MacroQueue(MyFrame):
Closing = False
Editting = False
Functions = {}
SystemMenuItems = []
# my_module = importlib.import_module('os.path')
def __init__(self,test=False):
self.test = test
Expand All @@ -94,6 +98,12 @@ def __init__(self,test=False):
self.m_FileMenu.Append( self.m_ExitMenuItem )
self.Bind( wx.EVT_MENU, self.OnClose, id = self.m_ExitMenuItem.GetId() )

for i,system in enumerate(self.Systems):
self.m_SystemmenuItem = wx.MenuItem( self.m_SystemMenu, wx.ID_ANY, system, wx.EmptyString, wx.ITEM_CHECK )
self.m_SystemMenu.Append( self.m_SystemmenuItem )
self.SystemMenuItems.append(self.m_SystemmenuItem)
OnTHISSoftware = partial(self.OnSoftware,i)
self.Bind( wx.EVT_MENU, OnTHISSoftware, id = self.m_SystemmenuItem.GetId() )
icon_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), IconFileName)
if os.path.exists(icon_file):
icon = wx.Icon(icon_file)
Expand Down Expand Up @@ -124,7 +134,7 @@ def __init__(self,test=False):
self.m_PauseAfterCancel.Check(self.SettingsDict['PauseAfterCancel'] != 'False')
self.Software = self.SettingsDict["Software"]
ThisChooseSoftwareDialog = MyChooseSoftwareDialog(self,self.FunctionsLoaded)
ThisChooseSoftwareDialog.SetSoftware(self.Software)
ThisChooseSoftwareDialog.SetSoftware(self.Systems.index(self.Software))

for item in self.m_NotSTMMenu.GetMenuItems():
if item.GetItemLabel() in self.FunctionsLoaded:
Expand Down Expand Up @@ -259,7 +269,7 @@ def LoadFunctions(self,Reloading=False):
# self.Functions[f"{FunctionName[:-3]}"] = import_source_file(os.path.abspath(f'Functions\\{FunctionName}'),os.path.abspath(f'Functions\\{FunctionName}'))
except Exception as e:
pass
for file in ["CreaTec.py","RHK.py","SXM.py","SXMRemote.py"]:
for file in self.NotAuxFiles:
try:
FunctionNames.remove(file)
except:
Expand All @@ -273,20 +283,22 @@ def LoadFunctions(self,Reloading=False):
if not Reloading:
CheckFunction = self.m_NotSTMMenu.AppendCheckItem(wx.ID_ANY,file[:-3])
self.Bind(wx.EVT_MENU,self.EditLoadedFunctionFiles,CheckFunction)
CheckFunction.Check()
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)
self.EditLoadedFunctionFiles()
def EditLoadedFunctionFiles(self,event=None):
self.FunctionsLoaded = []
for item in self.m_NotSTMMenu.GetMenuItems():
if item.IsChecked():
self.FunctionsLoaded.append(item.GetItemLabel())

ThisChooseSoftwareDialog = MyChooseSoftwareDialog(self,self.FunctionsLoaded)
ThisChooseSoftwareDialog.SetSoftware(self.Software)
if self.Software is not None:
ThisChooseSoftwareDialog = MyChooseSoftwareDialog(self,self.FunctionsLoaded)
ThisChooseSoftwareDialog.SetSoftware(self.Systems.index(self.Software))


def MakeFunctionButtons(self):
Expand Down Expand Up @@ -772,21 +784,13 @@ def AddDisconnectToQueue(self, event=None):
ThisStartMacroDialog.AddToQueue()
self.AddConnectToQueue()
return
def OnRHKSoftware(self, event):
ThisChooseSoftwareDialog = MyChooseSoftwareDialog(self)
ThisChooseSoftwareDialog.OnRHK()
return
def OnCreaTecSoftware(self, event):
ThisChooseSoftwareDialog = MyChooseSoftwareDialog(self)
ThisChooseSoftwareDialog.OnCreaTec()
return
def OnSXMSoftware(self, event):
def OnSoftware(self,i,event):
ThisChooseSoftwareDialog = MyChooseSoftwareDialog(self)
ThisChooseSoftwareDialog.OnSXM()
return
ThisChooseSoftwareDialog.SetSoftware(i)

def PauseAfterCancel(self,event):
ThisChooseSoftwareDialog = MyChooseSoftwareDialog(self,self.FunctionsLoaded)
ThisChooseSoftwareDialog.SetSoftware(self.Software)
ThisChooseSoftwareDialog.SetSoftware(self.Systems.index(self.Software))
pass
def ReloadFunctions(self,event):
self.LoadFunctions(Reloading=True)
Expand Down
Loading

0 comments on commit 0fd709a

Please sign in to comment.