Ejemplo n.º 1
0
 def __init__(self, parent):
     QtGui.QWidget.__init__(self, parent)
     
     # Make sure there is a configuration entry for this tool
     # The pyzo tool manager makes sure that there is an entry in
     # config.tools before the tool is instantiated.
     toolId = self.__class__.__name__.lower()        
     self._config = pyzo.config.tools[toolId]
     if not hasattr(self._config, 'hideTypes'):
         self._config.hideTypes = []
     
     # Create tool button
     self._up = QtGui.QToolButton(self)
     style = QtGui.qApp.style()
     self._up.setIcon( style.standardIcon(style.SP_ArrowLeft) )
     self._up.setIconSize(QtCore.QSize(16,16))
     
     # Create "path" line edit
     self._line = QtGui.QLineEdit(self)
     self._line.setReadOnly(True)
     self._line.setStyleSheet("QLineEdit { background:#ddd; }")
     self._line.setFocusPolicy(QtCore.Qt.NoFocus)
     
     # Create options menu
     self._options = QtGui.QToolButton(self)
     self._options.setIcon(pyzo.icons.filter)
     self._options.setIconSize(QtCore.QSize(16,16))
     self._options.setPopupMode(self._options.InstantPopup)
     self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
     #
     self._options._menu = QtGui.QMenu()
     self._options.setMenu(self._options._menu)
     self.onOptionsPress()  # create menu now
     
     # Create tree
     self._tree = WorkspaceTree(self)
     
     # Set layout
     layout = QtGui.QHBoxLayout()
     layout.addWidget(self._up, 0)
     layout.addWidget(self._line, 1)
     layout.addWidget(self._options, 0)
     #
     mainLayout = QtGui.QVBoxLayout(self)
     mainLayout.addLayout(layout, 0)
     mainLayout.addWidget(self._tree, 1)
     mainLayout.setSpacing(2)
     mainLayout.setContentsMargins(4,4,4,4)
     self.setLayout(mainLayout)
     
     # Bind events
     self._up.pressed.connect(self._tree._proxy.goUp)
     self._options.pressed.connect(self.onOptionsPress)
     self._options._menu.triggered.connect(self.onOptionMenuTiggered)
Ejemplo n.º 2
0
def loadIcons():
    """ loadIcons()
    Load all icons in the icon dir.
    """
    # Get directory containing the icons
    iconDir = os.path.join(pyzo.pyzoDir, "resources", "icons")

    # Construct other icons
    dummyIcon = IconArtist().finish()
    pyzo.icons = ssdf.new()
    for fname in os.listdir(iconDir):
        if fname.endswith(".png"):
            try:
                # Short and full name
                name = fname.split(".")[0]
                name = name.replace("pyzo_", "")  # discart prefix
                ffname = os.path.join(iconDir, fname)
                # Create icon
                icon = QtGui.QIcon()
                icon.addFile(ffname, QtCore.QSize(16, 16))
                # Store
                pyzo.icons[name] = icon
            except Exception as err:
                pyzo.icons[name] = dummyIcon
                print("Could not load icon %s: %s" % (fname, str(err)))
Ejemplo n.º 3
0
def loadAppIcons():
    """ loadAppIcons()
    Load the application iconsr.
    """
    # Get directory containing the icons
    appiconDir = os.path.join(pyzo.pyzoDir, "resources", "appicons")

    # Determine template for filename of the application icon-files.
    fnameT = "pyzologo{}.png"

    # Construct application icon. Include a range of resolutions. Note that
    # Qt somehow does not use the highest possible res on Linux/Gnome(?), even
    # the logo of qt-designer when alt-tabbing looks a bit ugly.
    pyzo.icon = QtGui.QIcon()
    for sze in [16, 32, 48, 64, 128, 256]:
        fname = os.path.join(appiconDir, fnameT.format(sze))
        if os.path.isfile(fname):
            pyzo.icon.addFile(fname, QtCore.QSize(sze, sze))

    # Set as application icon. This one is used as the default for all
    # windows of the application.
    QtWidgets.qApp.setWindowIcon(pyzo.icon)

    # Construct another icon to show when the current shell is busy
    artist = IconArtist(pyzo.icon)  # extracts the 16x16 version
    artist.setPenColor("#0B0")
    for x in range(11, 16):
        d = x - 11  # runs from 0 to 4
        artist.addLine(x, 6 + d, x, 15 - d)
    pm = artist.finish().pixmap(16, 16)
    #
    pyzo.iconRunning = QtGui.QIcon(pyzo.icon)
    pyzo.iconRunning.addPixmap(pm)  # Change only 16x16 icon
Ejemplo n.º 4
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # create toolbar
        self._toolbar = QtWidgets.QToolBar(self)
        self._toolbar.setMaximumHeight(26)
        self._toolbar.setIconSize(QtCore.QSize(16, 16))

        # create stack
        self._stack = QtWidgets.QStackedWidget(self)

        # Populate toolbar
        self._shellButton = ShellControl(self._toolbar, self._stack)
        self._debugmode = 0
        self._dbs = DebugStack(self._toolbar)
        #
        self._toolbar.addWidget(self._shellButton)
        self._toolbar.addSeparator()
        # self._toolbar.addWidget(self._dbc) -> delayed, see addContextMenu()

        self._interpreterhelp = InterpreterHelper(self)

        # widget layout
        layout = QtWidgets.QVBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._toolbar)
        layout.addWidget(self._stack, 0)
        layout.addWidget(self._interpreterhelp, 0)
        self.setLayout(layout)

        # make callbacks
        self._stack.currentChanged.connect(self.onCurrentChanged)

        self.showInterpreterHelper()
Ejemplo n.º 5
0
    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)

        # Create text field, checkbox, and button
        self._text = QtGui.QLineEdit(self)
        self._printBut = QtGui.QPushButton("Print", self)

        # Create options button
        self._options = QtGui.QToolButton(self)
        self._options.setIcon(pyzo.icons.wrench)
        self._options.setIconSize(QtCore.QSize(16, 16))
        self._options.setPopupMode(self._options.InstantPopup)
        self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        # Create options menu
        self._options._menu = QtGui.QMenu()
        self._options.setMenu(self._options._menu)

        # Create browser
        self._browser = QtGui.QTextBrowser(self)
        self._browser_text = initText

        # Create two sizers
        self._sizer1 = QtGui.QVBoxLayout(self)
        self._sizer2 = QtGui.QHBoxLayout()

        # Put the elements together
        self._sizer2.addWidget(self._text, 4)
        self._sizer2.addWidget(self._printBut, 0)
        self._sizer2.addWidget(self._options, 2)
        #
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._browser, 1)
        #
        self._sizer1.setSpacing(2)
        self._sizer1.setContentsMargins(4, 4, 4, 4)
        self.setLayout(self._sizer1)

        # Set config
        toolId = self.__class__.__name__.lower()
        self._config = config = pyzo.config.tools[toolId]
        #
        if not hasattr(config, 'smartNewlines'):
            config.smartNewlines = True
        if not hasattr(config, 'fontSize'):
            if sys.platform == 'darwin':
                config.fontSize = 12
            else:
                config.fontSize = 10

        # Create callbacks
        self._text.returnPressed.connect(self.queryDoc)
        self._printBut.clicked.connect(self.printDoc)
        #
        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)

        # Start
        self.setText()  # Set default text
        self.onOptionsPress()  # Fill menu
