Пример #1
0
    def __init__(self,
                 parent,
                 giface,
                 id=wx.ID_ANY,
                 simpleEditorHandler=None,
                 **kwargs):
        self.parent = parent
        self.giface = giface

        wx.Panel.__init__(self, parent=parent, id=id, **kwargs)

        self.intro = (
            _("Welcome to wxGUI Interactive Python Shell %s") % VERSION +
            "\n\n" +
            _("Type %s for more GRASS scripting related information.") %
            '"help(gs)"' + "\n" +
            _("Type %s to add raster or vector to the layer tree.") %
            "\"AddLayer('map_name')\"" + "\n\n")

        shellargs = dict(
            parent=self,
            id=wx.ID_ANY,
            introText=self.intro,
            locals={
                "gs": grass,
                "AddLayer": self.AddLayer,
                "help": self.Help
            },
        )
        # useStockId (available since wxPython 4.0.2) should be False on macOS
        if sys.platform == "darwin" and CheckWxVersion([4, 0, 2]):
            shellargs["useStockId"] = False
        self.shell = PyShell(**shellargs)
        if IsDark():
            SetDarkMode(self.shell)

        sys.displayhook = self._displayhook

        self.btnClear = ClearButton(self)
        self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear)
        self.btnClear.SetToolTip(_("Delete all text from the shell"))

        self.simpleEditorHandler = simpleEditorHandler
        if simpleEditorHandler:
            self.btnSimpleEditor = Button(self,
                                          id=wx.ID_ANY,
                                          label=_("Simple &editor"))
            self.btnSimpleEditor.Bind(wx.EVT_BUTTON, simpleEditorHandler)
            self.btnSimpleEditor.SetToolTip(
                _("Open a simple Python code editor"))

        self._layout()
Пример #2
0
    def __init__(self,
                 parent,
                 giface,
                 id=wx.ID_ANY,
                 title=_("Simple Python Editor"),
                 **kwargs):
        wx.Frame.__init__(self, parent=parent, id=id, title=title, **kwargs)
        self.parent = parent

        filename = os.path.join(globalvar.WXGUIDIR, "xml",
                                "menudata_pyedit.xml")
        self.menubar = Menu(
            parent=self,
            model=MenuTreeModelBuilder(filename).GetModel(separators=True))
        self.SetMenuBar(self.menubar)

        self.toolbar = PyEditToolbar(parent=self)
        # workaround for http://trac.wxwidgets.org/ticket/13888
        # TODO: toolbar is set in toolbar and here
        if sys.platform != "darwin":
            self.SetToolBar(self.toolbar)

        self.panel = PyStc(parent=self)
        if IsDark():
            SetDarkMode(self.panel)
        self.controller = PyEditController(panel=self.panel,
                                           guiparent=self,
                                           giface=giface)

        # don't start with an empty page
        self.panel.SetText(script_template())

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.panel, proportion=1, flag=wx.EXPAND)
        sizer.Fit(self)
        sizer.SetSizeHints(self)
        self.SetSizer(sizer)
        self.Fit()
        self.SetAutoLayout(True)
        self.Layout()
        self.Bind(wx.EVT_CLOSE, self.OnClose)