def __init__(self, parent, n): self.n = n wx.Frame.__init__(self, parent=parent, title="Setup") self.panel = wx.Panel(self) # Controls style = wx.TE_PROCESS_ENTER self.myLabel = ComboBox(self.panel, size=(320, -1), style=style) self.Value = ComboBox(self.panel, size=(320, -1), style=style) self.Format = ComboBox(self.panel, size=(320, -1), style=style) self.Test = ComboBox(self.panel, size=(320, -1), style=style) # Callbacks self.Bind(wx.EVT_COMBOBOX, self.OnLabel, self.myLabel) self.Bind(wx.EVT_TEXT_ENTER, self.OnLabel, self.myLabel) self.Bind(wx.EVT_COMBOBOX, self.OnValue, self.Value) self.Bind(wx.EVT_TEXT_ENTER, self.OnValue, self.Value) self.Bind(wx.EVT_COMBOBOX, self.OnFormat, self.Format) self.Bind(wx.EVT_TEXT_ENTER, self.OnFormat, self.Format) self.Bind(wx.EVT_COMBOBOX, self.OnTest, self.Test) 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 = "Label:" grid.Add(wx.StaticText(self.panel, label=label), flag=flag) grid.Add(self.myLabel, 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 labels, values, formats, tests = [], [], [], [] for label in checklist.defaults: labels += [label] values += [checklist.defaults[label]["value"]] formats += [checklist.defaults[label]["format"]] tests += [checklist.defaults[label]["test"]] self.myLabel.Items = labels self.Value.Items = values self.Format.Items = formats self.Test.Items = tests self.refresh()
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=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, 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,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, 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()
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,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 __init__(self, trans, title="Laser Attenuator"): """trans: attenautor objects""" self.trans = trans wx.Frame.__init__(self, parent=None, title=title) # Highlight an Edit control if its contents have been modified # but not applied yet by hitting the Enter key. self.edited = wx.Colour(255, 255, 220) panel = wx.Panel(self) # Controls style = wx.TE_PROCESS_ENTER size = (100, -1) choices = ["0"] self.Angle = ComboBox(panel, choices=choices, size=size, style=style) choices = ["1", "0.5", "0.2", "0.1", "0.05", "0.02", "0.01"] self.Transmission = ComboBox(panel, choices=choices, size=size, style=style) self.LiveCheckBox = wx.CheckBox(panel, label="Live") self.RefreshButton = wx.Button(panel, label="Refresh") # Callbacks self.Angle.Bind(wx.EVT_CHAR, self.OnEditAngle) self.Bind(wx.EVT_TEXT_ENTER, self.OnEnterAngle, self.Angle) self.Bind(wx.EVT_COMBOBOX, self.OnEnterAngle, self.Angle) self.Transmission.Bind(wx.EVT_CHAR, self.OnEditTransmission) self.Bind(wx.EVT_TEXT_ENTER, self.OnEnterTransmission, self.Transmission) self.Bind(wx.EVT_COMBOBOX, self.OnEnterTransmission, self.Transmission) self.Bind(wx.EVT_CHECKBOX, self.OnLive, self.LiveCheckBox) self.Bind(wx.EVT_BUTTON, self.OnRefresh, self.RefreshButton) # Layout layout = wx.GridBagSizer(1, 1) a = wx.ALIGN_CENTRE_VERTICAL e = wx.EXPAND # Specified a label length to prevent line wrapping. # This is a bug in the Linux version of wxPython 2.6, fixed in 2.8. size = (160, -1) t = wx.StaticText(panel, label="Angle [deg]:", size=size) layout.Add(t, (0, 0), flag=a) layout.Add(self.Angle, (0, 1), flag=a | e) t = wx.StaticText(panel, label="Transmission:", size=size) layout.Add(t, (1, 0), flag=a) layout.Add(self.Transmission, (1, 1), flag=a | e) # Leave a 10 pixel wide border. box = wx.BoxSizer(wx.VERTICAL) box.Add(layout, flag=wx.ALL, border=5) buttons = wx.BoxSizer(wx.HORIZONTAL) buttons.Add(self.LiveCheckBox, flag=wx.ALIGN_CENTER_VERTICAL) buttons.AddSpacer((5, 5)) buttons.Add(self.RefreshButton, flag=wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, border=5) box.Add(buttons, flag=wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, border=5) panel.SetSizer(box) panel.Fit() self.Fit() self.Show() # Initialization self.refresh()