Ejemplo n.º 6
0
    def __init__(self):
        QtWidgets.QToolButton.__init__(self)

        # Init
        self.setIconSize(QtCore.QSize(*self.SIZE))
        self.setStyleSheet(
            "QToolButton{ border:none; padding:0px; margin:0px; }")
        self.setIcon(self.getCrossIcon1())
Ejemplo n.º 7
0
    def __init__(self):
        QtWidgets.QToolButton.__init__(self)

        # Init
        self.setIconSize(QtCore.QSize(*self.SIZE))
        self.setStyleSheet("QToolButton{ border: none; }")

        # Create arrow pixmaps
        self._menuarrow1 = self._createMenuArrowPixmap(0)
        self._menuarrow2 = self._createMenuArrowPixmap(70)
        self._menuarrow = self._menuarrow1

        # Variable to keep icon
        self._icon = None

        # Variable to keep track of when the mouse was pressed, so that
        # we can allow dragging as well as clicking the menu.
        self._menuPressed = False
Ejemplo n.º 8
0
    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)

        # create toolbar
        self._toolbar = QtGui.QToolBar(self)
        self._toolbar.setMaximumHeight(25)
        self._toolbar.setIconSize(QtCore.QSize(16, 16))

        # create stack
        self._stack = QtGui.QStackedWidget(self)

        # Populate toolbar
        self._shellButton = ShellControl(self._toolbar, self._stack)
        self._debugmode = 0
        self._dbs = DebugStack(self._toolbar)
        #
        self._toolbar.addWidget(self._shellButton)
        self._toolbar.addSeparator()
        # self._toolbar.addWidget(self._dbc) -> delayed, see addContextMenu()

        self._condahelp = CondaHelper(self)

        # widget layout
        layout = QtGui.QVBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._toolbar)
        layout.addWidget(self._stack, 0)
        layout.addWidget(self._condahelp, 0)
        self.setLayout(layout)

        # make callbacks
        self._stack.currentChanged.connect(self.onCurrentChanged)

        # Make shared history (shared among shells)
        if PythonHistory is None:
            self.sharedHistory = None
        else:
            self.sharedHistory = PythonHistory('shellhistory.py')

        self.showCondaHelper()
