Exemplo n.º 1
0
class CustomScriptProfile(PybotProfile):
    '''A runner profile which uses script given by the user'''

    name = "custom script"
    default_settings = dict(PybotProfile.default_settings, runner_script="")

    def get_command(self):
        return self.runner_script

    def get_cwd(self):
        return os.path.dirname(self.runner_script)

    def get_toolbar_items(self):
        return [self.RunScriptPanel, self.ArgumentsPanel, self.TagsPanel]

    def _validate_arguments(self, args):
        # Can't say anything about custom script argument validity
        pass

    def _create_error_log_message(self, error, returncode):
        return None

    def RunScriptPanel(self, parent):
        panel = wx.Panel(parent, wx.ID_ANY)
        self._script = FileBrowseButton(
            panel, labelText="Script to run tests:", size=(-1, -1),
            fileMask="*", changeCallback=self.OnCustomScriptChanged)
        self._script.SetValue(self.runner_script)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self._script, 0, wx.ALL | wx.EXPAND)
        panel.SetSizerAndFit(sizer)
        return panel

    def OnCustomScriptChanged(self, evt):
        self.set_setting("runner_script", self._script.GetValue())
Exemplo n.º 2
0
    def createFileSelection(self, n, items, currentFilter, save=0):
        """
		create a file selection GUI element that shows the filename and has a button to select a file
		"""
        itemName = items[n][0]

        box = wx.BoxSizer(wx.VERTICAL)
        text = currentFilter.getDesc(itemName)
        defValue = currentFilter.getDefaultValue(itemName)
        ftype = defValue.split(".")[-1]
        conf = Configuration.getConfiguration()
        remember = conf.getConfigItem("RememberPath", "Paths")
        lastPath = ""
        if remember:
            lastPath = conf.getConfigItem("LastPath_%s" % ftype, "Paths")
            if not lastPath:
                lastPath = "."

        updateFilenameFunc = lambda event, its = items[n], f = currentFilter, i = itemName, \
            s = self: s.onSetFileName(f, i, event)

        if save:
            filemode = wx.SAVE
        else:
            filemode = wx.OPEN

        browse = FileBrowseButton(self,
                                  -1,
                                  size=(400, -1),
                                  labelText=text,
                                  fileMask=items[n][2],
                                  dialogTitle=items[n][1],
                                  startDirectory=lastPath,
                                  changeCallback=updateFilenameFunc,
                                  fileMode=filemode)
        browse.SetValue(defValue)

        setFilenameFunc = lambda obj, event, arg, b = browse, i = itemName, s = self: \
               s.onSetFileNameFromFilter(b, i, arg)
        lib.messenger.connect(currentFilter, "set_%s" % itemName,
                              setFilenameFunc)

        longDesc = currentFilter.getLongDesc(itemName)
        if longDesc:
            browse.SetToolTip(wx.ToolTip(s))

        box.Add(browse, 1)
        self.itemSizer.Add(box, (self.currentRow, 0),
                           flag=wx.EXPAND | wx.HORIZONTAL)
        self.items[itemName] = box

        return 1
Exemplo n.º 3
0
class SendFileFrame(sc.SizedFrame):
 """File sending options."""
 def __init__(self, callback, filename = '', prefix = '', suffix = '', linesep = '\n', preline = '', postline = '', ignore = ''):
  super(SendFileFrame, self).__init__(None, title = 'Send File')
  self.callback = callback
  s = wx.TE_RICH|wx.TE_MULTILINE
  p = self.GetContentsPane()
  p.SetSizerType('form')
  wx.StaticText(p, label = '&File name')
  self.filename = FileBrowseButton(p)
  self.filename.SetValue(filename)
  wx.StaticText(p, label = 'Text to &prefix the file with')
  self.prefix = wx.TextCtrl(p, value = prefix, style = s)
  wx.StaticText(p, label = 'Text to p&refix each line with')
  self.preLine = wx.TextCtrl(p, value = preline, style = s)
  wx.StaticText(p, label = 'Text to s&uffix each line with')
  self.postLine = wx.TextCtrl(p, value = postline, style = s)
  wx.StaticText(p, label = 'Line &seperator')
  self.linesep = wx.TextCtrl(p, value = linesep, style = s)
  wx.StaticText(p, label = 'Text to &suffix the file with')
  self.suffix = wx.TextCtrl(p, value = suffix, style = s)
  wx.StaticText(p, label = 'Text to &ignore')
  self.ignore = wx.TextCtrl(p, value = ignore)
  self.cancel = wx.Button(p, label = '&Cancel')
  self.cancel.Bind(wx.EVT_BUTTON, lambda event: self.Close(True))
  self.ok = wx.Button(p, label = '&OK')
  self.ok.Bind(wx.EVT_BUTTON, self.onOk)
  self.ok.SetDefault()
  self.Maximize(True)
 
 def onOk(self, event):
  """Sends the stuff using callback."""
  f = self.filename.GetValue()
  if not os.path.isfile(f):
   return wx.MessageBox('No such file: %s.' % f, 'Error', style = wx.ICON_ERROR)
  c = self.prefix.GetValue()
  sep = self.linesep.GetValue()
  c += sep
  pre = self.preLine.GetValue()
  post = self.postLine.GetValue()
  if self.ignore.GetValue():
   m = re.compile(self.ignore.GetValue())
  else:
   m = None
  with open(f, 'r') as f:
   for line in f:
    line = line[:-1]
    if not m or not m.match(line):
     c+= '%s%s%s%s' % (pre, line, post, sep)
  self.callback(c + self.suffix.GetValue())
  self.Close(True)
