예제 #1
0
def open_editor(path, line):
    global editor_windows
    print(path, line)
    editor = PyCodeEdit()
    # prevent the restoration of cursor position which will reset the position
    # we will set after opening the file
    editor.file.restore_cursor = False
    editor.file.open(path)
    TextHelper(editor).goto_line(line)
    editor.show()
    editor_windows.append(editor)
예제 #2
0
def open_editor(path, line):
    global editor_windows
    print(path, line)
    editor = PyCodeEdit()
    # prevent the restoration of cursor position which will reset the position
    # we will set after opening the file
    editor.file.restore_cursor = False
    editor.file.open(path)
    TextHelper(editor).goto_line(line)
    editor.show()
    editor_windows.append(editor)
예제 #3
0
    def __init__(self, *kargs):
        server_path = os.path.join('.', 'cq_server.py')
        libs_dir_path = '/home/jwright/Documents/cadquery-x/gui/libs'

        ver = hex(sys.hexversion)
        interpreter = "python%s.%s" % (ver[2], ver[4])  # => 'python2.7'

        PyCodeEdit(server_script=server_path,
                   interpreter=interpreter,
                   args=['-s', libs_dir_path])
예제 #4
0
 def _get_installed_panels(self):
     code_edit = PyCodeEdit()
     modes = [(m.name, self.extract_doc(m)) for m in code_edit.panels
              if m.name not in commons.DYNAMIC_PANELS]
     code_edit.close()
     code_edit.delete()
     del code_edit
     return modes
예제 #5
0
 def _get_installed_modes(self):
     code_edit = PyCodeEdit()
     installed_modes = [(m.name, self.extract_doc(m))
                        for m in code_edit.modes]
     code_edit.close()
     code_edit.delete()
     del code_edit
     return installed_modes
예제 #6
0
    def setupUi(self, parent):
        MainWindowUI.setupUi(self, parent)

        # content area
        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.content.setLayout(layout)

        # add video widget
        self.contentWidget = VideoWidget()
        self.content.layout().addWidget(self.contentWidget)

        self.prev_code = 'def f(img):\n    return img'
        self.te_code = PyCodeEdit()
        self.te_code.setPlainText(self.prev_code)
        self.content.layout().addWidget(self.te_code)

        # footer area
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.footer.setLayout(layout)

        self.bar_index = QScrollBar(Qt.Horizontal)
        self.bar_index.setFocusPolicy(Qt.WheelFocus)
        self.bar_index.setMinimum(0)
        self.bar_index.setSingleStep(1)
        self.bar_index.valueChanged.connect(self.indexChanged)
        layout.addWidget(self.bar_index)

        self.info = QLabel()
        layout.addWidget(self.info)

        # construct navigation tree
        self.refreshNavigation()

        # design the view
        self.treeView.header().hide()  # hide header
        self.treeView.expandToDepth(0)  # expand first level