Ejemplo n.º 9
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # Make sure there is a configuration entry for this tool
        # The pyzo tool manager makes sure that there is an entry in
        # config.tools before the tool is instantiated.

        toolId = self.__class__.__name__.lower()
        self._config = pyzo.config.tools[toolId]

        # Set config
        if not hasattr(self._config, "hideTypes"):
            self._config.hideTypes = []
        #
        if not hasattr(self._config, "fontSizeTree"):
            if sys.platform == "darwin":
                self._config.fontSizeTree = 12
            else:
                self._config.fontSizeTree = 10
        if not hasattr(self._config, "fontSizeHelp"):
            if sys.platform == "darwin":
                self._config.fontSizeHelp = 12
            else:
                self._config.fontSizeHelp = 10
        #
        if not hasattr(self._config, "historyMaximum"):
            self._config.historyMaximum = 10
        # if not hasattr(self._config, "historyFreeze"):
        #     self._config.historyFreeze = 0
        if not hasattr(self._config, "historyClearOnStartup"):
            self._config.historyClearOnStartup = 1

        style = QtWidgets.qApp.style()
        #
        self.initText = "<p>{}</p>".format(
            "Click an item in the list for Help information.")

        # Create empty label
        self._empty = QtWidgets.QLabel(self)
        self._empty.setText("")

        # ----- Layout 1 -----

        # Create Home tool button
        self._home = QtWidgets.QToolButton(self)
        self._home.setIcon(style.standardIcon(style.SP_ArrowUp))
        self._home.setIconSize(QtCore.QSize(16, 16))
        self._home.setToolTip("Home - return to the beginninig.")

        # Create Refresh tool button
        self._refresh = QtWidgets.QToolButton(self)
        self._refresh.setIcon(style.standardIcon(style.SP_BrowserReload))
        self._refresh.setIconSize(QtCore.QSize(16, 16))
        self._refresh.setToolTip("Reload the current command.")

        # Create Go back tool button
        self.back = QtWidgets.QToolButton(self)
        self.back.setIcon(style.standardIcon(style.SP_ArrowLeft))
        self.back.setIconSize(QtCore.QSize(16, 16))
        self.back.setToolTip("Go back to the previous command.")

        # Create "path" line edit
        self._line = QtWidgets.QLineEdit(self)
        self._line.setReadOnly(True)
        self._line.setStyleSheet("QLineEdit { background:#ddd; }")
        self._line.setFocusPolicy(QtCore.Qt.NoFocus)

        # Create selection tool button
        self._selection = QtWidgets.QToolButton(self)
        self._selection.setIcon(pyzo.icons.layout)
        self._selection.setIconSize(QtCore.QSize(16, 16))
        self._selection.setToolTip("Get selected  objects in the document.")
        self._selection.setEnabled(False)

        # Create "insert_code" button
        self._insert_code = QtWidgets.QToolButton(self)
        self._insert_code.setIcon(
            style.standardIcon(style.SP_FileDialogDetailedView))
        self._insert_code.setToolTip(
            "Insert code in the script at the cursor position")

        # ----- Layout 2 -----

        # Create element_index combo box
        self._element_index = QtWidgets.QComboBox(self)
        self._element_index.setToolTip(
            "Set the argument for getByIndex method.")
        self._element_index.setEnabled(False)

        # Create element_names combo box
        self._element_names = QtWidgets.QComboBox(self)
        self._element_names.setToolTip("Get by name")
        self._element_names.setEnabled(False)

        # Create enumerate combo box
        self._enumerate_index = QtWidgets.QComboBox(self)
        self._enumerate_index.setToolTip(
            "Objects enumerated by createEnumeration method")
        self._enumerate_index.setEnabled(False)

        # Create history combo box
        self._history = QtWidgets.QComboBox(self)
        self._history.setToolTip("Show the command history")
        self._history.setEnabled(True)

        # Create options menu
        self._options = QtWidgets.QToolButton(self)
        self._options.setToolTip("Tool configuration.")
        self._options.setIcon(pyzo.icons.filter)
        self._options.setIconSize(QtCore.QSize(16, 16))
        self._options.setPopupMode(self._options.InstantPopup)
        self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        # main menu
        self._options._menu = pyzo.core.menu.Menu(
            self, "Main menu")  # QtWidgets.QMenu()
        # submenus
        self._show_hide_menu = pyzo.core.menu.Menu(None, "Show/Hide")
        #
        self._font_size_menu = pyzo.core.menu.Menu(None, "Font size")
        self._font_size_tree_menu = pyzo.core.menu.Menu(None, "Workspace")
        self._font_size_help_menu = pyzo.core.menu.Menu(None, "Help")
        #
        self._history_menu = pyzo.core.menu.Menu(None, "History")

        # create menu
        self._options.setMenu(self._options._menu)
        self.onOptionsPress()

        # Show/hide Help button
        self._btn_toggle = QtWidgets.QToolButton(self)
        self._btn_toggle.setToolTip("Show/hide help")
        self._btn_toggle.setIcon(style.standardIcon(style.SP_DialogHelpButton))
        self._btn_toggle.setIconSize(QtCore.QSize(16, 16))
        self._btn_toggle.setCheckable(True)
        self._btn_toggle.setChecked(False)

        # ----- Layout 3 -----

        # Create tree
        self._tree = PyUNOWorkspaceTree(self)

        # Create message for when tree is empty
        self._initText = QtWidgets.QLabel(
            pyzo.translate(
                "pyzoWorkspace",
                """Lists the variables in the current shell's namespace.
        Currently, there are none. Some of them may be hidden because of the filters you configured.""",
            ),
            self,
        )

        self._initText.setVisible(False)
        self._initText.setWordWrap(True)

        # ----- Layout 4 -----
        # Create description widget

        self._description = QtWidgets.QTextBrowser(self)
        self._description.setText(self.initText)

        # ----- Layout 5 -----

        # Create counter
        self._desc_counter = QtWidgets.QLabel(self)
        self._desc_counter.setText("0")
        # Label
        self._desc_of = QtWidgets.QLabel(self)
        self._desc_of.setText(" of ")
        # Create all items counter
        self._desc_all_items = QtWidgets.QLabel(self)
        self._desc_all_items.setText("0")
        #
        self._search_line = QtWidgets.QLineEdit(self)
        self._search_line.setReadOnly(False)
        self._search_line.setToolTip("Search")
        self._search_line.setPlaceholderText("UNO API Search...")
        #
        self._match = QtWidgets.QCheckBox(self)
        self._match.setText("Match")
        self._match.setChecked(True)
        self._match.setToolTip("Match")
        #
        self._search = QtWidgets.QToolButton(self)
        self._search.setIconSize(QtCore.QSize(16, 16))
        self._search.setText("Search")
        self._search.setToolTip("Search")
        #
        self._clear = QtWidgets.QToolButton(self)
        self._clear.setIconSize(QtCore.QSize(16, 16))
        self._clear.setText("Clear")
        self._clear.setToolTip("Clear")

        # ------ Set layouts

        # Layout 1: Object and insert code layout
        layout_1 = QtWidgets.QHBoxLayout()
        layout_1.addWidget(self._home, 0)
        layout_1.addWidget(self._refresh, 0)
        layout_1.addWidget(self.back, 0)
        layout_1.addWidget(self._line, 1)
        layout_1.addWidget(self._selection, 0)
        layout_1.addWidget(self._insert_code, 0)

        # Layout 2: Display, arguments, history and option layout
        layout_2 = QtWidgets.QHBoxLayout()
        layout_2.addWidget(self._element_index, 0)
        layout_2.addWidget(self._element_names, 0)
        layout_2.addWidget(self._enumerate_index, 0)
        layout_2.addWidget(self._history, 1)
        layout_2.addWidget(self._options, 0)
        layout_2.addWidget(self._btn_toggle, 0)

        # Layout 3: Tree layout
        layout_3 = QtWidgets.QVBoxLayout()
        layout_3.addWidget(self._tree, 0)

        # Layout 5: Hidden help layout
        self._description_widget = QtWidgets.QWidget(self)
        self._description_widget.setVisible(False)

        layout_5 = QtWidgets.QVBoxLayout()
        layout_5.setSpacing(0)
        layout_5.setContentsMargins(0, 0, 0, 0)

        # Layout 6: Search layout
        layout_6 = QtWidgets.QHBoxLayout()
        layout_6.addWidget(self._desc_counter, 0)
        layout_6.addWidget(self._desc_of, 0)
        layout_6.addWidget(self._desc_all_items, 0)
        layout_6.addWidget(self._empty, 0)
        layout_6.addWidget(self._search_line, 0)
        layout_6.addWidget(self._empty, 0)
        layout_6.addWidget(self._match, 0)
        layout_6.addWidget(self._search, 0)
        layout_6.addWidget(self._clear, 0)

        # Layout 7: Help description layout
        layout_7 = QtWidgets.QVBoxLayout()
        layout_7.addWidget(self._description, 0)
        layout_5.addLayout(layout_7, 0)
        layout_5.addLayout(layout_6, 0)
        layout_7.setSpacing(0)
        layout_7.setContentsMargins(0, 0, 0, 0)

        # Main Layout
        mainLayout = QtWidgets.QVBoxLayout(self)
        mainLayout.addLayout(layout_1, 0)
        mainLayout.addLayout(layout_2, 0)
        mainLayout.addLayout(layout_3, 0)
        # add hidden widget
        mainLayout.addWidget(self._description_widget)
        self._description_widget.setLayout(layout_5)

        # set margins
        mainLayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(mainLayout)

        # ------ Bind events
        self._home.pressed.connect(self.onHomePress)
        self._refresh.pressed.connect(self.onRefreshPress)
        self.back.pressed.connect(self.onBackPress)
        #
        self._selection.pressed.connect(self.onCurrentSelectionPress)
        self._insert_code.pressed.connect(self.onInsertCodeInEditorPress)
        #
        self._element_names.activated[str].connect(self.onElementNamesPress)
        self._element_index.activated[str].connect(self.onElementIndexPress)
        self._enumerate_index.activated[str].connect(
            self.onEnumerateIndexPress)
        self._history.activated[str].connect(self.onHistoryPress)
        #
        self._options.pressed.connect(self.onOptionsPress)
        #
        self._show_hide_menu.triggered.connect(self.onShowHideMenuTiggered)
        self._font_size_help_menu.triggered.connect(
            self.onFontHelpOptionMenuTiggered)
        self._font_size_tree_menu.triggered.connect(
            self.onFontTreeOptionMenuTiggered)
        self._history_menu.triggered.connect(self.onHistoryOptionMenuTiggered)
        #
        self._btn_toggle.toggled.connect(self.onHelpTogglePress)
        #
        self._search.pressed.connect(self.onSearchPress)
        self._clear.pressed.connect(self.onClearHelpPress)

        # Create json result file
        createResultFile(),

        # Load History
        if self._config.historyClearOnStartup:
            #self._config.historyFreeze = 0
            createHistoryFile()
        self.loadHistory()
