Exemplo n.º 1
0
def create_action(parent,
                  text,
                  shortcut=None,
                  icon=None,
                  tip=None,
                  toggled=None,
                  triggered=None,
                  data=None,
                  menurole=None,
                  context=Qt.WindowShortcut):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        parent.connect(action, SIGNAL("triggered()"), triggered)
    if toggled is not None:
        parent.connect(action, SIGNAL("toggled(bool)"), toggled)
        action.setCheckable(True)
    if icon is not None:
        if is_text_string(icon):
            icon = get_icon(icon)
        action.setIcon(icon)
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(to_qvariant(data))
    if menurole is not None:
        action.setMenuRole(menurole)
    #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
    # (this will avoid calling shortcuts from another dockwidget
    #  since the context thing doesn't work quite well with these widgets)
    action.setShortcutContext(context)
    return action
Exemplo n.º 2
0
 def add_packages(self, fnames):
     """Add packages"""
     notsupported = []
     notcompatible = []
     dist = self.distribution
     for fname in fnames:
         bname = osp.basename(fname)
         try:
             package = wppm.Package(fname)
             if package.is_compatible_with(dist):
                 self.add_package(package)
             else:
                 notcompatible.append(bname)
         except NotImplementedError:
             notsupported.append(bname)
     self.emit(SIGNAL('package_added()'))
     if notsupported:
         QMessageBox.warning(
             self, "Warning", "The following packages are <b>not (yet) "
             "supported</b> by %s:\n\n%s" %
             (self.winname, "<br>".join(notsupported)), QMessageBox.Ok)
     if notcompatible:
         QMessageBox.warning(
             self, "Warning", "The following packages "
             "are <b>not compatible</b> with "
             "Python <u>%s %dbit</u>:\n\n%s" %
             (dist.version, dist.architecture, "<br>".join(notcompatible)),
             QMessageBox.Ok)
Exemplo n.º 3
0
 def setData(self, index, value, role=Qt.EditRole):
     if index.isValid() and 0 <= index.row() < len(self.packages)\
        and role == Qt.CheckStateRole:
         package = self.packages[index.row()]
         if package in self.checked:
             self.checked.remove(package)
         else:
             self.checked.add(package)
         self.emit(SIGNAL("dataChanged(QModelIndex,QModelIndex)"), index,
                   index)
         return True
     return False
Exemplo n.º 4
0
 def setup_widget(self):
     """Setup workspace selector widget"""
     self.label = QLabel()
     self.line_edit = QLineEdit()
     self.line_edit.setAlignment(Qt.AlignRight)
     self.line_edit.setReadOnly(True)
     #self.line_edit.setDisabled(True)
     self.browse_btn = QPushButton(get_std_icon('DirOpenIcon'), "", self)
     self.browse_btn.setToolTip(self.TITLE)
     self.connect(self.browse_btn, SIGNAL("clicked()"),
                  self.select_directory)
     layout = QHBoxLayout()
     layout.addWidget(self.label)
     layout.addWidget(self.line_edit)
     layout.addWidget(self.browse_btn)
     layout.setContentsMargins(0, 0, 0, 0)
     self.setLayout(layout)
Exemplo n.º 5
0
 def select_directory(self):
     """Select directory"""
     basedir = to_text_string(self.line_edit.text())
     if not osp.isdir(basedir):
         basedir = getcwd()
     while True:
         directory = getexistingdirectory(self, self.TITLE, basedir)
         if not directory:
             break
         if not utils.is_python_distribution(directory):
             QMessageBox.warning(self, self.TITLE,
                 "The following directory is not a Python distribution.",
                 QMessageBox.Ok)
             basedir = directory
             continue
         directory = osp.abspath(osp.normpath(directory))
         self.set_distribution(directory)
         self.emit(SIGNAL('selected_distribution(QString)'), directory)
         break
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def event(self, event):
     if event.type() == QEvent.FileOpen:
         fname = str(event.file())
         self.emit(SIGNAL('open_external_file(QString)'), fname)
     return QApplication.event(self, event)