def __init__(self, parent):

        wx.Dialog.__init__(self, parent, title="Add New Function")

        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0
        # row += 1 #let's start at 1, to give some space

        lbl_function = wx.StaticText(panel,
                                     label="Function Name:",
                                     style=wx.TE_PROCESS_ENTER)
        self.text_function = wx.TextCtrl(panel)
        self.text_function.Bind(wx.EVT_TEXT_ENTER, self.OnFunctionEnter)
        self.text_function.Bind(wx.EVT_TEXT, self.OnFunctionChange)

        grid.Add(lbl_function, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.text_function,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.AddGrowableCol(1)
        row += 1

        sbox_sizer.AddSpacer(10)
        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 2)
        #-----
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        self.btn_add = wx.Button(panel, label="Add", id=wx.ID_OK)
        self.btn_add.Bind(wx.EVT_BUTTON, self.OnButton)
        self.btn_add.Disable()
        hsizer.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer.Add(self.btn_add, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        sizer.Add(sbox_sizer, 0, wx.ALL | wx.EXPAND, 2)
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass
Exemple #2
0
 def __init__(self, parent):
 
     wx.Dialog.__init__(self,
                        parent,
                        title="Initialise Sequence...")
     
     panel = wx.Panel(self) 
     sizer = wx.BoxSizer(wx.VERTICAL)
     
     hsizer = wx.BoxSizer(wx.HORIZONTAL)
     sbox = wx.StaticBox(panel, label="")        
     sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
     grid = wx.GridBagSizer(5,5)
     
     row = 0
     # row += 1 #let's start at 1, to give some space
     for label in ["From", "To", "Name", "Author", "Tester", "Company", "Description", "Information"]:
         lbl = wx.StaticText(panel, label=label+":")
         self.textctrl = wx.TextCtrl(panel, value="")
         grid.Add(lbl, pos=(row,0), flag=wx.ALL|wx.EXPAND, border=5)
         grid.Add(self.textctrl, pos=(row,1), span=(0,5), flag=wx.ALL|wx.EXPAND, border=5)            
         row += 1
     grid.AddGrowableCol(1)
     
     sbox_sizer.Add(grid, 1, wx.ALL|wx.EXPAND, 0)
     sbox_sizer.AddSpacer(10)
     
     #-----
     hsizer = wx.BoxSizer(wx.HORIZONTAL)
     hsizer.AddStretchSpacer()
     btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
     btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
     btn_confirm = wx.Button(panel, label="Execute", id=wx.ID_OK)
     btn_confirm.Bind(wx.EVT_BUTTON, self.OnButton)
     hsizer.Add(btn_cancel, 0, wx.ALL|wx.EXPAND, 5)
     hsizer.Add(btn_confirm, 0, wx.ALL|wx.EXPAND, 5)
                     
     #add to main sizer
     sizer.Add(sbox_sizer, 0, wx.ALL|wx.EXPAND, 2)
     sizer.Add(hsizer, 0, wx.ALL|wx.EXPAND, 5)
     
     panel.SetSizer(sizer)  
     
     w, h = sizer.Fit(self)  
     # self.SetSize((w, h*1.5))
     # self.SetMinSize((w, h*1.5))
     
     # self.SetMaxSize(sizer.Fit(self))
     
     try:
         self.SetIcon(theme.GetIcon("psu_png"))
     except:
         pass
         
     self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)    
Exemple #3
0
 def __init__(self, parent):
 
     wx.Dialog.__init__(self,
                        parent,
                        title="Read Voltage")
     
     panel = wx.Panel(self) 
     sizer = wx.BoxSizer(wx.VERTICAL)
     
     hsizer = wx.BoxSizer(wx.HORIZONTAL)
     sbox = wx.StaticBox(panel, label="")        
     sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
     grid = wx.GridBagSizer(5,5)
     
     row = 0
     # row += 1 #let's start at 1, to give some space
     
     lbl_dmm = wx.StaticText(panel, label="Digital Multimeter Read:")
     choices = []
     self.cbox_dmm = wx.ComboBox(panel, choices=choices)
     grid.Add(lbl_dmm, pos=(row,0), flag=wx.ALL|wx.EXPAND, border=5)
     grid.Add(self.cbox_dmm, pos=(row,1), span=(0,3), flag=wx.ALL|wx.EXPAND, border=5)
     grid.AddGrowableCol(1)
    
     sbox_sizer.Add(grid, 1, wx.ALL|wx.EXPAND, 0)
     sbox_sizer.AddSpacer(10)
     
     #-----
     hsizer = wx.BoxSizer(wx.HORIZONTAL)
     hsizer.AddStretchSpacer()
     btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
     btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
     btn_confirm = wx.Button(panel, label="Confirm", id=wx.ID_OK)
     btn_confirm.Bind(wx.EVT_BUTTON, self.OnButton)
     hsizer.Add(btn_cancel, 0, wx.ALL|wx.EXPAND, 5)
     hsizer.Add(btn_confirm, 0, wx.ALL|wx.EXPAND, 5)
                     
     #add to main sizer
     sizer.Add(sbox_sizer, 0, wx.ALL|wx.EXPAND, 2)
     sizer.Add(hsizer, 0, wx.ALL|wx.EXPAND, 5)
     
     panel.SetSizer(sizer)  
     
     w, h = sizer.Fit(self)  
     # self.SetSize((w, h*1.5))
     # self.SetMinSize((w, h*1.5))
     
     # self.SetMaxSize(sizer.Fit(self))
     
     try:
         self.SetIcon(theme.GetIcon("psu_png"))
     except:
         pass
         
     self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)    