예제 #7
0
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(668, 645)
        self.verticalLayout = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")
        self.header = QtWidgets.QLabel(Form)
        self.header.setStyleSheet("border-radius: 3px;\n"
                                  "background-color: rgb(161, 161, 161);\n"
                                  "padding: 10px;")
        self.header.setAlignment(QtCore.Qt.AlignCenter)
        self.header.setObjectName("header")
        self.verticalLayout.addWidget(self.header)
        self.groupBox = QtWidgets.QGroupBox(Form)
        self.groupBox.setObjectName("groupBox")
        self.formLayout = QtWidgets.QFormLayout(self.groupBox)
        self.formLayout.setFieldGrowthPolicy(
            QtWidgets.QFormLayout.ExpandingFieldsGrow)
        self.formLayout.setObjectName("formLayout")
        self.label = QtWidgets.QLabel(self.groupBox)
        self.label.setObjectName("label")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole,
                                  self.label)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.line_edit_font = QtWidgets.QLineEdit(self.groupBox)
        self.line_edit_font.setObjectName("line_edit_font")
        self.horizontalLayout_2.addWidget(self.line_edit_font)
        self.bt_font = QtWidgets.QToolButton(self.groupBox)
        self.bt_font.setObjectName("bt_font")
        self.horizontalLayout_2.addWidget(self.bt_font)
        self.formLayout.setLayout(0, QtWidgets.QFormLayout.FieldRole,
                                  self.horizontalLayout_2)
        self.label_3 = QtWidgets.QLabel(self.groupBox)
        self.label_3.setObjectName("label_3")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole,
                                  self.label_3)
        self.spinbox_font_size = QtWidgets.QSpinBox(self.groupBox)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.spinbox_font_size.sizePolicy().hasHeightForWidth())
        self.spinbox_font_size.setSizePolicy(sizePolicy)
        self.spinbox_font_size.setObjectName("spinbox_font_size")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole,
                                  self.spinbox_font_size)
        self.label_4 = QtWidgets.QLabel(self.groupBox)
        self.label_4.setObjectName("label_4")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole,
                                  self.label_4)
        self.list_color_schemes = QtWidgets.QListWidget(self.groupBox)
        self.list_color_schemes.setObjectName("list_color_schemes")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole,
                                  self.list_color_schemes)
        self.label_2 = QtWidgets.QLabel(self.groupBox)
        self.label_2.setObjectName("label_2")
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole,
                                  self.label_2)
        self.checkbox_whitespaces = QtWidgets.QCheckBox(self.groupBox)
        self.checkbox_whitespaces.setText("")
        self.checkbox_whitespaces.setObjectName("checkbox_whitespaces")
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole,
                                  self.checkbox_whitespaces)
        self.verticalLayout.addWidget(self.groupBox)
        self.groupBox_2 = QtWidgets.QGroupBox(Form)
        self.groupBox_2.setObjectName("groupBox_2")
        self.gridLayout = QtWidgets.QGridLayout(self.groupBox_2)
        self.gridLayout.setObjectName("gridLayout")
        self.edit_preview = PyCodeEdit(self.groupBox_2)
        self.edit_preview.setObjectName("edit_preview")
        self.gridLayout.addWidget(self.edit_preview, 0, 0, 1, 1)
        self.verticalLayout.addWidget(self.groupBox_2)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
