예제 #1
0
 def __init__(self):
     """
     Constructor
     """
     ericPic = QPixmap(
         os.path.join(getConfig('ericPixDir'), 'pymakrSplash.png'))
     self.labelAlignment = Qt.Alignment(Qt.AlignBottom | Qt.AlignRight
                                        | Qt.AlignAbsolute)
     super(SplashScreen, self).__init__(ericPic)
     lblVersion = QLabel(self)
     lblVersion.setText(UI.Info.Version)
     lblVersion.adjustSize()
     lblVersion.setStyleSheet("QLabel { color : white; }")
     lblVersion.setAttribute(Qt.WA_TranslucentBackground)
     lblVersion.move(425 - lblVersion.width(), 195)
     self.show()
     self.raise_()  # needed for mac
     QApplication.flush()
    def _update_ranging_status_indicators(self):
        container = self._anchor_stats_container

        ids = sorted(self._anchors.keys())

        # Update existing labels or add new if needed
        count = 0
        for id in ids:
            col = count % 8
            row = int(count / 8)

            if count < container.count():
                label = container.itemAtPosition(row, col).widget()
            else:
                label = QLabel()
                label.setMinimumSize(30, 0)
                label.setProperty('frameShape', 'QFrame::Box')
                label.setAlignment(Qt.AlignCenter)
                container.addWidget(label, row, col)

            label.setText(str(id))

            if self._anchors[id].is_active():
                label.setStyleSheet(STYLE_GREEN_BACKGROUND)
            else:
                label.setStyleSheet(STYLE_RED_BACKGROUND)

            count += 1

        # Remove labels if there are too many
        for i in range(count, container.count()):
            col = i % 8
            row = int(i / 8)

            label = container.itemAtPosition(row, col).widget()
            label.deleteLater()
    def _update_ranging_status_indicators(self):
        container = self._anchor_stats_container

        ids = sorted(self._anchors.keys())

        # Update existing labels or add new if needed
        count = 0
        for id in ids:
            col = count % 8
            row = int(count / 8)

            if count < container.count():
                label = container.itemAtPosition(row, col).widget()
            else:
                label = QLabel()
                label.setMinimumSize(30, 0)
                label.setProperty('frameShape', 'QFrame::Box')
                label.setAlignment(Qt.AlignCenter)
                container.addWidget(label, row, col)

            label.setText(str(id))

            if self._anchors[id].is_active():
                label.setStyleSheet(STYLE_GREEN_BACKGROUND)
            else:
                label.setStyleSheet(STYLE_RED_BACKGROUND)

            count += 1

        # Remove labels if there are too many
        for i in range(count, container.count()):
            col = i % 8
            row = int(i / 8)

            label = container.itemAtPosition(row, col).widget()
            label.deleteLater()
