Ejemplo n.º 1
0
    def __init__(self,
                 parent=None,
                 server_script=server.__file__,
                 interpreter=sys.executable,
                 args=None,
                 create_default_actions=True,
                 color_scheme='qt',
                 reuse_backend=False):
        super(PyCodeEdit,
              self).__init__(parent=parent,
                             create_default_actions=create_default_actions)
        self.backend.start(server_script,
                           interpreter,
                           args,
                           reuse=reuse_backend)
        self.setLineWrapMode(self.NoWrap)
        self.setWindowTitle("pyQode - Python Editor")

        # install those modes first as they are required by other modes/panels
        self.modes.append(modes.OutlineMode(defined_names))

        # panels
        self.panels.append(panels.SearchAndReplacePanel(),
                           panels.SearchAndReplacePanel.Position.BOTTOM)
        self.panels.append(panels.FoldingPanel())
        self.panels.append(panels.LineNumberPanel())
        self.panels.append(panels.CheckerPanel())
        self.panels.append(panels.GlobalCheckerPanel(),
                           panels.GlobalCheckerPanel.Position.RIGHT)
        self.add_separator()

        # modes
        # generic
        self.modes.append(modes.ExtendedSelectionMode())
        self.modes.append(modes.CaseConverterMode())
        self.modes.append(modes.CaretLineHighlighterMode())
        self.modes.append(modes.FileWatcherMode())
        self.modes.append(modes.RightMarginMode())
        self.modes.append(modes.ZoomMode())
        self.modes.append(modes.SymbolMatcherMode())
        self.modes.append(modes.CodeCompletionMode())
        self.modes.append(modes.OccurrencesHighlighterMode())
        self.modes.append(modes.SmartBackSpaceMode())
        # python specifics
        self.modes.append(pymodes.PyAutoIndentMode())
        self.modes.append(pymodes.PyAutoCompleteMode())
        self.modes.append(pymodes.PyFlakesChecker())
        self.modes.append(pymodes.PEP8CheckerMode())
        self.modes.append(pymodes.CalltipsMode())
        self.modes.append(pymodes.PyIndenterMode())
        self.modes.append(pymodes.GoToAssignmentsMode())
        self.modes.append(pymodes.CommentsMode())
        self.modes.append(
            pymodes.PythonSH(self.document(),
                             color_scheme=ColorScheme(color_scheme)))
        self.syntax_highlighter.fold_detector = PythonFoldDetector()
        self.panels.append(pypanels.QuickDocPanel(), api.Panel.Position.BOTTOM)
        self.panels.append(panels.EncodingPanel(), api.Panel.Position.TOP)
        self.panels.append(panels.ReadOnlyPanel(), api.Panel.Position.TOP)
Ejemplo n.º 2
0
    def create_controls(self, path):
        editor = api.CodeEdit()
        editor.backend.start(server.__file__)

#        editor.panels.append(panels.FoldingPanel())
        editor.panels.append(panels.LineNumberPanel())
        editor.panels.append(panels.CheckerPanel())

        editor.modes.append(modes.CaretLineHighlighterMode())
        editor.modes.append(modes.CodeCompletionMode())
        editor.modes.append(modes.ExtendedSelectionMode())
        editor.modes.append(modes.FileWatcherMode())
        editor.modes.append(modes.RightMarginMode())
        editor.modes.append(modes.SmartBackSpaceMode())
        editor.modes.append(modes.OccurrencesHighlighterMode())
        editor.modes.append(modes.SymbolMatcherMode())
