Exemplo n.º 1
0
    def __init__(self):
        super(MyPythonCodeEdit, self).__init__()

        # starts the default pyqode.python server (which enable the jedi code
        # completion worker).
        self._backend = QtBackendManager(self)

        # 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()
Exemplo n.º 2
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        # 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(pymodes.DocumentAnalyserMode())

        # --- 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.FrostedCheckerMode())
        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()))
Exemplo n.º 3
0
    def __init__(self,
                 parent=None,
                 server_script=None,
                 interpreter=sys.executable,
                 args=None,
                 create_default_actions=True,
                 color_scheme='qt',
                 reuse_backend=False):
        super(RstCodeEdit, self).__init__(parent, create_default_actions)
        if server_script is None:
            server_script = self.DEFAULT_SERVER

        self.backend.start(server_script,
                           interpreter,
                           args,
                           reuse=reuse_backend)
        # append panels
        self.panels.append(panels.LineNumberPanel())
        self.panels.append(panels.SearchAndReplacePanel(),
                           api.Panel.Position.BOTTOM)

        # append modes
        self.modes.append(modes.CursorHistoryMode())
        self.modes.append(modes.CaseConverterMode())
        self.modes.append(modes.FileWatcherMode())
        self.modes.append(modes.CaretLineHighlighterMode())
        self.modes.append(modes.RightMarginMode())
        self.modes.append(
            rstmodes.RstSH(self.document(),
                           color_scheme=api.ColorScheme(color_scheme)))
        self.modes.append(modes.ZoomMode())
        cc = modes.CodeCompletionMode()
        cc.trigger_symbols[:] = []
        self.modes.append(cc)
        self.modes.append(modes.AutoIndentMode())
        self.modes.append(modes.IndenterMode())
        self.modes.append(modes.OccurrencesHighlighterMode())
        self.modes.append(modes.SmartBackSpaceMode())
        self.modes.append(modes.CheckerMode(workers.linter))

        self.panels.append(panels.EncodingPanel(), api.Panel.Position.TOP)
        self.panels.append(panels.ReadOnlyPanel(), api.Panel.Position.TOP)
        self.panels.append(panels.CheckerPanel())
Exemplo n.º 4
0
def setup_editor(code_edit):
    # append panels
    p = panels.FoldingPanel(highlight_caret_scope=True)
    code_edit.panels.append(p)
    p.show()
    p = panels.LineNumberPanel()
    code_edit.panels.append(p)
    p.show()
    p = panels.MarkerPanel()
    code_edit.panels.append(p)
    p.show()
    p = panels.CheckerPanel()
    code_edit.panels.append(p)
    p.show()
    p = panels.SearchAndReplacePanel()
    code_edit.panels.append(p, p.Position.BOTTOM)
    p.show()
    p = panels.GlobalCheckerPanel()
    code_edit.panels.append(p, p.Position.RIGHT)
    p.show()

    # append modes
    code_edit.modes.append(modes.AutoCompleteMode())
    code_edit.modes.append(modes.CaseConverterMode())
    code_edit.modes.append(modes.FileWatcherMode())
    code_edit.modes.append(modes.CaretLineHighlighterMode())
    code_edit.modes.append(modes.RightMarginMode())
    code_edit.modes.append(
        modes.PygmentsSyntaxHighlighter(code_edit.document()))
    code_edit.modes.append(modes.ZoomMode())
    code_edit.modes.append(modes.CodeCompletionMode())
    code_edit.modes.append(modes.AutoIndentMode())
    code_edit.modes.append(modes.IndenterMode())
    code_edit.modes.append(modes.SymbolMatcherMode())
    code_edit.modes.append(modes.WordClickMode())
    code_edit.modes.get(modes.FileWatcherMode).auto_reload = True
    code_edit.syntax_highlighter.fold_detector = IndentFoldDetector()
    code_edit.modes.append(modes.SmartBackSpaceMode())
    code_edit.modes.append(modes.ExtendedSelectionMode())
    code_edit.modes.append(modes.OccurrencesHighlighterMode())
