def __init__(self, parent):
        wx.Dialog.__init__(self, parent, wx.NewId(), "Edit Mask")

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.AddSpacer((10, 10))

        # if mask is defined
        vars = gaParams.getAppVars()
        if vars:
            options = [name for name in vars.iterkeys()]
            list = wx.CheckListBox(self, -1, choices=options)
            self.list = list
            i = 0
            for value in vars.values():
                if value.has_key("mask") and value["mask"]:
                    list.Check(i, True)
                i += 1

            sizer.Add(list)
        else:
            sizer.Add(wx.StaticText(self, -1, "No mask defined."))

        bSizer = wx.StdDialogButtonSizer()
        okButton = wx.Button(self, wx.ID_OK, "")
        cancelButton = wx.Button(self, wx.ID_CANCEL, "")
        bSizer.AddButton(okButton)
        bSizer.AddButton(cancelButton)
        bSizer.Realize()

        sizer.AddSpacer((10, 18))
        sizer.Add(bSizer)
        self.SetSizer(sizer)
        self.Fit()
Beispiel #2
0
    def __init__(self, parent, size = None, color = "LIGHT BLUE", style = None):
#wx.Panel.__init__(self, parent, -1, size=size, style = wx.RAISED_BORDER | wx.DOUBLE_BORDER)
        wx.Panel.__init__(self, parent, -1, size=size, style = wx.DOUBLE_BORDER)

        self.SetBackgroundColour('WHITE')
        self.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,wx.FONTWEIGHT_BOLD))
        self.gaWindow = parent.GetParent()

        yaml = gaParams.getYaml()
        f = open('config/guiconfig.yml', 'r')
        widgets = yaml.load(f)
        widgets = widgets['widgets']
        f.close()

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add((10, 14))

        # Population size label
        self.sizer.Add(wx.StaticText(self, -1, 'Population Size:'), 0, wx.ALIGN_CENTER)
        # Population size slider
        self.populationSlider = wx.Slider(self, -1, size=(100, 40), style= wx.SL_LABELS | wx.SL_AUTOTICKS)
        max = int(widgets['population']['max'])
        min = int(widgets['population']['min'])
        self.populationSlider.SetRange(min, max)
        self.populationSlider.SetValue(gaParams.getVar('population_size'))

        self.sizer.Add(self.populationSlider, 0, wx.ALIGN_CENTER)
        self.Bind(wx.EVT_SCROLL, self.onPopulationChange, self.populationSlider)

        xoRate, mutRate = gaParams.getGARates()
        # XO Rate Slider
        self.xoRateSlider = wx.Slider(self, -1, size = (100, 40), style = wx.SL_LABELS | wx.SL_AUTOTICKS)
        max = int(widgets['crossover']['max'])
        min = int(widgets['crossover']['min'])
        self.xoRateSlider.SetRange(min, max)
        self.xoRateSlider.SetValue(xoRate * max)

        # Add xo slider to sizer
        self.sizer.Add((10, 10))
        self.sizer.Add(wx.StaticText(self, -1, 'Crossover Rate:'), 0, wx.ALIGN_CENTER)
        self.sizer.Add(self.xoRateSlider, 0, wx.ALIGN_CENTER)

        self.Bind(wx.EVT_SCROLL, self.onCrossoverChange, self.xoRateSlider)

        # Mutation Rate
        self.mutBox = wx.TextCtrl(self, -1, size = (50, -1))
        self.mutBox.SetValue("%.3f" % mutRate)

        tempSizer = wx.BoxSizer(wx.HORIZONTAL)
        tempSizer.Add(wx.StaticText(self, -1, 'Mutation:'), 0, wx.ALIGN_CENTER_VERTICAL)
        tempSizer.Add(self.mutBox, 0)
        self.sizer.Add((10, 10))
        self.sizer.Add(tempSizer, 0, wx.ALIGN_CENTER)

        max = int(widgets['mutation']['max'])
        min = int(widgets['mutation']['min'])

        self.Bind(wx.EVT_TEXT, self.onMutationChange, self.mutBox)

        self.sizer.Add((10, 10))

        # Step size spinner control
        self.stepSize = wx.SpinCtrl(self, wx.ID_ANY, size = (50,23))
        self.stepSize.SetRange(1, 300)
        step = gaParams.getVar('stepSize') or 1
        self.stepSize.SetValue(step)

        self.Bind(wx.EVT_SPINCTRL, self.onSpin, self.stepSize)

        # Add spinner with text label to sizer
        tempSizer = wx.BoxSizer(wx.HORIZONTAL)
        tempSizer.Add(wx.StaticText(self, -1, 'Step Size:'), 0, wx.ALIGN_CENTER_VERTICAL)
        tempSizer.Add(self.stepSize)
        self.sizer.Add(tempSizer, 0, wx.ALIGN_CENTER)

        # edit mask button
        self.sizer.AddSpacer((10, 10))
        self.maskB = wx.Button(self, -1, 'Edit Mask')
        self.Bind(wx.EVT_BUTTON, self.onEditMask, self.maskB)
        self.sizer.Add(self.maskB, 0, wx.ALIGN_CENTER) 
        if not gaParams.getAppVars():
            self.maskB.Enable(False)

        # 8px spaces for widgets in same group
        # 10px for widgets not in the same group

        # -----------------------------------
        # peer stuff
        self.sizer.Add((10, 10))
        self.sizer.Add(wx.StaticLine(self), 0, wx.EXPAND)
        self.sizer.Add((10, 10))

        peers = {}
        peer_list = gaParams.getVar('peers')
        online = wx.Bitmap('gui/online.png')
        offline = wx.Bitmap('gui/offline.png')
        delete = wx.Bitmap('gui/delete.png')
        self.online, self.offline, self.delete = online, offline, delete

        # my status
        tmp_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.my_status = wx.StaticBitmap(self)
        self.my_status.SetBitmap(online)
        tmp_sizer.Add(self.my_status)
        tmp_sizer.Add(wx.StaticText(self, -1, 'Collaborate'))
        self.sizer.Add(tmp_sizer)

        # add peer button
        self.sizer.Add((10, 10))
        newButton = wx.Button(self, -1, 'Add Peer...')
        newButton.Bind(wx.EVT_BUTTON, self.onAddPeer, newButton)
        self.sizer.Add(newButton)
        self.sizer.Add((10, 10))

        # keeps track of each ID for each peer
        self.names = {}
        # add list of peers
        all_peers_sizer = wx.BoxSizer(wx.VERTICAL)
        for peer in peer_list:
            id = wx.NewId()

            peer_sizer = wx.BoxSizer(wx.HORIZONTAL)
            peer_status = wx.StaticBitmap(self)
            peer_status.SetBitmap(offline)
            peer_name = wx.StaticText(self, -1, peer)
            peer_name.Bind(wx.EVT_LEFT_DOWN, self.onEditPeer, peer_name)
            peer_sizer.Add(peer_status)
            peer_sizer.Add(peer_name)

            peer_delete = wx.BitmapButton(self, id = id, bitmap = delete, 
                                                style = wx.ALIGN_RIGHT)
            self.Bind(wx.EVT_BUTTON, self.onDeletePeer, peer_delete)

            peer_sizer.Add(wx.StaticText(self, -1, '  '), 1)
            peer_sizer.Add(peer_delete)

            all_peers_sizer.Add(peer_sizer, 0, wx.EXPAND)
            peers[id] = {'name': peer,
                         'sizer': peer_sizer, 'status': peer_status}
            self.names[peer] = id
                
        self.sizer.Add(all_peers_sizer)
        self.peer_sizer = all_peers_sizer

        self.peers = peers
        self.status_bitmap = {}
        self.status_bitmap['online'] = online
        self.status_bitmap['offline'] = offline

        # Disconnect button
        self.sizer.AddSpacer((10, 10))
        self.disconnect = wx.Button(self, -1, 'Disconnect')
        self.Bind(wx.EVT_BUTTON, self.onDisconnect, self.disconnect)
        self.sizer.Add(self.disconnect, 0, wx.ALIGN_CENTER) 

        # refresh button
        self.sizer.AddSpacer((10, 10))
        self.refresh = wx.Button(self, wx.ID_REFRESH, '')
        self.Bind(wx.EVT_BUTTON, self.onRefresh, self.refresh)
        self.sizer.Add(self.refresh, 0, wx.ALIGN_CENTER) 

        # back button
        self.sizer.AddSpacer((10, 10))
        self.back = wx.Button(self, wx.ID_BACKWARD, '')
        self.back.Enable(False)
        self.Bind(wx.EVT_BUTTON, self.onBack, self.back)
        self.sizer.Add(self.back, 0, wx.ALIGN_CENTER) 


        self.sizer.AddSpacer((10, 10))
        self.sizer.Add(wx.StaticLine(self), 0, wx.EXPAND)
        self.sizer.AddSpacer((10, 10))

        self.app_panels = []
        self.appSizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.appSizer, 0, wx.EXPAND)
        self.reset()

        # Add submit button
        self.submit = wx.Button(self, -1, 'Step %d Gen' % step, size = (130,-1))
        self.submit.Enable(False)
        self.Bind(wx.EVT_BUTTON, self.onSubmit, self.submit)
        self.sizer.Add(self.submit, 0, wx.ALIGN_CENTER)

        # final sizer and fitting stuff
        self.SetSizer(self.sizer)
        self.SetAutoLayout(True)
        self.sizer.Layout()
        self.sizer.Fit(self)
        self.sizer.SetSizeHints(self)
        self.Layout()

        # Keeps the textbox from having the default focus, which was annoying
        self.SetFocus()

        self.timestamp = 0.
        self.gen = 0