예제 #8
0
    def Activated(self):
        import os, sys
        import module_locator
        from Gui import Command, ImportCQ
        import Settings

        #Set up so that we can import from our embedded packages
        module_base_path = module_locator.module_path()
        libs_dir_path = os.path.join(module_base_path, 'Libs')
        sys.path.insert(0, libs_dir_path)

        #Make sure we get the right libs under the FreeCAD installation
        fc_base_path = os.path.dirname(os.path.dirname(module_base_path))
        fc_lib_path = os.path.join(fc_base_path, 'lib')
        fc_bin_path = os.path.join(fc_base_path, 'bin')

        #Make sure that the directories exist before we add them to sys.path
        #This could cause problems or solve them by overriding what CQ is setting for the paths
        if os.path.exists(fc_lib_path):
            sys.path.insert(1, fc_lib_path)
        if os.path.exists(fc_bin_path):
            sys.path.insert(1, fc_bin_path)

        import cadquery
        from pyqode.core.modes import FileWatcherMode
        from pyqode.python.widgets import PyCodeEdit
        from PySide import QtGui, QtCore

        msg = QtGui.QApplication.translate(
            "cqCodeWidget",
            "CadQuery " + cadquery.__version__ + "\r\n"
            "CadQuery is a parametric scripting language "
            "for creating and traversing CAD models\r\n"
            "Author: David Cowden\r\n"
            "License: LGPL\r\n"
            "Website: https://github.com/dcowden/cadquery\r\n",
            None,
            QtGui.QApplication.UnicodeUTF8)
        FreeCAD.Console.PrintMessage(msg)

        #Make sure that we enforce a specific version (2.7) of the Python interpreter
        ver = hex(sys.hexversion)
        interpreter = "python%s.%s" % (ver[2], ver[4])  # => 'python2.7'

        #If the user doesn't have Python 2.7, warn them
        if interpreter != 'python2.7':
            msg = QtGui.QApplication.translate(
                "cqCodeWidget",
                "Please install Python 2.7",
                None,
                QtGui.QApplication.UnicodeUTF8)
            FreeCAD.Console.PrintError("\r\n" + msg)

        #The extra version numbers won't work on Windows
        if sys.platform.startswith('win'):
            interpreter = 'python'

        #Getting the main window will allow us to start setting things up the way we want
        mw = FreeCADGui.getMainWindow()

        # TODO: Fix the extra newline foolishness with the output in the report view

        dockWidgets = mw.findChildren(QtGui.QDockWidget)

        for widget in dockWidgets:
            if widget.objectName() == "Report view":
                widget.setVisible(True)

        #Add a new widget here that's a simple text area to begin with. It will become the CQ coding area
        cqCodeWidget = QtGui.QDockWidget("CadQuery Code View")
        cqCodeWidget.setObjectName("cqCodeView")
        mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, cqCodeWidget)

        #Set up the text area for our CQ code
        server_path = os.path.join(module_base_path, 'cq_server.py')

        #Windows needs some extra help with paths
        if sys.platform.startswith('win'):
            codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter
                                  , args=['-s', fc_lib_path, libs_dir_path])
        else:
            codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter
                                  , args=['-s', libs_dir_path])

        # Allow easy use of an external editor
        if Settings.use_external_editor:
            codePane.modes.append(FileWatcherMode())
            codePane.modes.get(FileWatcherMode).file_reloaded.connect(self.AutoExecute)
            codePane.modes.get(FileWatcherMode).auto_reload = True

        codePane.setObjectName("cqCodePane")

        #Add the text area to our dock widget
        cqCodeWidget.setWidget(codePane)

        #Set up the paths to allow us to open and execute our introduction example
        example_path = os.path.join(module_base_path, 'Examples')
        example_path = os.path.join(example_path, 'Ex000_Introduction.py')

        # TODO: Enable this for FreeCAD 0.16 or greater
        # Make sure we get the correct MdiArea object
        # for child in mw.children():
        #     if child.__class__ == QtGui.QMdiArea:
        #         mdiArea = child
        #
        # # Set up the editor in a new subwindow
        # #sub_window = QtGui.QMdiSubWindow(mw.centralWidget())
        # sub_window = QtGui.QMdiSubWindow(mdiArea)
        # #sub_window.setWidget(codePane)
        # sub_window.setWidget(QtGui.QPlainTextEdit())
        # sub_window.setWindowTitle('Ex000_Introduction.py')
        # sub_window.setWindowIcon(QtGui.QIcon(':/icons/applications-python.svg'))
        #
        # #mw.centralWidget().addSubWindow(sub_window)
        # mdiArea.addSubWindow(sub_window)

        ImportCQ.open(example_path)
        docname = os.path.splitext(os.path.basename(example_path))[0]
        FreeCAD.newDocument(docname)
        Command.CadQueryExecuteScript().Activated()

        #Get a nice view of our example
        FreeCADGui.activeDocument().activeView().viewAxometric()
        FreeCADGui.SendMsgToActiveView("ViewFit")
