2
# Copyright (c) 2004 Conectiva, Inc.
4
# Written by Gustavo Niemeyer <niemeyer@conectiva.com>
6
# This file is part of Smart Package Manager.
8
# Smart Package Manager is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License as published
10
# by the Free Software Foundation; either version 2 of the License, or (at
11
# your option) any later version.
13
# Smart Package Manager is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with Smart Package Manager; if not, write to the Free Software
20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
from smart.interfaces.qt.progress import QtProgress
23
from smart.interfaces.qt.changes import QtChanges
24
from smart.interfaces.qt.log import QtLog
25
from smart.interface import Interface, getScreenWidth
26
from smart.fetcher import Fetcher
27
from smart.const import DEBUG
33
app = qt.QApplication(sys.argv)
35
class QtInterface(Interface):
37
def _currentThread(self):
38
if hasattr(qt, 'QThread'):
39
return qt.QThread.currentThread()
43
def __init__(self, ctrl, argv):
44
Interface.__init__(self, ctrl)
46
self._progress = QtProgress(False)
47
self._progress.setMainThread(self._currentThread())
48
self._hassubprogress = QtProgress(True)
49
self._hassubprogress.setMainThread(self._currentThread())
50
self._changes = QtChanges()
52
self._sys_excepthook = sys.excepthook
54
def run(self, command=None, argv=None):
55
self.setCatchExceptions(True)
56
result = Interface.run(self, command, argv)
57
self.setCatchExceptions(False)
60
def getProgress(self, obj, hassub=False):
63
fetcher = isinstance(obj, Fetcher) and obj or None
64
self._hassubprogress.setFetcher(fetcher)
65
return self._hassubprogress
67
self._hassubprogress.hide()
70
def getSubProgress(self, obj):
71
return self._hassubprogress
73
def askYesNo(self, question, default=False):
74
response = qt.QMessageBox.question(self._window,
81
if response == qt.QMessageBox.Yes:
83
elif response == qt.QMessageBox.No:
88
def askContCancel(self, question, default=False):
89
response = qt.QMessageBox.question(self._window,
96
#response.setButtonText(QMessageBox.Ok, )
105
def askOkCancel(self, question, default=False):
106
response = qt.QMessageBox.question(self._window,
110
qt.QMessageBox.Cancel)
113
if response == qt.QMessageBox.Ok:
115
elif response == qt.QMessageBox.Cancel:
120
def askInput(self, prompt, message=None, widthchars=40, echo=True):
121
if (message != None):
122
stringToShow = message + "\n" + prompt
124
stringToShow = prompt
126
echoMode = qt.QLineEdit.Normal
128
echoMode = qt.QLineEdit.Password
130
text, ok = qt.QInputDialog.getText( _("Input"), stringToShow, echoMode)
132
if (ok and text != None):
133
return text[0:widthchars]
137
def insertRemovableChannels(self, channels):
138
question = _("Insert one or more of the following removable "
141
for channel in channels:
143
question += channel.getName()
145
return self.askOkCancel(question, default=True)
147
def message(self, level, msg):
148
self._log.message(level, msg)
150
def confirmChange(self, oldchangeset, newchangeset, expected=1):
151
changeset = newchangeset.difference(oldchangeset)
153
for pkg in oldchangeset:
154
if pkg not in newchangeset:
156
if len(keep)+len(changeset) <= expected:
158
return self._changes.showChangeSet(changeset, keep=keep, confirm=True)
160
def confirmChangeSet(self, changeset):
161
return self._changes.showChangeSet(changeset, confirm=True)
163
# Non-standard interface methods
165
def _excepthook(self, type, value, tb):
166
if issubclass(type, Error) and not sysconf.get("log-level") is DEBUG:
167
self._hassubprogress.hide()
168
self._progress.hide()
169
iface.error(unicode(value[0]))
172
lines = traceback.format_exception(type, value, tb)
173
iface.error("\n".join(lines))
175
def setCatchExceptions(self, flag):
177
sys.excepthook = self._excepthook
179
sys.excepthook = self._sys_excepthook
181
def hideProgress(self):
182
self._progress.hide()
183
self._hassubprogress.hide()