Ejemplo n.º 10
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # Make sure there is a configuration entry for this tool
        # The pyzo tool manager makes sure that there is an entry in
        # config.tools before the tool is instantiated.
        toolId = self.__class__.__name__.lower()
        self._config = pyzo.config.tools[toolId]
        if not hasattr(self._config, 'showTypes'):
            self._config.showTypes = ['class', 'def', 'cell', 'todo']
        if not hasattr(self._config, 'level'):
            self._config.level = 2

        # Create icon for slider
        self._sliderIcon = QtWidgets.QToolButton(self)
        self._sliderIcon.setIcon(pyzo.icons.text_align_right)
        self._sliderIcon.setIconSize(QtCore.QSize(16, 16))
        self._sliderIcon.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")

        # Create slider
        self._slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
        self._slider.setTickPosition(QtWidgets.QSlider.TicksBelow)
        self._slider.setSingleStep(1)
        self._slider.setPageStep(1)
        self._slider.setRange(1, 9)
        self._slider.setValue(self._config.level)
        self._slider.valueChanged.connect(self.updateStructure)

        # Create options button
        #self._options = QtWidgets.QPushButton(self)
        #self._options.setText('Options'))
        #self._options.setToolTip("What elements to show.")
        self._options = QtWidgets.QToolButton(self)
        self._options.setIcon(pyzo.icons.filter)
        self._options.setIconSize(QtCore.QSize(16, 16))
        self._options.setPopupMode(self._options.InstantPopup)
        self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        # Create options menu
        self._options._menu = QtWidgets.QMenu()
        self._options.setMenu(self._options._menu)

        # Create tree widget
        self._tree = QtWidgets.QTreeWidget(self)
        self._tree.setHeaderHidden(True)
        self._tree.itemCollapsed.connect(self.updateStructure)  # keep expanded
        self._tree.itemClicked.connect(self.onItemClick)

        # Create two sizers
        self._sizer1 = QtWidgets.QVBoxLayout(self)
        self._sizer2 = QtWidgets.QHBoxLayout()
        self._sizer1.setSpacing(2)
        self._sizer1.setContentsMargins(4, 4, 4, 4)

        # Set layout
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._tree, 1)
        self._sizer2.addWidget(self._sliderIcon, 0)
        self._sizer2.addWidget(self._slider, 4)
        self._sizer2.addStretch(1)
        self._sizer2.addWidget(self._options, 2)
        #
        self.setLayout(self._sizer1)

        # Init current-file name
        self._currentEditorId = 0

        # Bind to events
        pyzo.editors.currentChanged.connect(self.onEditorsCurrentChanged)
        pyzo.editors.parserDone.connect(self.updateStructure)

        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)

        # Start
        # When the tool is loaded, the editorStack is already done loading
        # all previous files and selected the appropriate file.
        self.onOptionsPress()  # Create menu now
        self.onEditorsCurrentChanged()
Ejemplo n.º 11
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # Make sure there is a configuration entry for this tool
        # The pyzo tool manager makes sure that there is an entry in
        # config.tools before the tool is instantiated.
        toolId = self.__class__.__name__.lower()
        self._config = pyzo.config.tools[toolId]
        if not hasattr(self._config, "showTypes"):
            self._config.showTypes = ["class", "def", "cell", "todo"]
        if not hasattr(self._config, "level"):
            self._config.level = 2

        # Keep track of clicks so we can "go back"
        self._nav = {}  # editor-id -> Navigation object

        # Keep track of sorting order
        self._sort_order = None

        # Create buttons for navigation
        self._navbut_back = QtWidgets.QToolButton(self)
        self._navbut_back.setIcon(pyzo.icons.arrow_left)
        self._navbut_back.setIconSize(QtCore.QSize(16, 16))
        self._navbut_back.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")
        self._navbut_back.clicked.connect(self.onNavBack)
        #
        self._navbut_forward = QtWidgets.QToolButton(self)
        self._navbut_forward.setIcon(pyzo.icons.arrow_right)
        self._navbut_forward.setIconSize(QtCore.QSize(16, 16))
        self._navbut_forward.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")
        self._navbut_forward.clicked.connect(self.onNavForward)

        # Create button for sorting
        self._sortbut = QtWidgets.QToolButton(self)
        self._sortbut.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self._sortbut.setArrowType(QtCore.Qt.DownArrow)
        self._sortbut.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")
        self._sortbut.setText("A-z")
        self._sortbut.setToolTip("Sorted")
        self._sortbut.clicked.connect(self.onSortPress)

        # Create button for reload
        self._reload = QtWidgets.QToolButton(self)
        self._reload.setIcon(pyzo.icons.arrow_refresh)
        self._reload.setToolTip("Not sorted")
        self._reload.clicked.connect(self.onReloadPress)

        # # Create icon for slider
        # self._sliderIcon = QtWidgets.QToolButton(self)
        # self._sliderIcon.setIcon(pyzo.icons.text_align_right)
        # self._sliderIcon.setIconSize(QtCore.QSize(16,16))
        # self._sliderIcon.setStyleSheet("QToolButton { border: none; padding: 0px; }")

        # Create slider
        self._slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
        self._slider.setTickPosition(QtWidgets.QSlider.TicksBelow)
        self._slider.setSingleStep(1)
        self._slider.setPageStep(1)
        self._slider.setRange(1, 5)
        self._slider.setValue(self._config.level)
        self._slider.valueChanged.connect(self.updateStructure)

        # Create options button
        # self._options = QtWidgets.QPushButton(self)
        # self._options.setText('Options'))
        # self._options.setToolTip("What elements to show.")
        self._options = QtWidgets.QToolButton(self)
        self._options.setIcon(pyzo.icons.filter)
        self._options.setIconSize(QtCore.QSize(16, 16))
        self._options.setPopupMode(self._options.InstantPopup)
        self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        # Create options menu
        self._options._menu = QtWidgets.QMenu()
        self._options.setMenu(self._options._menu)

        # Create tree widget
        self._tree = QtWidgets.QTreeWidget(self)
        self._tree.setHeaderHidden(True)
        self._tree.setSortingEnabled(False)
        self._tree.itemCollapsed.connect(self.updateStructure)  # keep expanded
        self._tree.itemClicked.connect(self.onItemClick)
        # set widget stye
        background = self.getThemeItem(item="editor.text")
        textcolor = self.getThemeItem(item="syntax.identifier")
        styleKeys = ["background-color", "color"]
        styleValues = [background["back"], textcolor["fore"]]
        self.setWidgetStyleSheet(self._tree, styleKeys, styleValues)

        # Create two sizers
        self._sizer1 = QtWidgets.QVBoxLayout(self)
        self._sizer2 = QtWidgets.QHBoxLayout()
        self._sizer1.setSpacing(2)
        self._sizer1.setContentsMargins(0, 0, 0, 0)

        # Set layout
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._tree, 1)
        # self._sizer2.addWidget(self._sliderIcon, 0)
        self._sizer2.addWidget(self._reload, 0)
        self._sizer2.addWidget(self._sortbut, 0)
        self._sizer2.addWidget(self._navbut_back, 0)
        self._sizer2.addWidget(self._navbut_forward, 0)
        self._sizer2.addStretch(1)
        self._sizer2.addWidget(self._slider, 6)
        self._sizer2.addStretch(1)
        self._sizer2.addWidget(self._options, 0)
        #
        self.setLayout(self._sizer1)

        # Init current-file name
        self._currentEditorId = 0

        # Bind to events
        pyzo.editors.currentChanged.connect(self.onEditorsCurrentChanged)
        pyzo.editors.parserDone.connect(self.updateStructure)

        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)

        # Start
        # When the tool is loaded, the editorStack is already done loading
        # all previous files and selected the appropriate file.
        self.onOptionsPress()  # Create menu now
        self.onEditorsCurrentChanged()