Exemple #4
0
    def __init__(self, parent, instruments, variables):

        wx.Dialog.__init__(self, parent, title="Send and Receive Message")

        self._variables = variables

        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0
        # row += 1 #let's start at 1, to give some space

        ins_lbl = wx.StaticText(panel, label="Instruments:")
        choices = instruments
        choices.extend(instruments)
        self.cbox_ins = wx.ComboBox(panel, choices=choices)
        self.cbox_ins.Bind(wx.EVT_COMBOBOX, self.OnInstrumentSelect)
        grid.Add(ins_lbl, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.cbox_ins,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.AddGrowableCol(1)

        row += 1
        lbl_send = wx.StaticText(panel, label="Send Command:")
        self.command = wx.TextCtrl(panel)
        grid.Add(lbl_send, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.command,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        row += 1
        lbl_delay = wx.StaticText(panel, label="Delay before send:")
        self.spin_delay = wx.SpinCtrl(panel, max=10, min=0, size=(50, -1))
        self.spin_delay2 = wx.SpinCtrl(panel, max=59, min=0, size=(50, -1))
        self.spin_delay.Bind(wx.EVT_SPINCTRL, self.OnSpinDelay)
        self.spin_delay2.Bind(wx.EVT_SPINCTRL, self.OnSpinDelay)
        self.lbl_delay = wx.StaticText(panel, label="0.0s")
        grid.Add(lbl_delay, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_delay,
                 pos=(row, 1),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.Add(self.spin_delay2,
                 pos=(row, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.Add(self.lbl_delay,
                 pos=(row, 3),
                 flag=wx.ALL | wx.ALIGN_BOTTOM,
                 border=5)

        row += 1
        lbl_local = wx.StaticText(panel, label="Local Name:")
        default = defaultname = "serial_read"
        index = 1
        while defaultname in self._variables["locals"]:
            defaultname = default + str(index)
            index += 1
        self.text_local = wx.TextCtrl(panel, value=defaultname)
        grid.Add(lbl_local, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.text_local,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        row += 1
        lbl_global = wx.StaticText(panel, label="Global Name:")
        self.text_global = wx.TextCtrl(panel, value="")
        grid.Add(lbl_global, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.text_global,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 0)
        sbox_sizer.AddSpacer(10)

        #-----
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        self.btn_add = wx.Button(panel, label="Add", id=wx.ID_OK)
        self.btn_add.Bind(wx.EVT_BUTTON, self.OnButton)
        hsizer.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer.Add(self.btn_add, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        sizer.Add(sbox_sizer, 0, wx.ALL | wx.EXPAND, 2)
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)
        # self.SetSize((w, h*1.5))
        # self.SetMinSize((w, h*1.5))

        # self.SetMaxSize(sizer.Fit(self))

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass

        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
Exemple #5
0
    def __init__(self, parent, instrument_data, variables):

        wx.Dialog.__init__(self, parent, title="Setup Instruments")

        # sort data
        self._instrument_data = instrument_data

        self._variables = variables

        self.serial_options = [
            "baudrate", "port", "bytesize", "stopbits", "flowcontrol",
            "parity", "timeout", "idcmd", "id", "type"
        ]
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0
        # row += 1 #let's start at 1, to give some space

        ins_lbl = wx.StaticText(panel, label="Instruments:")
        choices = [k for k in self._instrument_data.keys()]
        self.cbox_ins = wx.ComboBox(panel,
                                    choices=choices,
                                    style=wx.CB_READONLY)
        self.cbox_ins.Bind(wx.EVT_COMBOBOX, self.OnInstrumentSelection)
        grid.Add(ins_lbl, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
        grid.Add(self.cbox_ins,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)
        grid.AddGrowableCol(1)

        self.serial_data = {}

        row += 1
        items = [
            ("port", "Port", "COM1"),
            ("baudrate", "Speed (baud)", "9600", [
                "110", "300", "600", "1200", "2400", "4800", "9600", "14400",
                "19200", "28800", "38400", "56000", "57600", "115200",
                "128000", "153600", "230400", "256000", "460800", "921600"
            ]), ("bytesize", "Data bits", "8", [str(x) for x in range(5, 10)]),
            ("stopbits", "Stop bits", "1", [str(x) for x in range(0, 3)]),
            ("parity", "Parity", "None",
             ["None", "Odd", "Even", "Mark", "Space"]),
            ("flowcontrol", "Flow control", "None",
             ["None", "XON/XOFF", "RTS/CTS", "DSR/DTR"]),
            ("timeout", "Timeout (s)", "1", [str(x) for x in range(1, 61, 1)])
        ]

        name, label, default = items[0]
        lbl = wx.StaticText(panel, label=label)
        self.serial_data[name] = wx.TextCtrl(panel, value=default)
        grid.Add(lbl, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
        grid.Add(self.serial_data[name],
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)
        row += 1

        for name, label, default, choices in items[1:]:
            lbl = wx.StaticText(panel, label=label)
            self.serial_data[name] = wx.ComboBox(panel,
                                                 choices=choices,
                                                 style=wx.CB_READONLY)
            self.serial_data[name].SetValue(default)
            grid.Add(lbl, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
            grid.Add(self.serial_data[name],
                     pos=(row, 1),
                     span=(0, 2),
                     flag=wx.ALL | wx.EXPAND,
                     border=2)
            row += 1

        # add a separator
        row += 1
        grid.Add(wx.StaticLine(panel),
                 pos=(row, 0),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)

        row += 1
        label_id = wx.StaticText(panel, label="Set identification command:")
        self.serial_data["idcmd"] = wx.TextCtrl(panel, value="*IDN?")
        get_id = wx.Button(panel, label="Get ID")
        get_id.Bind(wx.EVT_BUTTON, self.GetId)
        grid.Add(label_id, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
        grid.Add(self.serial_data["idcmd"],
                 pos=(row, 1),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)
        grid.Add(get_id, pos=(row, 2), flag=wx.ALL | wx.EXPAND, border=2)

        row += 1
        label_id2 = wx.StaticText(panel, label="Id:")
        self.serial_data["id"] = wx.TextCtrl(panel, value="")
        grid.Add(label_id2, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
        grid.Add(self.serial_data["id"],
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)
        row += 1

        # add a separator
        row += 1
        grid.Add(wx.StaticLine(panel),
                 pos=(row, 0),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)

        row += 1
        label_type = wx.StaticText(panel, label="Type:")
        ins_types = ["Multimeter", "PSU", "Waveform Generator", "Generic"]
        self.serial_data["type"] = wx.ComboBox(panel,
                                               choices=ins_types,
                                               style=wx.CB_READONLY)
        self.serial_data["type"].SetSelection(0)
        self.serial_data["type"].Bind(wx.EVT_COMBOBOX, self.OnTypeSelection)
        grid.Add(label_type, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
        grid.Add(self.serial_data["type"],
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)

        row += 1
        spacer = wx.StaticText(panel)
        grid.Add(spacer,
                 pos=(row, 0),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)
        grid.AddGrowableRow(row)

        # add a separator
        row += 1
        grid.Add(wx.StaticLine(panel),
                 pos=(row, 0),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)

        row += 1
        lbl_channel = wx.StaticText(panel, label="Channel:")
        self.spin_channel = wx.SpinCtrl(panel, min=1, max=2, value="1")
        self.spin_channel.Disable()
        grid.Add(lbl_channel, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_channel,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        row += 1
        lbl_global = wx.StaticText(panel, label="Global Name:")
        default = defaultname = "ins"
        index = 1
        while defaultname in self._variables:
            defaultname = default + str(index)
            index += 1
        self.text_global = wx.TextCtrl(panel, value=defaultname)
        grid.Add(lbl_global, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.text_global,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 0)
        sbox_sizer.AddSpacer(10)

        #-----
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        btn_add = wx.Button(panel, label="Add", id=wx.ID_OK)
        btn_add.Bind(wx.EVT_BUTTON, self.OnButton)
        hsizer.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer.Add(btn_add, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        sizer.Add(sbox_sizer, 0, wx.ALL | wx.EXPAND, 2)
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)
        # self.SetSize((w, h*1.5))
        # self.SetMinSize((w, h*1.5))

        # self.SetMaxSize(sizer.Fit(self))

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass

        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
    def __init__(self, parent, instruments, variables):

        wx.Dialog.__init__(self, parent, title="Step Voltage")

        self._variables = variables

        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0
        # row += 1 #let's start at 1, to give some space

        lbl_psu = wx.StaticText(panel, label="Power Supply:")
        choices = instruments
        self.cbox_psu = wx.ComboBox(panel, choices=choices)
        self.cbox_psu.Bind(wx.EVT_COMBOBOX, self.OnPsuSelected)
        grid.Add(lbl_psu, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.cbox_psu,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.AddGrowableCol(1)
        row += 1
        lbl_initial = wx.StaticText(panel, label="Initial Voltage:")
        self.spin_initial = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_initial2 = wx.SpinCtrl(panel, max=99, min=0, size=(50, -1))
        self.spin_initial.Bind(wx.EVT_SPINCTRL, self.OnSpinInitial)
        self.spin_initial2.Bind(wx.EVT_SPINCTRL, self.OnSpinInitial)
        self.lbl_voltage = wx.StaticText(panel, label="0.0v")
        grid.Add(lbl_initial, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_initial, pos=(row, 1), flag=wx.ALL, border=5)
        grid.Add(self.spin_initial2, pos=(row, 2), flag=wx.ALL, border=5)
        grid.Add(self.lbl_voltage, pos=(row, 3), flag=wx.ALL, border=5)

        row += 1
        lbl_final = wx.StaticText(panel, label="Final Voltage (Limit):")
        self.spin_final = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_final2 = wx.SpinCtrl(panel, max=99, min=0, size=(50, -1))
        self.spin_final.Bind(wx.EVT_SPINCTRL, self.OnSpinFinal)
        self.spin_final2.Bind(wx.EVT_SPINCTRL, self.OnSpinFinal)
        self.lbl_voltage2 = wx.StaticText(panel, label="0.0v")
        grid.Add(lbl_final, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_final, pos=(row, 1), flag=wx.ALL, border=5)
        grid.Add(self.spin_final2, pos=(row, 2), flag=wx.ALL, border=5)
        grid.Add(self.lbl_voltage2, pos=(row, 3), flag=wx.ALL, border=5)

        row += 1
        lbl_step = wx.StaticText(panel, label="Voltage Increment/Decrement:")
        self.spin_step = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_step2 = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_step.Bind(wx.EVT_SPINCTRL, self.OnSpinStep)
        self.spin_step2.Bind(wx.EVT_SPINCTRL, self.OnSpinStep)
        self.lbl_step2 = wx.StaticText(panel, label="0.0v")
        grid.Add(lbl_step, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_step, pos=(row, 1), flag=wx.ALL, border=5)
        grid.Add(self.spin_step2, pos=(row, 2), flag=wx.ALL, border=5)
        grid.Add(self.lbl_step2, pos=(row, 3), flag=wx.ALL, border=5)

        row += 1
        lbl_step_delay = wx.StaticText(
            panel, label="Delay before Increment/decrement (ms):")
        self.spin_step_delay = wx.SpinCtrl(panel, max=59, min=0, size=(50, -1))
        self.spin_step_delay2 = wx.SpinCtrl(panel,
                                            max=59,
                                            min=0,
                                            size=(50, -1))
        self.lbl_step_delay = wx.StaticText(panel, label="0.0s")
        self.spin_step_delay.Bind(wx.EVT_SPINCTRL, self.OnSpinStepDelay)
        self.spin_step_delay2.Bind(wx.EVT_SPINCTRL, self.OnSpinStepDelay)
        grid.Add(lbl_step_delay,
                 pos=(row, 0),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.Add(self.spin_step_delay, pos=(row, 1), flag=wx.ALL, border=5)
        grid.Add(self.spin_step_delay2, pos=(row, 2), flag=wx.ALL, border=5)
        grid.Add(self.lbl_step_delay, pos=(row, 3), flag=wx.ALL, border=5)

        row += 1
        lbl_repeat = wx.StaticText(panel, label="Repeat:")
        spin_repeat = wx.SpinCtrl(panel, max=999, min=0, size=(50, -1))
        grid.Add(lbl_repeat, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(spin_repeat, pos=(row, 1), flag=wx.ALL | wx.EXPAND, border=5)

        row += 1
        lbl_local = wx.StaticText(panel, label="Local Name:")
        default = defaultname = "stepvolt"
        index = 1
        while defaultname in self._variables["locals"]:
            defaultname = default + str(index)
            index += 1
        self.text_local = wx.TextCtrl(panel, value=defaultname)
        grid.Add(lbl_local, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.text_local,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        row += 1
        lbl_global = wx.StaticText(panel, label="Global Name:")
        self.text_global = wx.TextCtrl(panel, value="")
        grid.Add(lbl_global, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.text_global,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        # row += 1
        # self.lbl_error = wx.StaticText(panel, label="")
        # grid.Add(self.lbl_error, pos=(row,0), flag=wx.ALL|wx.EXPAND, border=5)
        # if self.cbox_psu.GetSelection() == -1:
        # self.lbl_error.SetLabel("*Cannot add this step unless a power supply is selected")

        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 0)
        sbox_sizer.AddSpacer(10)

        #-----
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        self.btn_add = wx.Button(panel, label="Add", id=wx.ID_OK)
        self.btn_add.Bind(wx.EVT_BUTTON, self.OnButton)
        # self.btn_add.Disable()
        hsizer.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer.Add(self.btn_add, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        sizer.Add(sbox_sizer, 0, wx.ALL | wx.EXPAND, 2)
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)
        # self.SetSize((w, h*1.5))
        # self.SetMinSize((w, h*1.5))

        # self.SetMaxSize(sizer.Fit(self))

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass

        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
    def __init__(self, parent, variables):

        wx.Dialog.__init__(self, parent, title="String Compare")

        self.operations = ["+", "-", "*", "/", "^", "(", ")"]
        self._variables = variables

        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0
        lbl_var1 = wx.StaticText(panel, label="variables:")
        grid.Add(lbl_var1, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)

        choices = variables["locals"]
        for var in variables["globals"]:
            if var in choices:
                continue
            choices.append(var)
        choices = sorted(choices)

        cbox_vars1 = wx.ComboBox(panel,
                                 choices=choices,
                                 name="var1",
                                 style=wx.CB_READONLY)
        cbox_vars1.Bind(wx.EVT_COMBOBOX, self.OnVarSelected)
        grid.Add(cbox_vars1, pos=(row, 1), flag=wx.ALL | wx.EXPAND, border=2)

        row += 1
        lbl_var1 = wx.StaticText(panel, label="var1 = ")
        self.text_var1 = wx.TextCtrl(panel, value="")
        self.text_var1.Bind(wx.EVT_TEXT, self.OnVarTextChange)
        grid.Add(lbl_var1,
                 pos=(row, 0),
                 flag=wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTRE,
                 border=2)
        grid.Add(self.text_var1,
                 pos=(row, 1),
                 span=(0, 1),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)

        row += 1
        self.chk_literal = wx.CheckBox(panel, label="Is literal?")
        self.chk_literal.SetValue(0)
        grid.Add(self.chk_literal,
                 pos=(row, 1),
                 flag=wx.ALL | wx.EXPAND,
                 border=2)

        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 0)

        #-----

        sbox = wx.StaticBox(panel, label="")
        sbox_sizer2 = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid2 = wx.GridBagSizer(5, 5)

        row = 0
        lbl_var2 = wx.StaticText(panel, label="variables:")
        grid2.Add(lbl_var2, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)

        cbox_vars2 = wx.ComboBox(panel,
                                 choices=choices,
                                 name="var2",
                                 style=wx.CB_READONLY)
        cbox_vars2.Bind(wx.EVT_COMBOBOX, self.OnVarSelected)
        grid2.Add(cbox_vars2, pos=(row, 1), flag=wx.ALL | wx.EXPAND, border=2)

        row += 1
        lbl_var2 = wx.StaticText(panel, label="var2 = ")
        self.text_var2 = wx.TextCtrl(panel, value="")
        self.text_var2.Bind(wx.EVT_TEXT, self.OnVarTextChange)
        grid2.Add(lbl_var2,
                  pos=(row, 0),
                  flag=wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTRE,
                  border=2)
        grid2.Add(self.text_var2,
                  pos=(row, 1),
                  span=(0, 1),
                  flag=wx.ALL | wx.EXPAND,
                  border=2)

        row += 1
        self.chk_literal2 = wx.CheckBox(panel, label="Is literal?")
        self.chk_literal2.SetValue(1)
        grid2.Add(self.chk_literal2,
                  pos=(row, 1),
                  flag=wx.ALL | wx.EXPAND,
                  border=2)

        sbox_sizer2.Add(grid2, 1, wx.ALL | wx.EXPAND, 0)

        hsizer.Add(sbox_sizer, 1, wx.ALL | wx.EXPAND, 0)
        hsizer.Add(sbox_sizer2, 1, wx.ALL | wx.EXPAND, 0)

        # -----
        sbox = wx.StaticBox(panel, label="Pass/Fail")
        sbox_sizer3 = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid3 = wx.GridBagSizer(5, 5)

        row = 0
        lbl_test = wx.StaticText(panel, label="Test:")
        self.cbox_var_x = wx.ComboBox(panel,
                                      choices=["var1", "var2"],
                                      value="var1",
                                      style=wx.CB_READONLY)
        self.cbox_cond = wx.ComboBox(panel,
                                     choices=["==", "!="],
                                     value="==",
                                     style=wx.CB_READONLY)
        self.cbox_var_y = wx.ComboBox(panel,
                                      choices=["var1", "var2"],
                                      value="var2",
                                      style=wx.CB_READONLY)
        grid3.Add(lbl_test, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
        grid3.Add(self.cbox_var_x,
                  pos=(row, 1),
                  flag=wx.ALL | wx.EXPAND,
                  border=2)
        grid3.Add(self.cbox_cond,
                  pos=(row, 2),
                  flag=wx.ALL | wx.EXPAND,
                  border=2)
        grid3.Add(self.cbox_var_y,
                  pos=(row, 3),
                  flag=wx.ALL | wx.EXPAND,
                  border=2)

        row += 1
        self.chk_match = wx.CheckBox(panel, label="Match case")
        self.chk_match.SetValue(1)
        grid3.Add(self.chk_match,
                  pos=(row, 1),
                  flag=wx.ALL | wx.EXPAND,
                  border=2)

        row += 2
        choices = ["continue", "terminate"]
        lbl_pass = wx.StaticText(panel, label="On Pass:"******"continue",
                                       style=wx.CB_READONLY)
        grid3.Add(lbl_pass, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
        grid3.Add(self.cbox_onpass,
                  pos=(row, 1),
                  flag=wx.ALL | wx.EXPAND,
                  border=2)

        row += 1
        lbl_failure = wx.StaticText(panel, label="On Failure:")
        self.cbox_onfailure = wx.ComboBox(panel,
                                          choices=choices,
                                          value="continue",
                                          style=wx.CB_READONLY)
        grid3.Add(lbl_failure, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=2)
        grid3.Add(self.cbox_onfailure,
                  pos=(row, 1),
                  flag=wx.ALL | wx.EXPAND,
                  border=2)

        row += 2
        lbl_local = wx.StaticText(panel, label="Local Name:")
        default = defaultname = "test"
        index = 1
        while defaultname in self._variables["locals"]:
            defaultname = default + str(index)
            index += 1
        self.text_local = wx.TextCtrl(panel, value=defaultname)
        grid3.Add(lbl_local, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid3.Add(self.text_local,
                  pos=(row, 1),
                  span=(0, 2),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)

        row += 1
        lbl_global = wx.StaticText(panel, label="Global Name:")
        self.text_global = wx.TextCtrl(panel, value="")
        grid3.Add(lbl_global, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid3.Add(self.text_global,
                  pos=(row, 1),
                  span=(0, 2),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)

        # grid3.AddGrowableCol(0)
        grid3.AddGrowableCol(1)
        grid3.AddGrowableCol(2)
        grid3.AddGrowableCol(3)
        # grid3.AddGrowableCol(4)

        sbox_sizer3.Add(grid3, 1, wx.ALL | wx.EXPAND, 0)

        #-----
        hsizer_controls = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_controls.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        self.btn_add = wx.Button(panel, label="Add", id=wx.ID_OK)
        self.btn_add.Bind(wx.EVT_BUTTON, self.OnButton)
        # self.btn_add.Disable()
        hsizer_controls.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer_controls.Add(self.btn_add, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        # sizer.Add(sbox_sizer, 0, wx.ALL|wx.EXPAND, 2)
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 5)
        sizer.Add(sbox_sizer3, 1, wx.ALL | wx.EXPAND, 5)
        sizer.Add(hsizer_controls, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass
    def __init__(self, parent, instruments):

        wx.Dialog.__init__(self, parent, title="Set Voltage")

        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0
        # row += 1 #let's start at 1, to give some space

        lbl_psu = wx.StaticText(panel, label="Power Supply:")
        choices = ["Choose on execution"]
        choices.extend(instruments)
        self.cbox_psu = wx.ComboBox(panel, choices=choices)
        # self.cbox_psu.Bind(wx.EVT_COMBOBOX, self.OnPsuSelected)
        grid.Add(lbl_psu, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.cbox_psu,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.AddGrowableCol(1)
        row += 1
        text_voltage = wx.StaticText(panel, label="Set Voltage:")
        self.spin_voltage = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_voltage2 = wx.SpinCtrl(panel, max=99, min=0, size=(50, -1))
        self.spin_voltage.Bind(wx.EVT_SPINCTRL, self.OnSpinVoltage)
        self.spin_voltage2.Bind(wx.EVT_SPINCTRL, self.OnSpinVoltage)
        self.lbl_voltage = wx.StaticText(panel, label="0.0v")
        grid.Add(text_voltage, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_voltage, pos=(row, 1), flag=wx.ALL, border=5)
        grid.Add(self.spin_voltage2, pos=(row, 2), flag=wx.ALL, border=5)
        grid.Add(self.lbl_voltage,
                 pos=(row, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 0)
        sbox_sizer.AddSpacer(10)

        #-----
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        self.btn_add = wx.Button(panel, label="Add", id=wx.ID_OK)
        self.btn_add.Bind(wx.EVT_BUTTON, self.OnButton)
        hsizer.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer.Add(self.btn_add, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        sizer.Add(sbox_sizer, 0, wx.ALL | wx.EXPAND, 2)
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)
        # self.SetSize((w, h*1.5))
        # self.SetMinSize((w, h*1.5))

        # self.SetMaxSize(sizer.Fit(self))

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass

        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
Exemple #9
0
    def __init__(self, parent, data):

        wx.Dialog.__init__(self, parent, title="Add Test")

        self.data = data
        self.items = data["items"]

        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0

        base_lbl = wx.StaticText(panel, label="Base:")
        choices = [self.items[0]]
        self.cbox_base = wx.ComboBox(panel,
                                     choices=choices,
                                     style=wx.CB_READONLY)
        self.cbox_base.SetSelection(0)
        grid.Add(base_lbl, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.cbox_base,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.AddGrowableCol(1)

        row += 1
        cmp_lbl = wx.StaticText(panel, label="Compare:")
        if len(self.items) > 0:
            choices = self.items[1:]
            selection = self.data["selection"]

        try:
            self.cbox_cmp = wx.ComboBox(panel,
                                        choices=choices,
                                        style=wx.CB_READONLY)
            self.cbox_cmp.Select(selection)
        except:
            self.cbox_cmp = wx.ComboBox(panel, style=wx.CB_READONLY)
            self.cbox_cmp.Disable()

        grid.Add(cmp_lbl, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.cbox_cmp,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        row += 1
        lbl_send = wx.StaticText(panel, label="Send Command:")
        self.command = wx.TextCtrl(panel)
        grid.Add(lbl_send, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.command,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        row += 1
        lbl_delay = wx.StaticText(panel, label="Delay before send:")
        self.spin_delay = wx.SpinCtrl(panel, max=10, min=0, size=(50, -1))
        self.spin_delay2 = wx.SpinCtrl(panel, max=59, min=0, size=(50, -1))
        self.spin_delay.Bind(wx.EVT_SPINCTRL, self.OnSpinDelay)
        self.spin_delay2.Bind(wx.EVT_SPINCTRL, self.OnSpinDelay)
        self.lbl_delay = wx.StaticText(panel, label="0.0s")
        grid.Add(lbl_delay, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_delay,
                 pos=(row, 1),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.Add(self.spin_delay2,
                 pos=(row, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.Add(self.lbl_delay,
                 pos=(row, 3),
                 flag=wx.ALL | wx.ALIGN_BOTTOM,
                 border=5)

        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 0)
        sbox_sizer.AddSpacer(10)

        #-----
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        btn_confirm = wx.Button(panel, label="Confirm", id=wx.ID_OK)
        btn_confirm.Bind(wx.EVT_BUTTON, self.OnButton)
        hsizer.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer.Add(btn_confirm, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        sizer.Add(sbox_sizer, 0, wx.ALL | wx.EXPAND, 2)
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)
        # self.SetSize((w, h*1.5))
        # self.SetMinSize((w, h*1.5))

        # self.SetMaxSize(sizer.Fit(self))

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass

        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
    def __init__(self):

        self._title = "Simple Sequence Creator 0.1"

        wx.Frame.__init__(self, parent=None, title=self._title)

        self._defaults = {
            "preferences": {
                'pos': '0',
                'startup': '0',
                'size': '0'
            },
            "instruments": {},
            "sequences": {}
        }

        self.getcwd = os.getcwd()
        self._file = "data.json"
        self._file = os.path.join(self.getcwd, "data", self._file)
        self._data = {}

        self._menus = {}
        self._panels = {}

        #load settings
        try:
            with open(self._file, 'r') as file:
                self._data = json.load(file)
        except:
            # write new config file
            with open(self._file, 'w') as file:
                json.dump(self._defaults, file, sort_keys=True, indent=1)
                self._data = self._defaults
        file.close()

        #-----
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.HORIZONTAL)

        self.notebook = aui.AuiNotebook(panel,
                                        agwStyle=aui.AUI_NB_TAB_MOVE
                                        | aui.AUI_NB_CLOSE_ON_ALL_TABS)
        self.notebook.SetTabCtrlHeight(32)
        # ----- notebook bindings
        # self.notebook.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGING, self.OnTabClicked)
        # EVT_AUINOTEBOOK_BUTTON
        #-----
        sizer.Add(self.notebook, 1, wx.ALL | wx.EXPAND, 0)

        panel.SetSizer(sizer)
        panel.Fit()
        # sizer.Fit(self)
        self.SetSize((600, 700))
        self.panel = panel

        #-----
        self.CreateMenu()
        self.CreateToolbar()
        self.CreateStatusBar()

        #----- create empty file
        self.CreateNewEditor()

        #-----
        self.Show()

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            print("Could not set icon")

        # configuration
        if self._data["preferences"]["pos"] == "0":
            self.Centre()
        else:
            x, y = self._data["preferences"]["pos"].split(",")
            self.SetPosition((int(x), int(y)))

        if self._data["preferences"]["size"] == "0":
            pass
        else:
            w, h = self._data["preferences"]["size"].split(",")
            self.SetSize((int(w), int(h)))
    def __init__(self, parent):

        wx.Dialog.__init__(self, parent, title="Step Voltage")

        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="Test Setup: Step Voltage")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0
        row += 1  #let's start at 1, to give some space

        lbl_psu = wx.StaticText(panel, label="Power Supply:")
        choices = []
        self.cbox_psu = wx.ComboBox(panel, choices=choices)
        grid.Add(lbl_psu, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.cbox_psu,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.AddGrowableCol(1)
        row += 1
        lbl_initial = wx.StaticText(panel, label="Initial Voltage:")
        self.spin_initial = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_initial2 = wx.SpinCtrl(panel, max=99, min=0, size=(50, -1))
        self.spin_initial.Bind(wx.EVT_SPINCTRL, self.OnSpinInitial)
        self.spin_initial2.Bind(wx.EVT_SPINCTRL, self.OnSpinInitial)
        self.lbl_voltage = wx.StaticText(panel, label="0.0v")
        grid.Add(lbl_initial, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_initial, pos=(row, 1), flag=wx.ALL, border=5)
        grid.Add(self.spin_initial2, pos=(row, 2), flag=wx.ALL, border=5)
        grid.Add(self.lbl_voltage, pos=(row, 3), flag=wx.ALL, border=5)

        row += 1
        lbl_final = wx.StaticText(panel, label="Final Voltage (Limit):")
        self.spin_final = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_final2 = wx.SpinCtrl(panel, max=99, min=0, size=(50, -1))
        self.spin_final.Bind(wx.EVT_SPINCTRL, self.OnSpinFinal)
        self.spin_final2.Bind(wx.EVT_SPINCTRL, self.OnSpinFinal)
        self.lbl_voltage2 = wx.StaticText(panel, label="0.0v")
        grid.Add(lbl_final, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_final, pos=(row, 1), flag=wx.ALL, border=5)
        grid.Add(self.spin_final2, pos=(row, 2), flag=wx.ALL, border=5)
        grid.Add(self.lbl_voltage2, pos=(row, 3), flag=wx.ALL, border=5)

        row += 1
        lbl_step = wx.StaticText(panel, label="Voltage Increment/Decrement:")
        self.spin_step = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_step2 = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_step.Bind(wx.EVT_SPINCTRL, self.OnSpinStep)
        self.spin_step2.Bind(wx.EVT_SPINCTRL, self.OnSpinStep)
        self.lbl_step2 = wx.StaticText(panel, label="0.0v")
        grid.Add(lbl_step, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.spin_step, pos=(row, 1), flag=wx.ALL, border=5)
        grid.Add(self.spin_step2, pos=(row, 2), flag=wx.ALL, border=5)
        grid.Add(self.lbl_step2, pos=(row, 3), flag=wx.ALL, border=5)

        row += 1
        lbl_step_delay = wx.StaticText(panel,
                                       label="Increment/decrement delay (ms):")
        self.spin_step_delay = wx.SpinCtrl(panel, max=0, min=0, size=(50, -1))
        grid.Add(lbl_step_delay,
                 pos=(row, 0),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.Add(self.spin_step_delay,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL,
                 border=5)

        row += 1
        lbl_repeat = wx.StaticText(panel, label="Repeat:")
        spin_repeat = wx.SpinCtrl(panel, max=999, min=0, size=(50, -1))
        grid.Add(lbl_repeat, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(spin_repeat, pos=(row, 1), flag=wx.ALL | wx.EXPAND, border=5)

        row += 1
        # hsizer = wx.BoxSizer(wx.HORIZONTAL)
        lbl_read = wx.StaticText(panel, label="Read Voltage:")
        choices = ["Choose on execution"]
        self.cbox_read = wx.ComboBox(panel, choices=choices, value=choices[0])
        grid.Add(lbl_read, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.cbox_read,
                 pos=(row, 1),
                 span=(0, 3),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 0)
        sbox_sizer.AddSpacer(20)

        #rhs staticboxsizer
        sbox2 = wx.StaticBox(panel, label="Pass/Fail Condition")
        sbox_sizer2 = wx.StaticBoxSizer(sbox2, wx.HORIZONTAL)

        vsizer = wx.BoxSizer(wx.VERTICAL)
        vsizer.AddSpacer(20)

        grid2 = wx.GridBagSizer(2, 2)
        row = 0
        vars = [
            "V - Voltage reading (V)", "I - Current reading (A)",
            "R - Resistance reading (%s)" % OHM
        ]
        conditions = [
            "in range", "not in range", "in % range", "not in % range",
            "> (greater than)", ">= (greater than/equal to)", "< (less than)",
            "<= (less than/equal to)"
        ]
        self.cbox_var = wx.ComboBox(panel,
                                    choices=vars,
                                    name="reading",
                                    style=wx.CB_READONLY)
        self.cbox_var.Bind(wx.EVT_COMBOBOX, self.OnComboBox)
        self.cbox_var.SetSelection(0)
        self.cbox_conditions = wx.ComboBox(panel,
                                           choices=conditions,
                                           name="condition",
                                           style=wx.CB_READONLY)
        self.cbox_conditions.Bind(wx.EVT_COMBOBOX, self.OnComboBox)
        self.cbox_conditions.SetSelection(0)

        grid2.Add(self.cbox_var,
                  pos=(row, 1),
                  span=(0, 0),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)
        grid2.Add(self.cbox_conditions,
                  pos=(row, 2),
                  span=(0, 0),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)

        row += 1
        lbl_testvar_a = wx.StaticText(panel, label="Value 1:")
        self.spin_var_a = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_var_a.Bind(wx.EVT_SPINCTRL, self.OnSpinVarA)
        self.spin_var_a2 = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_var_a2.Bind(wx.EVT_SPINCTRL, self.OnSpinVarA)
        self.lbl_var_a = wx.StaticText(panel, label="0.0V")

        grid2.Add(lbl_testvar_a,
                  pos=(row, 0),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)
        grid2.Add(self.spin_var_a,
                  pos=(row, 1),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)
        grid2.Add(self.spin_var_a2,
                  pos=(row, 2),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)
        grid2.Add(self.lbl_var_a,
                  pos=(row, 3),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)

        row += 1
        lbl_testvar_b = wx.StaticText(panel, label="Value 2:")
        self.spin_var_b = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_var_b.Bind(wx.EVT_SPINCTRL, self.OnSpinVarB)
        self.spin_var_b2 = wx.SpinCtrl(panel, max=30, min=0, size=(50, -1))
        self.spin_var_b2.Bind(wx.EVT_SPINCTRL, self.OnSpinVarB)
        self.lbl_var_b = wx.StaticText(panel, label="0.0V")

        grid2.Add(lbl_testvar_b,
                  pos=(row, 0),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)
        grid2.Add(self.spin_var_b,
                  pos=(row, 1),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)
        grid2.Add(self.spin_var_b2,
                  pos=(row, 2),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)
        grid2.Add(self.lbl_var_b,
                  pos=(row, 3),
                  flag=wx.ALL | wx.EXPAND,
                  border=5)

        grid2.AddGrowableCol(0)
        vsizer.Add(grid2, 0, wx.ALL | wx.EXPAND, 5)

        vsizer.Add(wx.StaticLine(panel), 0, wx.ALL | wx.EXPAND, 5)

        hsizer_radios = wx.BoxSizer(wx.HORIZONTAL)
        lbl_fail = wx.StaticText(panel, label="On Test Failure:")
        hsizer_radios.Add(lbl_fail, 0, wx.ALL | wx.EXPAND, 5)
        for label in ["Continue", "Stop", "Ask on failure"]:
            radio = wx.RadioButton(panel, label=label)
            radio.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton)
            hsizer_radios.Add(radio, 0, wx.ALL | wx.EXPAND, 5)
        vsizer.Add(hsizer_radios, 0, wx.ALL | wx.EXPAND, 5)

        sbox_sizer2.Add(vsizer, 1, wx.ALL | wx.EXPAND, 5)

        # add static boxes to hsizer
        hsizer.Add(sbox_sizer, 0, wx.ALL | wx.EXPAND, 5)
        hsizer.Add(sbox_sizer2, 0, wx.ALL | wx.EXPAND, 5)

        #-----
        hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer2.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel")
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        btn_confirm = wx.Button(panel, label="Confirm")
        btn_confirm.Bind(wx.EVT_BUTTON, self.OnButton)
        hsizer2.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer2.Add(btn_confirm, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 2)
        sizer.Add(hsizer2, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)
        # self.SetSize((w, h*1.5))
        # self.SetMinSize((w, h*1.5))

        # self.SetMaxSize(sizer.Fit(self))

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass
    def __init__(self, parent, functions, variables):

        wx.Dialog.__init__(self, parent, title="Add Function Call")

        self._variables = variables
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        sbox = wx.StaticBox(panel, label="")
        sbox_sizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
        grid = wx.GridBagSizer(5, 5)

        row = 0
        # row += 1 #let's start at 1, to give some space

        lbl_function = wx.StaticText(panel, label="Function Name:")
        choices = functions
        self.cbox_function = wx.ComboBox(panel, choices=choices)
        # self.cbox_function.Bind(wx.EVT_COMBOBOX, self.OnFunctionSelection)

        grid.Add(lbl_function, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.cbox_function,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)
        grid.AddGrowableCol(1)
        row += 1

        row += 1
        lbl_local = wx.StaticText(panel, label="Local Name:")
        default = defaultname = "func"
        index = 1
        while defaultname in self._variables["locals"]:
            defaultname = default + str(index)
            index += 1
        self.text_local = wx.TextCtrl(panel, value=defaultname)
        grid.Add(lbl_local, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.text_local,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        row += 1
        lbl_global = wx.StaticText(panel, label="Global Name:")
        self.text_global = wx.TextCtrl(panel, value="")
        grid.Add(lbl_global, pos=(row, 0), flag=wx.ALL | wx.EXPAND, border=5)
        grid.Add(self.text_global,
                 pos=(row, 1),
                 span=(0, 2),
                 flag=wx.ALL | wx.EXPAND,
                 border=5)

        sbox_sizer.AddSpacer(10)
        sbox_sizer.Add(grid, 1, wx.ALL | wx.EXPAND, 2)
        #-----
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.AddStretchSpacer()
        btn_cancel = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
        btn_cancel.Bind(wx.EVT_BUTTON, self.OnButton)
        self.btn_add = wx.Button(panel, label="Add", id=wx.ID_OK)
        self.btn_add.Bind(wx.EVT_BUTTON, self.OnButton)
        # self.btn_add.Disable()
        hsizer.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5)
        hsizer.Add(self.btn_add, 0, wx.ALL | wx.EXPAND, 5)

        #add to main sizer
        sizer.Add(sbox_sizer, 0, wx.ALL | wx.EXPAND, 2)
        sizer.Add(hsizer, 0, wx.ALL | wx.EXPAND, 5)

        panel.SetSizer(sizer)

        w, h = sizer.Fit(self)

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            pass
    def __init__(self):

        wx.Frame.__init__(self,
                          parent=None,
                          title="Simple Sequence Creator 0.1")

        self._defaults = {
            "preferences": {
                'pos': '0',
                'startup': '0',
                'size': '0'
            },
            "instruments": {},
            "sequences": {}
        }

        self.getcwd = os.getcwd()
        self._file = "data.json"
        self._file = os.path.join(self.getcwd, "data", self._file)
        self._data = {}
        #load settings
        try:
            with open(self._file, 'r') as file:
                self._data = json.load(file)
        except:
            # write new config file
            with open(self._file, 'w') as file:
                json.dump(self._defaults, file, sort_keys=True, indent=1)
                self._data = self._defaults
        file.close()
        #
        self._preferences = self._data["preferences"]
        self._sequences = self._data["sequences"]

        self.add_ins_page = None
        self.psu_connection = None

        self.SetBackgroundColour("white")
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.HORIZONTAL)

        # # populate instrument list control
        # self.RefreshInstrumentList()

        self.notebook = wx.Notebook(panel)
        self._sequence_page = sequences.SequencesPage(self.notebook)
        self._instrument_page = instruments.InstrumentsPage(self.notebook)
        self._instrument_page.SetInstrumentData(self._data["instruments"])
        self._preferences_page = preferences.PreferencesPage(self.notebook)

        self.notebook.AddPage(self._sequence_page, "Sequence Creator")
        self.notebook.AddPage(self._instrument_page, "Instruments")
        self.notebook.AddPage(self._preferences_page, "Preferences")

        sizer.Add(self.notebook, 1, wx.ALL | wx.EXPAND, 0)

        panel.SetSizer(sizer)
        sizer.Fit(self)
        self.SetMinSize(self.GetSize())

        self.panel = panel
        self.CreateStatusBar()
        self.Show()

        try:
            self.SetIcon(theme.GetIcon("psu_png"))
        except:
            print("Could not set icon")

        #event bindings
        self.timer_update_channel = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.UpdateChannel, self.timer_update_channel)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        # configuration
        if self._preferences["pos"] == "0":
            self.Centre()
        else:
            x, y = self._preferences["pos"].split(",")
            self.SetPosition((int(x), int(y)))

        if self._preferences["size"] == "0":
            pass
        else:
            w, h = self._preferences["size"].split(",")
            self.SetSize((int(w), int(h)))