From a9b07b7c0c6382eb8fadcc54d1d8a00075c38a29 Mon Sep 17 00:00:00 2001 From: necoro <> Date: Fri, 6 Apr 2007 00:31:03 +0000 Subject: First qt draft --- portato/gui/qt/__init__.py | 17 ++ portato/gui/qt/ui/AboutDialog.ui | 85 ++++++++ portato/gui/qt/ui/MainWindow.ui | 418 +++++++++++++++++++++++++++++++++++++++ portato/gui/qt/windows.py | 270 +++++++++++++++++++++++++ 4 files changed, 790 insertions(+) create mode 100644 portato/gui/qt/__init__.py create mode 100644 portato/gui/qt/ui/AboutDialog.ui create mode 100644 portato/gui/qt/ui/MainWindow.ui create mode 100644 portato/gui/qt/windows.py (limited to 'portato/gui') diff --git a/portato/gui/qt/__init__.py b/portato/gui/qt/__init__.py new file mode 100644 index 0000000..c714757 --- /dev/null +++ b/portato/gui/qt/__init__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# +# File: portato/gui/qt/__init__.py +# This file is part of the Portato-Project, a graphical portage-frontend. +# +# Copyright (C) 2007 René 'Necoro' Neumann +# This is free software. You may redistribute copies of it under the terms of +# the GNU General Public License version 2. +# There is NO WARRANTY, to the extent permitted by law. +# +# Written by René 'Necoro' Neumann + +from windows import MainWindow + +def run(): + m = MainWindow() + m.main() diff --git a/portato/gui/qt/ui/AboutDialog.ui b/portato/gui/qt/ui/AboutDialog.ui new file mode 100644 index 0000000..e7cd4ff --- /dev/null +++ b/portato/gui/qt/ui/AboutDialog.ui @@ -0,0 +1,85 @@ + + Dialog + + + Qt::ApplicationModal + + + + 0 + 0 + 369 + 279 + + + + About Portato + + + + 9 + + + 6 + + + + + TextLabel + + + Qt::AlignCenter + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + true + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 174 + 252 + + + 176 + 197 + + + + + diff --git a/portato/gui/qt/ui/MainWindow.ui b/portato/gui/qt/ui/MainWindow.ui new file mode 100644 index 0000000..c982485 --- /dev/null +++ b/portato/gui/qt/ui/MainWindow.ui @@ -0,0 +1,418 @@ + + MainWindow + + + + 0 + 0 + 466 + 695 + + + + Portato + + + + + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + + + + &Search + + + + + + + + + Qt::Vertical + + + + + 0 + + + 6 + + + + + false + + + QFrame::Sunken + + + + + + + + + + + 1 + + + + Package + + + + 9 + + + 6 + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + 0 + + + 6 + + + + + + 3 + 0 + 0 + 0 + + + + + + + + + 13 + 5 + 0 + 0 + + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600; color:#ff0000;">MISSING KEYWORD</span></p></body></html> + + + + + + + + 13 + 5 + 0 + 0 + + + + <b>Installed, but not in portage anymore</b> + + + + + + + + 3 + 0 + 0 + 0 + + + + Installed + + + + + + + true + + + + 3 + 0 + 0 + 0 + + + + Testing + + + + + + + + 3 + 0 + 0 + 0 + + + + Masked + + + + + + + + + Qt::ScrollBarAsNeeded + + + true + + + false + + + false + + + 3 + + + + 1 + + + + + 1 + + + + + 2 + + + + + + + + 0 + + + 6 + + + + + &Emerge + + + + + + + &Unmerge + + + + + + + Re&vert + + + + + + + E&build + + + + + + + + + + Queue + + + + 0 + + + 6 + + + + + + + + 2 + + + 6 + + + + + + 1 + 0 + 0 + 0 + + + + &Emerge + + + + + + + &Unmerge + + + + + + + Update &World + + + + + + + &Remove + + + + + + + + + + + + + + + + 0 + 0 + 466 + 28 + + + + + &File + + + + + + &? + + + + + + + + + true + + + + + + + + &Quit + + + QAction::TextHeuristicRole + + + + + &About + + + + + + + quitAction + triggered() + MainWindow + close() + + + -1 + -1 + + + 361 + 299 + + + + + diff --git a/portato/gui/qt/windows.py b/portato/gui/qt/windows.py new file mode 100644 index 0000000..475ac45 --- /dev/null +++ b/portato/gui/qt/windows.py @@ -0,0 +1,270 @@ +# -*- coding: utf-8 -*- +# +# File: portato/gui/qt/windows.py +# This file is part of the Portato-Project, a graphical portage-frontend. +# +# Copyright (C) 2007 René 'Necoro' Neumann +# This is free software. You may redistribute copies of it under the terms of +# the GNU General Public License version 2. +# There is NO WARRANTY, to the extent permitted by law. +# +# Written by René 'Necoro' Neumann + +from PyQt4 import QtGui, uic, QtCore +import sip + +# our backend stuff +from portato.helper import * +from portato.constants import CONFIG_LOCATION, VERSION, DATA_DIR +from portato.backend import flags, system +from portato.backend.exceptions import * + +from portato.gui.gui_helper import Database, Config, EmergeQueue + +UI_DIR = DATA_DIR+"ui/" + +app = QtGui.QApplication([]) + +def qCheck (check): + if check: + return QtCore.Qt.Checked + else: + return QtCore.Qt.Unchecked + +class WindowMeta (sip.wrappertype, type): + + def __new__ (cls, name, bases, dict): + new_bases = uic.loadUiType(UI_DIR+name+".ui") + dict.update(_bases = new_bases) + dict.update(_qt_base = new_bases[1]) + return super(WindowMeta, cls).__new__(cls, name, new_bases+bases, dict) + + def __init__ (cls, name, bases, dict): + b = dict["_bases"] + del dict["_bases"] + super(WindowMeta, cls).__init__(name, b+bases, dict) + +class Window: + + def __init__(self): + self._qt_base.__init__(self) + self.setupUi(self) + +class AboutDialog (Window): + __metaclass__ = WindowMeta + + def __init__ (self): + Window.__init__(self) + + self.label.setText(""" +Portato v.%s

