Пример #1
0
 def _add_table(self, table, title, icon):
     """Add table tab to main tab widget, return button layout"""
     widget = QWidget()
     tabvlayout = QVBoxLayout()
     widget.setLayout(tabvlayout)
     tabvlayout.addWidget(table)
     btn_layout = QHBoxLayout()
     tabvlayout.addLayout(btn_layout)
     self.tabwidget.addTab(widget, icon, title)
     return btn_layout
Пример #2
0
 def _add_table(self, table, title, icon):
     """Add table tab to main tab widget, return button layout"""
     widget = QWidget()
     tabvlayout = QVBoxLayout()
     widget.setLayout(tabvlayout)
     tabvlayout.addWidget(table)
     btn_layout = QHBoxLayout()
     tabvlayout.addLayout(btn_layout)
     self.tabwidget.addTab(widget, icon, title)
     return btn_layout
Пример #3
0
    def setup_window(self):
        """Setup main window"""
        self.setWindowTitle(self.NAME)
        self.setWindowIcon(get_icon('winpython.svg'))

        self.selector = DistributionSelector(self)
        self.connect(self.selector, SIGNAL('selected_distribution(QString)'),
                     self.distribution_changed)

        self.table = PackagesTable(self, 'install', self.NAME)
        self.connect(self.table, SIGNAL('package_added()'),
                     self.refresh_install_button)
        self.connect(self.table, SIGNAL("clicked(QModelIndex)"),
                     lambda index: self.refresh_install_button())

        self.untable = PackagesTable(self, 'uninstall', self.NAME)
        self.connect(self.untable, SIGNAL("clicked(QModelIndex)"),
                     lambda index: self.refresh_uninstall_button())

        self.selector.set_distribution(sys.prefix)
        self.distribution_changed(sys.prefix)

        self.tabwidget = QTabWidget()
        self.connect(self.tabwidget, SIGNAL('currentChanged(int)'),
                     self.current_tab_changed)
        btn_layout = self._add_table(self.table, "Install/upgrade packages",
                                     get_std_icon("ArrowDown"))
        unbtn_layout = self._add_table(self.untable, "Uninstall packages",
                                       get_std_icon("DialogResetButton"))

        central_widget = QWidget()
        vlayout = QVBoxLayout()
        vlayout.addWidget(self.selector)
        vlayout.addWidget(self.tabwidget)
        central_widget.setLayout(vlayout)
        self.setCentralWidget(central_widget)

        # Install tab
        add_action = create_action(self,
                                   "&Add packages...",
                                   icon=get_std_icon('DialogOpenButton'),
                                   triggered=self.add_packages)
        self.remove_action = create_action(self,
                                           "Remove",
                                           shortcut=keybinding('Delete'),
                                           icon=get_std_icon('TrashIcon'),
                                           triggered=self.remove_packages)
        self.remove_action.setEnabled(False)
        self.select_all_action = create_action(
            self,
            "(Un)Select all",
            shortcut=keybinding('SelectAll'),
            icon=get_std_icon('DialogYesButton'),
            triggered=self.table.select_all)
        self.install_action = create_action(
            self,
            "&Install packages",
            icon=get_std_icon('DialogApplyButton'),
            triggered=lambda: self.process_packages('install'))
        self.install_action.setEnabled(False)
        quit_action = create_action(self,
                                    "&Quit",
                                    icon=get_std_icon('DialogCloseButton'),
                                    triggered=self.close)
        packages_menu = self.menuBar().addMenu("&Packages")
        add_actions(packages_menu, [
            add_action, self.remove_action, self.install_action, None,
            quit_action
        ])

        # Uninstall tab
        self.uninstall_action = create_action(
            self,
            "&Uninstall packages",
            icon=get_std_icon('DialogCancelButton'),
            triggered=lambda: self.process_packages('uninstall'))
        self.uninstall_action.setEnabled(False)

        uninstall_btn = action2button(self.uninstall_action,
                                      autoraise=False,
                                      text_beside_icon=True)

        # Option menu
        option_menu = self.menuBar().addMenu("&Options")
        repair_action = create_action(
            self,
            "Repair packages",
            tip="Reinstall packages even if version is unchanged",
            toggled=self.toggle_repair)
        add_actions(option_menu, (repair_action, ))

        # Advanced menu
        option_menu = self.menuBar().addMenu("&Advanced")
        register_action = create_action(
            self,
            "Register distribution...",
            tip="Register file extensions, icons and context menu",
            triggered=self.register_distribution)
        unregister_action = create_action(
            self,
            "Unregister distribution...",
            tip="Unregister file extensions, icons and context menu",
            triggered=self.unregister_distribution)
        open_console_action = create_action(
            self,
            "Open console here",
            triggered=lambda: os.startfile(self.command_prompt_path))
        open_console_action.setEnabled(osp.exists(self.command_prompt_path))
        add_actions(
            option_menu,
            (register_action, unregister_action, None, open_console_action))

        # View menu
        #        view_menu = self.menuBar().addMenu("&View")
        #        popmenu = self.createPopupMenu()
        #        add_actions(view_menu, popmenu.actions())

        # Help menu
        about_action = create_action(
            self,
            "About %s..." % self.NAME,
            icon=get_std_icon('MessageBoxInformation'),
            triggered=self.about)
        report_action = create_action(self,
                                      "Report issue...",
                                      icon=get_icon('bug.png'),
                                      triggered=self.report_issue)
        help_menu = self.menuBar().addMenu("?")
        add_actions(help_menu, [about_action, None, report_action])

        # Status bar
        status = self.statusBar()
        status.setObjectName("StatusBar")
        status.showMessage("Welcome to %s!" % self.NAME, 5000)

        # Button layouts
        for act in (add_action, self.remove_action, None,
                    self.select_all_action, self.install_action):
            if act is None:
                btn_layout.addStretch()
            else:
                btn_layout.addWidget(
                    action2button(act, autoraise=False, text_beside_icon=True))
        unbtn_layout.addWidget(uninstall_btn)
        unbtn_layout.addStretch()

        self.resize(400, 500)