#        editor.modes.append(modes.WordClickMode())
        editor.modes.append(modes.ZoomMode())

        editor.modes.append(pymodes.PythonSH(editor.document()))
        editor.modes.append(pymodes.CommentsMode())
        editor.modes.append(ConsoleCodeCalltipsMode(self))
        editor.modes.append(ConsoleCodeCheckerMode(self))
        editor.modes.append(pymodes.PEP8CheckerMode())
        editor.modes.append(pymodes.PyAutoCompleteMode())
        editor.modes.append(pymodes.PyAutoIndentMode())
        editor.modes.append(pymodes.PyIndenterMode())

        if path is not None:
            editor.file._path = path
        self.editor = editor
        self.tab = TabWidget(self)
        if path is not None and os.path.isfile(path):
            self.tab.add_code_edit(editor)
        else:
            self.tab.add_code_edit(editor, tr("untitled") + "%d.py")

        self.btn_save = QPushButton(tr("Save"))
        self.btn_run = QPushButton(tr("Run"))
        self.btn_make_plugin = QPushButton(tr("Make Plugin"))
        self.btn_reg_plugin = QPushButton(tr("Register Plugin"))
        self.btn_reg_plugin.setVisible(False)

        self.btn_save.clicked.connect(self.save)
        self.btn_run.clicked.connect(self.run)
        self.btn_make_plugin.clicked.connect(self.make_plugin)
        self.btn_reg_plugin.clicked.connect(self.register_plugin)

        self.hbox = QHBoxLayout()
        for w in [self.btn_save, self.btn_run,
                  self.btn_make_plugin, self.btn_reg_plugin]:
            self.hbox.addWidget(w)

        vbox = QVBoxLayout(self)
        vbox.addWidget(self.tab)
        vbox.addLayout(self.hbox)

        self.setLayout(vbox)
Ejemplo n.º 3
0
    def __init__(self,
                 parent=None,
                 server_script=server.__file__,
                 interpreter=sys.executable,
                 args=None,
                 create_default_actions=True,
                 color_scheme='default'):
        super(PyCodeEditor,
              self).__init__(parent=parent,
                             create_default_actions=create_default_actions)
        self.backend.start(server_script, interpreter, args)
        self.setLineWrapMode(self.NoWrap)
        self.setWindowTitle("pyQode for LPy")

        # panels
        self.panels.append(panels.FoldingPanel())
        self.panels.append(panels.LineNumberPanel())
        self.panels.append(panels.CheckerPanel())
        self.panels.append(panels.GlobalCheckerPanel(),
                           panels.GlobalCheckerPanel.Position.RIGHT)
        self._panel_search = panels.SearchAndReplacePanel()
        self.panels.append(self._panel_search,
                           panels.SearchAndReplacePanel.Position.BOTTOM)
        self.panels.append(panels.EncodingPanel(), api.Panel.Position.TOP)
        self.add_separator()
        self.panels.append(pypanels.QuickDocPanel(), api.Panel.Position.BOTTOM)

        # modes

        # generic
        self.modes.append(modes.CaretLineHighlighterMode())
        self.modes.append(modes.FileWatcherMode())
        self.modes.append(modes.RightMarginMode())
        self.modes.append(modes.ZoomMode())
        self.modes.append(modes.SymbolMatcherMode())
        self.modes.append(modes.CodeCompletionMode())
        self.modes.append(modes.OccurrencesHighlighterMode())
        self.modes.append(modes.SmartBackSpaceMode())
        self.modes.append(modes.ExtendedSelectionMode())

        # python specifics
        self.modes.append(pymodes.PyAutoIndentMode())
        self.modes.append(pymodes.PyAutoCompleteMode())
        # self.modes.append(pymodes.FrostedCheckerMode())
        self.modes.append(pymodes.PEP8CheckerMode())
        self.modes.append(pymodes.CalltipsMode())
        self.modes.append(pymodes.PyIndenterMode())
        self.modes.append(pymodes.GoToAssignmentsMode())
        self.modes.append(pymodes.CommentsMode())

        self.modes.append(
            pymodes.PythonSH(self.document(),
                             color_scheme=ColorScheme(color_scheme)))
        self.syntax_highlighter.fold_detector = PythonFoldDetector()
