# -*- 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 <necoro@necoro.net>
# qt4
from PyQt4 import Qt, uic
import sip
# our backend stuff
from portato.helper import *
from portato.constants import CONFIG_LOCATION, VERSION, DATA_DIR, APP_ICON
from portato.backend import flags, system
from portato.backend.exceptions import *
from portato.gui.gui_helper import Database, Config, EmergeQueue
# plugins
from portato import plugin
# own GUI stuff
from terminal import QtConsole
from tree import QtTree
from highlighter import EbuildHighlighter
from dialogs import *
from helper import qCheck, qIsChecked
import types
UI_DIR = DATA_DIR+"ui/"
class WindowMeta (sip.wrappertype, type):
"""This is the metaclass of all Qt-Windows. It automatically
sets the correct base classes, so they do not have to be set
by the programmer.
@attention: The class has to have the same name as the .ui-file."""
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 (object):
"""Base class of all Qt-Windows.
Sets up the UI and provides the watch_cursor function."""
def __init__(self, parent = None):
self._qt_base.__init__(self, parent)
self.setupUi(self)
self.setWindowIcon(Qt.QIcon(APP_ICON))
@staticmethod
def watch_cursor (func):
"""This is a decorator for functions being so time consuming, that it is appropriate to show the watch-cursor."""
def wrapper (*args, **kwargs):
ret = None
Qt.QApplication.setOverrideCursor(Qt.Qt.WaitCursor)
try:
try:
ret = func(*args, **kwargs)
finally:
Qt.QApplication.restoreOverrideCursor()
except TypeError:
pass # invalid signature called
return ret
return wrapper
class PluginDialog (Window):
__metaclass__ = WindowMeta
def __init__ (self, parent, plugins):
Window.__init__(self, parent)
self.pluginList.setHeaderLabels(["Plugin", "Author"])
self.plugins = {}
self.changedPlugins = {}
for p in plugins:
item = Qt.QTreeWidgetItem(self.pluginList, [p.name,p.author])
item.setCheckState(0, qCheck(p.is_enabled()))
self.plugins.update({self.create_key(p.name,p.author) : p}) # create a list of plugins
self.pluginList.resizeColumnToContents(0)
Qt.QObject.connect(self.pluginList, Qt.SIGNAL("itemClicked(QTreeWidgetItem*, int)"), self.cb_plugin_toggled)
def create_key (self, name, author):
return str(name + "_" + author)
def cb_plugin_toggled (self, item, col):
if col != 0:
return
self.changedPlugins.update({ \
self.create_key(str(item.text(0)), str(item.text(1))) : \
qIsChecked(item.checkState(0))\
})
@Qt.pyqtSignature("")
def on_buttonBox_accepted(self):
for pluginKey, value in self.changedPlugins.iteritems():
self.plugins[pluginKey].set_option("disabled", not value)
self.accept()
class AboutDialog (Window):
"""A window showing the "about"-informations."""
__metaclass__ = WindowMeta
def __init__ (self, parent = None):
"""Constructor.
@param parent: the parent window
@type parent: Qt.QWidget"""
Window.__init__(self, parent)
self.pix = Qt.QPixmap(APP_ICON)
self.imgLabel.setPixmap(self.pix) # yes we have to use a label for the image ...
self.label.setText("""
<font size=5><b>Portato v.%s</b></font><br><br>
A Portage-GUI<br>
<br>
This software is licensed under the terms of the GPLv2.<br>
Copyright (C) 2006-2007 René 'Necoro' Neumann <necoro@necoro.net><br>
<br>
Icon created by P4R4D0X""" % VERSION)
class SearchDialog (Window):
"""A window showing the results of a search process."""
__metaclass__ = WindowMeta
def __init__ (self, parent, list, jumpTo):
"""Constructor.
@param parent: parent-window
@type parent: Qt.QWidget
@param list: list of results to show
@type list: string[]
@param jumpTo: function to call if "OK"-Button is hit
@type jumpTo: function(string)"""
Window.__init__(self, parent)
self.comboBox.addItems(list)
self.comboBox.setCurrentIndex(0)
self.jumpTo = jumpTo
Qt.QObject.connect(self, Qt.SIGNAL("accepted()"), self.finish)
def finish (self):
s = str(self.comboBox.currentText())
self.done(0)
self.jumpTo(s)
class UpdateDialog (Window):
"""Dialog showing updatable packages."""
__metaclass__ = WindowMeta
def __init__ (self, parent, packages, queue
|