Пример #4
0
    def setup_window(self):
        """Setup main window"""
        self.setWindowTitle(self.NAME)
        self.setWindowIcon(get_icon("winpython.svg"))

        self.selector = DistributionSelector(self)
        # PyQt4 old SIGNAL: self.connect(self.selector, SIGNAL('selected_distribution(QString)'),
        # PyQt4 old SIGNAL:              self.distribution_changed)
        self.selector.selected_distribution.connect(self.distribution_changed)

        self.table = PackagesTable(self, "install", self.NAME)
        # PyQt4 old SIGNAL:self.connect(self.table, SIGNAL('package_added()'),
        # PyQt4 old SIGNAL:             self.refresh_install_button)
        self.table.package_added.connect(self.refresh_install_button)

        # PyQt4 old SIGNAL: self.connect(self.table, SIGNAL("clicked(QModelIndex)"),
        # PyQt4 old SIGNAL:              lambda index: self.refresh_install_button())
        self.table.clicked.connect(lambda index: self.refresh_install_button())

        self.untable = PackagesTable(self, "uninstall", self.NAME)
        # PyQt4 old SIGNAL:self.connect(self.untable, SIGNAL("clicked(QModelIndex)"),
        # PyQt4 old SIGNAL:             lambda index: self.refresh_uninstall_button())
        self.untable.clicked.connect(lambda index: self.refresh_uninstall_button())

        self.selector.set_distribution(sys.prefix)
        self.distribution_changed(sys.prefix)

        self.tabwidget = QTabWidget()
        # PyQt4 old SIGNAL:self.connect(self.tabwidget, SIGNAL('currentChanged(int)'),
        # PyQt4 old SIGNAL:             self.current_tab_changed)
        self.tabwidget.currentChanged.connect(self.current_tab_changed)

        btn_layout = self._add_table(self.table, "Install/upgrade packages", get_std_icon("ArrowDown"))
        unbtn_layout = self._add_table(self.untable, "Uninstall packages", get_std_icon("DialogResetButton"))

        central_widget = QWidget()
        vlayout = QVBoxLayout()
        vlayout.addWidget(self.selector)
        vlayout.addWidget(self.tabwidget)
        central_widget.setLayout(vlayout)
        self.setCentralWidget(central_widget)

        # Install tab
        add_action = create_action(
            self, "&Add packages...", icon=get_std_icon("DialogOpenButton"), triggered=self.add_packages
        )
        self.remove_action = create_action(
            self,
            "Remove",
            shortcut=keybinding("Delete"),
            icon=get_std_icon("TrashIcon"),
            triggered=self.remove_packages,
        )
        self.remove_action.setEnabled(False)
        self.select_all_action = create_action(
            self,
            "(Un)Select all",
            shortcut=keybinding("SelectAll"),
            icon=get_std_icon("DialogYesButton"),
            triggered=self.table.select_all,
        )
        self.install_action = create_action(
            self,
            "&Install packages",
            icon=get_std_icon("DialogApplyButton"),
            triggered=lambda: self.process_packages("install"),
        )
        self.install_action.setEnabled(False)
        quit_action = create_action(self, "&Quit", icon=get_std_icon("DialogCloseButton"), triggered=self.close)
        packages_menu = self.menuBar().addMenu("&Packages")
        add_actions(packages_menu, [add_action, self.remove_action, self.install_action, None, quit_action])

        # Uninstall tab
        self.uninstall_action = create_action(
            self,
            "&Uninstall packages",
            icon=get_std_icon("DialogCancelButton"),
            triggered=lambda: self.process_packages("uninstall"),
        )
        self.uninstall_action.setEnabled(False)

        uninstall_btn = action2button(self.uninstall_action, autoraise=False, text_beside_icon=True)

        # Option menu
        option_menu = self.menuBar().addMenu("&Options")
        repair_action = create_action(
            self, "Repair packages", tip="Reinstall packages even if version is unchanged", toggled=self.toggle_repair
        )
        add_actions(option_menu, (repair_action,))

        # Advanced menu
        option_menu = self.menuBar().addMenu("&Advanced")
        register_action = create_action(
            self,
            "Register distribution...",
            tip="Register file extensions, icons and context menu",
            triggered=self.register_distribution,
        )
        unregister_action = create_action(
            self,
            "Unregister distribution...",
            tip="Unregister file extensions, icons and context menu",
            triggered=self.unregister_distribution,
        )
        open_console_action = create_action(
            self, "Open console here", triggered=lambda: os.startfile(self.command_prompt_path)
        )
        open_console_action.setEnabled(osp.exists(self.command_prompt_path))
        add_actions(option_menu, (register_action, unregister_action, None, open_console_action))

        # # View menu
        # view_menu = self.menuBar().addMenu("&View")
        # popmenu = self.createPopupMenu()
        # add_actions(view_menu, popmenu.actions())

        # Help menu
        about_action = create_action(
            self, "About %s..." % self.NAME, icon=get_std_icon("MessageBoxInformation"), triggered=self.about
        )
        report_action = create_action(self, "Report issue...", icon=get_icon("bug.png"), triggered=self.report_issue)
        help_menu = self.menuBar().addMenu("?")
        add_actions(help_menu, [about_action, None, report_action])

        # Status bar
        status = self.statusBar()
        status.setObjectName("StatusBar")
        status.showMessage("Welcome to %s!" % self.NAME, 5000)

        # Button layouts
        for act in (add_action, self.remove_action, None, self.select_all_action, self.install_action):
            if act is None:
                btn_layout.addStretch()
            else:
                btn_layout.addWidget(action2button(act, autoraise=False, text_beside_icon=True))
        unbtn_layout.addWidget(uninstall_btn)
        unbtn_layout.addStretch()

        self.resize(400, 500)