Ejemplo n.º 12
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # Make sure there is a configuration entry for this tool
        # The pyzo tool manager makes sure that there is an entry in
        # config.tools before the tool is instantiated.
        toolId = self.__class__.__name__.lower()
        self._config = pyzo.config.tools[toolId]
        if not hasattr(self._config, 'hideTypes'):
            self._config.hideTypes = []
        # <kludge 2>
        # configuring the typeTranslation dictionary
        if not hasattr(self._config, 'typeTranslation'):
            # to prevent the exception to be raised, one could init to :
            # {"method": "function", "function": "function", "type": "type", "private": "private", "module": "module"}
            self._config.typeTranslation = {}
        # Defaults
        self._config.typeTranslation['method'] = 'function'
        self._config.typeTranslation['builtin_function_or_method'] = 'function'
        # <kludge 2>

        # Create tool button
        self._up = QtWidgets.QToolButton(self)
        style = QtWidgets.qApp.style()
        self._up.setIcon(style.standardIcon(style.SP_ArrowLeft))
        self._up.setIconSize(QtCore.QSize(16, 16))

        # Create "path" line edit
        self._line = QtWidgets.QLineEdit(self)
        self._line.setReadOnly(True)
        self._line.setStyleSheet("QLineEdit { background:#ddd; }")
        self._line.setFocusPolicy(QtCore.Qt.NoFocus)

        # Create options menu
        self._options = QtWidgets.QToolButton(self)
        self._options.setIcon(pyzo.icons.filter)
        self._options.setIconSize(QtCore.QSize(16, 16))
        self._options.setPopupMode(self._options.InstantPopup)
        self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        #
        self._options._menu = QtWidgets.QMenu()
        self._options.setMenu(self._options._menu)
        self.onOptionsPress()  # create menu now

        # Create tree
        self._tree = WorkspaceTree(self)

        # Create message for when tree is empty
        self._initText = QtWidgets.QLabel(
            pyzo.translate(
                "pyzoWorkspace",
                """Lists the variables in the current shell's namespace.

Currently, there are none. Some of them may be hidden because of the filters you configured."""
            ), self)
        self._initText.setVisible(False)
        self._initText.setWordWrap(True)

        # Set layout
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self._up, 0)
        layout.addWidget(self._line, 1)
        layout.addWidget(self._options, 0)
        #
        mainLayout = QtWidgets.QVBoxLayout(self)
        mainLayout.addLayout(layout, 0)
        mainLayout.addWidget(self._initText, 1)
        mainLayout.addWidget(self._tree, 2)
        mainLayout.setSpacing(2)
        # set margins
        margin = pyzo.config.view.widgetMargin
        mainLayout.setContentsMargins(margin, margin, margin, margin)
        self.setLayout(mainLayout)

        # Bind events
        self._up.pressed.connect(self._tree._proxy.goUp)
        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)
Ejemplo n.º 13
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # Make sure there is a configuration entry for this tool
        # The pyzo tool manager makes sure that there is an entry in
        # config.tools before the tool is instantiated.

        tool_id = self.__class__.__name__.lower()
        self._config = pyzo.config.tools[tool_id]
        if not hasattr(self._config, "fontSize"):
            if sys.platform == "darwin":
                self._config.fontSize = 12
            else:
                self._config.fontSize = 10

        # Style
        theme = pyzo.themes[pyzo.config.settings.theme.lower()]["data"]
        background_style = theme["editor.text"].split(",")
        background = background_style[1].split(":")[1]
        textcolor_style = theme["syntax.identifier"].split(",")
        textcolor = textcolor_style[0].split(":")[1]

        # Keep track of linter output
        self.output = ""

        # Folder for linter output file
        self.output_folder = os.path.join(pyzo.appDataDir, "tools",
                                          "pyzoLinter")

        self.process = None
        self.locale_codec = pyzo.QtCore.QTextCodec.codecForLocale()

        self.cur_dir_path = ""

        # Create button for parsing scope
        self._reload = QtWidgets.QToolButton(self)
        self._reload.setIcon(pyzo.icons.arrow_refresh)
        self._reload.setToolTip("Parse")
        # event
        self._reload.clicked.connect(self.start)

        # Create combo box Scope
        scope_list = ["Current document", "Current document directory"]
        self._scope = QtWidgets.QComboBox(self)
        self._scope.setToolTip("Get by index")
        self._scope.addItems(scope_list)

        # Create font options menu
        self._font_options = QtWidgets.QToolButton(self)
        self._font_options.setIcon(pyzo.icons.wrench)
        self._font_options.setIconSize(QtCore.QSize(16, 16))
        self._font_options.setPopupMode(self._font_options.InstantPopup)
        self._font_options.setToolButtonStyle(
            QtCore.Qt.ToolButtonTextBesideIcon)
        self._font_options._menu = QtWidgets.QMenu()
        self._font_options.setMenu(self._font_options._menu)
        self.on_font_options_press()  # create menu now
        # event
        self._font_options.pressed.connect(self.on_font_options_press)
        self._font_options._menu.triggered.connect(
            self.on_font_option_menu_tiggered)

        # Create button for opening output file in the editor
        self._open_file = QtWidgets.QToolButton(self)
        self._open_file.setIcon(pyzo.icons.page_white_text)
        self._open_file.setIconSize(QtCore.QSize(16, 16))
        self._open_file.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")
        self._open_file.setToolTip("Open output file in the editor")
        # event
        self._open_file.clicked.connect(self.on_open_output_file)

        # Ratings label
        self._ratings = QtWidgets.QLabel(self)
        self._ratings.setText("")
        self._ratings.setAlignment(QtCore.Qt.AlignCenter)
        style_sheet = "QLabel{color: black;background-color: #FFFFE0;font : bold;}"
        self._ratings.setStyleSheet(style_sheet)

        # Create radio box All
        self._all = QtWidgets.QRadioButton(self)
        self._all.setText(ALL)
        self._all.setChecked(True)
        self._all.setToolTip(ALL)

        # Create radio box Convention
        self._convention = QtWidgets.QRadioButton(self)
        self._convention.setText(CONVENTION)
        self._convention.setToolTip(CONVENTION)

        # Create radio box Refactor
        self._refactor = QtWidgets.QRadioButton(self)
        self._refactor.setText(REFACTOR)
        self._refactor.setToolTip(REFACTOR)

        # Create radio box Warning
        self._warning = QtWidgets.QRadioButton(self)
        self._warning.setText(WARNING)
        self._warning.setToolTip(WARNING)

        # Create radio box Error
        self._error = QtWidgets.QRadioButton(self)
        self._error.setText(ERROR)
        self._error.setToolTip(ERROR)

        # Radio box event
        self._all.toggled.connect(
            lambda: self.on_radio_change_state(self._all))
        self._convention.toggled.connect(
            lambda: self.on_radio_change_state(self._convention))
        self._refactor.toggled.connect(
            lambda: self.on_radio_change_state(self._refactor))
        self._warning.toggled.connect(
            lambda: self.on_radio_change_state(self._warning))
        self._error.toggled.connect(
            lambda: self.on_radio_change_state(self._error))

        # Create tree widget
        self._tree = QtWidgets.QTreeWidget(self)
        self._tree.setColumnCount(5)
        self._tree.setHeaderLabels(
            ["Description", "File", "Code", "Line", "Column"])
        self._tree.setColumnWidth(0, 400)
        self._tree.setColumnWidth(1, 80)
        self._tree.setHeaderHidden(False)
        self._tree.setSortingEnabled(True)
        self._tree.sortItems(1, QtCore.Qt.AscendingOrder)
        self._tree.sortItems(2, QtCore.Qt.AscendingOrder)
        self._tree.setRootIsDecorated(False)
        # style
        # set widget stye
        background = self.get_theme_item(item="editor.text")
        textcolor = self.get_theme_item(item="syntax.identifier")
        style_keys = ["background-color", "color"]
        style_values = [background["back"], textcolor["fore"]]
        self.set_widget_style_sheet(self._tree, style_keys, style_values)
        # event
        self._tree.clicked.connect(self.on_item_clicked)

        # Create two sizers
        self._sizer1 = QtWidgets.QVBoxLayout(self)
        self._sizer2 = QtWidgets.QHBoxLayout()
        self._sizer4 = QtWidgets.QHBoxLayout()
        #
        self._sizer1.setSpacing(2)
        self._sizer1.setContentsMargins(0, 0, 0, 0)

        # Set layout
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addLayout(self._sizer4, 0)
        self._sizer1.addWidget(self._tree, 1)
        #
        self._sizer2.addWidget(self._reload, 0)
        self._sizer2.addWidget(self._scope, 0)
        self._sizer2.addWidget(self._ratings, 0)
        self._sizer2.addWidget(self._font_options, 0)
        #
        self._sizer4.addWidget(self._all, 0)
        self._sizer4.addWidget(self._convention, 0)
        self._sizer4.addWidget(self._refactor, 0)
        self._sizer4.addWidget(self._warning, 0)
        self._sizer4.addWidget(self._error, 0)
        self._sizer4.addWidget(self._open_file, 0)
        #
        self.setLayout(self._sizer1)
