Пример #1
0
    def __init__(self, suggested, parent=None):
        super(PythonDetectDialog, self).__init__(parent, Qt.Dialog)
        self.setMaximumSize(QSize(0, 0))
        self.setWindowTitle("Configure Python Path")

        vbox = QVBoxLayout(self)
        msg_str = ("We have detected that you are using "
                   "Windows,\nplease choose the proper "
                   "Python application for you:")
        lblMessage = QLabel(self.tr(msg_str))
        vbox.addWidget(lblMessage)

        self.listPaths = QListWidget()
        self.listPaths.setSelectionMode(QListWidget.SingleSelection)
        vbox.addWidget(self.listPaths)

        hbox = QHBoxLayout()
        hbox.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
        btnCancel = QPushButton(self.tr("Cancel"))
        btnAccept = QPushButton(self.tr("Accept"))
        hbox.addWidget(btnCancel)
        hbox.addWidget(btnAccept)
        vbox.addLayout(hbox)

        self.connect(btnAccept, SIGNAL("clicked()"), self._set_python_path)
        self.connect(btnCancel, SIGNAL("clicked()"), self.close)

        for path in suggested:
            self.listPaths.addItem(path)
        self.listPaths.setCurrentRow(0)
Пример #2
0
 def __init__(self, parent=None):
     super(MigrationWidget, self).__init__(parent, Qt.WindowStaysOnTopHint)
     self._migration, vbox, hbox = {}, QVBoxLayout(self), QHBoxLayout()
     lbl_title = QLabel(translations.TR_CURRENT_CODE)
     lbl_suggestion = QLabel(translations.TR_SUGGESTED_CHANGES)
     self.current_list, self.suggestion = QListWidget(), QPlainTextEdit()
     self.suggestion.setReadOnly(True)
     self.btn_apply = QPushButton(translations.TR_APPLY_CHANGES + " !")
     self.suggestion.setToolTip(translations.TR_SAVE_BEFORE_APPLY + " !")
     self.btn_apply.setToolTip(translations.TR_SAVE_BEFORE_APPLY + " !")
     # pack up all widgets
     hbox.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
     hbox.addWidget(self.btn_apply)
     vbox.addWidget(lbl_title)
     vbox.addWidget(self.current_list)
     vbox.addWidget(lbl_suggestion)
     vbox.addWidget(self.suggestion)
     vbox.addLayout(hbox)
     # connections
     self.connect(self.current_list,
                  SIGNAL("itemClicked(QListWidgetItem*)"),
                  self.load_suggestion)
     self.connect(self.btn_apply, SIGNAL("clicked()"), self.apply_changes)
     # registers
     IDE.register_service('tab_migration', self)
     ExplorerContainer.register_tab(translations.TR_TAB_MIGRATION, self)
Пример #3
0
 def __init__(self, parent=None):
     QListWidget.__init__(self, parent)
     self.iface = backend.pm.Iface()
     self.defaultIcon = KIcon(('applications-other', 'unknown'),
                              KIconLoader.SizeSmallMedium)
     self.connect(self, SIGNAL("itemClicked(QListWidgetItem*)"),
                  self.groupChanged)
     self._list = {}
Пример #4
0
    def __init__(self, parent):
        super(Theme, self).__init__()
        self._preferences, vbox = parent, QVBoxLayout(self)
        vbox.addWidget(QLabel(self.tr("<b>Select Theme:</b>")))
        self.list_skins = QListWidget()
        self.list_skins.setSelectionMode(QListWidget.SingleSelection)
        vbox.addWidget(self.list_skins)
        self.btn_delete = QPushButton(self.tr("Delete Theme"))
        self.btn_preview = QPushButton(self.tr("Preview Theme"))
        self.btn_create = QPushButton(self.tr("Create Theme"))
        hbox = QHBoxLayout()
        hbox.addWidget(self.btn_delete)
        hbox.addSpacerItem(QSpacerItem(10, 0, QSizePolicy.Expanding,
                           QSizePolicy.Fixed))
        hbox.addWidget(self.btn_preview)
        hbox.addWidget(self.btn_create)
        vbox.addLayout(hbox)
        self._refresh_list()

        self.connect(self.btn_preview, SIGNAL("clicked()"), self.preview_theme)
        self.connect(self.btn_delete, SIGNAL("clicked()"), self.delete_theme)
        self.connect(self.btn_create, SIGNAL("clicked()"), self.create_theme)

        self.connect(self._preferences, SIGNAL("savePreferences()"), self.save)