예제 #9
0
    def Activated(self):
        import os, sys
        import module_locator

        #Set up so that we can import from our embedded packages
        module_base_path = module_locator.module_path()
        libs_dir_path = os.path.join(module_base_path, 'Libs')
        sys.path.insert(0, libs_dir_path)

        #Make sure we get the right libs under the FreeCAD installation
        fc_base_path = os.path.dirname(os.path.dirname(module_base_path))
        fc_lib_path = os.path.join(fc_base_path, 'lib')
        fc_bin_path = os.path.join(fc_base_path, 'bin')
        sys.path.insert(1, fc_lib_path)
        sys.path.insert(1, fc_bin_path)

        import cadquery
        from Gui import ImportCQ
        from pyqode.python.widgets import PyCodeEdit
        from PySide import QtGui, QtCore

        msg = QtGui.QApplication.translate(
            "cqCodeWidget",
            "CadQuery " + cadquery.__version__ + "\r\n"
            "CadQuery is a parametric scripting language "
            "for creating and traversing CAD models\r\n"
            "Author: David Cowden\r\n"
            "License: LGPL\r\n"
            "Website: https://github.com/dcowden/cadquery\r\n",
            None,
            QtGui.QApplication.UnicodeUTF8)
        FreeCAD.Console.PrintMessage(msg)

        #Make sure that we enforce a specific version (2.7) of the Python interpreter
        ver = hex(sys.hexversion)
        interpreter = "python%s.%s" % (ver[2], ver[4])  # => 'python2.7'

        #If the user doesn't have Python 2.7, warn them
        if interpreter != 'python2.7':
            msg = QtGui.QApplication.translate(
                "cqCodeWidget",
                "Please install Python 2.7",
                None,
                QtGui.QApplication.UnicodeUTF8)
            FreeCAD.Console.PrintError("\r\n" + msg)

        #The extra version numbers won't work on Windows
        if sys.platform.startswith('win'):
            interpreter = 'python'

        #Getting the main window will allow us to start setting things up the way we want
        mw = Gui.getMainWindow()

        #Find all of the docks that are open so we can close them (except the Python console)
        dockWidgets = mw.findChildren(QtGui.QDockWidget)

        for widget in dockWidgets:
            if widget.objectName() != "Report view":
                #Only hide the widget if it isn't already hidden
                if not widget.isHidden():
                    widget.setVisible(False)
                    self.closedWidgets.append(widget)
            else:
                widget.setVisible(True)

        #Add a new widget here that's a simple text area to begin with. It will become the CQ coding area
        cqCodeWidget = QtGui.QDockWidget("CadQuery Code View")
        cqCodeWidget.setObjectName("cqCodeView")
        mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, cqCodeWidget)

        #Set up the text area for our CQ code
        server_path = os.path.join(module_base_path, 'cq_server.py')

        #Windows needs some exra help with paths
        if sys.platform.startswith('win'):
            codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter
                                  , args=['-s', fc_lib_path, libs_dir_path])
        else:
            codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter
                                  , args=['-s', libs_dir_path])

        codePane.setObjectName("cqCodePane")

        #Add the text area to our dock widget
        cqCodeWidget.setWidget(codePane)

        #Open our introduction example
        example_path = os.path.join(module_base_path, 'Examples')
        example_path = os.path.join(example_path, 'Ex000_Introduction.py')
        ImportCQ.open(example_path)