Ejemplo n.º 14
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)
        # Make sure there is a configuration entry for this tool
        # The pyzo tool manager makes sure that there is an entry in
        # config.tools before the tool is instantiated.
        # toolId = self.__class__.__name__.lower()
        # self._config = pyzo.config.tools[toolId]
        # if not hasattr(self._config, 'showTypes'):
        #     self._config.showTypes = ['class', 'def', 'cell', 'todo']
        # if not hasattr(self._config, 'level'):
        #     self._config.level = 2

        # Keep track of sorting order
        self._sort_order = None

        # Snippet folder
        self.snippet_folder = os.path.join(pyzo.appDataDir, "tools",
                                           "pyzoSnippetManager", "snippets")

        # Create button for reload
        self._reload = QtWidgets.QToolButton(self)
        self._reload.setIcon(pyzo.icons.arrow_refresh)
        self._reload.setToolTip("Reload")
        # event
        self._reload.clicked.connect(self.onReloadPress)

        # Create button for sorting
        self._sortbut = QtWidgets.QToolButton(self)
        self._sortbut.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self._sortbut.setArrowType(QtCore.Qt.DownArrow)
        self._sortbut.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")
        self._sortbut.setText("A-z")
        self._sortbut.setToolTip("Sorted")
        # event
        self._sortbut.clicked.connect(self.onSortPress)

        # Create button ofor opening snippet file in the editor
        self._open_file = QtWidgets.QToolButton(self)
        self._open_file.setIcon(pyzo.icons.page_white_text)
        self._open_file.setIconSize(QtCore.QSize(16, 16))
        self._open_file.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")
        self._open_file.setToolTip("Open snippet file")
        # event
        self._open_file.clicked.connect(self.onOpenFile)

        # Create options button
        # self._options = QtWidgets.QToolButton(self)
        # self._options.setIcon(pyzo.icons.filter)
        # self._options.setIconSize(QtCore.QSize(16,16))
        # self._options.setPopupMode(self._options.InstantPopup)
        # self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        # Create options menu
        # self._options._menu = QtWidgets.QMenu()
        # self._options.setMenu(self._options._menu)

        # Create tree widget
        self._tree = QtWidgets.QTreeWidget(self)
        self._tree.setColumnCount(2)
        self._tree.setHeaderLabels(["description", "prefix"])
        self._tree.setColumnWidth(0, 350)
        self._tree.setHeaderHidden(True)
        self._tree.setSortingEnabled(True)
        self._tree.sortItems(0, QtCore.Qt.AscendingOrder)
        # style
        self.setWidgetTextStyle(self._tree)

        # Create two sizers
        self._sizer1 = QtWidgets.QVBoxLayout(self)
        self._sizer2 = QtWidgets.QHBoxLayout()
        self._sizer1.setSpacing(2)
        self._sizer1.setContentsMargins(0, 0, 0, 0)

        # Set layout
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._tree, 1)
        # self._sizer2.addWidget(self._sliderIcon, 0)
        self._sizer2.addWidget(self._reload, 0)
        self._sizer2.addWidget(self._sortbut, 0)
        self._sizer2.addStretch(1)
        self._sizer2.addWidget(self._open_file, 0)
        #
        self.setLayout(self._sizer1)

        # Init current-file name
        self._currentEditorId = 0

        self.fillTree()

        # Bind to events
        self._tree.clicked.connect(self.onItemClicked)
Ejemplo n.º 15
0
    def __init__(self, parent):
        QtWidgets.QFrame.__init__(self, parent)

        # Init config
        toolId = self.__class__.__name__.lower()
        self._config = pyzo.config.tools[toolId]
        if not hasattr(self._config, 'zoomFactor'):
            self._config.zoomFactor = 1.0
        if not hasattr(self._config, 'bookMarks'):
            self._config.bookMarks = []
        for item in default_bookmarks:
            if item not in self._config.bookMarks:
                self._config.bookMarks.append(item)

        # Get style object (for icons)
        style = QtWidgets.QApplication.style()

        # Create some buttons
        self._back = QtWidgets.QToolButton(self)
        self._back.setIcon(style.standardIcon(style.SP_ArrowBack))
        self._back.setIconSize(QtCore.QSize(16, 16))
        #
        self._forward = QtWidgets.QToolButton(self)
        self._forward.setIcon(style.standardIcon(style.SP_ArrowForward))
        self._forward.setIconSize(QtCore.QSize(16, 16))

        # Create address bar
        #self._address = QtWidgets.QLineEdit(self)
        self._address = QtWidgets.QComboBox(self)
        self._address.setEditable(True)
        self._address.setInsertPolicy(self._address.NoInsert)
        #
        for a in self._config.bookMarks:
            self._address.addItem(a)
        self._address.setEditText('')

        # Create web view
        if imported_qtwebkit:
            self._view = QtWebKit.QWebView(self)
        else:
            self._view = WebView(self)
        #
#         self._view.setZoomFactor(self._config.zoomFactor)
#         settings = self._view.settings()
#         settings.setAttribute(settings.JavascriptEnabled, True)
#         settings.setAttribute(settings.PluginsEnabled, True)

# Layout
        self._sizer1 = QtWidgets.QVBoxLayout(self)
        self._sizer2 = QtWidgets.QHBoxLayout()
        #
        self._sizer2.addWidget(self._back, 0)
        self._sizer2.addWidget(self._forward, 0)
        self._sizer2.addWidget(self._address, 1)
        #
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._view, 1)
        #
        self._sizer1.setSpacing(2)
        self.setLayout(self._sizer1)

        # Bind signals
        self._back.clicked.connect(self.onBack)
        self._forward.clicked.connect(self.onForward)
        self._address.lineEdit().returnPressed.connect(self.go)
        self._address.activated.connect(self.go)
        self._view.loadFinished.connect(self.onLoadEnd)
        self._view.loadStarted.connect(self.onLoadStart)

        # Start
        self._view.show()
        self.go('http://docs.python.org')