Ejemplo n.º 4
0
    def __init__(self, parent=None, color_scheme='qt'):
        super().__init__(parent=parent)
        self.setLineWrapMode(self.NoWrap)
        # install those modes first as they are required by other modes/panels
        self.modes.append(modes.OutlineMode(defined_names))

        # panels
        self.panels.append(panels.SearchAndReplacePanel(),
                           panels.SearchAndReplacePanel.Position.BOTTOM)
        self.panels.append(panels.FoldingPanel())
        self.panels.append(panels.LineNumberPanel())
        self.panels.append(panels.CheckerPanel())
        self.panels.append(panels.GlobalCheckerPanel(),
                           panels.GlobalCheckerPanel.Position.RIGHT)
        # modes
        # generic
        self.modes.append(modes.CursorHistoryMode())
        self.modes.append(modes.ExtendedSelectionMode())
        self.modes.append(modes.CaseConverterMode())
        self.modes.append(modes.CaretLineHighlighterMode())
        self.modes.append(modes.FileWatcherMode())
        self.modes.append(modes.RightMarginMode())
        self.modes.append(modes.ZoomMode())
        self.modes.append(modes.SymbolMatcherMode())
        self.modes.append(modes.CodeCompletionMode())
        self.modes.append(modes.OccurrencesHighlighterMode())
        self.modes.append(modes.SmartBackSpaceMode())
        # python specifics
        self.modes.append(pymodes.PyAutoIndentMode())
        self.modes.append(pymodes.PyAutoCompleteMode())
        self.modes.append(pymodes.FrostedCheckerMode())
        self.modes.append(pymodes.PEP8CheckerMode())
        self.modes.append(pymodes.CalltipsMode())
        self.modes.append(pymodes.PyIndenterMode())
        self.add_separator()
        self.modes.append(AddImportMode())
        self.modes.append(pymodes.GoToAssignmentsMode())
        self.modes.append(pymodes.CommentsMode())
        self.modes.append(
            pymodes.PythonSH(self.document(),
                             color_scheme=ColorScheme(color_scheme)))
        self.syntax_highlighter.fold_detector = PythonFoldDetector()

        self.panels.append(pypanels.QuickDocPanel(),
                           pyqode_api.Panel.Position.BOTTOM)
        self.panels.append(panels.EncodingPanel(),
                           pyqode_api.Panel.Position.TOP)

        self.breakpoints_panel = self.panels.append(panels.MarkerPanel())
        self.line_highlighter = self.modes.append(modes.LineHighlighterMode())

        self.restart_backend()
Ejemplo n.º 5
0
 def __init__(self, parent=None, color_scheme='qt'):
     super().__init__(parent=parent)
     # panels
     self.panels.append(panels.FoldingPanel())
     self.panels.append(panels.LineNumberPanel())
     self.panels.append(panels.CheckerPanel())
     self.panels.append(panels.GlobalCheckerPanel(),
                        panels.GlobalCheckerPanel.Position.RIGHT)
     # modes
     self.modes.append(modes.RightMarginMode())
     self.caret_highlighter = self.modes.append(
         modes.CaretLineHighlighterMode())
     self.modes.append(
         pymodes.PythonSH(self.document(),
                          color_scheme=ColorScheme(color_scheme)))
     self.syntax_highlighter.fold_detector = PythonFoldDetector()
     self.breakpoints_panel = self.panels.append(panels.MarkerPanel())
Ejemplo n.º 6
0
    def __init__(self):
        super(MyPythonCodeEdit, self).__init__()

        # starts the default pyqode.python server (which enable the jedi code
        # completion worker).
        self.backend.start(server.__file__)

        # some other modes/panels require the analyser mode, the best is to
        # install it first
        self.modes.append(modes.OutlineMode(defined_names))

        #--- core panels
        self.panels.append(panels.FoldingPanel())
        self.panels.append(panels.LineNumberPanel())
        self.panels.append(panels.CheckerPanel())
        self.panels.append(panels.SearchAndReplacePanel(),
                           panels.SearchAndReplacePanel.Position.BOTTOM)
        self.panels.append(panels.EncodingPanel(), api.Panel.Position.TOP)
        # add a context menu separator between editor's
        # builtin action and the python specific actions
        self.add_separator()

        #--- python specific panels
        self.panels.append(pypanels.QuickDocPanel(), api.Panel.Position.BOTTOM)

        #--- core modes
        self.modes.append(modes.CaretLineHighlighterMode())
        self.modes.append(modes.CodeCompletionMode())
        self.modes.append(modes.ExtendedSelectionMode())
        self.modes.append(modes.FileWatcherMode())
        self.modes.append(modes.OccurrencesHighlighterMode())
        self.modes.append(modes.RightMarginMode())
        self.modes.append(modes.SmartBackSpaceMode())
        self.modes.append(modes.SymbolMatcherMode())
        self.modes.append(modes.ZoomMode())

        #---  python specific modes
        self.modes.append(pymodes.CommentsMode())
        self.modes.append(pymodes.CalltipsMode())
        self.modes.append(pymodes.PyFlakesChecker())
        self.modes.append(pymodes.PEP8CheckerMode())
        self.modes.append(pymodes.PyAutoCompleteMode())
        self.modes.append(pymodes.PyAutoIndentMode())
        self.modes.append(pymodes.PyIndenterMode())
        self.modes.append(pymodes.PythonSH(self.document()))
        self.syntax_highlighter.fold_detector = PythonFoldDetector()