예제 #10
0
def open(filename):
    #All of the CQGui.* calls in the Python console break after opening if we don't do this
    FreeCADGui.doCommand("import FreeCADGui as CQGui")

    # Make sure that we enforce a specific version (2.7) of the Python interpreter
    ver = hex(sys.hexversion)
    interpreter = "python%s.%s" % (ver[2], ver[4])  # => 'python2.7'

    # If the user doesn't have Python 2.7, warn them
    if interpreter != 'python2.7':
        msg = QtGui.QApplication.translate("cqCodeWidget",
                                           "Please install Python 2.7", None)
        FreeCAD.Console.PrintError(msg + "\r\n")

    # The extra version numbers won't work on Windows
    if sys.platform.startswith('win'):
        interpreter = 'python'

    # Set up so that we can import from our embedded packages
    module_base_path = module_locator.module_path()
    libs_dir_path = os.path.join(module_base_path, 'Libs')

    from pyqode.core.modes import FileWatcherMode
    from pyqode.core.modes import RightMarginMode
    from pyqode.python.widgets import PyCodeEdit

    # Make sure we get the right libs under the FreeCAD installation
    fc_base_path = os.path.dirname(os.path.dirname(module_base_path))
    fc_lib_path = os.path.join(fc_base_path, 'lib')

    #Getting the main window will allow us to find the children we need to work with
    mw = FreeCADGui.getMainWindow()

    # Grab just the file name from the path/file that's being executed
    docname = os.path.basename(filename)

    # Set up the text area for our CQ code
    server_path = os.path.join(module_base_path, 'cq_server.py')

    # Windows needs some extra help with paths
    if sys.platform.startswith('win'):
        codePane = PyCodeEdit(server_script=server_path,
                              interpreter=interpreter,
                              args=['-s', fc_lib_path, libs_dir_path])
    else:
        codePane = PyCodeEdit(server_script=server_path,
                              interpreter=interpreter,
                              args=['-s', libs_dir_path])

    # Allow easy use of an external editor
    if Settings.use_external_editor:
        codePane.modes.append(FileWatcherMode())
        codePane.modes.get(FileWatcherMode).file_reloaded.connect(AutoExecute)
        codePane.modes.get(FileWatcherMode).auto_reload = True

    # Set the margin to be at 119 characters instead of 79
    codePane.modes.get(RightMarginMode).position = Settings.max_line_length

    # Set the font size of the Python editor
    codePane.font_size = Settings.font_size

    codePane.setObjectName("cqCodePane_" +
                           os.path.splitext(os.path.basename(filename))[0])

    mdi = mw.findChild(QtGui.QMdiArea)
    # add a widget to the mdi area
    sub = mdi.addSubWindow(codePane)
    sub.setWindowTitle(docname)
    sub.setWindowIcon(QtGui.QIcon(':/icons/applications-python.svg'))
    sub.show()
    mw.update()

    #Pull the text of the CQ script file into our code pane
    codePane.file.open(filename)

    msg = QtGui.QApplication.translate("cqCodeWidget", "Opened ", None)
    FreeCAD.Console.PrintMessage(msg + filename + "\r\n")

    return
