def __init__(self,parent=None): wx.Frame.__init__(self,parent=parent,title="Configuration") panel = wx.Panel(self) # Controls style = wx.TE_PROCESS_ENTER self.UserValue = TextCtrl(self,size=(90,-1),style=style) self.DialValue = TextCtrl(self,size=(90,-1),style=style) self.HighLimit = TextCtrl(self,size=(90,-1),style=style) self.LowLimit = TextCtrl(self,size=(90,-1),style=style) self.Sign = ComboBox(self,size=(90,-1),style=style, choices=["+1","-1"]) self.Offset = TextCtrl(self,size=(90,-1),style=style) self.Speed = ComboBox (self,size=(90,-1),style=style, choices=["1.8","15","90"]) self.Bind (wx.EVT_TEXT_ENTER,self.OnEnter) self.Bind (wx.EVT_COMBOBOX,self.OnEnter) self.Bind (wx.EVT_TEXT_ENTER,self.OnEnterUserValue,self.UserValue) # Layout layout = wx.BoxSizer() grid = wx.FlexGridSizer (cols=2,hgap=5,vgap=5) flag = wx.ALIGN_CENTER_VERTICAL label = "User value:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.UserValue,flag=flag) label = "Dial value:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.DialValue,flag=flag) label = "High Limit:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.HighLimit,flag=flag) label = "Low Limit:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.LowLimit,flag=flag) label = "Sign:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.Sign,flag=flag) label = "Offset:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.Offset,flag=flag) label = "Speed:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.Speed,flag=flag) # Leave a 10-pixel wide space around the panel. layout.Add (grid,flag=wx.EXPAND|wx.ALL,border=10) self.SetSizer(layout) self.Fit() self.update()
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 __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,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): wx.Frame.__init__(self, parent=None, title="Sample Illumination (Ensemble)") panel = wx.Panel(self) # Controls self.Voltage = TextCtrl(panel, size=(100, -1), style=wx.TE_PROCESS_ENTER) OnButton = wx.Button(panel, label="On") OffButton = wx.Button(panel, label="Off") self.Bind(wx.EVT_TEXT_ENTER, self.OnEnterVoltage, self.Voltage) self.Bind(wx.EVT_BUTTON, self.OnOn, OnButton) self.Bind(wx.EVT_BUTTON, self.OnOff, OffButton) # Layout controls = wx.GridBagSizer(1, 1) a = wx.ALIGN_CENTRE_VERTICAL e = wx.EXPAND t = wx.StaticText(panel, label="Voltage [V]:") controls.Add(t, (0, 0), flag=a) controls.Add(self.Voltage, (0, 1), flag=a | e) # Leave a 10 pixel wide border. box = wx.BoxSizer(wx.VERTICAL) box.Add(controls, flag=wx.ALL, border=5) buttons = wx.BoxSizer(wx.HORIZONTAL) buttons.Add(OnButton, flag=wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, border=5) buttons.AddSpacer((5, 5)) buttons.Add(OffButton, flag=wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, border=5) box.Add(buttons, flag=wx.ALL, border=5) panel.SetSizer(box) panel.Fit() self.Fit() self.Show() # Initialization self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.refresh, self.timer) self.timer.Start(1000, oneShot=True)
def __init__(self): wx.Frame.__init__(self, parent=None, title="Editable Controls Test") panel = wx.Panel(self) # Controls choices = ["Hydrogen", "Helium", "Lithium", "Beryllium"] self.ComboBox = ComboBox(panel, choices=choices, style=wx.TE_PROCESS_ENTER, name="Sample ComboBox") self.TextCtrl = TextCtrl(panel, style=wx.TE_PROCESS_ENTER, name="Sample TextCtrl") # Callbacks self.Bind(wx.EVT_TEXT_ENTER, self.OnComboBox, self.ComboBox) self.Bind(wx.EVT_COMBOBOX, self.OnComboBox, self.ComboBox) self.Bind(wx.EVT_TEXT_ENTER, self.OnTextCtrl, self.TextCtrl) # Layout layout = wx.GridBagSizer(1, 1) a = wx.ALIGN_CENTRE_VERTICAL e = wx.EXPAND layout.Add(wx.StaticText(panel, label="ComboBox:"), (0, 0), flag=a) layout.Add(self.ComboBox, (0, 1), flag=a | e) layout.Add(wx.StaticText(panel, label="TextCtrl:"), (1, 0), flag=a) layout.Add(self.TextCtrl, (1, 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() # 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=None): wx.Dialog.__init__(self,parent,-1,"Diffractometer Setup") # Controls style = wx.TE_PROCESS_ENTER self.Configuration = ComboBox (self,size=(175,-1),style=style, choices=["BioCARS Diffractometer","NIH Diffractometer","LCLS Diffractometer"]) self.Apply = wx.Button(self,label="Apply",size=(75,-1)) self.Save = wx.Button(self,label="Save",size=(75,-1)) self.X = ComboBox (self,size=(160,-1),style=style, choices=["GonX","SampleX"]) self.Y = ComboBox (self,size=(160,-1),style=style, choices=["GonY","SampleY"]) self.Z = ComboBox (self,size=(160,-1),style=style, choices=["GonZ","SampleZ"]) self.Phi = ComboBox (self,size=(160,-1),style=style, choices=["Phi","SamplePhi"]) self.XYType = ComboBox (self,size=(160,-1),style=style, choices=["rotating","stationary"]) self.RotationCenterX = TextCtrl (self,size=(160,-1),style=style) self.RotationCenterY = TextCtrl (self,size=(160,-1),style=style) self.XScale = TextCtrl (self,size=(160,-1),style=style) self.YScale = TextCtrl (self,size=(160,-1),style=style) self.ZScale = TextCtrl (self,size=(160,-1),style=style) self.PhiScale = TextCtrl (self,size=(160,-1),style=style) self.Bind (wx.EVT_TEXT_ENTER,self.OnEnter) self.Bind (wx.EVT_COMBOBOX,self.OnEnter) self.Configuration.Bind (wx.EVT_COMBOBOX,self.OnSelectConfiguration) self.Save.Bind (wx.EVT_BUTTON,self.OnSave) self.Apply.Bind (wx.EVT_BUTTON,self.OnApply) # Layout layout = wx.BoxSizer() vbox = wx.BoxSizer(wx.VERTICAL) config = wx.BoxSizer(wx.HORIZONTAL) flag = wx.ALIGN_CENTER config.Add (self.Configuration,flag=flag) config.Add (self.Apply,flag=flag) config.Add (self.Save,flag=flag) vbox.Add (config,flag=wx.EXPAND|wx.ALL) grid = wx.FlexGridSizer(cols=2,hgap=5,vgap=5) flag = wx.ALIGN_CENTER_VERTICAL label = "X Translation:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.X,flag=flag) label = "Y Translation:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.Y,flag=flag) label = "Z Translation:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.Z,flag=flag) label = "Phi Rotation:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.Phi,flag=flag) label = "XY Translation Type:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.XYType,flag=flag) label = "Rotation Center X:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.RotationCenterX,flag=flag) label = "Rotation Center Y:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.RotationCenterY,flag=flag) label = "X Scale Factor:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.XScale,flag=flag) label = "Y Scale Factor:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.YScale,flag=flag) label = "Z Scale Factor:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.ZScale,flag=flag) label = "Phi Scale Factor:" grid.Add (wx.StaticText(self,label=label),flag=flag) grid.Add (self.PhiScale,flag=flag) # Leave a 10-pixel wide space around the panel. vbox.Add (grid,flag=wx.EXPAND|wx.ALL) layout.Add (vbox,flag=wx.EXPAND|wx.ALL,border=10) self.SetSizer(layout) self.Fit() self.Show() self.update()
class LogPanel(wx.Frame): name = "LogPanel" attributes = "log","label" refresh_period = 1.0 levels = ["DEBUG","INFO","WARNING","ERROR"] from persistent_property import persistent_property level = persistent_property("level","DEBUG") 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 keep_updated(self): """Periodically refresh the displayed settings.""" from time import time,sleep while True: try: t0 = time() if self.Shown: self.update_data() if self.data_changed: event = wx.PyCommandEvent(wx.EVT_TIMER.typeId,self.Id) # call OnUpdate in GUI thread wx.PostEvent(self.EventHandler,event) while time() < t0+self.refresh_period: sleep(0.5) except wx.PyDeadObjectError: break def OnUpdate(self,event): """Periodically refresh the displayed settings.""" self.refresh_status() def refresh(self): """Force update""" from threading import Thread self.thread = Thread(target=self.refresh_background, name=self.name+".refresh") self.thread.daemon = True self.thread.start() def refresh_background(self): """Force update""" self.update_data() if self.data_changed: event = wx.PyCommandEvent(wx.EVT_TIMER.typeId,self.Id) wx.PostEvent(self.EventHandler,event) # call OnUpdate in GUI thread def update_data(self): """Retreive status information""" self.old_values = dict(self.values) # make a copy for n in self.attributes: try: self.values[n] = getattr(self.server,n) except Exception,msg: error("%s\n%s" % (msg,traceback.format_exc())) @property def data_changed(self): """Did the last 'update_data' change the data to be plotted?""" changed = (self.values != self.old_values) return changed @property def server(self): return servers[self.n] def refresh_status(self): if "label" in self.values: self.Title = "Log: "+self.values["label"] if "log" in self.values: text = self.values["log"] text = self.filter(text) text = last_lines(text) self.Log.Value = text # Scroll to the end self.Log.ShowPosition(self.Log.LastPosition) self.Level.StringSelection = self.level def OnLog(self,event): self.server.log = self.Log.Value self.refresh() def OnClear(self,event): self.server.log = "" self.refresh() def OnLevel(self,event): self.level = self.Level.StringSelection self.refresh_status() def filter(self,text): words_to_filter = [] if self.level in self.levels: i = self.levels.index(self.level) words_to_filter = self.levels[0:i] debug("level: %r, filtering %r" % (self.level,words_to_filter)) if words_to_filter: lines = text.splitlines() for word in words_to_filter: lines = [line for line in lines if not word in line] text = "\n".join(lines)+"\n" return text
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,parent,motor,refresh_period=1.0): wx.Panel.__init__(self,parent) self.motor = motor self.refresh_period = refresh_period # Controls self.MotorName = wx.StaticText(self,size=(100,-1),style=wx.ALIGN_CENTRE) self.background = self.MotorName.BackgroundColour self.Unit = wx.StaticText(self,size=(100,-1),style=wx.ALIGN_CENTRE) self.Value = wx.StaticText(self,size=(100,-1),style=wx.ALIGN_CENTRE) self.CommandValue = TextCtrl(self,size=(100,-1),style=wx.TE_PROCESS_ENTER) self.TweakValue = ComboBox(self,size=(50,-1),style=wx.TE_PROCESS_ENTER) left = wx.ArtProvider.GetBitmap(wx.ART_GO_BACK) right = wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD) self.TweakDownButton = wx.BitmapButton(self,bitmap=left) self.TweakUpButton = wx.BitmapButton(self,bitmap=right) self.EnableButton = wx.ToggleButton(self,label="Enabled",size=(70,-1)) w,h = self.EnableButton.Size self.HomeButton = wx.ToggleButton(self,label="Homed",size=(w,h)) self.Bind(wx.EVT_CONTEXT_MENU,self.OnConfigureMenu,self.MotorName) self.Bind(wx.EVT_CONTEXT_MENU,self.OnConfigureMenu,self.Unit) self.Bind(wx.EVT_CONTEXT_MENU,self.OnSetValueMenu,self.Value) self.Bind(wx.EVT_TEXT_ENTER,self.OnEnterCommandValue,self.CommandValue) self.Bind(wx.EVT_CONTEXT_MENU,self.OnSetValueMenu,self.CommandValue) self.Bind(wx.EVT_COMBOBOX,self.OnEnterTweakValue,self.TweakValue) self.Bind(wx.EVT_TEXT_ENTER,self.OnEnterTweakValue,self.TweakValue) self.Bind(wx.EVT_CONTEXT_MENU,self.OnTweakMenu,self.TweakValue) self.Bind(wx.EVT_BUTTON,self.OnTweakDown,self.TweakDownButton) self.Bind(wx.EVT_BUTTON,self.OnTweakUp,self.TweakUpButton) self.Bind(wx.EVT_TOGGLEBUTTON,self.OnEnable,self.EnableButton) self.Bind(wx.EVT_TOGGLEBUTTON,self.OnHome,self.HomeButton) # Layout controls = wx.GridBagSizer(1,1) a = wx.ALIGN_CENTRE_HORIZONTAL|wx.ALIGN_CENTRE_VERTICAL e = wx.EXPAND controls.Add(self.MotorName,(0,0),span=(1,3),flag=a|e) controls.Add(self.Unit,(1,0),span=(1,3),flag=a|e) controls.Add(self.Value,(2,0),span=(1,3),flag=a|e) controls.Add(self.CommandValue,(3,0),span=(1,3),flag=a|e) controls.Add(self.TweakDownButton,(4,0),flag=a|e) controls.Add(self.TweakValue,(4,1),flag=a|e) controls.Add(self.TweakUpButton,(4,2),flag=a|e) controls.Add(self.EnableButton,(5,1),flag=a) controls.Add(self.HomeButton,(6,1),flag=a) # Leave a 10 pixel wide border. box = wx.BoxSizer(wx.VERTICAL) box.Add(controls,flag=wx.ALL,border=5) self.SetSizer(box) self.Fit() # Initialization self.CommandValue.Enabled = False self.TweakDownButton.Enabled = False self.TweakUpButton.Enabled = False self.EnableButton.Enabled = False self.HomeButton.Enabled = False # Refresh self.attributes = ["name","unit","value","command_value", "moving","enabled","homed","homing"] from numpy import nan self.values = dict([(n,nan) for n in self.attributes]) self.values["name"] = "" self.values["unit"] = "" self.old_values = {} from threading import Thread self.refresh_thread = Thread(target=self.refresh_background, name=self.name+".refresh") self.refreshing = False from wx.lib.newevent import NewEvent self.EVT_THREAD = NewEvent()[1] self.Bind(self.EVT_THREAD,self.OnUpdate) self.thread = Thread(target=self.keep_updated,name=self.name) self.thread.start()
def ControlPanel(self): # Controls and Layout from EditableControls import TextCtrl panel = wx.Panel(self) panel.vertical = self.configuration.vertical def flip(i, j): return (j, i) if panel.vertical else (i, j) # Leave a 5 pixel wide border. border_box = wx.BoxSizer(wx.VERTICAL) # Labels grid = panel.grid = wx.GridBagSizer(1, 1) flag = wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALL style = wx.TE_PROCESS_ENTER if not panel.vertical: style |= wx.TE_MULTILINE left, center, right = wx.ALIGN_LEFT, wx.ALIGN_CENTER_HORIZONTAL, wx.ALIGN_RIGHT row_height = self.configuration.row_height # Labels header_flag = wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALL | wx.ALIGN_TOP | wx.EXPAND width = self.configuration.description_width if panel.vertical: width = -1 panel.DescriptionLabel = wx.Button(panel, label="Name", size=(width, row_height)) panel.DescriptionLabel.Enabled = False grid.Add(panel.DescriptionLabel, flip(0, 1), flag=header_flag) width = 100 if panel.vertical: width = -1 panel.DateLabel = wx.Button(panel, label="Updated", size=(width, row_height)) panel.DateLabel.Enabled = False grid.Add(panel.DateLabel, flip(0, 2), flag=header_flag) panel.PositionLabels = [] for i in range(0, self.configuration.n_motors): label = self.configuration.motor_labels[i] if i < len( self.configuration.motor_labels) else "" width = self.configuration.widths[i] if i < len( self.configuration.widths) else 100 if panel.vertical: width = -1 button = wx.Button(panel, label=label, size=(width, row_height), id=300 + i * 100 + 98) button.Enabled = self.configuration.are_configuration[ i] if i < len(self.configuration.are_configuration) else False self.Bind(wx.EVT_BUTTON, self.OnShowConfiguration, button) grid.Add(button, flip(0, i + 3), flag=header_flag) panel.PositionLabels += [button] # Controls panel.Descriptions = ndarray(self.configuration.nrows, object) for i in range(0, self.configuration.nrows): width = self.configuration.description_width if panel.vertical: width = self.configuration.description_width align = center if panel.vertical else left panel.Descriptions[i] = TextCtrl(panel, size=(width, row_height), style=style | align, id=100 + i) grid.Add(panel.Descriptions[i], flip(i + 1, 1), flag=flag) self.NormalBackgroundColour = panel.Descriptions[0].BackgroundColour \ if len(panel.Descriptions) > 0 else panel.BackgroundColour panel.Dates = ndarray(self.configuration.nrows, object) for i in range(0, self.configuration.nrows): width = self.date_width if panel.vertical: width = self.configuration.description_width panel.Dates[i] = TextCtrl(panel, size=(width, row_height), style=style, id=200 + i) grid.Add(panel.Dates[i], flip(i + 1, 2), flag=flag) panel.Positions = ndarray( (self.configuration.nrows, self.configuration.n_motors), object) for i in range(0, self.configuration.nrows): for j in range(0, self.configuration.n_motors): width = self.configuration.widths[j] align = right if j < len( self.configuration.are_numeric ) and self.configuration.are_numeric[j] else left panel.Positions[i, j] = TextCtrl(panel, size=(width, row_height), style=style | align, id=300 + j * 100 + i) panel.Positions[i, j].BackgroundColour = panel.BackgroundColour grid.Add(panel.Positions[i, j], flip(i + 1, j + 3), flag=flag | wx.EXPAND) header_flag = wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALL | wx.ALIGN_TOP | wx.EXPAND panel.SelectButtons = [] height = panel.Descriptions[0].Size[1] if len( panel.Descriptions) > 0 else -1 for i in range(0, self.configuration.nrows): label = self.configuration.apply_button_label width = int(20 + 6.5 * len(label)) if len(label) <= 10 else -1 if panel.vertical: width = self.configuration.description_width button = wx.ToggleButton(panel, label=label, size=(width, height), id=i) button.Shown = self.configuration.show_apply_buttons grid.Add(button, flip(i + 1, 0), flag=flag) self.Bind(wx.EVT_TOGGLEBUTTON, self.OnSelect, button) panel.SelectButtons += [button] panel.DefineButtons = [] height = panel.Descriptions[0].Size[1] if len( panel.Descriptions) > 0 else -1 for i in range(0, self.configuration.nrows): label = self.configuration.define_button_label width = 20 + 7 * len(label) if len(label) <= 10 else -1 if panel.vertical: width = self.configuration.description_width button = wx.Button(panel, label=label, size=(width, height), id=100 + i) button.Shown = self.configuration.show_define_buttons grid.Add(button, flip(i + 1, self.configuration.n_motors + 3), flag=flag) self.Bind(wx.EVT_BUTTON, self.define_setting, button) panel.DefineButtons += [button] # Current values width = panel.SelectButtons[0].Size[0] if len( panel.SelectButtons) > 0 else -1 if panel.vertical: width = self.configuration.description_width label = wx.StaticText(panel, label="Current", size=(width, row_height)) label.Shown = self.configuration.show_apply_buttons grid.Add(label, flip(self.configuration.nrows + 1, 0), flag=flag) width = self.configuration.description_width align = center if panel.vertical else left panel.CurrentDescription = TextCtrl(panel, size=(width, row_height), style=style | align, id=100 + 99) panel.CurrentDescription.BackgroundColour = panel.BackgroundColour grid.Add(panel.CurrentDescription, flip(self.configuration.nrows + 1, 1), flag=flag) width = self.date_width if panel.vertical: width = self.configuration.description_width panel.CurrentDate = TextCtrl(panel, size=(width, row_height), style=style, id=200 + 99) panel.CurrentDate.BackgroundColour = panel.BackgroundColour panel.CurrentDate.Enabled = True grid.Add(panel.CurrentDate, flip(self.configuration.nrows + 1, 2), flag=flag) panel.CurrentPositions = ndarray(self.configuration.n_motors, object) for i in range(0, self.configuration.n_motors): width = self.configuration.widths[i] align = right if i < len( self.configuration.are_numeric ) and self.configuration.are_numeric[i] else left panel.CurrentPositions[i] = TextCtrl(panel, size=(width, row_height), style=style | align, id=300 + i * 100 + 99) panel.CurrentPositions[i].BackgroundColour = panel.BackgroundColour grid.Add(panel.CurrentPositions[i], flip(self.configuration.nrows + 1, i + 3), flag=flag) border_box.Add(grid, flag=wx.ALL | wx.EXPAND, border=5) panel.StopButton = wx.Button(panel, label="Stop") panel.StopButton.Shown = self.configuration.show_stop_button self.Bind(wx.EVT_BUTTON, self.stop, panel.StopButton) border_box.Add(panel.StopButton, flag=wx.ALL | wx.ALIGN_CENTRE_HORIZONTAL, border=2) panel.SetSizer(border_box) panel.Fit() return panel
def __init__(self, parent=None, title="Goniometer Saved Positions", name="goniometer_saved", motors=[], motor_names=[], formats=[], nrows=8): """ name: basename of settings file """ wx.Frame.__init__(self, parent=parent, title=title) self.name = name self.motors = motors self.motor_names = motor_names self.formats = formats for i in range(len(self.motor_names), len(self.motors)): self.motor_names += [self.motors[i].name] while len(self.formats) < len(self.motors): self.formats += ["%+6.3f"] panel = wx.Panel(self) # Leave a 5 pixel wide border. border_box = wx.BoxSizer(wx.VERTICAL) # Controls # Labels flag = wx.ALIGN_CENTRE_VERTICAL | wx.ALL grid = wx.GridBagSizer(1, 1) labels = ["", "Description", "Updated"] for i in range(len(self.motors)): labels += ["%s\n[%s]" % (self.motor_names[i], self.motors[i].unit)] self.Labels = ndarray(len(labels), object) for i in range(0, len(labels)): self.Labels[i] = wx.StaticText(panel, label=labels[i], style=wx.ALIGN_CENTRE) grid.Add(self.Labels[i], (0, i), flag=flag) # Settings style = wx.TE_PROCESS_ENTER self.Descriptions = ndarray(nrows, object) for i in range(0, nrows): self.Descriptions[i] = TextCtrl(panel, size=(200, -1), style=style) grid.Add(self.Descriptions[i], (i + 1, 1), flag=flag) self.NormalBackgroundColour = self.Descriptions[0].BackgroundColour self.Dates = ndarray(nrows, object) for i in range(0, nrows): self.Dates[i] = TextCtrl(panel, size=(100, -1), style=style) grid.Add(self.Dates[i], (i + 1, 2), flag=flag) self.Positions = ndarray((nrows, len(self.motors)), object) for i in range(0, nrows): for j in range(0, len(self.motors)): width = max(75, self.Labels[j + 3].GetSize()[0] + 5) self.Positions[i, j] = TextCtrl(panel, size=(width, -1), style=style) grid.Add(self.Positions[i, j], (i + 1, j + 3), flag=flag) # Current positions label = wx.StaticText(panel) grid.Add(label, (nrows + 1, 1), flag=flag) label.Label = "Current value:" # 'Go To' Buttons height = self.Descriptions[0].GetSize()[1] for i in range(0, nrows): button = wx.Button(panel, label="Go To", size=(60, height), id=i) grid.Add(button, (i + 1, 0), flag=flag) self.Bind(wx.EVT_BUTTON, self.goto_setting, button) # 'Set' Buttons height = self.Descriptions[0].GetSize()[1] for i in range(0, nrows): button = wx.Button(panel, label="Set", size=(45, height), id=100 + i) grid.Add(button, (i + 1, len(self.motors) + 3), flag=flag) self.Bind(wx.EVT_BUTTON, self.define_setting, button) self.Current = ndarray(len(motors), object) for i in range(0, len(self.motors)): self.Current[i] = wx.StaticText(panel) grid.Add(self.Current[i], (nrows + 1, i + 3), flag=flag) border_box.Add(grid, flag=wx.ALL, border=5) button = wx.Button(panel, label="Stop") self.Bind(wx.EVT_BUTTON, self.stop, button) border_box.Add(button, flag=wx.ALL | wx.ALIGN_CENTRE_HORIZONTAL, border=5) panel.SetSizer(border_box) panel.Fit() self.Fit() self.Show() self.update_settings() # 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) # Call the "on_input" routine whenever the user navigates between # fields, using Enter, Tab or the mouse self.Bind(wx.EVT_CHILD_FOCUS, self.on_child_focus) # Periodically update the displayed fields. self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer) self.timer.Start(1000, oneShot=True)
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)