Exemple #1
0
    def onAnalyzeFinished(self, settings, project_path):
        # type: (ProjectSettings, str, str) -> None
        index = self.find(project_path)
        if not index.isValid():
            return

        item = self.itemFromIndex(index)
        item.setSettings(settings)
        if settings.is_valid():
            item.setIcon(icon.load("book"))
            self.projectLoaded.emit(item.index())
        else:
            item.setIcon(icon.load("error"))
            # logger.error(settings.error_msg)

        if settings.project:
            item.setText("{} ({})".format(settings.project, project_path))
        else:
            item.setText(project_path)

        if item.model():
            _left = item.index()  # QModelIndex
            _right = item.model().index(_left.row(), 1)
            # noinspection PyUnresolvedReferences
            item.model().dataChanged.emit(_left, _right)
Exemple #2
0
    def _create_item(self, project_path):
        # type: (str) -> QStandardItem
        item = ProjectItem("-", os.path.normpath(project_path))
        item.setIcon(icon.load("eye"))

        self._analyze_item(item)

        return item
Exemple #3
0
    def __init__(self, parent=None):
        super(SystemSettingsDialog, self).__init__(parent)
        self.widget = QWidget(self)
        self.ui = Ui_Form()
        self.ui.setupUi(self.widget)

        self.ui.splitter.setStretchFactor(1, 1)
        self.ui.splitter.setSizes([310, 643])

        self.settings = None
        self.home_dir = None
        self.params_dict = {}

        self.property_model = PropertyModel(self)
        self.category_model = CategoryFilterModel(self)
        self.category_model.setSourceModel(self.property_model)
        self.ui.property_widget.setModel(self.property_model)

        self._buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
            self
        )

        self.open_setting_dir_button = QPushButton(self)
        self.open_setting_dir_button.setText(self.tr("Open Setting Directory"))

        self.layout = QVBoxLayout(self)
        self.h_layout = QHBoxLayout()
        self.h_layout.addWidget(self.open_setting_dir_button)
        self.h_layout.addWidget(self._buttons)
        self.layout.addWidget(self.widget)
        self.layout.addLayout(self.h_layout)
        self.setLayout(self.layout)

        self.setWindowTitle(self.tr(str("SystemSettings")))
        self.resize(1000, 600)

        # self._setup_category()
        self.ui.tree_view_category.setModel(self.category_model)
        self.category_selection_model = self.ui.tree_view_category.selectionModel()

        # setup buttons
        self.open_setting_dir_button.setIcon(icon.load("open_folder"))

        self._connect()
    def __init__(self, title, property_model, parent=None):
        # type: (string_types, QWidget) -> None
        super(ExecCommandPage, self).__init__(parent)
        self.console_widget = QConsoleWidget(self)
        self.property_model = property_model
        self.property_widget = property_widget.PropertyWidget(self, property_model)
        self.gen_button = QPushButton(self)
        self.gen_button.setMinimumHeight(self.BUTTON_HEIGHT)
        self.gen_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.gen_button.setIconSize(QSize(self.BUTTON_ICON_SIZE, self.BUTTON_ICON_SIZE))

        self.v_layout = QVBoxLayout(self)
        self.v_layout.addWidget(self.gen_button)
        self.v_layout.addWidget(self.console_widget)
        self.v_layout.setContentsMargins(0, 0, 0, 0)
        self.panel = QWidget(self)
        self.panel.setLayout(self.v_layout)
        self.panel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.splitter = QSplitter(self)
        self.splitter.addWidget(self.property_widget)
        self.splitter.addWidget(self.panel)
        self.splitter.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.splitter.setStretchFactor(1, 1)
        self.splitter.setSizes([310, 643])

        layout = QVBoxLayout(self)
        layout.addWidget(self.splitter)
        self.setLayout(layout)

        self.console_widget.finished.connect(self.finished)
        # noinspection PyUnresolvedReferences
        self.gen_button.clicked.connect(self.exec_)

        self.setTitle(title)
        self.gen_button.setText(self.tr(str("Generate")))
        self.gen_button.setIcon(icon.load("thunder"))

        self.setTabOrder(self.gen_button, self.console_widget)
        self.setTabOrder(self.console_widget, self.property_widget)
        self.succeeded = False
        self.cmd = ""
    def __init__(self, sys_dir, home_dir, parent=None):
        super(MainWindow, self).__init__(parent)
        self.wizard_path = os.path.join(sys_dir, "settings")

        # load plugin
        plugin.init(self)
        plugin.load_plugin(os.path.join(sys_dir, "settings"))
        plugin.load_plugin(home_dir)

        # setup property widget css path
        property_widget.set_css_path(os.path.join(sys_dir, "settings", "css"))

        # make setting dir
        self.setting_dir = home_dir
        if not os.path.isdir(self.setting_dir):
            os.makedirs(self.setting_dir)
        self.settings = SystemSettings(
            os.path.join(self.setting_dir, SETTINGS_TOML))

        # setting value types
        sphinx_value_types.init()

        # setup params dict
        params_toml_path = os.path.join(self.wizard_path, "params.toml")
        self.params_dict = toml.load(params_toml_path, OrderedDict)

        for ext_name, ext in plugin.extension.list_iter():
            self.params_dict[ext_name] = {
                "value_type": "TypeCheck",
                "default": False,
                "description": ext.description,
                "description_path": ext.ext_path,
            }

        # create actions
        self.open_act = self._act("editor", self.tr("Open Editor"),
                                  self._open_dir)
        self.show_act = self._act("open_folder", self.tr("Open Directory"),
                                  self._show_directory)
        self.terminal_act = self._act("terminal", self.tr("Open Terminal"),
                                      self._open_terminal)
        self.auto_build_act = self._act("reload", self.tr("Auto Build"),
                                        self._auto_build)
        self.update_apidoc_act = self._act("update",
                                           self.tr("Update sphinx-apidoc"),
                                           self._update_apidoc)
        self.open_html_act = self._act("chrome", self.tr("Open browser"),
                                       self._open_browser)
        self.copy_path_act = self._act("clippy", self.tr("Copy Path"),
                                       self._on_copy_path)
        self.project_setting_act = self._act("setting",
                                             self.tr("Project Setting"),
                                             self._project_setting)

        self.close_act = self._act(None, self.tr("Exit"), self.close)
        self.make_html_act = self._act("html5", self.tr("HTML"),
                                       self._on_make_html)
        self.make_epub_act = self._act("epub", self.tr("Epub"),
                                       self._on_make_epub)
        self.make_latex_pdf_act = self._act("pdf", self.tr("LaTex PDF"),
                                            self._on_make_latex_pdf)
        self.make_clean_act = self._act("eraser", self.tr("Clean"),
                                        self._on_make_clean)
        self.make_preview_act = self._act("eye", self.tr("Preview"))

        self.make_preview_act.setCheckable(True)
        self.make_preview_act.setChecked(True)

        # setup ui
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # setup logger
        self.gui_logger = GuiLogger(self)
        self.gui_logger.edit = self.ui.text_edit_error
        logging.getLogger().addHandler(self.gui_logger)

        # create models
        self.project_list_model = ProjectListModel(parent=self)

        # setup file menu
        self.ui.menuFile_F.addSeparator()
        self.ui.menuFile_F.addAction(self.close_act)

        # setup icon
        self.ui.action_add_document.setIcon(icon.load("plus"))
        self.ui.action_settings.setIcon(icon.load("setting"))
        self.ui.action_wizard.setIcon(icon.load("magic"))
        self.ui.action_move_up.setIcon(icon.load("arrow_up"))
        self.ui.action_move_down.setIcon(icon.load("arrow_down"))
        self.ui.action_delete_document.setIcon(icon.load("remove"))

        # setup tool button
        self.ui.button_add.setDefaultAction(self.ui.action_add_document)
        self.ui.button_up.setDefaultAction(self.ui.action_move_up)
        self.ui.button_down.setDefaultAction(self.ui.action_move_down)
        self.ui.button_del.setDefaultAction(self.ui.action_delete_document)

        self.ui.action_delete_document.setShortcut(QKeySequence.Delete)
        self.ui.action_delete_document.setShortcutContext(Qt.WidgetShortcut)
        self.ui.action_move_up.setShortcutContext(Qt.WidgetShortcut)
        self.ui.action_move_down.setShortcutContext(Qt.WidgetShortcut)
        self.copy_path_act.setShortcut(QKeySequence.Copy)
        self.copy_path_act.setShortcutContext(Qt.WidgetShortcut)

        # connect
        self.ui.action_reload.triggered.connect(self.reload)

        # setup project tree view
        self.ui.tree_view_projects.addAction(self.ui.action_move_up)
        self.ui.tree_view_projects.addAction(self.ui.action_move_down)
        self.ui.tree_view_projects.addAction(self.ui.action_delete_document)
        self.ui.tree_view_projects.addAction(self.ui.action_reload)
        self.ui.tree_view_projects.addAction(self.copy_path_act)

        self.ui.tree_view_projects.setIndentation(0)
        self.ui.tree_view_projects.setModel(self.project_list_model)
        self.ui.tree_view_projects.resizeColumnToContents(0)
        self.projects_selection_model = self.ui.tree_view_projects.selectionModel(
        )

        self.projects_selection_model.currentChanged.connect(
            self._on_project_changed)

        # setup project model
        self.project_list_model.projectLoaded.connect(self.onProjectLoaded)

        # setup context menu
        self.ui.tree_view_projects.setContextMenuPolicy(Qt.CustomContextMenu)

        # setup toolbar
        self.ui.toolBar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        # move to center
        r = self.geometry()
        # noinspection PyArgumentList
        r.moveCenter(QApplication.desktop().availableGeometry().center())
        self.setGeometry(r)

        # set icon
        if platform.system() == "Windows":
            # noinspection PyBroadException
            try:
                ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
                    "Sphinx Explorer")
            except:
                pass

        self.setWindowIcon(icon.load("sphinx"))

        # setup project tool frame
        self.ui.project_tool_layout.setAlignment(Qt.AlignLeft)
        self.add_tool_action(self.make_clean_act)
        self.add_tool_action(self.make_preview_act)
        self.add_tool_action(None)
        self.add_tool_action(self.make_html_act)
        self.add_tool_action(self.make_epub_act)
        self.add_tool_action(self.make_latex_pdf_act)
        self.add_tool_action(None)
        self.add_tool_action(self.open_act)
        self.add_tool_action(self.show_act)
        self.add_tool_action(self.terminal_act)
        self.add_tool_action(self.open_html_act)
        self.add_tool_action(self.auto_build_act)
        self.add_tool_action(None)
        self.add_tool_action(self.project_setting_act)

        # set icon
        # TODO: This is Feature Support.
        # ProjectTools.set_file_icons(
        #     folder_icon=icon.load("folder"),
        #     file_icon=icon.load("file_text")
        # )

        property_widget.set_icon(
            add_icon=icon.load("plus"),
            up_icon=icon.load("arrow_up"),
            down_icon=icon.load("arrow_down"),
            delete_icon=icon.load("remove"),
            cog_icon=icon.load("cog"),
            open_dir_icon=icon.load("open_folder"),
        )

        python_venv.ICON_DICT["sys"] = icon.load("python")
        python_venv.ICON_DICT["anaconda"] = icon.load("anaconda")
        python_venv.ICON_DICT["venv"] = icon.load("python")

        # system init task
        task = SystemInitTask(self.setting_dir, self.settings, self)
        task.messaged.connect(self._on_task_message)
        task.checkPythonEnvFinished.connect(self._on_check_python_env_finished)
        task.checkPythonPackageFinished.connect(
            self._on_check_python_package_finished)
        task.checkLatestPackageFinished.connect(
            self._on_check_latest_package_finished)

        push_task(task)

        self.update_icon()

        # setup end
        self.setAcceptDrops(True)
        self._setup()
        self.ui.tree_view_projects.setFocus()
 def _act(self, icon_name, name, triggered=None):
     kwargs = {"triggered": triggered} if triggered else {}
     if icon_name:
         return QAction(icon.load(icon_name), name, self, **kwargs)
     else:
         return QAction(name, self, **kwargs)