def __init__(self, configuration=None, name=None, globals=None, locals=None, parent=None, title=None): """ configuration: object of type "configuration" from "configuration.py" name: name of configuration, e.g. "alio_diffractometer_saved_positions", "timing_modes" globals: When using "name=...", dictionary containing available motor objects. e.g. "from instrumentation import *" populates the global names space, globals=globals() to make these available inside the SavedPositionsPanel title: overrides user-configurable title (for backward compatibility) """ self.cache = {} self.locals = locals self.globals = globals if name is not None: self.name = name if configuration is not None: self.configuration = configuration if self.configuration is None and self.name is None: raise RuntimeError( "SavedPositionsPanel requires 'configuration' or 'name'") if self.configuration is None: from configuration import configuration self.configuration = configuration(self.name, globals=globals, locals=locals) if title is not None: self.configuration.title = title wx.Frame.__init__(self, parent=parent) # Icon from Icon import SetIcon SetIcon(self, self.icon, self.configuration.name) self.layout() self.Fit() self.Show() # Make sure "on_input" is called only after "update_settings". # Call the "on_input" routine whenever the user presses Enter. self.Bind(wx.EVT_TEXT_ENTER, self.on_input) # Periodically update the displayed fields. self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer) self.timer.Start(5000, oneShot=True) from threading import Thread self.update_thread = Thread(target=self.keep_updated) self.update_thread.daemon = True self.update_thread.start()
def update(self): self.Title = self.title from Icon import SetIcon SetIcon(self, self.icon) panel = self.ControlPanel if hasattr(self, "panel"): self.panel.Destroy() self.panel = panel self.Fit()
def __init__(self,parent,n): self.n = n wx.Frame.__init__(self,parent=parent,title="Setup") from Icon import SetIcon SetIcon(self,"Server") self.panel = wx.Panel(self) # Controls style = wx.TE_PROCESS_ENTER self.myLabel = TextCtrl(self.panel,size=(320,-1),style=style) self.Command = TextCtrl(self.panel,size=(320,-1),style=style) self.LogfileBasename = TextCtrl(self.panel,size=(320,-1),style=style) self.Value = TextCtrl(self.panel,size=(320,-1),style=style) self.Format = TextCtrl(self.panel,size=(320,-1),style=style) self.Test = TextCtrl(self.panel,size=(320,-1),style=style) # Callbacks self.Bind(wx.EVT_TEXT_ENTER,self.OnLabel,self.myLabel) self.Bind(wx.EVT_TEXT_ENTER,self.OnCommand,self.Command) self.Bind(wx.EVT_TEXT_ENTER,self.OnLogfileBasename,self.LogfileBasename) self.Bind(wx.EVT_TEXT_ENTER,self.OnValue,self.Value) self.Bind(wx.EVT_TEXT_ENTER,self.OnFormat,self.Format) self.Bind(wx.EVT_TEXT_ENTER,self.OnTest,self.Test) self.Bind(wx.EVT_SIZE,self.OnResize) # Layout self.layout = wx.BoxSizer() grid = wx.FlexGridSizer(cols=2,hgap=5,vgap=5) flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND label = "Name:" grid.Add(wx.StaticText(self.panel,label=label),flag=flag) grid.Add(self.myLabel,flag=flag,proportion=1) label = "Command:" grid.Add(wx.StaticText(self.panel,label=label),flag=flag) grid.Add(self.Command,flag=flag,proportion=1) label = "Logfile basename:" grid.Add(wx.StaticText(self.panel,label=label),flag=flag) grid.Add(self.LogfileBasename,flag=flag,proportion=1) label = "Value:" grid.Add(wx.StaticText(self.panel,label=label),flag=flag) grid.Add(self.Value,flag=flag,proportion=1) label = "Format:" grid.Add(wx.StaticText(self.panel,label=label),flag=flag) grid.Add(self.Format,flag=flag,proportion=1) label = "Test:" grid.Add(wx.StaticText(self.panel,label=label),flag=flag) grid.Add(self.Test,flag=flag,proportion=1) # Leave a 10-pixel wide space around the panel. self.layout.Add(grid,flag=wx.EXPAND|wx.ALL,proportion=1,border=10) self.panel.SetSizer(self.layout) self.panel.Fit() self.Fit() # Intialization self.refresh()
def __init__(self,parent=None,title="IOCs & Servers"): wx.Frame.__init__(self,parent=parent,title=title) from Icon import SetIcon SetIcon(self,"Server") # Controls self.panel = wx.Panel(self) self.controls = [] # Menus menuBar = wx.MenuBar() self.ViewMenu = wx.Menu() for i in range(0,len(self.views)): self.ViewMenu.AppendCheckItem(10+i,self.views.keys()[i]) self.ViewMenu.AppendSeparator() menuBar.Append (self.ViewMenu,"&View") self.SetupMenu = wx.Menu() self.SetupMenu.AppendCheckItem(200,"Setup") self.SetupMenu.AppendSeparator() self.SetupMenu.Append(201,"Add Line") self.SetupMenu.Append(202,"Remove Line") menuBar.Append(self.SetupMenu,"&More") menu = wx.Menu() menu.Append(wx.ID_ABOUT,"About...") menuBar.Append(menu,"&Help") self.SetMenuBar(menuBar) # Callbacks self.Bind(wx.EVT_MENU_OPEN,self.OnOpenView) for i in range(0,len(self.views)): self.Bind(wx.EVT_MENU,self.OnSelectView,id=10+i) self.Bind(wx.EVT_MENU,self.OnSetup,id=200) self.Bind(wx.EVT_MENU,self.OnAdd,id=201) self.Bind(wx.EVT_MENU,self.OnRemove,id=202) self.Bind(wx.EVT_MENU,self.OnAbout,id=wx.ID_ABOUT) self.Bind(wx.EVT_CLOSE,self.OnClose) # Layout self.sizer = wx.BoxSizer(wx.VERTICAL) self.panel.SetSizer(self.sizer) self.update_controls() self.Show() # Refresh from numpy import nan self.values = {} self.old_values = {} self.Bind(wx.EVT_TIMER,self.OnUpdate) from threading import Thread self.thread = Thread(target=self.keep_updated,name=self.name) self.thread.daemon = True self.thread.start()
def __init__ (self,parent=None): wx.Frame.__init__(self,parent,title="Configurations",size=self.size) from Icon import SetIcon SetIcon(self,"Tool") # Controls self.panel = wx.lib.scrolledpanel.ScrolledPanel(self) style = wx.TE_PROCESS_ENTER self.Configuration = ComboBox(self.panel,size=(240,-1),style=style) self.SavedToCurrent = wx.Button(self.panel,label=" Saved ->",size=(160,-1)) self.CurrentToSaved = wx.Button(self.panel,label="<- Current ",size=(160,-1)) N = len(configurations.parameters.descriptions) self.Descriptions = [TextCtrl(self.panel,size=(240,-1),style=style) for i in range(0,N)] self.CurrentValues = [ComboBox(self.panel,size=(160,-1),style=style) for i in range(0,N)] self.SavedValues = [ComboBox(self.panel,size=(160,-1),style=style) for i in range(0,N)] # Callbacks self.Configuration.Bind(wx.EVT_TEXT_ENTER,self.OnConfiguration) self.Configuration.Bind(wx.EVT_COMBOBOX,self.OnConfiguration) self.SavedToCurrent.Bind(wx.EVT_BUTTON,self.OnSavedToCurrent) self.CurrentToSaved.Bind(wx.EVT_BUTTON,self.OnCurrentToSaved) self.Bind(wx.EVT_TEXT_ENTER,self.OnEnter) self.Bind(wx.EVT_COMBOBOX,self.OnEnter) self.Bind(wx.EVT_SIZE,self.OnResize) ##self.Bind(wx.EVT_CLOSE,self.OnClose) # Layout layout = wx.BoxSizer() grid = wx.FlexGridSizer(cols=3,hgap=2,vgap=2) flag = wx.ALIGN_LEFT grid.Add (self.Configuration,flag=flag) grid.Add (self.SavedToCurrent,flag=flag) grid.Add (self.CurrentToSaved,flag=flag) for i in range(0,N): grid.Add (self.Descriptions[i],flag=flag) grid.Add (self.SavedValues[i],flag=flag) grid.Add (self.CurrentValues[i],flag=flag) # Leave a 10-pixel wide space around the panel. border_box = wx.BoxSizer(wx.VERTICAL) border_box.Add (grid,flag=wx.EXPAND|wx.ALL) layout.Add (border_box,flag=wx.EXPAND|wx.ALL,border=10) self.panel.SetSizer(layout) ##self.panel.SetAutoLayout(True) self.panel.SetupScrolling() ##self.panel.Fit() ##self.Fit() self.Show() self.keep_alive()
def layout(self): self.Title = self.title from Icon import SetIcon SetIcon(self, self.icon) if not self.MenuBar: self.MenuBar = self.menu_bar panel = self.ControlPanel if hasattr(self, "panel"): self.panel.Destroy() self.panel = panel self.Fit()
def __init__(self, parent=None, name="TimingPanel"): wx.Frame.__init__(self, parent=parent, title=self.title) self.name = name panel = wx.Panel(self) from Icon import SetIcon SetIcon(self, self.icon) # Controls from EditableControls import ComboBox style = wx.TE_PROCESS_ENTER width = 160 self.Prefix = ComboBox(panel, style=style, size=(width, -1)) self.Address = wx.TextCtrl(panel, style=wx.TE_READONLY, size=(width, -1)) self.Address.Enabled = False # Callbacks self.Bind(wx.EVT_TEXT_ENTER, self.OnEnterPrefix, self.Prefix) self.Bind(wx.EVT_COMBOBOX, self.OnEnterPrefix, self.Prefix) self.Bind(wx.EVT_CLOSE, self.OnClose) # Layout layout = wx.GridBagSizer(1, 1) a = wx.ALIGN_CENTRE_VERTICAL e = wx.EXPAND row = 0 label = wx.StaticText(panel, label="EPICS Record:") layout.Add(label, (row, 0), flag=a) layout.Add(self.Prefix, (row, 1), flag=a | e) row += 1 label = wx.StaticText(panel, label="IP Address (auto detect):") layout.Add(label, (row, 0), flag=a) layout.Add(self.Address, (row, 1), flag=a | e) # Leave a 5-pixel wide border. box = wx.BoxSizer(wx.VERTICAL) box.Add(layout, flag=wx.ALL, border=5) panel.SetSizer(box) panel.Fit() self.Fit() self.Show() self.refresh()
def __init__(self): wx.Frame.__init__(self, parent=None, title=self.title) # Icon from Icon import SetIcon SetIcon(self, "Tool") self.panel = self.ControlPanel self.Fit() self.Show() # Refresh self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.timer.Start(5000, oneShot=True)
def __init__(self,parent,n): self.n = n wx.Frame.__init__(self,parent=parent,title="Log",size=(640,240)) from Icon import SetIcon SetIcon(self,"Server") self.panel = wx.Panel(self) # Controls from EditableControls import TextCtrl,ComboBox style = wx.TE_PROCESS_ENTER|wx.TE_MULTILINE|wx.TE_DONTWRAP self.Log = TextCtrl(self.panel,size=(-1,-1),style=style) self.Log.Font = wx.Font(pointSize=10,family=wx.TELETYPE,style=wx.NORMAL, weight=wx.NORMAL) self.Clear = wx.Button(self.panel,size=(-1,-1),label="Clear Log") self.Level = ComboBox(self.panel,size=(-1,-1),choices=self.levels) # Callbacks self.Bind(wx.EVT_TEXT_ENTER,self.OnLog,self.Log) self.Bind(wx.EVT_BUTTON,self.OnClear,self.Clear) self.Bind(wx.EVT_COMBOBOX,self.OnLevel,self.Level) self.Bind(wx.EVT_TEXT_ENTER,self.OnLevel,self.Level) # Layout self.layout = wx.BoxSizer(wx.VERTICAL) self.layout.Add(self.Log,flag=wx.ALL|wx.EXPAND,proportion=1,border=2) self.controls = wx.BoxSizer(wx.HORIZONTAL) self.layout.Add(self.controls,flag=wx.ALL|wx.EXPAND,proportion=0,border=2) self.controls.Add(self.Clear,flag=wx.ALL|wx.EXPAND,proportion=0,border=2) self.controls.Add(self.Level,flag=wx.ALL|wx.EXPAND,proportion=0,border=2) self.panel.SetSizer(self.layout) self.Layout() # Periodically refresh the displayed settings. self.values = {} self.Bind(wx.EVT_TIMER,self.OnUpdate) from threading import Thread self.thread = Thread(target=self.keep_updated,name=self.name) self.thread.daemon = True self.thread.start()
def __init__(self): wx.Frame.__init__(self,parent=None) self.Title = "Lightwave Temperature Controller DL" # Icon from Icon import SetIcon SetIcon(self,"Temperature Controller") # Controls panel = wx.Panel(self) style = wx.TE_PROCESS_ENTER self.SetPoint = ComboBox(panel,style=style) style = wx.TE_READONLY self.ActualTemperature = wx.TextCtrl(panel,style=style) self.CurrentPower = wx.TextCtrl(panel,style=style) self.Status = ComboBox(panel,style=style,choices=["On","Off",""]) self.LiveCheckBox = wx.CheckBox (panel,label="Live") self.RefreshButton = wx.Button (panel,label="Refresh",size=(65,-1)) self.MoreButton = wx.Button (panel,label="More...",size=(60,-1)) self.RampButton = wx.Button (panel,label="Ramp...",size=(60,-1)) w,h = self.MoreButton.Size self.AboutButton = wx.Button (panel,label="?",size=(h*1.25,h*0.75)) # Callbacks self.Bind (wx.EVT_TEXT_ENTER,self.OnEnterSetPoint,self.SetPoint) self.Bind (wx.EVT_COMBOBOX,self.OnEnterSetPoint,self.SetPoint) self.Bind (wx.EVT_TEXT_ENTER,self.OnChangeStatus,self.Status) self.Bind (wx.EVT_COMBOBOX,self.OnChangeStatus,self.Status) self.Bind (wx.EVT_CHECKBOX,self.OnLive,self.LiveCheckBox) self.Bind (wx.EVT_BUTTON,self.OnRefresh,self.RefreshButton) self.Bind (wx.EVT_BUTTON,self.OnMore,self.MoreButton) self.Bind (wx.EVT_BUTTON,self.OnAbout,self.AboutButton) self.Bind (wx.EVT_BUTTON,self.OnTemperatureRamp,self.RampButton) # Layout layout = wx.GridBagSizer(1,1) a = wx.ALIGN_CENTRE_VERTICAL e = wx.EXPAND # Under Linux, if the version of wxWidget is 2.6 or older, # the label size needs to be specified to prevent line wrapping. # (This bug has been corrected in version 2.8). layout.Add (wx.StaticText(panel,label="Set Point:"),(0,0),flag=a) layout.Add (self.SetPoint,(0,1),flag=a|e) t = wx.StaticText(panel,label="Actual Temperature:") layout.Add (t,(1,0),flag=a) layout.Add (self.ActualTemperature,(1,1),flag=a|e) t = wx.StaticText(panel,label="Current / Power:") layout.Add (t,(2,0),flag=a) layout.Add (self.CurrentPower,(2,1),flag=a|e) t = wx.StaticText(panel,label="Status:") layout.Add (t,(3,0),flag=a) layout.Add (self.Status,(3,1),flag=a|e) buttons = wx.BoxSizer(wx.HORIZONTAL) buttons.Add (self.LiveCheckBox,flag=wx.ALIGN_CENTER_VERTICAL) buttons.AddSpacer(5) buttons.Add (self.RefreshButton,flag=wx.ALIGN_CENTER_VERTICAL) buttons.AddSpacer(5) buttons.Add (self.MoreButton,flag=wx.ALIGN_CENTER_VERTICAL) buttons.AddSpacer(5) buttons.Add (self.RampButton,flag=wx.ALIGN_CENTER_VERTICAL) buttons.AddSpacer(5) buttons.Add (self.AboutButton,flag=wx.ALIGN_CENTER_VERTICAL) # Leave a 5 pixel wide border. box = wx.BoxSizer(wx.VERTICAL) box.Add (layout,flag=wx.ALL,border=5) box.Add (buttons,flag=wx.ALL|wx.ALIGN_CENTER_HORIZONTAL,border=5) panel.SetSizer(box) panel.Fit() self.Fit() self.Show() # Restore saved history. config_dir = wx.StandardPaths.Get().GetUserDataDir() config_file = config_dir+"/TemperatureController.py" self.config = wx.FileConfig (localFilename=config_file) value = self.config.Read('History') if value: self.history = eval(value) else: self.history = [] self.update_history() # Initialization self.timer = wx.Timer(self) self.Bind (wx.EVT_TIMER,self.refresh,self.timer) self.timer.Start(1000,oneShot=True)
def __init__(self, parent, register, title, update=[lambda: None], pre_update=None, post_update=None, keep_value=False, attribute="offset", *args, **kwargs): """ update: list of procedures to be called after tweeking the offset pre_update: procedure to be called before tweeking the offset """ wx.Panel.__init__(self, parent) self.title = title self.register = register if update is not None: self.update = update if pre_update is not None: self.pre_update = pre_update if post_update is not None: self.post_update = post_update self.keep_value = keep_value self.attribute = attribute self.name = "TimingPanel.Calibration." + str(register) from Icon import SetIcon SetIcon(self, self.icon) # Controls style = wx.TE_PROCESS_ENTER from EditableControls import TextCtrl self.Current = TextCtrl(self, size=(155, -1), style=style) self.Decr = wx.Button(self, label="<", size=(30, -1)) self.Incr = wx.Button(self, label=">", size=(30, -1)) self.Set = wx.Button(self, label="Set...", size=(50, -1)) from numpy import arange, unique from timing_system import round_next choices = 10**arange(-11.0, -2.01, 1) dt = self.register.stepsize choices = [round_next(t, dt) for t in choices] choices = unique(choices) choices = choices[choices > 0] from time_string import time_string choices = [time_string(t) for t in choices] from EditableControls import ComboBox self.Step = ComboBox(self, size=(80, -1), choices=choices, style=style, value=time_string(self.next_step(self.step))) # Callbacks self.Bind(wx.EVT_TEXT_ENTER, self.OnChange, self.Current) self.Bind(wx.EVT_COMBOBOX, self.OnChange, self.Current) self.Bind(wx.EVT_TEXT_ENTER, self.OnStep, self.Step) self.Bind(wx.EVT_COMBOBOX, self.OnStep, self.Step) self.Bind(wx.EVT_BUTTON, self.OnDecr, self.Decr) self.Bind(wx.EVT_BUTTON, self.OnIncr, self.Incr) self.Bind(wx.EVT_BUTTON, self.OnSet, self.Set) # Layout layout = wx.GridBagSizer(1, 1) layout.SetEmptyCellSize((0, 0)) av = wx.ALIGN_CENTRE_VERTICAL ah = wx.ALIGN_CENTRE_HORIZONTAL e = wx.EXPAND t = wx.StaticText(self, label=self.title, size=(110, -1)) t.Wrap(110) layout.Add(t, (0, 0), span=(2, 1), flag=av) layout.Add(self.Decr, (0, 2), flag=av) layout.Add(self.Current, (0, 3), flag=av | e) layout.Add(self.Incr, (0, 4), flag=av) group = wx.BoxSizer(wx.HORIZONTAL) t = wx.StaticText(self, label="Step") group.Add(t, flag=av) group.AddSpacer((5, 5)) group.Add(self.Step, flag=av) group.AddSpacer((5, 5)) group.Add(self.Set, flag=av) layout.Add(group, (1, 2), span=(1, 3), flag=ah) self.SetSizer(layout) self.Fit() self.keep_alive()
def __init__(self): wx.Frame.__init__(self, parent=None, title="SAXS-WAXS Control") # Icon from Icon import SetIcon SetIcon(self, "SAXS-WAXS Control") # Controls panel = wx.Panel(self) from EditableControls import ComboBox, TextCtrl from Controls import Control self.Environment = Control(panel, type=ComboBox, name="SAXS_WAXS_Control_Panel.Environment", globals=globals(), size=(80, -1), choices=["0 (NIH)", "1 (APS)", "2 (LCLS)"]) self.Home = Control(panel, type=wx.ToggleButton, name="SAXS_WAXS_Control_Panel.Home", globals=globals(), size=(100, -1)) self.ProgramRunning = Control( panel, type=wx.ToggleButton, name="SAXS_WAXS_Control_Panel.ProgramRunning", globals=globals(), size=(100, -1)) self.GotoSaved = Control(panel, type=wx.Button, name="SAXS_WAXS_Control_Panel.GotoSaved", globals=globals(), label="Go To Saved Position", size=(180, -1)) self.Save = Control(panel, type=wx.Button, name="SAXS_WAXS_Control_Panel.Save", globals=globals(), label="Save Current X,Y Positions", size=(180, -1)) self.Inserted = Control(panel, type=wx.ToggleButton, name="SAXS_WAXS_Control_Panel.Inserted", globals=globals(), size=(150, -1)) self.Mode = Control(panel, type=wx.ComboBox, name="SAXS_WAXS_Control_Panel.Mode", globals=globals(), size=(100, -1), choices=SAXS_WAXS_control.modes) self.ShutterEnabled = Control( panel, type=wx.CheckBox, name="SAXS_WAXS_Control_Panel.ShutterEnabled", globals=globals(), size=(80, -1)) self.PumpEnabled = Control(panel, type=wx.CheckBox, name="SAXS_WAXS_Control_Panel.PumpEnabled", globals=globals(), size=(80, -1)) self.PumpStep = Control(panel, type=ComboBox, name="SAXS_WAXS_Control_Panel.PumpStep", globals=globals(), size=(80, -1), choices=SAXS_WAXS_control.pump_step_choices) self.PumpPosition = Control( panel, type=TextCtrl, name="SAXS_WAXS_Control_Panel.PumpPosition", globals=globals(), size=(70, -1)) self.PumpHomed = Control(panel, type=wx.ToggleButton, name="SAXS_WAXS_Control_Panel.PumpHomed", globals=globals(), size=(140, -1)) choices = ["500", "600", "700", "800", "1000"] self.LoadSampleStep = Control( panel, type=ComboBox, name="SAXS_WAXS_Control_Panel.LoadSampleStep", globals=globals(), size=(70, -1), choices=choices) self.LoadSample = Control(panel, type=wx.ToggleButton, name="SAXS_WAXS_Control_Panel.LoadSample", globals=globals(), label="Load Sample", size=(140, -1)) choices = ["-500", "-600", "-700", "-800", "-1000"] self.ExtractSampleStep = Control( panel, type=ComboBox, name="SAXS_WAXS_Control_Panel.ExtractSampleStep", globals=globals(), size=(70, -1), choices=choices) self.ExtractSample = Control( panel, type=wx.ToggleButton, name="SAXS_WAXS_Control_Panel.ExtractSample", globals=globals(), label="Extract Sample", size=(140, -1)) choices = ["500", "600", "700", "800", "1000"] self.CirculateSampleStep = Control( panel, type=ComboBox, name="SAXS_WAXS_Control_Panel.CirculateSampleStep", globals=globals(), size=(70, -1), choices=choices) self.CirculateSample = Control( panel, type=wx.ToggleButton, name="SAXS_WAXS_Control_Panel.CirculateSample", globals=globals(), label="Circulate Sample", size=(140, -1)) self.PumpSpeed = Control(panel, type=TextCtrl, name="SAXS_WAXS_Control_Panel.PumpSpeed", globals=globals(), size=(70, -1)) # Layout flag = wx.ALIGN_CENTRE_HORIZONTAL | wx.ALL border = 5 layout = wx.BoxSizer(wx.HORIZONTAL) left_panel = wx.BoxSizer(wx.VERTICAL) group = wx.BoxSizer(wx.HORIZONTAL) text = wx.StaticText(panel, label="Environment:") group.Add(text, flag=flag, border=border) group.Add(self.Environment, flag=flag, border=border) left_panel.Add(group, flag=flag, border=border) group = wx.BoxSizer(wx.VERTICAL) text = wx.StaticText(panel, label="Ensemble Operation") group.Add(text, flag=flag, border=border) group.Add(self.Home, flag=flag, border=border) group.Add(self.ProgramRunning, flag=flag, border=border) left_panel.Add(group, flag=flag, border=border) group = wx.BoxSizer(wx.VERTICAL) text = wx.StaticText(panel, label="Capillary Position") group.Add(text, flag=flag, border=border) group.Add(self.GotoSaved, flag=flag, border=border) group.Add(self.Save, flag=flag, border=border) group.Add(self.Inserted, flag=flag, border=border) left_panel.Add(group, flag=flag, border=border) layout.Add(left_panel, flag=flag, border=border) right_panel = wx.BoxSizer(wx.VERTICAL) group = wx.GridBagSizer(4, 2) l = wx.ALIGN_LEFT r = wx.ALIGN_RIGHT cv = wx.ALIGN_CENTER_VERTICAL a = wx.ALL text = wx.StaticText(panel, label="Mode: ") group.Add(text, (0, 0), flag=r | cv) group.Add(self.Mode, (0, 1), flag=l | cv) text = wx.StaticText(panel, label="X-ray ms shutter: ") group.Add(text, (1, 0), flag=r | cv) group.Add(self.ShutterEnabled, (1, 1), flag=l | cv) text = wx.StaticText(panel, label="Pump: ") group.Add(text, (2, 0), flag=r | cv) group.Add(self.PumpEnabled, (2, 1), flag=l | cv) text = wx.StaticText(panel, label="Pump Steps/Stroke: ") group.Add(text, (3, 0), flag=r | cv) group.Add(self.PumpStep, (3, 1), flag=l | cv) right_panel.Add(group, flag=flag, border=border) text = wx.StaticText(panel, label="Peristaltic Pump Operation [motor steps]") right_panel.Add(text, flag=flag, border=border) group = wx.GridBagSizer(1, 1) group.Add(self.PumpPosition, (0, 0), flag=r | cv | a, border=border) group.Add(self.PumpHomed, (0, 1), flag=l | cv | a, border=border) group.Add(self.LoadSampleStep, (1, 0), flag=r | cv | a, border=border) group.Add(self.LoadSample, (1, 1), flag=l | cv | a, border=border) group.Add(self.ExtractSampleStep, (2, 0), flag=r | cv | a, border=border) group.Add(self.ExtractSample, (2, 1), flag=l | cv | a, border=border) group.Add(self.CirculateSampleStep, (3, 0), flag=r | cv | a, border=border) group.Add(self.CirculateSample, (3, 1), flag=l | cv | a, border=border) group.Add(self.PumpSpeed, (4, 0), flag=r | cv | a, border=border) text = wx.StaticText(panel, label="Pump Speed [steps/s]", size=(140, -1)) group.Add(text, (4, 1), flag=l | cv | a, border=border) right_panel.Add(group, flag=flag, border=border) layout.Add(right_panel, flag=flag, border=border) panel.SetSizer(layout) panel.Fit() self.Fit() # Settings self.Environment.defaults = {"Value": "offline?", "Enabled": False} self.Environment.value = "SAXS_WAXS_control.environment" self.Environment.properties = { "Enabled": [ (True, "SAXS_WAXS_control.ensemble_online"), ], } self.Home.defaults = {"Label": "Home", "Enabled": False} self.Home.action = { False: "SAXS_WAXS_control.ensemble_homing = True", True: "SAXS_WAXS_control.ensemble_homing = True", } self.Home.properties = { "Value": [ (False, "SAXS_WAXS_control.ensemble_homed == False"), (True, "SAXS_WAXS_control.ensemble_homed == True"), ], "Enabled": [ (False, "SAXS_WAXS_control.ensemble_program_running == True"), (True, "SAXS_WAXS_control.ensemble_program_running == False"), ], "Label": [ ("Homing", "SAXS_WAXS_control.ensemble_homing == True"), ("Home", "SAXS_WAXS_control.ensemble_homed == False"), ("Homed", "SAXS_WAXS_control.ensemble_homed == True"), ], "BackgroundColour": [ ("yellow", "SAXS_WAXS_control.ensemble_homing == True"), ("green", "SAXS_WAXS_control.ensemble_homed == True"), ("red", "SAXS_WAXS_control.ensemble_homed == False"), ], } self.ProgramRunning.defaults = { "Label": "Start [Stop]", "Enabled": False } self.ProgramRunning.action = { False: "SAXS_WAXS_control.ensemble_program_running = False", True: "SAXS_WAXS_control.ensemble_program_running = True", } self.ProgramRunning.properties = { "Value": [ (False, "SAXS_WAXS_control.ensemble_program_running == False"), (True, "SAXS_WAXS_control.ensemble_program_running == True"), ], "Enabled": [ (False, "SAXS_WAXS_control.fault == True"), (True, "SAXS_WAXS_control.fault == False"), ], "Label": [ ("Fault", "SAXS_WAXS_control.fault == True"), ("Start", "SAXS_WAXS_control.ensemble_program_running == False"), ("Stop", "SAXS_WAXS_control.ensemble_program_running == True"), ], "BackgroundColour": [ ("green", "SAXS_WAXS_control.ensemble_program_running == True"), ("red", "SAXS_WAXS_control.ensemble_program_running == False"), ], } self.GotoSaved.action = { True: "SAXS_WAXS_control.inserted = True", } self.GotoSaved.defaults = {"Enabled": False} self.GotoSaved.properties = { "Enabled": [ (True, "1-SAXS_WAXS_control.inserted"), ], "BackgroundColour": [ ("red", "SAXS_WAXS_control.XY_enabled == False"), ], } self.Save.action = { True: "SAXS_WAXS_control.at_inserted_position = True", } self.Save.defaults = {"Enabled": False} self.Save.properties = { "Enabled": [ (True, "SAXS_WAXS_control.at_inserted_position == False"), ], } self.Inserted.action = { True: "SAXS_WAXS_control.inserted = True", False: "SAXS_WAXS_control.retracted = True", } self.Inserted.defaults = { "Enabled": False, "Label": "Inserted [Withdrawn]" } self.Inserted.properties = { "Value": [ (True, "SAXS_WAXS_control.inserted == True"), (False, "SAXS_WAXS_control.retracted == True"), ], "Enabled": [ (True, "SAXS_WAXS_control.XY_enabled"), ], "Label": [ ("Inserted", "SAXS_WAXS_control.inserted == True"), ("Retracted", "SAXS_WAXS_control.retracted == True"), ("Insert", "SAXS_WAXS_control.inserted == SAXS_WAXS_control.retracted"), ], "BackgroundColour": [ ("green", "SAXS_WAXS_control.inserted == True"), ("yellow", "SAXS_WAXS_control.retracted == True"), ("red", "SAXS_WAXS_control.inserted == SAXS_WAXS_control.retracted"), ], } self.Mode.defaults = {"Value": "offline", "Enabled": False} self.Mode.value = "SAXS_WAXS_control.mode" self.Mode.properties = { "Enabled": [ (True, "SAXS_WAXS_control.timing_system_running == True"), ], } self.ShutterEnabled.defaults = {"Enabled": False, "Label": "offline"} self.ShutterEnabled.action = { False: "SAXS_WAXS_control.ms_on = False", True: "SAXS_WAXS_control.ms_on = True", } self.ShutterEnabled.properties = { "Value": [ (False, "SAXS_WAXS_control.ms_on == False"), (True, "SAXS_WAXS_control.ms_on == True"), ], "Label": [ ("", "SAXS_WAXS_control.timing_system_running == True"), ("stopped", "SAXS_WAXS_control.timing_system_running == False"), ], "Enabled": [ (True, "SAXS_WAXS_control.timing_system_running == True"), ], } self.PumpEnabled.defaults = {"Enabled": False, "Label": "offline"} self.PumpEnabled.action = { False: "SAXS_WAXS_control.pump_on = False", True: "SAXS_WAXS_control.pump_on = True", } self.PumpEnabled.properties = { "Value": [ (False, "SAXS_WAXS_control.pump_on == False"), (True, "SAXS_WAXS_control.pump_on == True"), ], "Label": [ ("", "SAXS_WAXS_control.timing_system_running == True"), ("stopped", "SAXS_WAXS_control.timing_system_running == False"), ], "Enabled": [ (True, "SAXS_WAXS_control.timing_system_running == True"), ], } self.PumpStep.defaults = {"Value": "offline", "Enabled": False} self.PumpStep.value = "SAXS_WAXS_control.pump_step" self.PumpStep.properties = { "Enabled": [ (True, "SAXS_WAXS_control.ensemble_online"), ], } self.PumpPosition.defaults = {"Value": "offline", "Enabled": False} self.PumpPosition.value = "SAXS_WAXS_control.pump_position" self.PumpPosition.format = "%.1f" self.PumpPosition.properties = { "Enabled": [ (True, "SAXS_WAXS_control.ensemble_online"), ], } self.PumpHomed.defaults = {"Label": "Home", "Enabled": False} self.PumpHomed.action = { False: "SAXS_WAXS_control.pump_homed = True", True: "SAXS_WAXS_control.pump_homed = True", } self.PumpHomed.properties = { "Value": [ (True, "SAXS_WAXS_control.pump_homed == True"), ], "Enabled": [ (True, "SAXS_WAXS_control.pump_movable"), ], "Label": [ ("Home", "SAXS_WAXS_control.pump_homed == False"), ("Homed", "SAXS_WAXS_control.pump_homed == True"), ], "BackgroundColour": [ ("green", "SAXS_WAXS_control.pump_homed == True"), ("red", "SAXS_WAXS_control.pump_homed == False"), ], } self.LoadSampleStep.value = "SAXS_WAXS_control.load_step" self.ExtractSampleStep.value = "SAXS_WAXS_control.extract_step" self.CirculateSampleStep.value = "SAXS_WAXS_control.circulate_step" self.LoadSample.action = { False: "SAXS_WAXS_control.sample_loading = False", True: "SAXS_WAXS_control.sample_loading = True", } self.LoadSample.defaults = {"Enabled": False} self.LoadSample.properties = { "Value": [ (True, "SAXS_WAXS_control.sample_loading == True"), ], "Enabled": [ (True, "SAXS_WAXS_control.pump_movable"), ], "Label": [ ("Load Sample", "not SAXS_WAXS_control.sample_loading"), ("Cancel Load", "SAXS_WAXS_control.sample_loading"), ], "BackgroundColour": [ ("yellow", "SAXS_WAXS_control.sample_loading"), ("red", "SAXS_WAXS_control.pump_enabled == False"), ], } self.ExtractSample.action = { False: "SAXS_WAXS_control.sample_extracting = False", True: "SAXS_WAXS_control.sample_extracting = True", } self.ExtractSample.defaults = {"Enabled": False} self.ExtractSample.properties = { "Value": [ (True, "SAXS_WAXS_control.sample_extracting == True"), ], "Enabled": [ (True, "SAXS_WAXS_control.pump_movable"), ], "Label": [ ("Extract Sample", "not SAXS_WAXS_control.sample_extracting"), ("Cancel Extract", "SAXS_WAXS_control.sample_extracting"), ], "BackgroundColour": [ ("yellow", "SAXS_WAXS_control.sample_extracting == True"), ("red", "SAXS_WAXS_control.pump_enabled == False"), ], } self.CirculateSample.action = { False: "SAXS_WAXS_control.sample_circulating = False", True: "SAXS_WAXS_control.sample_circulating = True", } self.CirculateSample.defaults = {"Enabled": False} self.CirculateSample.properties = { "Value": [ (True, "SAXS_WAXS_control.sample_circulating == True"), ], "Enabled": [ (True, "SAXS_WAXS_control.pump_movable"), ], "Label": [ ("Circulate Sample", "not SAXS_WAXS_control.sample_circulating"), ("Cancel Circulate", "SAXS_WAXS_control.sample_circulating"), ], "BackgroundColour": [ ("yellow", "SAXS_WAXS_control.sample_circulating"), ("red", "SAXS_WAXS_control.pump_enabled == False"), ], } self.PumpSpeed.defaults = {"Value": "offline", "Enabled": False} self.PumpSpeed.value = "SAXS_WAXS_control.pump_speed" self.PumpSpeed.properties = { "Enabled": [ (True, "SAXS_WAXS_control.ensemble_online"), ], } self.Show()
def __init__(self, name=""): """name: defines settings filename.""" if name == "": name = type(self).__name__ self.name = name ##debug("DataLogger: name: %r" % self.name) wx.Frame.__init__(self, parent=None) # Icon from Icon import SetIcon SetIcon(self, "Data Logger") # Menus self.title = self.name menuBar = wx.MenuBar() menu = wx.Menu() menu.Append(101, "Logfile...\tCtrl+O", "Where to store the timing history files to watch.") self.Bind(wx.EVT_MENU, self.OnSelectLogfile, id=101) menu.Append(121, "E&xit", "Closes this window.") self.Bind(wx.EVT_MENU, self.OnExit, id=121) menuBar.Append(menu, "&File") self.Bind(wx.EVT_CLOSE, self.OnExit) menu = wx.Menu() menu.Append(402, "&Options...", "Parameters") self.Bind(wx.EVT_MENU, self.OnOptions, id=402) menuBar.Append(menu, "&Options") menu = wx.Menu() menu.Append(501, "&About...", "Version information") self.Bind(wx.EVT_MENU, self.OnAbout, id=501) menuBar.Append(menu, "&Help") self.SetMenuBar(menuBar) # Controls from matplotlib.figure import Figure from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg self.figure = Figure(figsize=(4, 3)) self.canvas = FigureCanvasWxAgg(self, -1, self.figure) self.figure.subplots_adjust(bottom=0.2) self.plot = self.figure.add_subplot(1, 1, 1) self.active = wx.ToggleButton(self, label="Active") self.Bind(wx.EVT_TOGGLEBUTTON, self.OnActive, self.active) self.TimeFraction = wx.ScrollBar(self) self.TimeFraction.SetScrollbar(0, 200, 1000, 100, True) # SetScrollbar(position,thumbSize,range,pageSize,refresh) # [Arguments misnamed "orientation,position,thumbSize,range,refresh" # in WxPython 2.9.1.1] self.TimeFraction.DefaultColour = self.TimeFraction.BackgroundColour events = [ wx.EVT_SCROLL_TOP, wx.EVT_SCROLL_BOTTOM, wx.EVT_SCROLL_LINEUP, wx.EVT_SCROLL_LINEDOWN, wx.EVT_SCROLL_PAGEUP, wx.EVT_SCROLL_PAGEDOWN, wx.EVT_SCROLL_THUMBRELEASE ] for e in events: self.Bind(e, self.OnTimeFractionChanged, self.TimeFraction) choices = [ "10s", "30s", "1min", "2min", "5min", "10min", "30min", "1h", "2h", "6h", "12h", "1d", "2d", "5d" ] style = wx.TE_PROCESS_ENTER self.TimeWindow = wx.ComboBox(self, style=style, choices=choices) self.Bind(wx.EVT_COMBOBOX, self.OnTimeWindowChanged, self.TimeWindow) self.Bind(wx.EVT_TEXT_ENTER, self.OnTimeWindowChanged, self.TimeWindow) self.CreateStatusBar() # Layout vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.canvas, proportion=1, flag=wx.EXPAND) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add(self.active, proportion=0) hbox.Add(self.TimeFraction, proportion=1, flag=wx.EXPAND) vbox.Add(hbox, proportion=0, flag=wx.EXPAND) hbox.Add(self.TimeWindow, proportion=0) self.SetSizer(vbox) self.Fit() # Default settings. self.time_window = 60 # seconds self.max_value = nan self.min_value = nan self.waiting_time = 0.3 self.reject_outliers = False self.outlier_cutoff = 2.5 self.show_statistics = True self.average_count = 1 self.Size = 640, 480 # Restore last saved settings. self.settings = [ "counter_name", "Size", "logfile", "average_count", "max_value", "min_value", "end_fraction", "reject_outliers", "outlier_cutoff", "show_statistics", "time_window" ] self.update_settings() # Initialization self.npoints = 0 self.Show() self.update() start_new_thread(measure, ()) start_new_thread(watch_logfile, ())
def __init__(self, parent=None): wx.Frame.__init__(self, parent=parent, title="Channel Archiver") from Icon import SetIcon SetIcon(self, "Archiver") self.panel = wx.Panel(self) border = wx.BoxSizer(wx.VERTICAL) flag = wx.ALL | wx.EXPAND box = wx.BoxSizer(wx.VERTICAL) from wx import grid self.Table = grid.Grid(self.panel) nrows = max(len(self.PVs), 1) self.Table.CreateGrid(nrows, 4) self.Table.SetRowLabelSize(20) # 1,2,... self.Table.SetColLabelSize(20) self.Table.SetColLabelValue(0, "Log") self.Table.SetColLabelValue(1, "Description") self.Table.SetColLabelValue(2, "Process Variable") self.Table.SetColLabelValue(3, "Value") for i in range(0, min(nrows, len(self.PVs))): if i < len(self.PVsuse) and self.PVsuse[i]: text = "Yes" else: text = "No" self.Table.SetCellValue(i, 0, text) if i < len(self.PVnames): self.Table.SetCellValue(i, 1, self.PVnames[i]) self.Table.SetCellValue(i, 2, self.PVs[i]) self.Table.AutoSize() self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnEnterCell, self.Table) self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnSelectCell, self.Table) box.Add(self.Table, flag=flag, proportion=1) buttons = wx.BoxSizer() button = wx.Button(self.panel, label="+", style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.add_row, button) buttons.Add(button, flag=flag) size = button.GetSize() button = wx.Button(self.panel, label="-", size=size) self.Bind(wx.EVT_BUTTON, self.delete_row, button) buttons.Add(button, flag=flag) box.Add(buttons, flag=flag) # Leave a 10-pixel wide space around the panel. border.Add(box, flag=flag, border=10, proportion=1) flag = wx.ALL | wx.EXPAND group = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, label="Destination:") group.Add(label, flag=flag) style = wx.TE_PROCESS_ENTER self.Directory = TextCtrl(self.panel, size=(250, -1), style=style) self.Directory.Value = channel_archiver.directory self.Bind(wx.EVT_TEXT_ENTER, self.OnDirectory, self.Directory) group.Add(self.Directory, flag=flag, proportion=1) button = wx.Button(self.panel, label="Browse...") self.Bind(wx.EVT_BUTTON, self.OnBrowse, button) group.Add(button, flag=flag) # Leave a 10-pixel wide space around the panel. flag = wx.ALL | wx.EXPAND border.Add(group, flag=flag, border=10) buttons = wx.BoxSizer() button = wx.ToggleButton(self.panel, label="Active") self.Bind(wx.EVT_TOGGLEBUTTON, self.OnActive, button) buttons.Add(button, flag=flag) buttons.AddSpacer((10, 10)) button = wx.Button(self.panel, label="Test") self.Bind(wx.EVT_BUTTON, self.test, button) buttons.Add(button, flag=flag) # Leave a 10-pixel wide space around the panel. border.Add(buttons, flag=flag, border=10) self.panel.Sizer = border self.panel.Fit() self.Fit() self.Show() self.Bind(wx.EVT_SIZE, self.OnResize)