Пример #5
0
class PythonDetectDialog(QDialog):
    def __init__(self, suggested, parent=None):
        super(PythonDetectDialog, self).__init__(parent, Qt.Dialog)
        self.setMaximumSize(QSize(0, 0))
        self.setWindowTitle("Configure Python Path")

        vbox = QVBoxLayout(self)
        msg_str = ("We have detected that you are using "
                   "Windows,\nplease choose the proper "
                   "Python application for you:")
        lblMessage = QLabel(self.tr(msg_str))
        vbox.addWidget(lblMessage)

        self.listPaths = QListWidget()
        self.listPaths.setSelectionMode(QListWidget.SingleSelection)
        vbox.addWidget(self.listPaths)

        hbox = QHBoxLayout()
        hbox.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
        btnCancel = QPushButton(self.tr("Cancel"))
        btnAccept = QPushButton(self.tr("Accept"))
        hbox.addWidget(btnCancel)
        hbox.addWidget(btnAccept)
        vbox.addLayout(hbox)

        self.connect(btnAccept, SIGNAL("clicked()"), self._set_python_path)
        self.connect(btnCancel, SIGNAL("clicked()"), self.close)

        for path in suggested:
            self.listPaths.addItem(path)
        self.listPaths.setCurrentRow(0)

    def _set_python_path(self):
        python_path = self.listPaths.currentItem().text()

        qsettings = QSettings(resources.SETTINGS_PATH, QSettings.IniFormat)
        settings.PYTHON_PATH = python_path
        settings.PYTHON_EXEC = python_path
        settings.PYTHON_EXEC_CONFIGURED_BY_USER = True
        qsettings.setValue('preferences/execution/pythonExec', python_path)
        qsettings.setValue('preferences/execution/pythonExecConfigured', True)
        self.close()
Пример #6
0
class MigrationWidget(QDialog):
    """2to3 Migration Assistance Widget Class"""
    def __init__(self, parent=None):
        super(MigrationWidget, self).__init__(parent, Qt.WindowStaysOnTopHint)
        self._migration, vbox, hbox = {}, QVBoxLayout(self), QHBoxLayout()
        lbl_title = QLabel(translations.TR_CURRENT_CODE)
        lbl_suggestion = QLabel(translations.TR_SUGGESTED_CHANGES)
        self.current_list, self.suggestion = QListWidget(), QPlainTextEdit()
        self.suggestion.setReadOnly(True)
        self.btn_apply = QPushButton(translations.TR_APPLY_CHANGES + " !")
        self.suggestion.setToolTip(translations.TR_SAVE_BEFORE_APPLY + " !")
        self.btn_apply.setToolTip(translations.TR_SAVE_BEFORE_APPLY + " !")
        # pack up all widgets
        hbox.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
        hbox.addWidget(self.btn_apply)
        vbox.addWidget(lbl_title)
        vbox.addWidget(self.current_list)
        vbox.addWidget(lbl_suggestion)
        vbox.addWidget(self.suggestion)
        vbox.addLayout(hbox)
        # connections
        self.connect(self.current_list,
                     SIGNAL("itemClicked(QListWidgetItem*)"),
                     self.load_suggestion)
        self.connect(self.btn_apply, SIGNAL("clicked()"), self.apply_changes)
        # registers
        IDE.register_service('tab_migration', self)
        ExplorerContainer.register_tab(translations.TR_TAB_MIGRATION, self)

    def install_tab(self):
        """Install the Tab on the IDE."""
        ide = IDE.get_service('ide')
        self.connect(ide, SIGNAL("goingDown()"), self.close)

    def apply_changes(self):
        """Apply the suggested changes on the Python code."""
        lineno = int(self.current_list.currentItem().data(Qt.UserRole))
        lines = self._migration[lineno][0].split('\n')
        remove, code = -1, ""
        for line in lines:
            if line.startswith('-'):
                remove += 1  # line to remove
            elif line.startswith('+'):
                code += '{line_to_add}\n'.format(line_to_add=line[1:])
        # get and apply changes on editor
        main_container = IDE.get_service('main_container')
        if main_container:
            editorWidget = main_container.get_current_editor()
            position = editorWidget.SendScintilla(
                editorWidget.SCI_POSITIONFROMLINE, lineno)
            curpos = editorWidget.SendScintilla(editorWidget.SCI_GETCURRENTPOS)
            if curpos != position:
                editorWidget.SendScintilla(editorWidget.SCI_GOTOPOS, position)
            endpos = editorWidget.SendScintilla(
                editorWidget.SCI_GETLINEENDPOSITION, lineno)
            editorWidget.SendScintilla(editorWidget.SCI_SETCURRENTPOS, endpos)
            editorWidget.replaceSelectedText(code[:-1])

    def load_suggestion(self, item):
        """Take an argument item and load the suggestion."""
        lineno, code = int(item.data(Qt.UserRole)), ""
        lines = self._migration[lineno][0].split('\n')
        for line in lines:
            if line.startswith('+'):
                code += '{line_to_add}\n'.format(line_to_add=line[1:])
        self.suggestion.setPlainText(code)
        main_container = IDE.get_service('main_container')
        if main_container:
            editorWidget = main_container.get_current_editor()
            if editorWidget:
                editorWidget.jump_to_line(lineno)
                editorWidget.setFocus()

    def refresh_lists(self, migration):
        """Refresh the list of code suggestions."""
        self._migration, base_lineno = migration, -1
        self.current_list.clear()
        for lineno in sorted(migration.keys()):
            linenostr = 'L{line_number}\n'.format(line_number=str(lineno + 1))
            data = migration[lineno]
            lines = data[0].split('\n')
            if base_lineno == data[1]:
                continue
            base_lineno = data[1]
            message = ''
            for line in lines:
                if line.startswith('-'):
                    message += '{line_to_load}\n'.format(line_to_load=line)
            item = QListWidgetItem(linenostr + message)
            item.setToolTip(linenostr + message)
            item.setData(Qt.UserRole, lineno)
            self.current_list.addItem(item)

    def clear(self):
        """Clear the widget."""
        self.current_list.clear()
        self.suggestion.clear()

    def reject(self):
        """Reject"""
        if self.parent() is None:
            self.emit(SIGNAL("dockWidget(PyQt_PyObject)"), self)

    def closeEvent(self, event):
        """Close"""
        self.emit(SIGNAL("dockWidget(PyQt_PyObject)"), self)
        event.ignore()