+A Portage-GUI
+
+This software is licensed under the terms of the GPLv2.
+Copyright (C) 2006-2007 René 'Necoro' Neumann <necoro@necoro.net>
+
+Thanks to Fred for support and ideas :P""" % VERSION) + + self.adjustSize() + +class PackageDetails: + + def __init__ (self, window): + self.window = window + self.window.pkgTab.setHidden(True) + self.window.tabWidget.removeTab(0) + + QtCore.QObject.connect(self.window.versCombo, QtCore.SIGNAL("currentIndexChanged(int)"), self.cb_combo_changed) + + def update (self, cp, version = None): + self.cp = cp + self.version = version + + # packages and installed packages + self.packages = system.sort_package_list(system.find_packages(cp, masked = True)) + self.instPackages = system.sort_package_list(system.find_installed_packages(cp, masked = True)) + + # comboBox + self.set_combo() + + # the labels + desc = self.actual_package().get_package_settings("DESCRIPTION").replace("&","&") + + if not desc: + desc = "" + else: + desc = "%s" % desc + + self.window.descLabel.setText(desc) + self.window.nameLabel.setText("%s" % self.actual_package().get_cp()) + + # first update -> show + if self.window.pkgTab.isHidden(): + self.window.tabWidget.insertTab(0, self.window.pkgTab, "Package") + self.window.pkgTab.setHidden(False) + + self.window.tabWidget.setCurrentIndex(0) + + def set_combo (self): + self.window.versCombo.clear() + self.window.versCombo.addItems([x.get_version() for x in self.packages]) + + try: + best_version = "" + if self.version: + best_version = self.version + else: + best_version = system.find_best_match(self.packages[0].get_cp(), (self.instPackages != [])).get_version() + + for i in range(len(self.packages)): + if self.packages[i].get_version() == best_version: + self.window.versCombo.setCurrentIndex(i) + except AttributeError: + self.window.versCombo.setCurrentIndex(0) + + def build_use_list (self): + self.window.useList.clear() + self.window.useList.setHeaderLabels(["Enabled","Flag","Description"]) + + pkg = self.actual_package() + pkg_flags = pkg.get_all_use_flags() + pkg_flags.sort() + + actual_exp = None + actual_exp_it = self.window.useList + + for use in pkg_flags: + exp = pkg.use_expanded(use, suggest = actual_exp) + if exp is not None: + if exp != actual_exp: + actual_exp_it = QtGui.QTreeWidgetItem(self.window.useList, ["", exp, ""]) + actual_exp = exp + else: + actual_exp_it = self.window.useList + actual_exp = None + + item = QtGui.QTreeWidgetItem(actual_exp_it, ["", use, system.get_use_desc(use, self.cp)]) + item.setCheckState(0, qCheck(pkg.is_use_flag_enabled(use))) + + def cb_combo_changed (self, combo): + """Callback for the changed ComboBox. + It then rebuilds the useList and the checkboxes.""" + + # build new + self.build_use_list() + pkg = self.actual_package() + + shown = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed) + hidden = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Fixed) + + # + # rebuild the buttons and checkboxes in all the different manners which are possible + # + if (not pkg.is_in_system()) or pkg.is_missing_keyword(): + if not pkg.is_in_system(): + self.window.missingLabel.setSizePolicy(hidden) + self.window.notInSysLabel.setSizePolicy(shown) + else: # missing keyword + self.window.missingLabel.setSizePolicy(shown) + self.window.notInSysLabel.setSizePolicy(hidden) + + self.window.installedCheck.setSizePolicy(hidden) + self.window.maskedCheck.setSizePolicy(hidden) + self.window.testingCheck.setSizePolicy(hidden) + #self.window.pkgEmergeBtn.setEnabled(False) + else: # normal package + self.window.missingLabel.setSizePolicy(hidden) + self.window.notInSysLabel.setSizePolicy(hidden) + self.window.installedCheck.setSizePolicy(shown) + self.window.maskedCheck.setSizePolicy(shown) + self.window.testingCheck.setSizePolicy(shown) + #if self.doEmerge: + # self.emergeBtn.set_sensitive(True) + self.window.installedCheck.setCheckState(qCheck(pkg.is_installed())) + + if pkg.is_masked(use_changed = False) and not pkg.is_masked(use_changed = True): + self.window.maskedCheck.setText("(Masked)") + else: + self.window.maskedCheck.setText("Masked") + + self.window.maskedCheck.setCheckState(qCheck(pkg.is_masked(use_changed = False))) + + if pkg.is_testing(use_keywords = False) and not pkg.is_testing(use_keywords = True): + self.window.testingCheck.setText("(Testing)") + else: + self.window.testingCheck.setText("Testing") + + self.window.testingCheck.setCheckState(qCheck(pkg.is_testing(use_keywords = False))) + +# if self.doEmerge: +# # set emerge-button-label +# if not self.actual_package().is_installed(): +# self.emergeBtn.set_label("E_merge") +# self.unmergeBtn.set_sensitive(False) +# else: +# self.emergeBtn.set_label("Re_merge") +# self.unmergeBtn.set_sensitive(True) + + def actual_package (self): + """Returns the actual selected package. + + @returns: the actual selected package + @rtype: backend.Package""" + + return self.packages[self.window.versCombo.currentIndex()] + +class MainWindow (Window): + + __metaclass__ = WindowMeta + + def __init__ (self): + Window.__init__(self) + + self.setWindowTitle(("Portato (%s)" % VERSION)) + self.statusbar.showMessage("Portato - A Portage GUI") + + self.pkgDetails = PackageDetails(self) + + # package db + self.db = Database() + self.db.populate() + + self.build_pkg_list() + self.build_cat_list() + QtCore.QObject.connect(self.selCatListModel, QtCore.SIGNAL("currentChanged(QModelIndex, QModelIndex)"), self.cb_cat_list_selected) + QtCore.QObject.connect(self.selPkgListModel, QtCore.SIGNAL("currentChanged(QModelIndex, QModelIndex)"), self.cb_pkg_list_selected) + + QtCore.QObject.connect(self.aboutAction, QtCore.SIGNAL("triggered()"), self.cb_about_triggered) + + self.show() + + def cb_about_triggered (self): + AboutDialog().exec_() + + def cb_cat_list_selected (self, index, prev): + self.selCatName = str(index.data().toString()) + self.fill_pkg_list(self.selCatName) + + def cb_pkg_list_selected (self, index, prev): + self.pkgDetails.update(self.selCatName+"/"+str(index.data().toString())) + + def fill_pkg_list (self, cat): + self.pkgListModel.setStringList([name for (name,inst) in self.db.get_cat(cat)]) + + def build_pkg_list (self): + self.pkgListModel = QtGui.QStringListModel([]) + self.pkgListModel.sort(0) + self.selPkgListModel = QtGui.QItemSelectionModel(self.pkgListModel) + self.pkgList.setModel(self.pkgListModel) + self.pkgList.setSelectionModel(self.selPkgListModel) + + def build_cat_list (self): + self.catListModel = QtGui.QStringListModel(system.list_categories()) + self.catListModel.sort(0) + self.selCatListModel = QtGui.QItemSelectionModel(self.catListModel) + self.catList.setModel(self.catListModel) + self.catList.setSelectionModel(self.selCatListModel) + + def main (self): + app.exec_() + -- cgit v1.2.3-54-g00ecf