예제 #1
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

        # 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 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.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)
        # set margins
        margin = pyzo.config.view.widgetMargin
        self._sizer1.setContentsMargins(margin, margin, margin, margin)

        # Set layout
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._tree, 1)
        # self._sizer2.addWidget(self._sliderIcon, 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()
예제 #2
0
    def __init__(self):
        super().__init__()

        from pyzo.qt import QtPrintSupport

        self.printer = QtPrintSupport.QPrinter(
            QtPrintSupport.QPrinter.HighResolution, )

        # To allow pdf export with color
        self.printer.setColorMode(QtPrintSupport.QPrinter.Color)

        # Default settings
        self.show_line_number = True
        self._enable_syntax_highlighting = True

        # Set title
        self.setWindowTitle(translate("menu dialog", "Pdf Export"))

        # Set dialog size
        size = 1000, 600
        offset = 0
        size2 = size[0], size[1] + offset
        self.resize(*size2)
        # self.setMinimumSize(*size2)

        # Button to export to pdf
        self.validation_button = QtWidgets.QPushButton("Export")
        self.validation_button.clicked.connect(self._export_pdf)

        # Button to update the preview
        self.button_update_preview = QtWidgets.QPushButton(
            "Update preview", self)
        self.button_update_preview.clicked.connect(self._update_preview)

        # Previw widget
        self.preview = QtPrintSupport.QPrintPreviewWidget(self.printer)

        # Lines numbers option
        self.checkbox_line_number = QtWidgets.QCheckBox(
            "Print line number", self, checked=self.show_line_number)

        self.checkbox_line_number.stateChanged.connect(
            self._get_show_line_number)

        # Make of copy of the editor
        self.current_editor = pyzo.editors.getCurrentEditor()
        self.editor_name = self.current_editor.name
        self.editor_filename = self.current_editor.filename
        self.editor = pyzo.core.editor.PyzoEditor(
            pyzo.editors.getCurrentEditor().toPlainText())

        # Zoom
        # The default zoom is the current zoom used by the editor
        self.original_zoom = pyzo.config.view.zoom
        self.zoom_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.zoom_slider.setMinimum(-10)  # Maybe too much ?
        self.zoom_slider.setMaximum(10)
        self.zoom_slider.setTickInterval(1)
        self.zoom_selected = self.original_zoom
        self.zoom_slider.setValue(self.zoom_selected)
        self.zoom_value_label = QtWidgets.QLabel()
        self._zoom_value_changed()
        self.zoom_slider.valueChanged.connect(self._zoom_value_changed)

        # Option for syntax highlighting
        self.checkbox_syntax_highlighting = QtWidgets.QCheckBox(
            "Enable syntax highlighting",
            self,
            checked=self._enable_syntax_highlighting)

        self.checkbox_syntax_highlighting.stateChanged.connect(
            self._change_syntax_highlighting_option)

        self.combobox_file_name = QtWidgets.QComboBox(self)
        self.combobox_file_name.addItem("Do not print the file name", 0)
        self.combobox_file_name.addItem("Print with file name", 1)
        self.combobox_file_name.addItem(
            "Print with file name and absolute path", 2)
        self.combobox_file_name.setCurrentIndex(1)
        self.combobox_file_name.setToolTip(
            "The title at the top of the document")

        # Orientation
        self.combobox_orientation = QtWidgets.QComboBox(self)
        self.combobox_orientation.addItem("Portrait", 0)
        self.combobox_orientation.addItem("Landscape", 1)
        self.combobox_orientation.setToolTip("Orientation of the document")

        # Layout
        self.main_layout = QtWidgets.QHBoxLayout()
        self.setLayout(self.main_layout)
        self.preview.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                   QtWidgets.QSizePolicy.Expanding)
        self.right_layout = QtWidgets.QVBoxLayout()
        self.option_layout = QtWidgets.QFormLayout()
        self.main_layout.addWidget(self.preview)

        self.main_layout.addLayout(self.right_layout)
        self.right_layout.addLayout(self.option_layout)
        self.option_layout.addRow(self.combobox_file_name)
        self.option_layout.addRow(self.checkbox_line_number)
        self.option_layout.addRow(self.checkbox_syntax_highlighting)
        self.option_layout.addRow(self.zoom_value_label, self.zoom_slider)
        # self.option_layout.addRow(self.combobox_orientation)  # orientation appears to be broken
        self.bottom_layout = QtWidgets.QHBoxLayout()
        self.right_layout.addLayout(self.bottom_layout)
        self.bottom_layout.addStretch()
        self.bottom_layout.addWidget(self.button_update_preview)
        self.bottom_layout.addWidget(self.validation_button)

        self._update_preview()