Exemple #1
0
    def InitDlg(self):
        self._btbox = DLGButtonPanel(self,style=wx.SUNKEN_BORDER)
      
        self.pnl_bcb = wx.Panel(self)   
        self.cdb_label_list = WX_CDB.getColourList()  
        self.cdb_info_list  = WX_CDB.getColourInfoList()  #

        bcb = BitmapComboBox(self.pnl_bcb,size=(140,-1))
        size_h_w = 16
        slidx=0
        for c in self.color_list:

            idx = self.cdb_label_list.index(c.upper())
            (r,g,b) = self.cdb_info_list[idx][1:]
            bmp = wx.EmptyBitmapRGBA(size_h_w, size_h_w,red=r,green=g,blue=b,alpha= wx.ALPHA_OPAQUE)
            bcb.Append(c, bmp, c)
            self.Bind(wx.EVT_COMBOBOX,self.OnCombo,bcb)
            if ( self.selected_color_label == c ):
               bcb.SetSelection( bcb.GetCount() -1)
Exemple #2
0
    def Configure(self, parent=None):
        if OptionsDialog.instance:
            OptionsDialog.instance.Raise()
            return
        OptionsDialog.instance = self

        text = Text
        config = eg.config
        self.useFixedFont = config.useFixedFont

        eg.TaskletDialog.__init__(
            self,
            parent=parent,
            title=text.Title,
        )

        languageNames = eg.Translation.languageNames
        languageList = ["en_EN"]
        for item in os.listdir(eg.languagesDir):
            name, ext = os.path.splitext(item)
            if ext == ".py" and name in languageNames:
                languageList.append(name)
        languageList.sort()
        languageNameList = [languageNames[x] for x in languageList]
        notebook = wx.Notebook(self, -1)
        page1 = eg.Panel(notebook)
        notebook.AddPage(page1, text.Tab1)

        # page 1 controls
        startWithWindowsCtrl = page1.CheckBox(
            exists(join((eg.folderPath.Startup or ""), eg.APP_NAME + ".lnk")),
            text.StartWithWindows)
        if eg.folderPath.Startup is None:
            startWithWindowsCtrl.Enable(False)

        checkUpdateCtrl = page1.CheckBox(config.checkUpdate, text.CheckUpdate)
        checkPreReleaseCtrl = page1.CheckBox(config.checkPreRelease,
                                             text.CheckPreRelease)
        checkPreReleaseCtrl.Enable(config.checkUpdate)

        def OnCheckUpdateCheckBox(event):
            checkPreReleaseCtrl.Enable(event.IsChecked())

        checkUpdateCtrl.Bind(wx.EVT_CHECKBOX, OnCheckUpdateCheckBox)

        confirmDeleteCtrl = page1.CheckBox(config.confirmDelete,
                                           text.confirmDelete)

        showTrayIconCtrl = page1.CheckBox(config.showTrayIcon,
                                          text.showTrayIcon)

        hideOnCloseCtrl = page1.CheckBox(config.hideOnClose, text.HideOnClose)

        memoryLimitCtrl = page1.CheckBox(config.limitMemory, text.limitMemory1)
        memoryLimitSpinCtrl = page1.SpinIntCtrl(config.limitMemorySize,
                                                min=4,
                                                max=999)

        def OnMemoryLimitCheckBox(dummyEvent):
            memoryLimitSpinCtrl.Enable(memoryLimitCtrl.IsChecked())

        memoryLimitCtrl.Bind(wx.EVT_CHECKBOX, OnMemoryLimitCheckBox)
        OnMemoryLimitCheckBox(None)

        refreshEnvCtrl = page1.CheckBox(config.refreshEnv, text.refreshEnv)

        propResizeCtrl = page1.CheckBox(config.propResize, text.propResize)

        useFixedFontCtrl = page1.CheckBox(config.useFixedFont,
                                          text.UseFixedFont)

        def OnFixedFontBox(evt):
            self.UpdateFont(evt.IsChecked())

        useFixedFontCtrl.Bind(wx.EVT_CHECKBOX, OnFixedFontBox)

        datestampCtrl = page1.TextCtrl(config.datestamp)
        datestampCtrl.SetToolTipString(text.DatestampHelp)
        datestampLabel = page1.StaticText(text.Datestamp)
        datestampLabel.SetToolTipString(text.DatestampHelp)
        datestampSzr = wx.BoxSizer(wx.HORIZONTAL)
        datestampSzr.AddMany(
            ((datestampLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5),
             (datestampCtrl, 1, wx.EXPAND)))

        def OnDatestampKillFocus(_):
            dt_fmt = datestampCtrl.GetValue()
            try:
                strftime(dt_fmt, localtime())
            except ValueError:
                wx.MessageBox("Invalid format string!", "Error")
                datestampCtrl.SetBackgroundColour("pink")
                datestampCtrl.Refresh()
                wx.CallAfter(datestampCtrl.SetFocus)
            else:
                datestampCtrl.SetBackgroundColour(
                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
                datestampCtrl.Refresh()

        datestampCtrl.Bind(wx.EVT_KILL_FOCUS, OnDatestampKillFocus)

        languageChoice = BitmapComboBox(page1, style=wx.CB_READONLY)
        for name, code in zip(languageNameList, languageList):
            filename = os.path.join(eg.imagesDir, "flags", "%s.png" % code)
            if os.path.exists(filename):
                image = wx.Image(filename)
                image.Resize((16, 16), (0, 3))
                bmp = image.ConvertToBitmap()
                languageChoice.Append(name, bmp)
            else:
                languageChoice.Append(name)
        languageChoice.SetSelection(languageList.index(config.language))
        languageChoice.SetMinSize((150, -1))

        buttonRow = eg.ButtonRow(self, (wx.ID_OK, wx.ID_CANCEL))

        # construction of the layout with sizers

        flags = wx.ALIGN_CENTER_VERTICAL
        memoryLimitSizer = eg.HBoxSizer(
            (memoryLimitCtrl, 0, flags),
            (memoryLimitSpinCtrl, 0, flags),
            (page1.StaticText(text.limitMemory2), 0, flags | wx.LEFT, 2),
        )

        startGroupSizer = wx.GridSizer(cols=1, vgap=2, hgap=2)
        startGroupSizer.AddMany((
            (startWithWindowsCtrl, 0, flags),
            (checkUpdateCtrl, 0, flags),
            (checkPreReleaseCtrl, 0, flags | wx.LEFT, INDENT_WIDTH),
            (confirmDeleteCtrl, 0, flags),
            (showTrayIconCtrl, 0, flags),
            (hideOnCloseCtrl, 0, flags),
            (memoryLimitSizer, 0, flags),
            (refreshEnvCtrl, 0, flags),
            (propResizeCtrl, 0, flags),
            (useFixedFontCtrl, 0, flags),
            (datestampSzr, 0, flags),
        ))

        langGroupSizer = page1.VStaticBoxSizer(
            text.LanguageGroup,
            (languageChoice, 0, wx.LEFT | wx.RIGHT, INDENT_WIDTH),
        )

        page1Sizer = eg.VBoxSizer(
            ((15, 7), 1),
            (startGroupSizer, 0, wx.EXPAND | wx.ALL, 5),
            ((15, 7), 1),
            (langGroupSizer, 0, wx.EXPAND | wx.ALL, 5),
        )
        page1.SetSizer(page1Sizer)
        page1.SetAutoLayout(True)

        sizer = eg.VBoxSizer(
            (notebook, 1, wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, 5),
            (buttonRow.sizer, 0, wx.EXPAND),
        )
        self.SetSizerAndFit(sizer)
        self.SetMinSize(self.GetSize())
        notebook.ChangeSelection(0)

        oldLanguage = config.language

        while self.Affirmed():
            config.checkUpdate = checkUpdateCtrl.GetValue()
            config.checkPreRelease = checkPreReleaseCtrl.GetValue()
            config.confirmDelete = confirmDeleteCtrl.GetValue()
            config.showTrayIcon = showTrayIconCtrl.GetValue()
            config.hideOnClose = hideOnCloseCtrl.GetValue()
            config.limitMemory = bool(memoryLimitCtrl.GetValue())
            config.limitMemorySize = memoryLimitSpinCtrl.GetValue()
            config.refreshEnv = refreshEnvCtrl.GetValue()
            config.propResize = propResizeCtrl.GetValue()
            config.useFixedFont = useFixedFontCtrl.GetValue()
            config.datestamp = datestampCtrl.GetValue()
            config.language = languageList[languageChoice.GetSelection()]
            config.Save()
            self.SetResult()

        eg.Utils.UpdateStartupShortcut(startWithWindowsCtrl.GetValue())

        if config.showTrayIcon:
            eg.taskBarIcon.Show()
        else:
            eg.taskBarIcon.Hide()

        if eg.mainFrame:
            eg.mainFrame.SetWindowStyleFlag()
            eg.mainFrame.logCtrl.SetDTLogging()

        if config.language != oldLanguage:
            wx.CallAfter(self.ShowLanguageWarning)

        OptionsDialog.instance = None
Exemple #3
0
class panelCustomiseParameters(wx.Dialog):
    def __init__(self, parent, config, icons, **kwargs):
        wx.Dialog.__init__(self, parent, -1, 'Other parameters...', size=(-1, -1),
                              style=wx.DEFAULT_FRAME_STYLE & ~
                              (wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX))

        self.parent = parent
        self.config = config
        self.icons = icons
        
        self.makeGUI()
        self.CentreOnParent()
        
        
    def onClose(self, evt):
        """Destroy this frame."""
        self.Destroy()
    # ----
    
    def onOK(self, evt):
        self.EndModal(wx.OK)
        
    def makeGUI(self):
        
        # make panel
        panel = self.makePanel()
        
        # pack element
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.mainSizer.Add(panel, 0, wx.EXPAND, 10)
        
        # fit layout
        self.mainSizer.Fit(self)
        self.SetSizer(self.mainSizer)
        
    def makePanel(self):
        panel = wx.Panel(self, -1)
        
        general_staticBox = makeStaticBox(panel, "General", size=(-1, -1), color=wx.BLACK)
        general_staticBox.SetSize((-1,-1))
        general_box_sizer = wx.StaticBoxSizer(general_staticBox, wx.HORIZONTAL)
        
        unidec_view_label = wx.StaticText(panel, -1, "Panel view:")
        self.unidec_view_value = wx.Choice(panel, -1, choices=["Single page view", "Tabbed view"],
                                          size=(-1, -1))
        self.unidec_view_value.SetStringSelection(self.config.unidec_plot_panel_view)
        self.unidec_view_value.Bind(wx.EVT_CHOICE, self.onUniDecView)
        
        remove_label_overlap_label = wx.StaticText(panel, wx.ID_ANY, u"Optimise label position:")
        self.unidec_labels_optimise_position_check = makeCheckbox(panel, u"")
        self.unidec_labels_optimise_position_check.SetValue(self.config.unidec_optimiseLabelPositions)
        self.unidec_labels_optimise_position_check.Bind(wx.EVT_CHECKBOX, self.onApply)
        
        general_grid = wx.GridBagSizer(2, 2)
        y = 0
        general_grid.Add(unidec_view_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        general_grid.Add(self.unidec_view_value, (y,1), flag=wx.EXPAND)
        y = y + 1
        general_grid.Add(remove_label_overlap_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        general_grid.Add(self.unidec_labels_optimise_position_check, (y,1), flag=wx.EXPAND)
        general_box_sizer.Add(general_grid, 0, wx.EXPAND, 10)
        
        # MS and MS Fit
        MS_staticBox = makeStaticBox(panel, "MS and UniDec Fit", size=(-1, -1), color=wx.BLACK)
        MS_staticBox.SetSize((-1,-1))
        MS_box_sizer = wx.StaticBoxSizer(MS_staticBox, wx.HORIZONTAL)
        
        fit_lineColor_label = wx.StaticText(panel, -1, "Line color:")
        self.fit_lineColor_Btn = wx.Button(panel, ID_unidecPanel_fitLineColor,
                                           u"", wx.DefaultPosition, 
                                           wx.Size( 26, 26 ), 0 )
        self.fit_lineColor_Btn.SetBackgroundColour(convertRGB1to255(self.config.unidec_plot_fit_lineColor))
        self.fit_lineColor_Btn.Bind(wx.EVT_BUTTON, self.onChangeColour)
        
        MS_grid = wx.GridBagSizer(2, 2)
        y = 0
        MS_grid.Add(fit_lineColor_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        MS_grid.Add(self.fit_lineColor_Btn, (y,1), flag=wx.EXPAND)
        MS_box_sizer.Add(MS_grid, 0, wx.EXPAND, 10)
        
        # m/z vs charge
        contour_staticBox = makeStaticBox(panel, "m/z vs charge | MW vs charge", size=(-1, -1), color=wx.BLACK)
        contour_staticBox.SetSize((-1,-1))
        contour_box_sizer = wx.StaticBoxSizer(contour_staticBox, wx.HORIZONTAL)

        speedy_label = wx.StaticText(panel, wx.ID_ANY, u"Quick plot:")
        self.speedy_check = makeCheckbox(panel, u"")
        self.speedy_check.SetValue(self.config.unidec_speedy)
        self.speedy_check.Bind(wx.EVT_CHECKBOX, self.onApply)

        contour_levels_label = wx.StaticText(panel, -1, "Contour levels:")
        self.contour_levels_value = wx.SpinCtrlDouble(panel, -1, 
                                                      value=str(self.config.unidec_plot_contour_levels), 
                                                      min=25, max=200, initial=25, inc=25,
                                                      size=(90, -1))
        self.contour_levels_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)

        contour_grid = wx.GridBagSizer(2, 2)
        y = 0
        contour_grid.Add(speedy_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        contour_grid.Add(self.speedy_check, (y,1), flag=wx.EXPAND)
        y = y + 1
        contour_grid.Add(contour_levels_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        contour_grid.Add(self.contour_levels_value, (y,1), flag=wx.EXPAND)
        contour_box_sizer.Add(contour_grid, 0, wx.EXPAND, 10)
        
        # Zero-charge MS
        MW_staticBox = makeStaticBox(panel, "Zero-charge Mass Spectrum", size=(-1, -1), color=wx.BLACK)
        MW_staticBox.SetSize((-1,-1))
        MW_box_sizer = wx.StaticBoxSizer(MW_staticBox, wx.HORIZONTAL)
        
        MW_show_markers = wx.StaticText(panel, -1, "Show markers:")
        self.MW_show_markers_check = makeCheckbox(panel, u"")
        self.MW_show_markers_check.SetValue(self.config.unidec_plot_MW_showMarkers)
        self.MW_show_markers_check.Bind(wx.EVT_CHECKBOX, self.onApply)
        
        MW_markerSize_label = wx.StaticText(panel, -1, "Marker size:")
        self.MW_markerSize_value = wx.SpinCtrlDouble(panel, -1, 
                                               value=str(self.config.unidec_plot_MW_markerSize), 
                                               min=1, max=100, initial=1, inc=5,
                                               size=(90, -1))
        self.MW_markerSize_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)

        MW_grid = wx.GridBagSizer(2, 2)
        y = 0
        MW_grid.Add(MW_show_markers, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        MW_grid.Add(self.MW_show_markers_check, (y,1), flag=wx.EXPAND)
        y = y + 1
        MW_grid.Add(MW_markerSize_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        MW_grid.Add(self.MW_markerSize_value, (y,1), flag=wx.EXPAND)
        MW_box_sizer.Add(MW_grid, 0, wx.EXPAND, 10)
        
#         # Zero-charge MS
#         MW_staticBox = makeStaticBox(panel, "Zero-charge Mass Spectrum", size=(-1, -1), color=wx.BLACK)
#         MW_staticBox.SetSize((-1,-1))
#         MW_box_sizer = wx.StaticBoxSizer(MW_staticBox, wx.HORIZONTAL)
#         
#         MW_show_markers = wx.StaticText(panel, -1, "Show markers:")
#         self.MW_show_markers_check = makeCheckbox(panel, u"")
#         self.MW_show_markers_check.SetValue(self.config.unidec_plot_MW_showMarkers)
#         self.MW_show_markers_check.Bind(wx.EVT_CHECKBOX, self.onApply)
#         
#         MW_markerSize_label = wx.StaticText(panel, -1, "Marker size:")
#         self.MW_markerSize_value = wx.SpinCtrlDouble(panel, -1, 
#                                                value=str(self.config.unidec_plot_MW_markerSize), 
#                                                min=1, max=100, initial=1, inc=5,
#                                                size=(90, -1))
#         self.MW_markerSize_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)
# 
#         MW_grid = wx.GridBagSizer(2, 2)
#         y = 0
#         MW_grid.Add(MW_show_markers, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
#         MW_grid.Add(self.MW_show_markers_check, (y,1), flag=wx.EXPAND)
#         y = y + 1
#         MW_grid.Add(MW_markerSize_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
#         MW_grid.Add(self.MW_markerSize_value, (y,1), flag=wx.EXPAND)
#         MW_box_sizer.Add(MW_grid, 0, wx.EXPAND, 10)
        
        # MS with isolated species
        isolatedMS_staticBox = makeStaticBox(panel, "MS with isolated species", size=(-1, -1), color=wx.BLACK)
        isolatedMS_staticBox.SetSize((-1,-1))
        isolatedMS_box_sizer = wx.StaticBoxSizer(isolatedMS_staticBox, wx.HORIZONTAL)
        
        isolatedMS_markerSize_label = wx.StaticText(panel, -1, "Marker size:")
        self.isolatedMS_markerSize_value = wx.SpinCtrlDouble(panel, -1, 
                                               value=str(self.config.unidec_plot_isolatedMS_markerSize), 
                                               min=1, max=100, initial=1, inc=5,
                                               size=(90, -1))
        self.isolatedMS_markerSize_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)

        isolatedMS_grid = wx.GridBagSizer(2, 2)
        y = 0
        isolatedMS_grid.Add(isolatedMS_markerSize_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        isolatedMS_grid.Add(self.isolatedMS_markerSize_value, (y,1), flag=wx.EXPAND)
        isolatedMS_box_sizer.Add(isolatedMS_grid, 0, wx.EXPAND, 10)

        # Barchart
        barParameters_staticBox = makeStaticBox(panel, "Peak intensities (Barchart)", 
                                                 size=(-1, -1), color=wx.BLACK)
        barParameters_staticBox.SetSize((-1,-1))
        bar_box_sizer = wx.StaticBoxSizer(barParameters_staticBox, wx.HORIZONTAL)
        
        bar_markerSize_label = wx.StaticText(panel, -1, "Marker size:")
        self.bar_markerSize_value = wx.SpinCtrlDouble(panel, -1, 
                                               value=str(self.config.unidec_plot_bar_markerSize), 
                                               min=1, max=100, initial=1, inc=5,
                                               size=(90, -1))
        self.bar_markerSize_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)
        
        bar_width_label = wx.StaticText(panel, -1, "Bar width:")
        self.bar_width_value = wx.SpinCtrlDouble(panel, -1, 
                                               value=str(self.config.unidec_plot_bar_width), 
                                               min=0.01, max=10, inc=0.1,
                                               initial=self.config.unidec_plot_bar_width, 
                                               size=(90, -1))
        self.bar_width_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)

        bar_alpha_label = wx.StaticText(panel, -1, "Bar transparency:")
        self.bar_alpha_value = wx.SpinCtrlDouble(panel, -1, 
                                                    value=str(self.config.unidec_plot_bar_alpha), 
                                                    min=0, max=1, initial=self.config.unidec_plot_bar_alpha, 
                                                    inc=0.25, size=(90, -1))
        self.bar_alpha_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)        

        bar_lineWidth_label = wx.StaticText(panel, -1, "Edge line width:")
        self.bar_lineWidth_value = wx.SpinCtrlDouble(panel, -1, 
                                                    value=str(self.config.unidec_plot_bar_lineWidth), 
                                                    min=0, max=5, initial=self.config.unidec_plot_bar_lineWidth, 
                                                    inc=1, size=(90, -1))
        self.bar_lineWidth_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)        

        bar_edgeColor_label = wx.StaticText(panel, -1, "Edge color:")
        self.bar_edgeColor_Btn = wx.Button(panel, ID_unidecPanel_barEdgeColor,
                                              u"", wx.DefaultPosition, 
                                              wx.Size( 26, 26 ), 0 )
        self.bar_edgeColor_Btn.SetBackgroundColour(convertRGB1to255(self.config.unidec_plot_bar_edge_color))
        self.bar_edgeColor_Btn.Bind(wx.EVT_BUTTON, self.onChangeColour)

        bar_colorEdge_check_label = wx.StaticText(panel, -1, "Same as fill:")
        self.bar_colorEdge_check = makeCheckbox(panel, u"")
        self.bar_colorEdge_check.SetValue(self.config.unidec_plot_bar_sameAsFill)
        self.bar_colorEdge_check.Bind(wx.EVT_CHECKBOX, self.onApply)
        
        bar_grid = wx.GridBagSizer(2, 2)
        y = 0
        bar_grid.Add(bar_markerSize_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_markerSize_value, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        y = y+1
        bar_grid.Add(bar_width_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_width_value, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        y = y+1
        bar_grid.Add(bar_alpha_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_alpha_value, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        y = y+1
        bar_grid.Add(bar_lineWidth_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_lineWidth_value, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        y = y+1
        bar_grid.Add(bar_edgeColor_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_edgeColor_Btn, (y,1), wx.GBSpan(1,1), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
        y = y+1
        bar_grid.Add(bar_colorEdge_check_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_colorEdge_check, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        bar_box_sizer.Add(bar_grid, 0, wx.EXPAND, 10)

        # Color
        color_staticBox = makeStaticBox(panel, "Color scheme", size=(-1, -1), color=wx.BLACK)
        color_staticBox.SetSize((-1,-1))
        color_box_sizer = wx.StaticBoxSizer(color_staticBox, wx.HORIZONTAL)
  
        color_scheme_label = wx.StaticText(panel, -1, "Color scheme:")
        self.colorScheme_value= wx.Choice(panel, -1, choices=["Color palette", "Colormap"],
                                          size=(-1, -1), name="color")
        self.colorScheme_value.SetStringSelection(self.config.violin_color_value)
        self.colorScheme_value.Bind(wx.EVT_CHOICE, self.onApply)

        cmap_list = self.config.cmaps2[:]
        cmap_list.remove("jet")
        colormap_label = wx.StaticText(panel, -1, "Colormap:")
        self.colormap_value = wx.Choice(panel, -1, choices=cmap_list,
                                        size=(-1, -1), name="color")
        self.colormap_value.SetStringSelection(self.config.unidec_plot_colormap)
        self.colormap_value.Bind(wx.EVT_CHOICE, self.onApply)

        palette_label = wx.StaticText(panel, -1, "Color palette:")
        self.color_palette_value = BitmapComboBox(panel, -1, choices=[],
                                                  size=(160, -1), style=wx.CB_READONLY)
        self.color_palette_value.Bind(wx.EVT_COMBOBOX, self.onApply)
        
        # add choices
        self.color_palette_value.Append("HLS", bitmap=self.icons.iconsLib['cmap_hls'])
        self.color_palette_value.Append("HUSL", bitmap=self.icons.iconsLib['cmap_husl'])
        self.color_palette_value.Append("Cubehelix", bitmap=self.icons.iconsLib['cmap_cubehelix'])
        self.color_palette_value.Append("Spectral", bitmap=self.icons.iconsLib['cmap_spectral'])
        self.color_palette_value.Append("Viridis", bitmap=self.icons.iconsLib['cmap_viridis'])
        self.color_palette_value.Append("Rainbow", bitmap=self.icons.iconsLib['cmap_rainbow'])
        self.color_palette_value.Append("Inferno", bitmap=self.icons.iconsLib['cmap_inferno'])
        self.color_palette_value.Append("Cividis", bitmap=self.icons.iconsLib['cmap_cividis'])
        self.color_palette_value.Append("Winter", bitmap=self.icons.iconsLib['cmap_winter'])
        self.color_palette_value.Append("Cool", bitmap=self.icons.iconsLib['cmap_cool'])
        self.color_palette_value.Append("Gray", bitmap=self.icons.iconsLib['cmap_gray'])
        self.color_palette_value.Append("RdPu", bitmap=self.icons.iconsLib['cmap_rdpu'])
        self.color_palette_value.Append("Tab20b", bitmap=self.icons.iconsLib['cmap_tab20b'])
        self.color_palette_value.Append("Tab20c", bitmap=self.icons.iconsLib['cmap_tab20c'])
        
        self.color_palette_value.SetStringSelection(self.config.unidec_plot_palette)
    
        color_grid = wx.GridBagSizer(2, 2)
        y = 0
        color_grid.Add(color_scheme_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        color_grid.Add(self.colorScheme_value, (y,1), flag=wx.EXPAND)
        y = y + 1
        color_grid.Add(colormap_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        color_grid.Add(self.colormap_value, (y,1), flag=wx.EXPAND)
        y = y + 1
        color_grid.Add(palette_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        color_grid.Add(self.color_palette_value, (y,1), flag=wx.EXPAND)
        color_box_sizer.Add(color_grid, 0, wx.EXPAND, 10)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(general_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(MS_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(contour_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(MW_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(isolatedMS_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(bar_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(color_box_sizer, 0, wx.EXPAND, 10)

        # fit layout
        mainSizer.Fit(panel)
        panel.SetSizerAndFit(mainSizer)

        return panel
    
    def onChangePalette(self, evt):
        pass
    
    def onChangeColour(self, evt):
        evtID = evt.GetId()
        
        # Restore custom colors
        custom = wx.ColourData()
        for key in range(len(self.config.customColors)): #key in self.config.customColors:
            custom.SetCustomColour(key, self.config.customColors[key])
        dlg = wx.ColourDialog(self, custom)
        dlg.GetColourData().SetChooseFull(True)
        
        # Show dialog and get new colour
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetColourData()
            newColour = list(data.GetColour().Get())
            dlg.Destroy()
            # Retrieve custom colors
            for i in xrange(15):
                self.config.customColors[i] = data.GetCustomColour(i)
        else:
            return
        
        if evtID == ID_unidecPanel_barEdgeColor:
            self.config.unidec_plot_bar_edge_color = convertRGB255to1(newColour)
            self.bar_edgeColor_Btn.SetBackgroundColour(newColour)
            
        elif evtID == ID_unidecPanel_fitLineColor:
            self.config.unidec_plot_fit_lineColor = convertRGB255to1(newColour)
            self.fit_lineColor_Btn.SetBackgroundColour(newColour)

    def onApply(self, evt):
        
        self.config.unidec_plot_MW_showMarkers = self.MW_show_markers_check.GetValue()
        self.config.unidec_plot_MW_markerSize = self.MW_markerSize_value.GetValue()
        self.config.unidec_plot_contour_levels = int(self.contour_levels_value.GetValue())
        self.config.unidec_plot_isolatedMS_markerSize = self.isolatedMS_markerSize_value.GetValue()
        self.config.unidec_plot_bar_width = self.bar_width_value.GetValue()
        self.config.unidec_plot_bar_alpha = self.bar_alpha_value.GetValue()
        self.config.unidec_plot_bar_sameAsFill = self.bar_colorEdge_check.GetValue()
        self.config.unidec_plot_bar_lineWidth = self.bar_lineWidth_value.GetValue()
        self.config.unidec_plot_bar_markerSize = self.bar_markerSize_value.GetValue()
        self.config.unidec_plot_color_scheme = self.colorScheme_value.GetStringSelection()
        self.config.unidec_plot_colormap = self.colormap_value.GetStringSelection()
        self.config.unidec_plot_palette = self.color_palette_value.GetStringSelection()
        
        self.config.unidec_optimiseLabelPositions = self.unidec_labels_optimise_position_check.GetValue()
        self.config.unidec_speedy = self.speedy_check.GetValue()
        
    def onUniDecView(self, evt):
        self.config.unidec_plot_panel_view = self.unidec_view_value.GetStringSelection()
        
        dlgBox(exceptionTitle="Warning",
               exceptionMsg="Changing the panel view will not take place until you restart ORIGAMI.", 
               type="Warning")
        
        
Exemple #4
0
    def makePanel(self):
        panel = wx.Panel(self, -1)
        
        general_staticBox = makeStaticBox(panel, "General", size=(-1, -1), color=wx.BLACK)
        general_staticBox.SetSize((-1,-1))
        general_box_sizer = wx.StaticBoxSizer(general_staticBox, wx.HORIZONTAL)
        
        unidec_view_label = wx.StaticText(panel, -1, "Panel view:")
        self.unidec_view_value = wx.Choice(panel, -1, choices=["Single page view", "Tabbed view"],
                                          size=(-1, -1))
        self.unidec_view_value.SetStringSelection(self.config.unidec_plot_panel_view)
        self.unidec_view_value.Bind(wx.EVT_CHOICE, self.onUniDecView)
        
        remove_label_overlap_label = wx.StaticText(panel, wx.ID_ANY, u"Optimise label position:")
        self.unidec_labels_optimise_position_check = makeCheckbox(panel, u"")
        self.unidec_labels_optimise_position_check.SetValue(self.config.unidec_optimiseLabelPositions)
        self.unidec_labels_optimise_position_check.Bind(wx.EVT_CHECKBOX, self.onApply)
        
        general_grid = wx.GridBagSizer(2, 2)
        y = 0
        general_grid.Add(unidec_view_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        general_grid.Add(self.unidec_view_value, (y,1), flag=wx.EXPAND)
        y = y + 1
        general_grid.Add(remove_label_overlap_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        general_grid.Add(self.unidec_labels_optimise_position_check, (y,1), flag=wx.EXPAND)
        general_box_sizer.Add(general_grid, 0, wx.EXPAND, 10)
        
        # MS and MS Fit
        MS_staticBox = makeStaticBox(panel, "MS and UniDec Fit", size=(-1, -1), color=wx.BLACK)
        MS_staticBox.SetSize((-1,-1))
        MS_box_sizer = wx.StaticBoxSizer(MS_staticBox, wx.HORIZONTAL)
        
        fit_lineColor_label = wx.StaticText(panel, -1, "Line color:")
        self.fit_lineColor_Btn = wx.Button(panel, ID_unidecPanel_fitLineColor,
                                           u"", wx.DefaultPosition, 
                                           wx.Size( 26, 26 ), 0 )
        self.fit_lineColor_Btn.SetBackgroundColour(convertRGB1to255(self.config.unidec_plot_fit_lineColor))
        self.fit_lineColor_Btn.Bind(wx.EVT_BUTTON, self.onChangeColour)
        
        MS_grid = wx.GridBagSizer(2, 2)
        y = 0
        MS_grid.Add(fit_lineColor_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        MS_grid.Add(self.fit_lineColor_Btn, (y,1), flag=wx.EXPAND)
        MS_box_sizer.Add(MS_grid, 0, wx.EXPAND, 10)
        
        # m/z vs charge
        contour_staticBox = makeStaticBox(panel, "m/z vs charge | MW vs charge", size=(-1, -1), color=wx.BLACK)
        contour_staticBox.SetSize((-1,-1))
        contour_box_sizer = wx.StaticBoxSizer(contour_staticBox, wx.HORIZONTAL)

        speedy_label = wx.StaticText(panel, wx.ID_ANY, u"Quick plot:")
        self.speedy_check = makeCheckbox(panel, u"")
        self.speedy_check.SetValue(self.config.unidec_speedy)
        self.speedy_check.Bind(wx.EVT_CHECKBOX, self.onApply)

        contour_levels_label = wx.StaticText(panel, -1, "Contour levels:")
        self.contour_levels_value = wx.SpinCtrlDouble(panel, -1, 
                                                      value=str(self.config.unidec_plot_contour_levels), 
                                                      min=25, max=200, initial=25, inc=25,
                                                      size=(90, -1))
        self.contour_levels_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)

        contour_grid = wx.GridBagSizer(2, 2)
        y = 0
        contour_grid.Add(speedy_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        contour_grid.Add(self.speedy_check, (y,1), flag=wx.EXPAND)
        y = y + 1
        contour_grid.Add(contour_levels_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        contour_grid.Add(self.contour_levels_value, (y,1), flag=wx.EXPAND)
        contour_box_sizer.Add(contour_grid, 0, wx.EXPAND, 10)
        
        # Zero-charge MS
        MW_staticBox = makeStaticBox(panel, "Zero-charge Mass Spectrum", size=(-1, -1), color=wx.BLACK)
        MW_staticBox.SetSize((-1,-1))
        MW_box_sizer = wx.StaticBoxSizer(MW_staticBox, wx.HORIZONTAL)
        
        MW_show_markers = wx.StaticText(panel, -1, "Show markers:")
        self.MW_show_markers_check = makeCheckbox(panel, u"")
        self.MW_show_markers_check.SetValue(self.config.unidec_plot_MW_showMarkers)
        self.MW_show_markers_check.Bind(wx.EVT_CHECKBOX, self.onApply)
        
        MW_markerSize_label = wx.StaticText(panel, -1, "Marker size:")
        self.MW_markerSize_value = wx.SpinCtrlDouble(panel, -1, 
                                               value=str(self.config.unidec_plot_MW_markerSize), 
                                               min=1, max=100, initial=1, inc=5,
                                               size=(90, -1))
        self.MW_markerSize_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)

        MW_grid = wx.GridBagSizer(2, 2)
        y = 0
        MW_grid.Add(MW_show_markers, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        MW_grid.Add(self.MW_show_markers_check, (y,1), flag=wx.EXPAND)
        y = y + 1
        MW_grid.Add(MW_markerSize_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        MW_grid.Add(self.MW_markerSize_value, (y,1), flag=wx.EXPAND)
        MW_box_sizer.Add(MW_grid, 0, wx.EXPAND, 10)
        
#         # Zero-charge MS
#         MW_staticBox = makeStaticBox(panel, "Zero-charge Mass Spectrum", size=(-1, -1), color=wx.BLACK)
#         MW_staticBox.SetSize((-1,-1))
#         MW_box_sizer = wx.StaticBoxSizer(MW_staticBox, wx.HORIZONTAL)
#         
#         MW_show_markers = wx.StaticText(panel, -1, "Show markers:")
#         self.MW_show_markers_check = makeCheckbox(panel, u"")
#         self.MW_show_markers_check.SetValue(self.config.unidec_plot_MW_showMarkers)
#         self.MW_show_markers_check.Bind(wx.EVT_CHECKBOX, self.onApply)
#         
#         MW_markerSize_label = wx.StaticText(panel, -1, "Marker size:")
#         self.MW_markerSize_value = wx.SpinCtrlDouble(panel, -1, 
#                                                value=str(self.config.unidec_plot_MW_markerSize), 
#                                                min=1, max=100, initial=1, inc=5,
#                                                size=(90, -1))
#         self.MW_markerSize_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)
# 
#         MW_grid = wx.GridBagSizer(2, 2)
#         y = 0
#         MW_grid.Add(MW_show_markers, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
#         MW_grid.Add(self.MW_show_markers_check, (y,1), flag=wx.EXPAND)
#         y = y + 1
#         MW_grid.Add(MW_markerSize_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
#         MW_grid.Add(self.MW_markerSize_value, (y,1), flag=wx.EXPAND)
#         MW_box_sizer.Add(MW_grid, 0, wx.EXPAND, 10)
        
        # MS with isolated species
        isolatedMS_staticBox = makeStaticBox(panel, "MS with isolated species", size=(-1, -1), color=wx.BLACK)
        isolatedMS_staticBox.SetSize((-1,-1))
        isolatedMS_box_sizer = wx.StaticBoxSizer(isolatedMS_staticBox, wx.HORIZONTAL)
        
        isolatedMS_markerSize_label = wx.StaticText(panel, -1, "Marker size:")
        self.isolatedMS_markerSize_value = wx.SpinCtrlDouble(panel, -1, 
                                               value=str(self.config.unidec_plot_isolatedMS_markerSize), 
                                               min=1, max=100, initial=1, inc=5,
                                               size=(90, -1))
        self.isolatedMS_markerSize_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)

        isolatedMS_grid = wx.GridBagSizer(2, 2)
        y = 0
        isolatedMS_grid.Add(isolatedMS_markerSize_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        isolatedMS_grid.Add(self.isolatedMS_markerSize_value, (y,1), flag=wx.EXPAND)
        isolatedMS_box_sizer.Add(isolatedMS_grid, 0, wx.EXPAND, 10)

        # Barchart
        barParameters_staticBox = makeStaticBox(panel, "Peak intensities (Barchart)", 
                                                 size=(-1, -1), color=wx.BLACK)
        barParameters_staticBox.SetSize((-1,-1))
        bar_box_sizer = wx.StaticBoxSizer(barParameters_staticBox, wx.HORIZONTAL)
        
        bar_markerSize_label = wx.StaticText(panel, -1, "Marker size:")
        self.bar_markerSize_value = wx.SpinCtrlDouble(panel, -1, 
                                               value=str(self.config.unidec_plot_bar_markerSize), 
                                               min=1, max=100, initial=1, inc=5,
                                               size=(90, -1))
        self.bar_markerSize_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)
        
        bar_width_label = wx.StaticText(panel, -1, "Bar width:")
        self.bar_width_value = wx.SpinCtrlDouble(panel, -1, 
                                               value=str(self.config.unidec_plot_bar_width), 
                                               min=0.01, max=10, inc=0.1,
                                               initial=self.config.unidec_plot_bar_width, 
                                               size=(90, -1))
        self.bar_width_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)

        bar_alpha_label = wx.StaticText(panel, -1, "Bar transparency:")
        self.bar_alpha_value = wx.SpinCtrlDouble(panel, -1, 
                                                    value=str(self.config.unidec_plot_bar_alpha), 
                                                    min=0, max=1, initial=self.config.unidec_plot_bar_alpha, 
                                                    inc=0.25, size=(90, -1))
        self.bar_alpha_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)        

        bar_lineWidth_label = wx.StaticText(panel, -1, "Edge line width:")
        self.bar_lineWidth_value = wx.SpinCtrlDouble(panel, -1, 
                                                    value=str(self.config.unidec_plot_bar_lineWidth), 
                                                    min=0, max=5, initial=self.config.unidec_plot_bar_lineWidth, 
                                                    inc=1, size=(90, -1))
        self.bar_lineWidth_value.Bind(wx.EVT_SPINCTRLDOUBLE, self.onApply)        

        bar_edgeColor_label = wx.StaticText(panel, -1, "Edge color:")
        self.bar_edgeColor_Btn = wx.Button(panel, ID_unidecPanel_barEdgeColor,
                                              u"", wx.DefaultPosition, 
                                              wx.Size( 26, 26 ), 0 )
        self.bar_edgeColor_Btn.SetBackgroundColour(convertRGB1to255(self.config.unidec_plot_bar_edge_color))
        self.bar_edgeColor_Btn.Bind(wx.EVT_BUTTON, self.onChangeColour)

        bar_colorEdge_check_label = wx.StaticText(panel, -1, "Same as fill:")
        self.bar_colorEdge_check = makeCheckbox(panel, u"")
        self.bar_colorEdge_check.SetValue(self.config.unidec_plot_bar_sameAsFill)
        self.bar_colorEdge_check.Bind(wx.EVT_CHECKBOX, self.onApply)
        
        bar_grid = wx.GridBagSizer(2, 2)
        y = 0
        bar_grid.Add(bar_markerSize_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_markerSize_value, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        y = y+1
        bar_grid.Add(bar_width_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_width_value, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        y = y+1
        bar_grid.Add(bar_alpha_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_alpha_value, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        y = y+1
        bar_grid.Add(bar_lineWidth_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_lineWidth_value, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        y = y+1
        bar_grid.Add(bar_edgeColor_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_edgeColor_Btn, (y,1), wx.GBSpan(1,1), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
        y = y+1
        bar_grid.Add(bar_colorEdge_check_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        bar_grid.Add(self.bar_colorEdge_check, (y,1), wx.GBSpan(1,1), flag=wx.EXPAND)
        bar_box_sizer.Add(bar_grid, 0, wx.EXPAND, 10)

        # Color
        color_staticBox = makeStaticBox(panel, "Color scheme", size=(-1, -1), color=wx.BLACK)
        color_staticBox.SetSize((-1,-1))
        color_box_sizer = wx.StaticBoxSizer(color_staticBox, wx.HORIZONTAL)
  
        color_scheme_label = wx.StaticText(panel, -1, "Color scheme:")
        self.colorScheme_value= wx.Choice(panel, -1, choices=["Color palette", "Colormap"],
                                          size=(-1, -1), name="color")
        self.colorScheme_value.SetStringSelection(self.config.violin_color_value)
        self.colorScheme_value.Bind(wx.EVT_CHOICE, self.onApply)

        cmap_list = self.config.cmaps2[:]
        cmap_list.remove("jet")
        colormap_label = wx.StaticText(panel, -1, "Colormap:")
        self.colormap_value = wx.Choice(panel, -1, choices=cmap_list,
                                        size=(-1, -1), name="color")
        self.colormap_value.SetStringSelection(self.config.unidec_plot_colormap)
        self.colormap_value.Bind(wx.EVT_CHOICE, self.onApply)

        palette_label = wx.StaticText(panel, -1, "Color palette:")
        self.color_palette_value = BitmapComboBox(panel, -1, choices=[],
                                                  size=(160, -1), style=wx.CB_READONLY)
        self.color_palette_value.Bind(wx.EVT_COMBOBOX, self.onApply)
        
        # add choices
        self.color_palette_value.Append("HLS", bitmap=self.icons.iconsLib['cmap_hls'])
        self.color_palette_value.Append("HUSL", bitmap=self.icons.iconsLib['cmap_husl'])
        self.color_palette_value.Append("Cubehelix", bitmap=self.icons.iconsLib['cmap_cubehelix'])
        self.color_palette_value.Append("Spectral", bitmap=self.icons.iconsLib['cmap_spectral'])
        self.color_palette_value.Append("Viridis", bitmap=self.icons.iconsLib['cmap_viridis'])
        self.color_palette_value.Append("Rainbow", bitmap=self.icons.iconsLib['cmap_rainbow'])
        self.color_palette_value.Append("Inferno", bitmap=self.icons.iconsLib['cmap_inferno'])
        self.color_palette_value.Append("Cividis", bitmap=self.icons.iconsLib['cmap_cividis'])
        self.color_palette_value.Append("Winter", bitmap=self.icons.iconsLib['cmap_winter'])
        self.color_palette_value.Append("Cool", bitmap=self.icons.iconsLib['cmap_cool'])
        self.color_palette_value.Append("Gray", bitmap=self.icons.iconsLib['cmap_gray'])
        self.color_palette_value.Append("RdPu", bitmap=self.icons.iconsLib['cmap_rdpu'])
        self.color_palette_value.Append("Tab20b", bitmap=self.icons.iconsLib['cmap_tab20b'])
        self.color_palette_value.Append("Tab20c", bitmap=self.icons.iconsLib['cmap_tab20c'])
        
        self.color_palette_value.SetStringSelection(self.config.unidec_plot_palette)
    
        color_grid = wx.GridBagSizer(2, 2)
        y = 0
        color_grid.Add(color_scheme_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        color_grid.Add(self.colorScheme_value, (y,1), flag=wx.EXPAND)
        y = y + 1
        color_grid.Add(colormap_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        color_grid.Add(self.colormap_value, (y,1), flag=wx.EXPAND)
        y = y + 1
        color_grid.Add(palette_label, (y,0), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
        color_grid.Add(self.color_palette_value, (y,1), flag=wx.EXPAND)
        color_box_sizer.Add(color_grid, 0, wx.EXPAND, 10)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(general_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(MS_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(contour_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(MW_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(isolatedMS_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(bar_box_sizer, 0, wx.EXPAND, 10)
        mainSizer.Add(color_box_sizer, 0, wx.EXPAND, 10)

        # fit layout
        mainSizer.Fit(panel)
        panel.SetSizerAndFit(mainSizer)

        return panel
Exemple #5
0
def _ColourMap(parent, hasProps, propObj, propVal, labels=None, **kwargs):
    """Creates and returns a combobox, allowing the user to change the value
    of the given :class:`.ColourMap` property value.

    :arg labels: A dictionary containing ``{name : label}`` mappings,
                 defining a display name/label for each colour map. If
                 not provided, the colour map ``name`` attribute is used
                 as the display name.

                 Can alternately be a function which accepts a colour map
                 identifier name, and returns its display name.

    See also the :func:`_makeColourMapBitmap` function.
    """

    import matplotlib.cm as mplcm

    # These are used by the inner-functions defined
    # below, and are dynamically updated when the
    # list of available colour maps change. I'm
    # storing each of them in a list, so the inner
    # functions will have access to updated versions.
    cmapKeys = [list(propObj.getColourMaps(hasProps))]
    cmapObjs = [list(map(mplcm.get_cmap, cmapKeys[0]))]

    # create the combobox
    cbox = BitmapComboBox(parent, style=wx.CB_READONLY | wx.CB_DROPDOWN)

    # OwnerDrawnComboBoxes seem to absorb mouse
    # events and, under OSX/cocoa at least, this
    # causes the currently selected item to
    # change. I don't want this.
    def wheel(ev):
        parent.GetEventHandler().ProcessEvent(ev)

    cbox.Bind(wx.EVT_MOUSEWHEEL, wheel)

    def widgetGet():
        sel = cbox.GetSelection()
        if sel == -1:
            sel = 0
        return cmapObjs[0][sel]

    def widgetSet(value):
        if value is not None:
            cbox.SetSelection(cmapObjs[0].index(value))
        else:
            cbox.SetSelection(0)

    # Called when the list of available
    # colour maps changes - updates the
    # options displayed in the combobox
    def cmapsChanged(*a):

        selected = cbox.GetSelection()
        cmapKeys[0] = list(propObj.getColourMaps(hasProps))
        cmapObjs[0] = list(map(mplcm.get_cmap, cmapKeys[0]))

        cbox.Clear()

        # Store the width of the biggest bitmap,
        # and the width of the biggest label.
        # the BitmapComboBox doesn't size itself
        # properly on all platforms, so we'll
        # do it manually, dammit
        maxBmpWidth = 0
        maxLblWidth = 0
        dc = wx.ClientDC(cbox)

        # Make a little bitmap for every colour
        # map, and add it to the combobox
        for cmap in cmapObjs[0]:

            # Labels can either be None
            if labels is None:
                name = cmap.name

            # Or a function
            elif hasattr(labels, '__call__'):
                name = labels(cmap.name)

            # Or a dictionary
            else:
                name = labels.get(cmap.name, cmap.name)

            bitmap = _makeColourMapBitmap(cmap)
            cbox.Append(name, bitmap)

            # use the DC to get the label size
            lblWidth = dc.GetTextExtent(name)[0]
            bmpWidth = bitmap.GetWidth()

            if bmpWidth > maxBmpWidth: maxBmpWidth = bmpWidth
            if lblWidth > maxLblWidth: maxLblWidth = lblWidth

        # Explicitly set the minimum size from
        # the maximum bitmap/label sizes, with
        # some extra to account for the drop
        # down button
        cbox.InvalidateBestSize()
        bestHeight = cbox.GetBestSize().GetHeight()
        cbox.SetMinSize((maxBmpWidth + maxLblWidth + 40, bestHeight))

        cbox.SetSelection(selected)
        cbox.Refresh()

    # Initialise the combobox options
    cmapsChanged()

    # Make sure the combobox options are updated
    # when the property options change
    lName = 'ColourMap_ComboBox_{}'.format(id(cbox))
    propVal.addAttributeListener(lName, cmapsChanged, weak=False)

    def onDestroy(ev):
        propVal.removeAttributeListener(lName)

    # Bind the combobox to the property
    _propBind(hasProps,
              propObj,
              propVal,
              cbox,
              evType=wx.EVT_COMBOBOX,
              widgetGet=widgetGet,
              widgetSet=widgetSet,
              widgetDestroy=onDestroy)

    # Set the initial combobox selection
    currentVal = propVal.get()
    if currentVal is None: currentVal = 0
    else: currentVal = cmapObjs[0].index(currentVal)

    cbox.SetSelection(currentVal)

    return cbox