Ejemplo n.º 16
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # Create text field, checkbox, and button
        self._text = QtWidgets.QLineEdit(self)
        self._printBut = QtWidgets.QPushButton("Print", self)

        style = QtWidgets.qApp.style()

        self._backBut = QtWidgets.QToolButton(self)
        self._backBut.setIcon(style.standardIcon(style.SP_ArrowLeft))
        self._backBut.setIconSize(QtCore.QSize(16, 16))
        self._backBut.setPopupMode(self._backBut.DelayedPopup)
        self._backBut.setMenu(
            PyzoInteractiveHelpHistoryMenu("Backward menu", self, False))

        self._forwBut = QtWidgets.QToolButton(self)
        self._forwBut.setIcon(style.standardIcon(style.SP_ArrowRight))
        self._forwBut.setIconSize(QtCore.QSize(16, 16))
        self._forwBut.setPopupMode(self._forwBut.DelayedPopup)
        self._forwBut.setMenu(
            PyzoInteractiveHelpHistoryMenu("Forward menu", self, True))

        # Create options button
        self._options = QtWidgets.QToolButton(self)
        self._options.setIcon(pyzo.icons.wrench)
        self._options.setIconSize(QtCore.QSize(16, 16))
        self._options.setPopupMode(self._options.InstantPopup)
        self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        # Create options menu
        self._options._menu = QtWidgets.QMenu()
        self._options.setMenu(self._options._menu)

        # Create browser
        self._browser = QtWidgets.QTextBrowser(self)
        self._browser_text = initText
        self._browser.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self._browser.customContextMenuRequested.connect(self.showMenu)

        # Create two sizers
        self._sizer1 = QtWidgets.QVBoxLayout(self)
        self._sizer2 = QtWidgets.QHBoxLayout()

        # Put the elements together
        self._sizer2.addWidget(self._backBut, 1)
        self._sizer2.addWidget(self._forwBut, 2)
        self._sizer2.addWidget(self._text, 4)
        self._sizer2.addWidget(self._printBut, 0)
        self._sizer2.addWidget(self._options, 3)
        #
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._browser, 1)
        #
        self._sizer1.setSpacing(2)
        # set margins
        margin = pyzo.config.view.widgetMargin
        self._sizer1.setContentsMargins(margin, margin, margin, margin)

        self.setLayout(self._sizer1)

        # Set config
        toolId = self.__class__.__name__.lower()
        self._config = config = pyzo.config.tools[toolId]
        #
        if not hasattr(config, "smartNewlines"):
            config.smartNewlines = True
        if not hasattr(config, "fontSize"):
            if sys.platform == "darwin":
                config.fontSize = 12
            else:
                config.fontSize = 10

        # Create callbacks
        self._text.returnPressed.connect(self.queryDoc)
        self._printBut.clicked.connect(self.printDoc)
        self._backBut.clicked.connect(self.goBack)
        self._forwBut.clicked.connect(self.goForward)
        #
        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)

        # Start
        self._history = []
        self._histindex = 0
        self.setText()  # Set default text
        self.onOptionsPress()  # Fill menu
Ejemplo n.º 17
0
    def __init__(self, *args):
        QtWidgets.QToolButton.__init__(self, *args)

        # Init
        self.setIconSize(QtCore.QSize(*self.SIZE))
        self.setStyleSheet("QToolButton{ border: none; }")
Ejemplo n.º 18
0
    def __init__(self, *args):
        QtGui.QFrame.__init__(self, *args)

        self.setFocusPolicy(QtCore.Qt.ClickFocus)

        # init layout
        layout = QtGui.QHBoxLayout(self)
        layout.setSpacing(0)
        self.setLayout(layout)

        # Create some widgets first to realize a correct tab order
        self._hidebut = QtGui.QToolButton(self)
        self._findText = QtGui.QLineEdit(self)
        self._replaceText = QtGui.QLineEdit(self)

        if True:
            # Create sub layouts
            vsubLayout = QtGui.QVBoxLayout()
            vsubLayout.setSpacing(0)
            layout.addLayout(vsubLayout, 0)

            # Add button
            self._hidebut.setFont(QtGui.QFont('helvetica', 7))
            self._hidebut.setToolTip(
                translate('search', 'Hide search widget (Escape)'))
            self._hidebut.setIcon(pyzo.icons.cancel)
            self._hidebut.setIconSize(QtCore.QSize(16, 16))
            vsubLayout.addWidget(self._hidebut, 0)

            vsubLayout.addStretch(1)

        layout.addSpacing(10)

        if True:

            # Create sub layouts
            vsubLayout = QtGui.QVBoxLayout()
            hsubLayout = QtGui.QHBoxLayout()
            vsubLayout.setSpacing(0)
            hsubLayout.setSpacing(0)
            layout.addLayout(vsubLayout, 0)

            # Add find text
            self._findText.setToolTip(translate('search', 'Find pattern'))
            vsubLayout.addWidget(self._findText, 0)

            vsubLayout.addLayout(hsubLayout)

            # Add previous button
            self._findPrev = QtGui.QToolButton(self)
            t = translate(
                'search',
                'Previous ::: Find previous occurrence of the pattern.')
            self._findPrev.setText(t)
            self._findPrev.setToolTip(t.tt)

            hsubLayout.addWidget(self._findPrev, 0)

            hsubLayout.addStretch(1)

            # Add next button
            self._findNext = QtGui.QToolButton(self)
            t = translate('search',
                          'Next ::: Find next occurrence of the pattern.')
            self._findNext.setText(t)
            self._findNext.setToolTip(t.tt)
            #self._findNext.setDefault(True) # Not possible with tool buttons
            hsubLayout.addWidget(self._findNext, 0)

        layout.addSpacing(10)

        if True:

            # Create sub layouts
            vsubLayout = QtGui.QVBoxLayout()
            hsubLayout = QtGui.QHBoxLayout()
            vsubLayout.setSpacing(0)
            hsubLayout.setSpacing(0)
            layout.addLayout(vsubLayout, 0)

            # Add replace text
            self._replaceText.setToolTip(translate('search',
                                                   'Replace pattern'))
            vsubLayout.addWidget(self._replaceText, 0)

            vsubLayout.addLayout(hsubLayout)

            # Add replace-all button
            self._replaceAll = QtGui.QToolButton(self)
            t = translate(
                'search',
                'Repl. all ::: Replace all matches in current document.')
            self._replaceAll.setText(t)
            self._replaceAll.setToolTip(t.tt)
            hsubLayout.addWidget(self._replaceAll, 0)

            hsubLayout.addStretch(1)

            # Add replace button
            self._replace = QtGui.QToolButton(self)
            t = translate('search', 'Replace ::: Replace this match.')
            self._replace.setText(t)
            self._replace.setToolTip(t.tt)
            hsubLayout.addWidget(self._replace, 0)

        layout.addSpacing(10)

        if True:

            # Create sub layouts
            vsubLayout = QtGui.QVBoxLayout()
            vsubLayout.setSpacing(0)
            layout.addLayout(vsubLayout, 0)

            # Add match-case checkbox
            t = translate('search',
                          'Match case ::: Find words that match case.')
            self._caseCheck = QtGui.QCheckBox(t, self)
            self._caseCheck.setToolTip(t.tt)
            vsubLayout.addWidget(self._caseCheck, 0)

            # Add regexp checkbox
            t = translate('search',
                          'RegExp ::: Find using regular expressions.')
            self._regExp = QtGui.QCheckBox(t, self)
            self._regExp.setToolTip(t.tt)
            vsubLayout.addWidget(self._regExp, 0)

        if True:

            # Create sub layouts
            vsubLayout = QtGui.QVBoxLayout()
            vsubLayout.setSpacing(0)
            layout.addLayout(vsubLayout, 0)

            # Add whole-word checkbox
            t = translate('search', 'Whole words ::: Find only whole words.')
            self._wholeWord = QtGui.QCheckBox(t, self)
            self._wholeWord.setToolTip(t.tt)
            self._wholeWord.resize(60, 16)
            vsubLayout.addWidget(self._wholeWord, 0)

            # Add autohide dropbox
            t = translate(
                'search',
                'Auto hide ::: Hide search/replace when unused for 10 s.')
            self._autoHide = QtGui.QCheckBox(t, self)
            self._autoHide.setToolTip(t.tt)
            self._autoHide.resize(60, 16)
            vsubLayout.addWidget(self._autoHide, 0)

        layout.addStretch(1)

        # Set placeholder texts
        for lineEdit in [self._findText, self._replaceText]:
            if hasattr(lineEdit, 'setPlaceholderText'):
                lineEdit.setPlaceholderText(lineEdit.toolTip())
            lineEdit.textChanged.connect(self.autoHideTimerReset)

        # Set focus policy
        for but in [
                self._findPrev, self._findNext, self._replaceAll,
                self._replace, self._caseCheck, self._wholeWord, self._regExp
        ]:
            #but.setFocusPolicy(QtCore.Qt.ClickFocus)
            but.clicked.connect(self.autoHideTimerReset)

        # create timer objects
        self._timerBeginEnd = QtCore.QTimer(self)
        self._timerBeginEnd.setSingleShot(True)
        self._timerBeginEnd.timeout.connect(self.resetAppearance)
        #
        self._timerAutoHide = QtCore.QTimer(self)
        self._timerAutoHide.setSingleShot(False)
        self._timerAutoHide.setInterval(500)  # ms
        self._timerAutoHide.timeout.connect(self.autoHideTimerCallback)
        self._timerAutoHide_t0 = time.time()
        self._timerAutoHide.start()

        # create callbacks
        self._findText.returnPressed.connect(self.findNext)
        self._hidebut.clicked.connect(self.hideMe)
        self._findNext.clicked.connect(self.findNext)
        self._findPrev.clicked.connect(self.findPrevious)
        self._replace.clicked.connect(self.replaceOne)
        self._replaceAll.clicked.connect(self.replaceAll)
        #
        self._regExp.stateChanged.connect(self.handleReplacePossible)

        # init case and regexp
        self._caseCheck.setChecked(bool(pyzo.config.state.find_matchCase))
        self._regExp.setChecked(bool(pyzo.config.state.find_regExp))
        self._wholeWord.setChecked(bool(pyzo.config.state.find_wholeWord))
        self._autoHide.setChecked(bool(pyzo.config.state.find_autoHide))

        # show or hide?
        if bool(pyzo.config.state.find_show):
            self.show()
        else:
            self.hide()