Exemplo n.º 5
0
    def __init__(self):
        super(scripteditoritem, 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(pymodes.DocumentAnalyserMode())

        # --- 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())
        self.modes.append(modes.PygmentsSyntaxHighlighter(self.document()))

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

        self.syntax_highlighter.color_scheme = api.ColorScheme('darcula')

        QApplication.instance().aboutToQuit.connect(
            self.cleanup)  # TODO: use this approach in Xi-cam

        # self.file.open('test.py')
        self.insertPlainText('''
# Required to allow controls manipulation in background
import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
        
# Setup RunEngine
from bluesky import RunEngine
from bluesky.plans import inner_product_scan
RE = RunEngine({})
        
# Set up simulated hardware.
from ophyd.sim import det4, motor1, motor2, motor3
# The 'det4' example detector a 2D Gaussian function of motor1, motor2.

# Move motor1 from 1-5 while moving motor2 from 10-50 -- both in 5 steps.
RE(inner_product_scan([det4], 5,
                      motor1, 1, 5,
                      motor2, 10, 50))
''')
Exemplo n.º 6
0
    def __init__(self):
        super(scripteditoritem, 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(pymodes.DocumentAnalyserMode())

        # --- 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())
        self.modes.append(modes.PygmentsSyntaxHighlighter(self.document()))

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

        self.syntax_highlighter.color_scheme = api.ColorScheme('darcula')

        QApplication.instance().aboutToQuit.connect(self.cleanup)  # TODO: use this approach in Xi-cam

        # self.file.open('test.py')
        self.insertPlainText('''from bluesky.plans import scan
from ophyd.sim import det4, motor1, motor2, motor3
from pyqtgraph.parametertree.parameterTypes import SimpleParameter
from xicam.gui.utils import ParameterizablePlan

min1 = SimpleParameter(name='Axis 1 Min', type='float')
min2 = SimpleParameter(name='Axis 2 Min', type='float')
max2 = SimpleParameter(name='Axis 2 Max', type='float')
max1 = SimpleParameter(name='Axis 1 Max', type='float')
steps = SimpleParameter(name='Steps', type='int')

scan = ParameterizablePlan(scan)

plan = scan([det4],
            motor1, min1, max1,
            motor2, min2, max2,
            steps)

''')
Exemplo n.º 7
0
    def __init__(self,
                 parent=None,
                 server_script=server.__file__,
                 interpreter=sys.executable,
                 args=None,
                 create_default_actions=True,
                 color_scheme='monokai',
                 reuse_backend=False):
        super(PyCodeEditBase,
              self).__init__(parent=parent,
                             create_default_actions=create_default_actions)

        if not getattr(sys, 'frozen', False):
            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.zoom_in = functools.partial(
            self.zoom_in,
            increment=1)  #Fix a bug in pyqode (#16 in github:easypie)
        self.zoom_out = functools.partial(self.zoom_in, increment=-1)
        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
        if not getattr(sys, 'frozen', False):
            self.modes.append(pymodes.CalltipsMode())
            self.modes.append(pymodes.PyAutoCompleteMode())
            self.panels.append(pypanels.QuickDocPanel(),
                               api.Panel.Position.BOTTOM)

        self.modes.append(pymodes.PyAutoIndentMode())
        self.modes.append(pymodes.PyFlakesChecker())
        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(panels.EncodingPanel(), api.Panel.Position.TOP)
        self.panels.append(panels.ReadOnlyPanel(), api.Panel.Position.TOP)
Exemplo n.º 8
0
    def __init__(self, args):
        QMainWindow.__init__(self)
        self.setupUi(self)

        self.moderat = args['moderat']
        self.client = args['client']
        self.module_id = args['module_id']
        self.alias = args['alias']
        self.ip_address = args['ip_address']
        self.p2p = args['p2p']

        title_prefix = self.alias if len(self.alias) > 0 else self.ip_address
        self.setWindowTitle(u'[{}] {}'.format(
            title_prefix, self.moderat.MString('MSCRIPTING_TITLE')))

        # init idle
        self.editor = api.CodeEdit()
        #self.editor.setStyleSheet('border: 0px; padding: 0px; background: #34495e;')
        # start the backend as soon as possible
        self.editor.backend.start(server.__file__)
        # append some modes and panels
        self.editor.modes.append(modes.CodeCompletionMode())
        self.editor.modes.append(modes.AutoIndentMode())
        self.editor.modes.append(modes.AutoCompleteMode())
        self.editor.modes.append(modes.IndenterMode())
        self.editor.modes.append(modes.ExtendedSelectionMode())
        self.editor.modes.append(modes.SymbolMatcherMode())
        self.editor.modes.append(modes.ZoomMode())
        self.editor.modes.append(modes.LineHighlighterMode())
        self.editor.modes.append(
            modes.PygmentsSyntaxHighlighter(self.editor.document()))
        sh = self.editor.modes.append(modes.PygmentsSH(self.editor.document()))
        sh.fold_detector = api.IndentFoldDetector()
        self.editor.modes.get(
            modes.PygmentsSyntaxHighlighter).pygments_style = 'monokai'
        self.editor.panels.append(panels.SearchAndReplacePanel(),
                                  api.Panel.Position.BOTTOM)
        self.editor.panels.append(panels.CheckerPanel())
        self.editor.panels.append(panels.LineNumberPanel())
        self.editor.panels.append(panels.MarkerPanel())
        self.editor.panels.append(panels.EncodingPanel())
        self.editor.panels.append(panels.FoldingPanel())
        self.editor.panels.append(panels.ReadOnlyPanel())

        self.output = Output(self.editor, self.moderat)
        self.splitter = QSplitter()
        self.splitter.setOrientation(Qt.Vertical)
        self.splitter.addWidget(self.editor)
        self.splitter.addWidget(self.output)

        self.setCentralWidget(self.splitter)

        # self.runButton.clicked.connect(self.run_script)
        # self.testButton.clicked.connect(self.run_test)
        # self.openButton.clicked.connect(self.from_file)
        # self.pluginsListButton.clicked.connect(self.open_list)
        # self.addPluginButton.clicked.connect(self.insert_plugin)
        # self.saveButton.clicked.connect(self.save_plugin)
        # self.pluginSearchLine.returnPressed.connect(self.insert_plugin)
        # self.clearButton.clicked.connect(self.clear_script)
        # self.pinButton.clicked.connect(self.always_top)

        # Autocompleter
        self.completer = QCompleter(self.moderat.plugins.keys())
        self.completer.setCompletionMode(QCompleter.PopupCompletion)
        self.completer.setCaseSensitivity(Qt.CaseInsensitive)
        self.completer.popup().setStyleSheet('''background-color: #273747;
                                        color: #c9f5f7;
                                        border: 1px solid #243342;
                                        border-top: none;''')
        self.addTools()
Exemplo n.º 9
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()