Ejemplo n.º 7
0
    def __init__(self, parent, **kwargs):
        """
        Args:
            parent (QWidget): Parent widget
        """
        # Foe help, see
        # https://github.com/pyQode/pyqode.python/blob/master/examples/custom.py

        super().__init__(parent, **kwargs)

        self.gui = None  # type: MetalGUI
        self.component_class_name = None  # type: str - 'TransmonPocket'
        # type: str - 'qiskit_metal.qlibrary.qubits.transmon_pocket'
        self.component_module_name = None
        # type: str - '/Users/zlatko.minev/qiskit_metal/qiskit_metal/qlibrary/qubits/transmon_pocket.py'
        self.component_module_path = None

        # starts the default pyqode.python server (which enable the jedi code
        # completion worker).
        self.backend.start(server.__file__)

        # some other modes/panels require the analyser mode, the best is to
        # install it first
        self.modes.append(modes.OutlineMode(defined_names))

        # --- core panels
        # in pyqode/core/panels/folding.py there is:
        #   if os.environ['QT_API'].lower() not in PYQT5_API

        self.panels.append(MetalPyqodeFoldingPanel())
        self.panels.append(panels.LineNumberPanel())
        self.panels.append(panels.CheckerPanel())
        self.panels.append(panels.SearchAndReplacePanel(),
                           panels.SearchAndReplacePanel.Position.BOTTOM)
        self.panels.append(panels.EncodingPanel(), api.Panel.Position.TOP)
        # add a context menu separator between editor's
        # builtin action and the python specific actions
        self.add_separator()

        # --- python specific panels
        self.quick_doc_panel = pypanels.QuickDocPanel()
        self.panels.append(self.quick_doc_panel, api.Panel.Position.BOTTOM)

        ############################################################################
        # core modes
        self.modes.append(modes.CaretLineHighlighterMode())
        self.code_completion_mode = modes.CodeCompletionMode()
        self.modes.append(self.code_completion_mode)
        self.modes.append(modes.ExtendedSelectionMode())
        self.modes.append(modes.FileWatcherMode())
        self.modes.append(modes.OccurrencesHighlighterMode())
        # self.modes.append(modes.RightMarginMode())
        self.modes.append(modes.SmartBackSpaceMode())
        self.modes.append(modes.SymbolMatcherMode())
        self.modes.append(modes.ZoomMode())

        # ---  python specific modes
        # Help: https://pythonhosted.org/pyqode.python/pyqode.python.modes.html

        # Comments/uncomments a set of lines using Ctrl+/.
        self.modes.append(pymodes.CommentsMode())

        # Shows function calltips.
        # This mode shows function/method call tips in a QToolTip using jedi.Script.call_signatures().
        # https://pythonhosted.org/pyqode.python/pyqode.python.modes.html#calltipsmode
        self.calltips_mode = pymodes.CalltipsMode()
        self.calltips_mode.tooltipDisplayRequested.connect(self.calltip_called)
        self.modes.append(self.calltips_mode)

        self.modes.append(pymodes.PyFlakesChecker())
        # self.modes.append(pymodes.PEP8CheckerMode())
        self.auto_complete_mode = pymodes.PyAutoCompleteMode()
        self.modes.append(self.auto_complete_mode)
        self.modes.append(pymodes.PyAutoIndentMode())
        self.modes.append(pymodes.PyIndenterMode())
        self.modes.append(pymodes.PythonSH(self.document()))
        self.syntax_highlighter.fold_detector = PythonFoldDetector()

        # --- handle modifed text in other application
        # self.textChanged.connect(self.check_modified) # user function

        # Options
        # self.file.safe_save  = False

        self.script = jedi.Script('')  # get overwritten in set

        self.style_me()