Ejemplo n.º 19
0
    def __init__(self):
        QtWidgets.QToolBar.__init__(self, "MainToolBar", parent=None)

        self.setObjectName("MainToolBar")
        self.setMovable(True)
        self.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)

        TOOLBARSIZE = pyzo.config.tools.pyzotoolbar.toolbarSize
        self.setMinimumSize(TOOLBARSIZE, TOOLBARSIZE)
        self.setIconSize(QtCore.QSize(TOOLBARSIZE, TOOLBARSIZE))

        # ---------- Toolbars sections ----------

        # File menu
        addItem(self, "New", pyzo.icons.page_add, pyzo.editors.newFile, None)

        addItem(self, "Open", pyzo.icons.folder_page, pyzo.editors.openFile,
                None)

        addItem(self, "Save", pyzo.icons.disk, pyzo.editors.saveFile, None)

        addItem(
            self,
            "Save all",
            pyzo.icons.disk_multiple,
            pyzo.editors.saveAllFiles,
            None,
        )

        # Edit menu
        addItem(self, "Undo", pyzo.icons.arrow_undo, self.itemActionCallback,
                "undo")

        addItem(self, "Redo", pyzo.icons.arrow_redo, self.itemActionCallback,
                "redo")

        self.addSeparator()

        addItem(self, "Cut", pyzo.icons.cut, self.itemActionCallback, "cut")

        addItem(
            self,
            "Copy",
            pyzo.icons.page_white_copy,
            self.itemActionCallback,
            "copy",
        )

        addItem(
            self,
            "Paste",
            pyzo.icons.paste_plain,
            self.itemActionCallback,
            "paste",
        )

        self.addSeparator()

        addItem(
            self,
            "Indent",
            pyzo.icons.text_indent,
            self.itemActionCallback,
            "indentSelection",
        )

        addItem(
            self,
            "Dedent",
            pyzo.icons.text_indent_remove,
            self.itemActionCallback,
            "dedentSelection",
        )

        self.addSeparator()

        addItem(
            self,
            "Comment",
            pyzo.icons.comment_add,
            self.itemActionCallback,
            "commentCode",
        )

        addItem(
            self,
            "Uncomment",
            pyzo.icons.comment_delete,
            self.itemActionCallback,
            "uncommentCode",
        )

        self.addSeparator()

        addItem(
            self,
            "Find or replace",
            pyzo.icons.find,
            pyzo.editors._findReplace.startFind,
            None,
        )

        self.addSeparator()

        # Run menu
        addItem(
            self,
            "Run file as script",
            pyzo.icons.run_file_script,
            RunMenu(name="Run")._runFile,
            (True, False),
        )

        addItem(
            self,
            "Run main file as script",
            pyzo.icons.run_mainfile_script,
            RunMenu(name="Run")._runFile,
            (True, False),
        )

        self.addSeparator()

        # Debug
        addItem(
            self,
            "Insert selected or clipboard text as print('TEXT: ' + text)",
            pyzo.icons.bug,
            printify,
            None,
        )

        self.addSeparator()

        addItem(
            self,
            "Advanced settings",
            pyzo.icons.cog,
            lambda: AdvancedSettings().exec_(),
            None,
        )

        addItem(
            self,
            "Edit shell configurations",
            pyzo.icons.application_wrench,
            self.editShellConfig,
            None,
        )

        addItem(
            self,
            "Local documentation",
            pyzo.icons.help,
            PyzoAssistant().show,
            None,
        )

        # Close toolbar
        self.addSeparator()
        self.addSeparator()
        # TODO:  Tools menu action on closing don't work,
        addItem(
            self,
            "Close toolbar",
            pyzo.icons.cross,
            lambda: self.closeToolbar(),
            None,
        )

        self.addSeparator()
        self.addSeparator()