예제 #11
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(924, 971)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icons/QIdle.png"), QtGui.QIcon.Normal,
                       QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setSpacing(0)
        self.gridLayout.setObjectName("gridLayout")
        self.codeEdit = PyCodeEdit(self.centralwidget)
        self.codeEdit.setObjectName("codeEdit")
        self.gridLayout.addWidget(self.codeEdit, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.dockWidgetClassExplorer = QtWidgets.QDockWidget(MainWindow)
        self.dockWidgetClassExplorer.setObjectName("dockWidgetClassExplorer")
        self.dockWidgetContents_2 = QtWidgets.QWidget()
        self.dockWidgetContents_2.setObjectName("dockWidgetContents_2")
        self.gridLayout_3 = QtWidgets.QGridLayout(self.dockWidgetContents_2)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.classExplorer = PyOutlineTreeWidget(self.dockWidgetContents_2)
        self.classExplorer.setObjectName("classExplorer")
        self.classExplorer.headerItem().setText(0, "1")
        self.classExplorer.header().setVisible(False)
        self.gridLayout_3.addWidget(self.classExplorer, 0, 0, 1, 1)
        self.dockWidgetClassExplorer.setWidget(self.dockWidgetContents_2)
        MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(2),
                                 self.dockWidgetClassExplorer)
        self.dockWidgetProgramOutput = QtWidgets.QDockWidget(MainWindow)
        self.dockWidgetProgramOutput.setObjectName("dockWidgetProgramOutput")
        self.dockWidgetContents_3 = QtWidgets.QWidget()
        self.dockWidgetContents_3.setObjectName("dockWidgetContents_3")
        self.gridLayout_4 = QtWidgets.QGridLayout(self.dockWidgetContents_3)
        self.gridLayout_4.setObjectName("gridLayout_4")
        self.textEditPgmOutput = PyInteractiveConsole(
            self.dockWidgetContents_3)
        self.textEditPgmOutput.setObjectName("textEditPgmOutput")
        self.gridLayout_4.addWidget(self.textEditPgmOutput, 0, 0, 1, 1)
        self.dockWidgetProgramOutput.setWidget(self.dockWidgetContents_3)
        MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(8),
                                 self.dockWidgetProgramOutput)
        self.dockWidgetPyConsole = QtWidgets.QDockWidget(MainWindow)
        self.dockWidgetPyConsole.setObjectName("dockWidgetPyConsole")
        self.dockWidgetContents_4 = QtWidgets.QWidget()
        self.dockWidgetContents_4.setObjectName("dockWidgetContents_4")
        self.gridLayout_5 = QtWidgets.QGridLayout(self.dockWidgetContents_4)
        self.gridLayout_5.setObjectName("gridLayout_5")
        self.pyconsole = IPythonConsole(self.dockWidgetContents_4)
        self.pyconsole.setObjectName("pyconsole")
        self.gridLayout_5.addWidget(self.pyconsole, 0, 0, 1, 1)
        self.dockWidgetPyConsole.setWidget(self.dockWidgetContents_4)
        MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(8),
                                 self.dockWidgetPyConsole)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 924, 34))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        self.menuRecents = QtWidgets.QMenu(self.menuFile)
        self.menuRecents.setObjectName("menuRecents")
        self.menuRun = QtWidgets.QMenu(self.menubar)
        self.menuRun.setObjectName("menuRun")
        self.menuOptions = QtWidgets.QMenu(self.menubar)
        self.menuOptions.setObjectName("menuOptions")
        self.menuWindows = QtWidgets.QMenu(self.menubar)
        self.menuWindows.setObjectName("menuWindows")
        self.menuTools = QtWidgets.QMenu(self.menuWindows)
        self.menuTools.setObjectName("menuTools")
        self.menuHelp = QtWidgets.QMenu(self.menubar)
        self.menuHelp.setObjectName("menuHelp")
        self.menuEdit = QtWidgets.QMenu(self.menubar)
        self.menuEdit.setObjectName("menuEdit")
        MainWindow.setMenuBar(self.menubar)
        self.toolBarSave = QtWidgets.QToolBar(MainWindow)
        self.toolBarSave.setObjectName("toolBarSave")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBarSave)
        self.toolBarRun = QtWidgets.QToolBar(MainWindow)
        self.toolBarRun.setObjectName("toolBarRun")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBarRun)
        self.actionOpen_file = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("document-open")
        self.actionOpen_file.setIcon(icon)
        self.actionOpen_file.setObjectName("actionOpen_file")
        self.actionOpen_directory = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("folder-open")
        self.actionOpen_directory.setIcon(icon)
        self.actionOpen_directory.setObjectName("actionOpen_directory")
        self.actionSave = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("document-save")
        self.actionSave.setIcon(icon)
        self.actionSave.setObjectName("actionSave")
        self.actionSave_as = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("document-save-as")
        self.actionSave_as.setIcon(icon)
        self.actionSave_as.setObjectName("actionSave_as")
        self.actionClose = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("window-close")
        self.actionClose.setIcon(icon)
        self.actionClose.setObjectName("actionClose")
        self.actionQuit = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("exit")
        self.actionQuit.setIcon(icon)
        self.actionQuit.setObjectName("actionQuit")
        self.actionRun = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("media-playback-start")
        self.actionRun.setIcon(icon)
        self.actionRun.setObjectName("actionRun")
        self.actionConfigureRun = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("system-run")
        self.actionConfigureRun.setIcon(icon)
        self.actionConfigureRun.setObjectName("actionConfigureRun")
        self.actionConfigure_IDLE = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("preferences-system")
        self.actionConfigure_IDLE.setIcon(icon)
        self.actionConfigure_IDLE.setObjectName("actionConfigure_IDLE")
        self.actionZoom_height = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("zoom-fit-best")
        self.actionZoom_height.setIcon(icon)
        self.actionZoom_height.setObjectName("actionZoom_height")
        self.actionAbout_QIdle = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("help-about")
        self.actionAbout_QIdle.setIcon(icon)
        self.actionAbout_QIdle.setObjectName("actionAbout_QIdle")
        self.actionHelp_content = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("help-contents")
        self.actionHelp_content.setIcon(icon)
        self.actionHelp_content.setObjectName("actionHelp_content")
        self.actionPython_docs = QtWidgets.QAction(MainWindow)
        self.actionPython_docs.setObjectName("actionPython_docs")
        self.actionNew_file = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("document-new")
        self.actionNew_file.setIcon(icon)
        self.actionNew_file.setObjectName("actionNew_file")
        self.actionNew_project = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon.fromTheme("folder-new")
        self.actionNew_project.setIcon(icon)
        self.actionNew_project.setObjectName("actionNew_project")
        self.menuFile.addAction(self.actionNew_file)
        self.menuFile.addAction(self.actionOpen_file)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionNew_project)
        self.menuFile.addAction(self.actionOpen_directory)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.menuRecents.menuAction())
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionSave)
        self.menuFile.addAction(self.actionSave_as)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionClose)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionQuit)
        self.menuRun.addAction(self.actionRun)
        self.menuRun.addAction(self.actionConfigureRun)
        self.menuOptions.addAction(self.actionConfigure_IDLE)
        self.menuWindows.addAction(self.actionZoom_height)
        self.menuWindows.addSeparator()
        self.menuWindows.addAction(self.menuTools.menuAction())
        self.menuWindows.addSeparator()
        self.menuHelp.addAction(self.actionAbout_QIdle)
        self.menuHelp.addSeparator()
        self.menuHelp.addAction(self.actionHelp_content)
        self.menuHelp.addAction(self.actionPython_docs)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuEdit.menuAction())
        self.menubar.addAction(self.menuRun.menuAction())
        self.menubar.addAction(self.menuOptions.menuAction())
        self.menubar.addAction(self.menuWindows.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())
        self.toolBarSave.addAction(self.actionNew_file)
        self.toolBarSave.addAction(self.actionOpen_file)
        self.toolBarSave.addSeparator()
        self.toolBarSave.addAction(self.actionSave)
        self.toolBarSave.addAction(self.actionSave_as)
        self.toolBarRun.addAction(self.actionConfigureRun)
        self.toolBarRun.addAction(self.actionRun)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