Пример #7
0
class Theme(QWidget):
    """Theme widget class."""

    def __init__(self, parent):
        super(Theme, self).__init__()
        self._preferences, vbox = parent, QVBoxLayout(self)
        vbox.addWidget(QLabel(self.tr("<b>Select Theme:</b>")))
        self.list_skins = QListWidget()
        self.list_skins.setSelectionMode(QListWidget.SingleSelection)
        vbox.addWidget(self.list_skins)
        self.btn_delete = QPushButton(self.tr("Delete Theme"))
        self.btn_preview = QPushButton(self.tr("Preview Theme"))
        self.btn_create = QPushButton(self.tr("Create Theme"))
        hbox = QHBoxLayout()
        hbox.addWidget(self.btn_delete)
        hbox.addSpacerItem(QSpacerItem(10, 0, QSizePolicy.Expanding,
                           QSizePolicy.Fixed))
        hbox.addWidget(self.btn_preview)
        hbox.addWidget(self.btn_create)
        vbox.addLayout(hbox)
        self._refresh_list()

        self.connect(self.btn_preview, SIGNAL("clicked()"), self.preview_theme)
        self.connect(self.btn_delete, SIGNAL("clicked()"), self.delete_theme)
        self.connect(self.btn_create, SIGNAL("clicked()"), self.create_theme)

        self.connect(self._preferences, SIGNAL("savePreferences()"), self.save)

    def delete_theme(self):
        if self.list_skins.currentRow() != 0:
            file_name = ("%s.qss" % self.list_skins.currentItem().text())
            qss_file = file_manager.create_path(resources.NINJA_THEME_DOWNLOAD,
                                                file_name)
            file_manager.delete_file(qss_file)
            self._refresh_list()

    def create_theme(self):
        designer = preferences_theme_editor.ThemeEditor(self)
        designer.exec_()
        self._refresh_list()

    def showEvent(self, event):
        self._refresh_list()
        super(Theme, self).showEvent(event)

    def _refresh_list(self):
        self.list_skins.clear()
        self.list_skins.addItem("Default")

        files = [file_manager.get_file_name(filename) for filename in
                 file_manager.get_files_from_folder(
                     resources.NINJA_THEME_DOWNLOAD, "qss")]
        files.sort()
        self.list_skins.addItems(files)

        if settings.NINJA_SKIN in files:
            index = files.index(settings.NINJA_SKIN)
            self.list_skins.setCurrentRow(index + 1)
        else:
            self.list_skins.setCurrentRow(0)

    def save(self):
        qsettings = IDE.ninja_settings()
        settings.NINJA_SKIN = self.list_skins.currentItem().text()
        qsettings.setValue("preferences/theme/skin", settings.NINJA_SKIN)
        self.preview_theme()

    def preview_theme(self):
        if self.list_skins.currentRow() == 0:
            qss_file = resources.NINJA_THEME
        else:
            file_name = ("%s.qss" % self.list_skins.currentItem().text())
            qss_file = file_manager.create_path(resources.NINJA_THEME_DOWNLOAD,
                                                file_name)
        with open(qss_file) as f:
            qss = f.read()
        QApplication.instance().setStyleSheet(qss)