Exemplo n.º 4
0
class CustomScriptProfile(PybotProfile):
    """A runner profile which uses script given by the user"""

    name = "custom script"
    default_settings = dict(PybotProfile.default_settings, runner_script="")

    def get_command(self):
        # strip the starting and ending spaces to ensure
        # /bin/sh finding the executable file
        return self.runner_script.strip()

    def get_cwd(self):
        return os.path.dirname(self.runner_script)

    @overrides(PybotProfile)
    def get_toolbar_items(self, parent):
        return [
            self._get_run_script_panel(parent),
            self._get_arguments_panel(parent),
            self._get_tags_panel(parent),
            self._get_log_options_panel(parent)
        ]

    def _validate_arguments(self, args):
        # Can't say anything about custom script argument validity
        pass

    def _create_error_log_message(self, error, returncode):
        return None

    def _get_run_script_panel(self, parent):
        panel = wx.Panel(parent, wx.ID_ANY)
        self._script_ctrl = FileBrowseButton(
            panel,
            labelText="Script to run tests:",
            size=(-1, -1),
            fileMask="*",
            changeCallback=self.OnCustomScriptChanged)
        self._script_ctrl.SetValue(self.runner_script)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self._script_ctrl, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)

        panel.SetSizerAndFit(sizer)
        return panel

    def OnCustomScriptChanged(self, evt):
        self.set_setting("runner_script", self._script_ctrl.GetValue())