예제 #12
0
"""
This simple example shows you how to use the pre-configured python editor.
"""
import logging
logging.basicConfig()
# optionally, set the qt api to use (in ['pyqt4', 'pyqt5', 'pyside'])
# import os; os.environ['QT_API'] = 'pyside'
import sys
from pyqode.qt import QtWidgets
from pyqode.python.backend import server
from pyqode.python.widgets import PyCodeEdit
from pyqode.python.widgets import code_edit

app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
editor = PyCodeEdit(server_script=server.__file__)
# show the PyCodeEdit module in the editor
editor.file.open(code_edit.__file__.replace('.pyc', '.py'))
window.setCentralWidget(editor)
window.show()
app.exec_()
예제 #13
0
class MainWindow(MainWindowBase, MainWindowUI):

    VIDEOS = ('front_video_file', 'eyes_video_file')

    def __init__(self, manager, parent=None):
        MainWindowBase.__init__(self, parent)

        self.manager = manager
        self.current_segment = None
        self.current_video = 0
        self.nav_hide_empty = True

        self.setupUi(self)
        self.setupConnections()

    def setupUi(self, parent):
        MainWindowUI.setupUi(self, parent)

        # content area
        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.content.setLayout(layout)

        # add video widget
        self.contentWidget = VideoWidget()
        self.content.layout().addWidget(self.contentWidget)

        self.prev_code = 'def f(img):\n    return img'
        self.te_code = PyCodeEdit()
        self.te_code.setPlainText(self.prev_code)
        self.content.layout().addWidget(self.te_code)

        # footer area
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.footer.setLayout(layout)

        self.bar_index = QScrollBar(Qt.Horizontal)
        self.bar_index.setFocusPolicy(Qt.WheelFocus)
        self.bar_index.setMinimum(0)
        self.bar_index.setSingleStep(1)
        self.bar_index.valueChanged.connect(self.indexChanged)
        layout.addWidget(self.bar_index)

        self.info = QLabel()
        layout.addWidget(self.info)

        # construct navigation tree
        self.refreshNavigation()

        # design the view
        self.treeView.header().hide()  # hide header
        self.treeView.expandToDepth(0)  # expand first level

    def setupConnections(self):

        # shortcuts
        self.sc_next = QShortcut(QKeySequence("Right"), self)
        self.sc_next.activated.connect(self.nextImage)

        self.sc_prev = QShortcut(QKeySequence("Left"), self)
        self.sc_prev.activated.connect(self.prevImage)

        self.treeView.doubleClicked.connect(self.navigation_doubleClicked)

        self.pb_video_toggle.clicked.connect(self.toggleVideo)
        self.pb_hide_toggle.clicked.connect(self.toggleHideEmpty)

    def toggleVideo(self):
        self.current_video = (self.current_video + 1) % len(MainWindow.VIDEOS)
        self.setSegment(self.current_segment)

    def toggleHideEmpty(self):
        self.nav_hide_empty = not self.nav_hide_empty
        self.refreshNavigation()

    def refreshNavigation(self):
        items = []
        for project_id in self.manager.getProjectNames():
            project = self.manager.getProject(project_id)
            p_node = NavigationNode(project.info['Name'])
            p_node.obj_data = project
            items.append(p_node)

            for r_id in sorted(p_node.obj_data.getRecordingNames()):
                print(r_id)
                recording = p_node.obj_data.getRecording(r_id)
                print(recording)

                if recording:
                    r_node = NavigationNode(r_id)
                    r_node.obj_data = recording

                    p_node.addChild(r_node)
                    for segment_id in r_node.obj_data.getSegmentIDs():
                        s_node = NavigationNode(segment_id)
                        s_node.obj_data = r_node.obj_data.getSegment(
                            segment_id)
                        r_node.addChild(s_node)

        self.treeView.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.treeView.setUniformRowHeights(True)
        self.treeView.setModel(NavigationModel(items))

    def navigation_doubleClicked(self, _):
        item = self.treeView.selectedIndexes()[0]
        obj = item.internalPointer().obj_data

        if hasattr(obj, 'segments') and obj.segments_data:
            obj = obj.segments_data[0]

        if hasattr(obj, 'eyes_video_file'):
            self.setSegment(obj)

    def applyCode(self):
        code = self.te_code.toPlainText()
        if self.prev_code != code:
            try:
                exec(code, globals(), locals())
                self.contentWidget.onImage = locals()['f']
            except Exception as e:
                print(e)

    def prevImage(self):
        self.bar_index.setValue(self.bar_index.value() - 1)

    def nextImage(self):
        self.bar_index.setValue(self.bar_index.value() + 1)

    def setVideo(self, path):
        self.contentWidget.openVideo(path)
        self.bar_index.setMaximum(self.contentWidget.video.length)

    def indexChanged(self, value):
        self.applyCode()
        video = self.contentWidget.video
        video.pos_frame = value
        self.contentWidget.updateImage()

        info_msg = []
        info_msg.append('FPS:   %s' % video.fps)
        info_msg.append('Frame: %d / %d (%.4f)' %
                        (video.pos_frame + 1, video.length, video.pos_msec))

        self.info.setText('\n'.join(info_msg))

    def setSegment(self, segment):
        try:
            self.current_segment = segment
            self.setVideo(
                getattr(self.current_segment,
                        MainWindow.VIDEOS[self.current_video]))
            self.bar_index.setValue(0)
            self.indexChanged(0)
        except:
            pass
예제 #14
0
"""
This example show you how to use the PyOuytlineTreeWidget to show the structure
of a python document.

The widget works in combination with a DocumentAnalyserMode. Such a mode must
be installed on the editor widget otherwise no data will be displayed.
"""
import sys
from pyqode.qt import QtCore, QtWidgets
from pyqode.core.api import code_edit
from pyqode.core.widgets import OutlineTreeWidget
from pyqode.python.widgets import PyCodeEdit


app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
editor = PyCodeEdit()
editor.file.open(code_edit.__file__)
window.setCentralWidget(editor)
window.resize(800, 600)
outline = OutlineTreeWidget()
outline.set_editor(editor)
dock_outline = QtWidgets.QDockWidget('Outline')
dock_outline.setWidget(outline)
window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock_outline)
window.show()
app.exec_()