class EditorSchemeDesigner(QDialog):
    """Editor Scheme Designer Class Widget"""
    def __init__(self, scheme, parent):
        super(EditorSchemeDesigner, self).__init__(parent, Qt.Dialog)
        self.original_style = copy.copy(resources.CUSTOM_SCHEME)
        self._avoid_on_loading, self.saved, self._components = True, False, {}
        self.setWindowTitle(translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER)
        self.setMinimumSize(450, 480)
        self.setMaximumSize(500, 900)
        self.resize(450, 600)

        # all layouts and groupboxes
        group0 = QGroupBox(translations.TR_PROJECT_NAME)  # scheme filename
        group1 = QGroupBox(translations.TR_PROJECT_PROPERTIES)  # properties
        group2 = QGroupBox(translations.TR_PREVIEW)  # quick preview thingy
        group0_hbox, group1_vbox = QHBoxLayout(group0), QVBoxLayout(group1)
        this_dialog_vbox, group2_vbox = QVBoxLayout(self), QVBoxLayout(group2)
        self._grid, scrollArea, frame = QGridLayout(), QScrollArea(), QFrame()

        # widgets
        self.line_name, btnSave = QLineEdit(), QPushButton(
            translations.TR_SAVE)
        self.line_name.setPlaceholderText(getuser().capitalize() + "s_scheme")
        group0_hbox.addWidget(self.line_name)
        group0_hbox.addWidget(btnSave)
        self.connect(btnSave, SIGNAL("clicked()"), self.save_scheme)
        _demo = "<center>" + ascii_letters  # demo text for preview
        self.preview_label1, self.preview_label2 = QLabel(_demo), QLabel(_demo)
        group2_vbox.addWidget(self.preview_label1)
        group2_vbox.addWidget(self.preview_label2)

        # rows titles
        self._grid.addWidget(QLabel("<b>" + translations.TR_PROJECT_NAME), 0,
                             0)
        self._grid.addWidget(QLabel("<b>" + translations.TR_CODE), 0, 1)
        self._grid.addWidget(
            QLabel("<b>" + translations.TR_EDITOR_SCHEME_PICK_COLOR), 0, 2)

        # fill rows
        for key in sorted(tuple(resources.COLOR_SCHEME.keys())):
            self.add_item(key, scheme)
        self.preview_label1.setStyleSheet('background:transparent')
        self.preview_label2.setStyleSheet('color:     transparent')

        # fill the scroll area
        frame.setLayout(self._grid)
        scrollArea.setWidget(frame)
        group1_vbox.addWidget(scrollArea)

        # put groups on the dialog
        this_dialog_vbox.addWidget(group1)
        this_dialog_vbox.addWidget(group2)
        this_dialog_vbox.addWidget(group0)
        self._avoid_on_loading = self._modified = False

    def add_item(self, key, scheme):
        """Take key and scheme arguments and fill up the grid with widgets."""
        row = self._grid.rowCount()
        self._grid.addWidget(QLabel(key), row, 0)
        isnum = isinstance(scheme[key], int)
        text = QLineEdit(str(scheme[key]))
        self._grid.addWidget(text, row, 1)
        if not isnum:
            btn = QPushButton()
            btn.setToolTip(translations.TR_EDITOR_SCHEME_PICK_COLOR)
            self.apply_button_style(btn, scheme[key])
            self._grid.addWidget(btn, row, 2)

            self.connect(text, SIGNAL("textChanged(QString)"),
                         lambda: self.apply_button_style(btn, text.text()))
            self.connect(btn, SIGNAL("clicked()"),
                         lambda: self._pick_color(text, btn))
        else:
            self.connect(text, SIGNAL("textChanged(QString)"),
                         self._preview_style)
        self._components[key] = (text, isnum)

    def apply_button_style(self, btn, color_name):
        """Take a button widget and color name and apply as stylesheet."""
        if QColor(color_name).isValid():
            self._modified = True
            btn.setStyleSheet('background:' + color_name)
            self.preview_label1.setStyleSheet('background:' + color_name)
            self.preview_label2.setStyleSheet('color:' + color_name)
            self._preview_style()

    def _pick_color(self, lineedit, btn):
        """Pick a color name using lineedit and button data."""
        color = QColorDialog.getColor(QColor(lineedit.text()), self,
                                      translations.TR_EDITOR_SCHEME_PICK_COLOR)
        if color.isValid():
            lineedit.setText(str(color.name()))
            self.apply_button_style(btn, color.name())

    def _preview_style(self):
        """Live preview style on editor."""
        if self._avoid_on_loading:
            return
        scheme = {}
        keys = sorted(tuple(resources.COLOR_SCHEME.keys()))
        for key in keys:
            isnum = self._components[key][1]
            if isnum:
                num = self._components[key][0].text()
                if num.isdigit():
                    scheme[key] = int(num)
                else:
                    scheme[key] = 0
            else:
                scheme[key] = self._components[key][0].text()
        resources.CUSTOM_SCHEME = scheme
        editorWidget = self._get_editor()
        if editorWidget is not None:
            editorWidget.restyle(editorWidget.lang)
            editorWidget.highlight_current_line()
        return scheme

    def _get_editor(self):
        """Return current Editor."""
        main_container = IDE.get_service("main_container")
        editorWidget = main_container.get_current_editor()
        return editorWidget

    def reject(self):
        """Reject this dialog."""
        if self._modified:
            answer = QMessageBox.No
            answer = QMessageBox.question(
                self, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
                (translations.TR_IDE_CONFIRM_EXIT_TITLE + ".\n" +
                 translations.TR_PREFERENCES_GENERAL_CONFIRM_EXIT + "?"),
                QMessageBox.Yes, QMessageBox.No)
            if answer == QMessageBox.No:
                return
        super(EditorSchemeDesigner, self).reject()

    def hideEvent(self, event):
        """Handle Hide event on this dialog."""
        super(EditorSchemeDesigner, self).hideEvent(event)
        resources.CUSTOM_SCHEME = self.original_style
        editorWidget = self._get_editor()
        if editorWidget is not None:
            editorWidget.restyle(editorWidget.lang)

    def _is_valid_scheme_name(self, name):
        """Check if a given name is a valid name for an editor scheme.
        Params:
            name := the name to check
        Returns:
            True if and only if the name is okay to use for a scheme. """
        return name not in ('', 'default')

    def save_scheme(self):
        """Save current scheme."""
        name = self.line_name.text().strip()
        if not self._is_valid_scheme_name(name):
            QMessageBox.information(
                self, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
                translations.TR_SCHEME_INVALID_NAME)
            return
        fileName = ('{0}.color'.format(
            file_manager.create_path(resources.EDITOR_SKINS, name)))
        answer = True
        if file_manager.file_exists(fileName):
            answer = QMessageBox.question(
                self, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
                translations.TR_WANT_OVERWRITE_FILE +
                ": {0}?".format(fileName), QMessageBox.Yes, QMessageBox.No)

        if answer in (QMessageBox.Yes, True):
            scheme = self._preview_style()
            self.original_style = copy.copy(scheme)
            json_manager.save_editor_skins(fileName, scheme)
            self._modified = False
            self.saved = True
            qsettings = IDE.ninja_settings()
            qsettings.setValue('preferences/editor/scheme', name)
            QMessageBox.information(
                self, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
                translations.TR_SCHEME_SAVED + ": {0}.".format(fileName))
            self.close()
        elif answer == QMessageBox.Yes:
            QMessageBox.information(
                self, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
                translations.TR_INVALID_FILENAME)