Exemplo n.º 5
0
class panelConfigure(wx.Panel):
    """
    """
    def __init__(self, parent):
        """
        """
        wx.Panel.__init__(self,
                          parent,
                          wx.ID_ANY,
                          size=(-1, 300),
                          style=wx.SUNKEN_BORDER | wx.TAB_TRAVERSAL)
        self.parent = parent

        self.thumbnail = None
        self.mask_file = None
        self.source = None
        self.sourceType = None
        self.track = None
        self.trackType = None

        lowerSizer = wx.BoxSizer(wx.HORIZONTAL)

        #Static box1 (LEFT)
        sb_1 = wx.StaticBox(self, -1, "Select Monitor")  #, size=(250,-1))
        sbSizer_1 = wx.StaticBoxSizer(sb_1, wx.VERTICAL)

        n_monitors = options.GetOption("Monitors")
        self.MonitorList = [
            'Monitor %s' % (int(m) + 1) for m in range(n_monitors)
        ]
        self.thumbnailNumber = wx.ComboBox(self,
                                           -1,
                                           size=(-1, -1),
                                           choices=self.MonitorList,
                                           style=wx.CB_DROPDOWN
                                           | wx.CB_READONLY | wx.CB_SORT)
        self.Bind(wx.EVT_COMBOBOX, self.onChangingMonitor,
                  self.thumbnailNumber)

        self.currentSource = wx.TextCtrl(self,
                                         -1,
                                         "No Source Selected",
                                         style=wx.TE_READONLY)

        btnSizer_1 = wx.BoxSizer(wx.HORIZONTAL)
        self.btnPlay = wx.Button(self, wx.ID_FORWARD, label="Play")
        self.btnStop = wx.Button(self, wx.ID_STOP, label="Stop")
        self.Bind(wx.EVT_BUTTON, self.onPlay, self.btnPlay)
        self.Bind(wx.EVT_BUTTON, self.onStop, self.btnStop)
        self.btnPlay.Enable(False)
        self.btnStop.Enable(False)
        self.applyButton = wx.Button(self, wx.ID_APPLY)
        self.applyButton.SetToolTip(wx.ToolTip("Apply and Save to file"))
        self.Bind(wx.EVT_BUTTON, self.onApplySource, self.applyButton)

        btnSizer_1.Add(self.btnPlay, 0, wx.ALIGN_LEFT | wx.ALL, 5)
        btnSizer_1.Add(self.btnStop, 0,
                       wx.ALIGN_CENTER | wx.LEFT | wx.TOP | wx.DOWN, 5)
        btnSizer_1.Add(self.applyButton, 0,
                       wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT | wx.TOP, 5)

        sbSizer_1.Add(self.thumbnailNumber, 0,
                      wx.ALIGN_CENTRE | wx.LEFT | wx.RIGHT | wx.TOP, 5)
        sbSizer_1.Add(
            self.currentSource, 0,
            wx.EXPAND | wx.ALIGN_CENTRE | wx.LEFT | wx.RIGHT | wx.TOP, 5)
        sbSizer_1.Add(btnSizer_1, 0, wx.EXPAND | wx.ALIGN_BOTTOM | wx.TOP, 5)

        lowerSizer.Add(sbSizer_1, 0, wx.EXPAND | wx.ALL, 5)

        #Static box2 (CENTER)
        sb_2 = wx.StaticBox(self, -1, "Select Video input")
        sbSizer_2 = wx.StaticBoxSizer(sb_2, wx.VERTICAL)
        grid2 = wx.FlexGridSizer(0, 2, 0, 0)

        n_cams = options.GetOption("Webcams")
        self.WebcamsList = ['Webcam %s' % (int(w) + 1) for w in range(n_cams)]
        rb1 = wx.RadioButton(self, -1, 'Camera', style=wx.RB_GROUP)
        source1 = wx.ComboBox(self,
                              -1,
                              size=(285, -1),
                              choices=self.WebcamsList,
                              style=wx.CB_DROPDOWN | wx.CB_READONLY
                              | wx.CB_SORT)
        self.Bind(wx.EVT_COMBOBOX, self.sourceCallback, source1)

        rb2 = wx.RadioButton(self, -1, 'File')
        source2 = FileBrowseButton(self,
                                   -1,
                                   labelText='',
                                   size=(300, -1),
                                   changeCallback=self.sourceCallback)

        rb3 = wx.RadioButton(self, -1, 'Folder')
        source3 = DirBrowseButton(self,
                                  style=wx.DD_DIR_MUST_EXIST,
                                  labelText='',
                                  size=(300, -1),
                                  changeCallback=self.sourceCallback)

        self.controls = []
        self.controls.append((rb1, source1))
        self.controls.append((rb2, source2))
        self.controls.append((rb3, source3))

        for radio, source in self.controls:
            grid2.Add(radio, 0,
                      wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
            grid2.Add(source, 0,
                      wx.ALIGN_CENTRE | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
            self.Bind(wx.EVT_RADIOBUTTON, self.onChangeSource, radio)
            source.Enable(False)

        self.controls[0][1].Enable(True)

        #grid2.Add(wx.StaticText(self, -1, ""))

        sbSizer_2.Add(grid2)
        lowerSizer.Add(sbSizer_2, 0, wx.EXPAND | wx.ALL, 5)

        #Static box3 (RIGHT)
        sb_3 = wx.StaticBox(self, -1, "Set Tracking Parameters")
        sbSizer_3 = wx.StaticBoxSizer(sb_3, wx.VERTICAL)

        sbSizer_31 = wx.BoxSizer(wx.HORIZONTAL)

        self.activateTracking = wx.CheckBox(self, -1, "Activate Tracking")
        self.activateTracking.SetValue(False)
        self.activateTracking.Bind(wx.EVT_CHECKBOX, self.onActivateTracking)

        self.isSDMonitor = wx.CheckBox(self, -1, "Sleep Deprivation Monitor")
        self.isSDMonitor.SetValue(False)
        self.isSDMonitor.Bind(wx.EVT_CHECKBOX, self.onSDMonitor)
        self.isSDMonitor.Enable(False)

        sbSizer_31.Add(self.activateTracking, 0,
                       wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 5)
        sbSizer_31.Add(self.isSDMonitor, 0,
                       wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 5)

        self.pickMaskBrowser = FileBrowseButton(self,
                                                -1,
                                                labelText='Mask File')

        #sbSizer_3.Add ( self.activateTracking , 0, wx.ALIGN_LEFT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
        sbSizer_3.Add(sbSizer_31, 0,
                      wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 5)
        sbSizer_3.Add(self.pickMaskBrowser, 0,
                      wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP | wx.EXPAND,
                      5)

        #trackingTypeSizer = wx.Sizer(wx.HORIZONTAL)
        self.trackDistanceRadio = wx.RadioButton(
            self, -1, "Activity as distance traveled", style=wx.RB_GROUP)
        self.trackVirtualBM = wx.RadioButton(
            self, -1, "Activity as midline crossings count")
        self.trackPosition = wx.RadioButton(self, -1, "Only position of flies")
        sbSizer_3.Add(wx.StaticText(self, -1, "Calculate fly activity as..."),
                      0, wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 5)
        sbSizer_3.Add(self.trackDistanceRadio, 0,
                      wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 2)
        sbSizer_3.Add(self.trackVirtualBM, 0,
                      wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 2)
        sbSizer_3.Add(self.trackPosition, 0,
                      wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, 2)

        lowerSizer.Add(sbSizer_3, -1, wx.EXPAND | wx.ALL, 5)

        self.SetSizer(lowerSizer)
        self.Bind(EVT_THUMBNAIL_CLICKED, self.onThumbnailClicked)

    def __getSource(self):
        """
        check which source is ticked and what is the associated value
        """

        for (r, s), st in zip(self.controls, range(3)):
            if r.GetValue():
                source = s.GetValue()
                sourceType = st

        return source, sourceType

    def __getTrackingType(self):
        """
        return which tracking we are chosing
        ['DISTANCE','VBS','XY_COORDS']
        """
        if self.trackDistanceRadio.GetValue(): trackType = "DISTANCE"
        elif self.trackVirtualBM.GetValue(): trackType = "VBS"
        elif self.trackPosition.GetValue(): trackType = "XY_COORDS"

        return trackType

    def onPlay(self, event=None):
        """
        """
        if self.thumbnail:
            self.thumbnail.Play()
            self.btnStop.Enable(True)

    def onStop(self, event=None):
        """
        """
        if self.thumbnail and self.thumbnail.isPlaying:
            self.thumbnail.Stop()
            self.btnStop.Enable(False)

    def onThumbnailClicked(self, evt):
        """
        Picking thumbnail by clicking on it
        """
        self.monitor_number = evt.number + 1
        self.thumbnail = evt.thumbnail
        self.thumbnailNumber.SetValue(self.MonitorList[self.monitor_number -
                                                       1])
        self.updateThumbnail()

    def onChangingMonitor(self, evt):
        """
        Picking thumbnail by using the dropbox
        """
        sel = evt.GetString()
        self.monitor_number = self.MonitorList.index(sel) + 1
        self.thumbnail = self.parent.scrollThumbnails.previewPanels[
            self.monitor_number]  #this is not very elegant
        self.updateThumbnail()

    def updateThumbnail(self):
        """
        Refreshing thumbnail data
        """
        if options.HasMonitor(self.monitor_number):
            sourceType, source, track, mask_file, trackType, isSDMonitor = options.GetMonitor(
                self.monitor_number)
        else:
            sourceType, source, track, mask_file, trackType, isSDMonitor = [
                0, '', False, '', 1, False
            ]

        if sourceType == 0 and source != '':
            source = self.WebcamsList[source]

        self.source = self.thumbnail.source = source
        self.sourceType = self.thumbnail.sourceType = sourceType
        self.thumbnail.track = track
        if self.thumbnail.hasMonitor():
            self.thumbnail.mon.isSDMonitor = isSDMonitor

        #update first static box
        active = self.thumbnail.hasMonitor()
        self.applyButton.Enable(active)
        self.btnPlay.Enable(active)
        self.btnStop.Enable(active and self.thumbnail.isPlaying)

        text = os.path.split(str(self.source))[1] or "No Source Selected"
        self.currentSource.SetValue(text)

        #update second static box
        for radio, src in self.controls:
            src.Enable(False)
            src.SetValue('')

        radio, src = self.controls[self.sourceType]
        radio.SetValue(True)
        src.Enable(True)
        src.SetValue(self.source)

        #update third static box
        self.activateTracking.SetValue(self.thumbnail.track)
        self.isSDMonitor.SetValue(isSDMonitor)
        self.pickMaskBrowser.SetValue(mask_file or '')
        [self.trackDistanceRadio, self.trackVirtualBM,
         self.trackPosition][trackType].SetValue(True)

    def sourceCallback(self, event):
        """
        """
        self.applyButton.Enable(True)

    def onChangeSource(self, event):
        """

        """

        radio_selected = event.GetEventObject()

        for radio, source in self.controls:
            if radio is radio_selected:
                source.Enable(True)
            else:
                source.Enable(False)

        self.applyButton.Enable(True)

    def onApplySource(self, event):
        """
        """

        source, sourceType = self.__getSource()
        track = self.activateTracking.GetValue()
        self.mask_file = self.pickMaskBrowser.GetValue()
        self.trackType = self.__getTrackingType()

        if self.thumbnail:

            if sourceType > 0: camera = source
            else: camera = self.WebcamsList.index(source)

            self.thumbnail.source = camera
            self.thumbnail.sourceType = sourceType

            #Change the source text
            self.currentSource.SetValue(os.path.split(source)[1])

            #Set thumbnail's source
            self.thumbnail.setMonitor(camera)

            #Enable buttons
            self.btnPlay.Enable(True)
            self.activateTracking.Enable(True)
            self.pickMaskBrowser.Enable(True)

            self.saveMonitorConfiguration()

    def saveMonitorConfiguration(self):
        """
        """

        options.SetMonitor(self.monitor_number, self.thumbnail.sourceType,
                           self.thumbnail.source + 1, self.thumbnail.track,
                           self.mask_file, self.trackType,
                           self.thumbnail.mon.isSDMonitor)
        options.Save()

    def onActivateTracking(self, event):
        """
        """
        if self.thumbnail:
            self.thumbnail.track = event.IsChecked()

    def onSDMonitor(self, event):
        """
        """
        if self.thumbnail:
            self.thumbnail.mon.isSDMonitor = event.IsChecked()
Exemplo n.º 6
0
class MainFrame(wx.Frame):
    def _init_ctrls(self, parent):
        self.DecYear = wx.Button(self, -1, '<<', size=(48, 36))
        self.DecYear.Bind(wx.EVT_BUTTON, self.OnDecYear)
        self.DecMonth = wx.Button(self, -1, ' < ', size=(48, 36))
        self.DecMonth.Bind(wx.EVT_BUTTON, self.OnDecMonth)
        self.Current = wx.Button(self, -1, 'Today')
        self.Current.Bind(wx.EVT_BUTTON, self.OnCurrent)
        self.IncMonth = wx.Button(self, -1, ' > ', size=(48, 36))
        self.IncMonth.Bind(wx.EVT_BUTTON, self.OnIncMonth)
        self.IncYear = wx.Button(self, -1, '>>', size=(48, 36))
        self.IncYear.Bind(wx.EVT_BUTTON, self.OnIncYear)
        bsizer = wx.BoxSizer(wx.HORIZONTAL)
        bsizer.Add(self.DecYear, 0, wx.ALL, 2)
        bsizer.Add(self.DecMonth, 0, wx.ALL, 2)
        bsizer.Add(self.Current, 1, wx.ALL | wx.EXPAND, 2)
        bsizer.Add(self.IncMonth, 0, wx.ALL, 2)
        bsizer.Add(self.IncYear, 0, wx.ALL, 2)

        self.Calendar = Calendar(self, -1, size=(200, 300))
        self.Calendar.Bind(wx.lib.calendar.EVT_CALENDAR, self.OnCalendarChange)
        self.Calendar.SetCurrentDay()
        self.Calendar.grid_color = 'BLUE'
        self.Calendar.SetBusType()

        self.FBB = FileBrowseButton(self,
                                    size=(450, -1),
                                    changeCallback=self.OnFBBChange)
        self.FBB.SetLabel('Symbols File:')

        self.DBB = DirBrowseButton(self,
                                   size=(450, -1),
                                   changeCallback=self.OnDBBChange)
        self.DBB.SetLabel('Prices Folder:')

        self.ListBox = gizmos.EditableListBox(
            self,
            -1,
            #              style=gizmos.EL_DEFAULT_STYLE | gizmos.EL_NO_REORDER
        )
        self.ListBox.GetUpButton().Show(False)
        self.ListBox.GetDownButton().Show(False)
        self.ListBox.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnSymbolListChange)
        self.ListBox.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnSymbolListChange)

        self.Download = wx.Button(self, wx.OK, 'Download Prices')
        self.Download.Bind(wx.EVT_BUTTON, self.OnDownload)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.AddSizer(bsizer, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, 5)
        sizer.AddWindow(self.Calendar, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, 5)
        sizer.AddWindow(self.FBB, 0, wx.ALL | wx.EXPAND, 5)
        sizer.AddWindow(self.DBB, 0, wx.ALL | wx.EXPAND, 5)
        sizer.AddWindow(self.ListBox, 1, wx.ALL | wx.EXPAND, 5)
        sizer.AddWindow(self.Download, 0, wx.ALL | wx.ALIGN_RIGHT, 5)
        self.SetSizer(sizer)

    def __init__(self, parent=None):
        wx.Frame.__init__(self, parent=parent, size=(800, 600))
        self._init_ctrls(self)

        self._blocking = Blocker()
        self._clean = True

        # Get download directory and symbol filename
        download_dir = ''
        symbol_file = ''

        if os.path.exists('settings.ini'):
            with file('settings.ini', 'r') as settings:
                symbol_file = settings.readline().strip()
                download_dir = settings.readline().strip()
            if not os.path.exists(symbol_file):
                symbol_file = ''
            if not os.path.exists(download_dir):
                download_dir = ''

        download_dir = download_dir or os.path.realpath('.')
        symbol_file = symbol_file or os.path.join(download_dir, 'symbols.txt')

        self.SetDownloadDir(download_dir)
        if os.path.exists(symbol_file):
            self.SetSymbolFile(symbol_file)

        # Update the calendar
        self.Download.SetFocus()
        self.OnCalendarChange(None)

    def OnCalendarChange(self, event):
        self.day = self.Calendar.day
        self.month = self.Calendar.month
        self.year = self.Calendar.year

    def OnCurrent(self, event):
        self.Calendar.SetCurrentDay()
        self.ResetDisplay()

    def OnDBBChange(self, event):
        if self._blocking:
            return
        self.SetDownloadDir(event.GetString())

    def OnDecMonth(self, event):
        self.Calendar.DecMonth()
        self.ResetDisplay()

    def OnDecYear(self, event):
        self.Calendar.DecYear()
        self.ResetDisplay()

    def OnDownload(self, event):
        if not self._clean:
            with file(self.symbol_file, 'w') as symbols:
                symbols.write('\n'.join(self.ListBox.GetStrings()))
            self._clean = True

        dt = datetime.date(self.year, self.month, self.day)
        pricer.download_date(self.ListBox.GetStrings(), dt, self.download_dir)

        with file('settings.ini', 'w') as settings:
            settings.write(self.symbol_file + '\n')
            settings.write(self.download_dir + '\n')

    def OnFBBChange(self, event):
        if self._blocking:
            return
        self.ListBox.SetStrings([])
        self.SetSymbolFile(event.GetString())

    def OnIncMonth(self, event):
        self.Calendar.IncMonth()
        self.ResetDisplay()

    def OnIncYear(self, event):
        self.Calendar.IncYear()
        self.ResetDisplay()

    def OnSymbolListChange(self, event):
        self._clean = False
        self.Download.Enable(len(self.ListBox.GetStrings()) > 0)

    def ResetDisplay(self):
        self.Calendar.Refresh()

    def SetDownloadDir(self, download_dir):
        with self._blocking:
            self.download_dir = download_dir
            self.DBB.SetValue(self.download_dir)

    def SetSymbolFile(self, symbol_file):
        self.Download.Enable(False)
        with self._blocking:
            if not os.path.exists(symbol_file):
                return
            self.symbol_file = symbol_file

            with file(self.symbol_file, 'r') as symbols:
                l = []
                for symbol in symbols:
                    s = symbol.strip().upper()
                    if len(s) and not s.startswith('#'):
                        l.append(s)
                l.sort()
                self.ListBox.SetStrings(l)
                self._clean = True
            self.FBB.SetValue(self.symbol_file)