Exemple #1
0
    def _layout(self):
        """Creates the main panel with all the controls on it:
             * mpl canvas
             * mpl navigation toolbar
             * Control panel for interaction
        """
        self.mainPanel = wx.Panel(self)
        # Create the mpl Figure and FigCanvas objects.
        # 5x4 inches, 100 dots-per-inch
        #
        # color =  wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND)
        # ------------CANVAS AND TOOLBAR------------
        self.fig = Figure((5.0, 4.0), facecolor=(1, 1, 1))
        self.canvas = FigCanvas(self.mainPanel, wx.ID_ANY, self.fig)
        # axes are initialized later
        self.axes2d = None
        self.axes3d = None

        # Create the navigation toolbar, tied to the canvas
        #
        self.toolbar = NavigationToolbar(self.canvas)

        #
        # Layout
        #
        # ------------MAIN VERTICAL SIZER------------
        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
        self.vbox.Add(self.toolbar, 0, wx.EXPAND)
        # self.vbox.AddSpacer(10)

        # ------------ADD NOTEBOOK------------
        self.ntb = GNotebook(parent=self.mainPanel, style=FN.FNB_FANCY_TABS)

        # ------------ITEMS IN NOTEBOOK PAGE (RASTER)------------------------

        self.controlPanelRaster = wx.Panel(parent=self.ntb, id=wx.ID_ANY)
        self.datasetSelectLabelR = wx.StaticText(
            parent=self.controlPanelRaster,
            id=wx.ID_ANY,
            label=_('Raster temporal '
                    'dataset (strds)'))

        self.datasetSelectR = gselect.Select(
            parent=self.controlPanelRaster,
            id=wx.ID_ANY,
            size=globalvar.DIALOG_GSELECT_SIZE,
            type='strds',
            multiple=True)
        self.coor = wx.StaticText(parent=self.controlPanelRaster,
                                  id=wx.ID_ANY,
                                  label=_('X and Y coordinates separated by '
                                          'comma:'))
        try:
            self._giface.GetMapWindow()
            self.coorval = gselect.CoordinatesSelect(
                parent=self.controlPanelRaster, giface=self._giface)
        except:
            self.coorval = wx.TextCtrl(parent=self.controlPanelRaster,
                                       id=wx.ID_ANY,
                                       size=globalvar.DIALOG_TEXTCTRL_SIZE,
                                       validator=CoordinatesValidator())

        self.coorval.SetToolTipString(
            _("Coordinates can be obtained for example"
              " by right-clicking on Map Display."))
        self.controlPanelSizerRaster = wx.BoxSizer(wx.VERTICAL)
        # self.controlPanelSizer.Add(wx.StaticText(self.panel, id=wx.ID_ANY,
        # label=_("Select space time raster dataset(s):")),
        # pos=(0, 0), flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
        self.controlPanelSizerRaster.Add(self.datasetSelectLabelR,
                                         flag=wx.EXPAND)
        self.controlPanelSizerRaster.Add(self.datasetSelectR, flag=wx.EXPAND)

        self.controlPanelSizerRaster.Add(self.coor, flag=wx.EXPAND)
        self.controlPanelSizerRaster.Add(self.coorval, flag=wx.EXPAND)

        self.controlPanelRaster.SetSizer(self.controlPanelSizerRaster)
        self.controlPanelSizerRaster.Fit(self)
        self.ntb.AddPage(page=self.controlPanelRaster,
                         text=_('STRDS'),
                         name='STRDS')

        # ------------ITEMS IN NOTEBOOK PAGE (VECTOR)------------------------
        self.controlPanelVector = wx.Panel(parent=self.ntb, id=wx.ID_ANY)
        self.datasetSelectLabelV = wx.StaticText(
            parent=self.controlPanelVector,
            id=wx.ID_ANY,
            label=_('Vector temporal '
                    'dataset (stvds)\n'
                    'Press ENTER if you'
                    ' type the name of the'
                    ' stvds instead of'
                    ' selecting with the'
                    ' combobox'))
        self.datasetSelectV = gselect.Select(
            parent=self.controlPanelVector,
            id=wx.ID_ANY,
            size=globalvar.DIALOG_GSELECT_SIZE,
            type='stvds',
            multiple=True)
        self.datasetSelectV.Bind(wx.EVT_TEXT, self.OnVectorSelected)

        self.attribute = gselect.ColumnSelect(parent=self.controlPanelVector)
        self.attributeLabel = wx.StaticText(parent=self.controlPanelVector,
                                            id=wx.ID_ANY,
                                            label=_('Select attribute column'))
        # TODO fix the category selection as done for coordinates
        try:
            self._giface.GetMapWindow()
            self.cats = gselect.VectorCategorySelect(
                parent=self.controlPanelVector, giface=self._giface)
        except:
            self.cats = wx.TextCtrl(parent=self.controlPanelVector,
                                    id=wx.ID_ANY,
                                    size=globalvar.DIALOG_TEXTCTRL_SIZE)
        self.catsLabel = wx.StaticText(parent=self.controlPanelVector,
                                       id=wx.ID_ANY,
                                       label=_('Select category of vector(s)'))

        self.controlPanelSizerVector = wx.BoxSizer(wx.VERTICAL)
        # self.controlPanelSizer.Add(wx.StaticText(self.panel, id=wx.ID_ANY,
        # label=_("Select space time raster dataset(s):")),
        # pos=(0, 0), flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
        self.controlPanelSizerVector.Add(self.datasetSelectLabelV,
                                         flag=wx.EXPAND)
        self.controlPanelSizerVector.Add(self.datasetSelectV, flag=wx.EXPAND)

        self.controlPanelSizerVector.Add(self.attributeLabel, flag=wx.EXPAND)
        self.controlPanelSizerVector.Add(self.attribute, flag=wx.EXPAND)

        self.controlPanelSizerVector.Add(self.catsLabel, flag=wx.EXPAND)
        self.controlPanelSizerVector.Add(self.cats, flag=wx.EXPAND)

        self.controlPanelVector.SetSizer(self.controlPanelSizerVector)
        self.controlPanelSizerVector.Fit(self)
        self.ntb.AddPage(page=self.controlPanelVector,
                         text=_('STVDS'),
                         name='STVDS')

        # ------------Buttons on the bottom(draw,help)------------
        self.vButtPanel = wx.Panel(self.mainPanel, id=wx.ID_ANY)
        self.vButtSizer = wx.BoxSizer(wx.HORIZONTAL)

        self.drawButton = wx.Button(self.vButtPanel,
                                    id=wx.ID_ANY,
                                    label=_("Draw"))
        self.drawButton.Bind(wx.EVT_BUTTON, self.OnRedraw)
        self.helpButton = wx.Button(self.vButtPanel,
                                    id=wx.ID_ANY,
                                    label=_("Help"))
        self.helpButton.Bind(wx.EVT_BUTTON, self.OnHelp)
        self.vButtSizer.Add(self.drawButton)
        self.vButtSizer.Add(self.helpButton)
        self.vButtPanel.SetSizer(self.vButtSizer)

        self.mainPanel.SetSizer(self.vbox)
        self.vbox.Add(self.ntb, flag=wx.EXPAND)
        self.vbox.Add(self.vButtPanel, flag=wx.EXPAND)
        self.vbox.Fit(self)
        self.mainPanel.Fit()
    def __init__(self, parent, Rinstance, controller, *args, **kwargs):
        wx.Panel.__init__(self, parent, *args, **kwargs)

        self.parent = parent
        self.border = 4

        #    1. Input data
        InputBoxSizer = wx.StaticBoxSizer(
            wx.StaticBox(self, id=wx.ID_ANY, label=_("Input Data")),
            orient=wx.HORIZONTAL,
        )

        flexSizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
        flexSizer.AddGrowableCol(1)

        flexSizer.Add(
            wx.StaticText(self, id=wx.ID_ANY, label=_("Point dataset:")),
            flag=wx.ALIGN_CENTER_VERTICAL,
        )
        self.InputDataMap = gselect.VectorSelect(parent=self,
                                                 ftype="points",
                                                 updateOnPopup=False)
        self.InputDataMap.SetFocus()
        flexSizer.Add(self.InputDataMap, flag=wx.ALIGN_CENTER_VERTICAL)

        RefreshButton = wx.Button(self, id=wx.ID_REFRESH)
        RefreshButton.Bind(wx.EVT_BUTTON, self.OnButtonRefresh)
        flexSizer.Add(RefreshButton, flag=wx.ALIGN_CENTER_VERTICAL)

        flexSizer.Add(
            wx.StaticText(self, id=wx.ID_ANY, label=_("Numeric column:")),
            flag=wx.ALIGN_CENTER_VERTICAL,
        )
        self.InputDataColumn = gselect.ColumnSelect(self, id=wx.ID_ANY)
        flexSizer.Add(self.InputDataColumn)

        self.InputDataMap.GetChildren()[0].Bind(wx.EVT_TEXT,
                                                self.OnInputMapChanged)
        self.InputDataColumn.GetChildren()[0].Bind(wx.EVT_TEXT,
                                                   self.OnInputColumnChanged)

        InputBoxSizer.Add(flexSizer)

        # 2. Kriging. In book pages one for each R package. Includes variogram
        # fit.
        KrigingSizer = wx.StaticBoxSizer(
            wx.StaticBox(self, id=wx.ID_ANY, label=_("Kriging")),
            wx.HORIZONTAL)

        self.RPackagesBook = GNotebook(parent=self,
                                       style=globalvar.FNPageDStyle)

        # , "geoR"]: #@TODO: enable it if/when it'll be implemented.
        for Rpackage in ["gstat"]:
            self.CreatePage(package=Rpackage,
                            Rinstance=Rinstance,
                            controller=controller)

        # Command output. From menuform module, cmdPanel class
        self._gconsole = gconsole.GConsole(guiparent=self)
        self.goutput = goutput.GConsoleWindow(parent=self,
                                              gconsole=self._gconsole,
                                              margin=False)
        self.goutputId = self.RPackagesBook.GetPageCount()
        self.outpage = self.RPackagesBook.AddPage(page=self.goutput,
                                                  text=_("Command output"),
                                                  name="output")
        self._gconsole.Bind(
            gconsole.EVT_CMD_RUN,
            lambda event: self._switchPageHandler(
                event=event, notification=Notification.MAKE_VISIBLE),
        )
        self._gconsole.Bind(
            gconsole.EVT_CMD_DONE,
            lambda event: self._switchPageHandler(
                event=event, notification=Notification.RAISE_WINDOW),
        )
        self.RPackagesBook.SetSelection(0)
        KrigingSizer.Add(self.RPackagesBook, proportion=1, flag=wx.EXPAND)

        #    3. Output Parameters.
        OutputSizer = wx.StaticBoxSizer(
            wx.StaticBox(self, id=wx.ID_ANY, label=_("Output")), wx.HORIZONTAL)

        OutputParameters = wx.GridBagSizer(hgap=5, vgap=5)
        OutputParameters.Add(
            wx.StaticText(self,
                          id=wx.ID_ANY,
                          label=_("Name for the output raster map:")),
            flag=wx.ALIGN_CENTER_VERTICAL,
            pos=(0, 0),
        )
        self.OutputMapName = gselect.Select(parent=self,
                                            id=wx.ID_ANY,
                                            type="raster",
                                            mapsets=[grass.gisenv()["MAPSET"]])
        OutputParameters.Add(self.OutputMapName,
                             flag=wx.EXPAND | wx.ALL,
                             pos=(0, 1))
        self.VarianceRasterCheckbox = wx.CheckBox(
            self, id=wx.ID_ANY, label=_("Export variance map as well: "))
        self.VarianceRasterCheckbox.SetValue(state=True)
        OutputParameters.Add(self.VarianceRasterCheckbox,
                             flag=wx.ALIGN_CENTER_VERTICAL,
                             pos=(1, 0))
        self.OutputVarianceMapName = gselect.Select(
            parent=self,
            id=wx.ID_ANY,
            type="raster",
            mapsets=[grass.gisenv()["MAPSET"]])
        self.VarianceRasterCheckbox.Bind(wx.EVT_CHECKBOX,
                                         self.OnVarianceCBChecked)
        OutputParameters.Add(self.OutputVarianceMapName,
                             flag=wx.EXPAND | wx.ALL,
                             pos=(1, 1))

        self.OverwriteCheckBox = wx.CheckBox(
            self,
            id=wx.ID_ANY,
            label=_("Allow output files to overwrite existing files"),
        )
        self.OverwriteCheckBox.SetValue(
            UserSettings.Get(group="cmd", key="overwrite", subkey="enabled"))
        OutputParameters.Add(self.OverwriteCheckBox, pos=(2, 0), span=(1, 2))

        OutputParameters.AddGrowableCol(1)
        OutputSizer.Add(OutputParameters,
                        proportion=0,
                        flag=wx.EXPAND | wx.ALL,
                        border=self.border)

        #    4. Run Button and Quit Button
        ButtonSizer = wx.BoxSizer(wx.HORIZONTAL)
        HelpButton = wx.Button(self, id=wx.ID_HELP)
        HelpButton.Bind(wx.EVT_BUTTON, self.OnHelpButton)
        QuitButton = wx.Button(self, id=wx.ID_EXIT)
        QuitButton.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
        # no stock ID for Run button..
        self.RunButton = wx.Button(self, id=wx.ID_ANY, label=_("&Run"))
        self.RunButton.Bind(wx.EVT_BUTTON, self.OnRunButton)
        # disable it on loading the interface, as input map is not set
        self.RunButton.Enable(False)
        ButtonSizer.Add(HelpButton,
                        proportion=0,
                        flag=wx.ALIGN_LEFT | wx.ALL,
                        border=self.border)
        ButtonSizer.Add(QuitButton,
                        proportion=0,
                        flag=wx.ALIGN_RIGHT | wx.ALL,
                        border=self.border)
        ButtonSizer.Add(
            self.RunButton,
            proportion=0,
            flag=wx.ALIGN_RIGHT | wx.ALL,
            border=self.border,
        )

        #    Main Sizer. Add each child sizer as soon as it is ready.
        Sizer = wx.BoxSizer(wx.VERTICAL)
        Sizer.Add(InputBoxSizer,
                  proportion=0,
                  flag=wx.EXPAND | wx.ALL,
                  border=self.border)
        Sizer.Add(KrigingSizer,
                  proportion=1,
                  flag=wx.EXPAND | wx.ALL,
                  border=self.border)
        Sizer.Add(OutputSizer,
                  proportion=0,
                  flag=wx.EXPAND | wx.ALL,
                  border=self.border)
        Sizer.Add(ButtonSizer,
                  proportion=0,
                  flag=wx.ALIGN_RIGHT | wx.ALL,
                  border=self.border)
        self.SetSizerAndFit(Sizer)

        # last action of __init__: update imput data list.
        # it's performed in the few seconds gap while user examines interface before clicking anything.
        # @TODO: implement a splashcreen IF the maps cause a noticeable lag [markus' suggestion]
        self.InputDataMap.GetElementList()