diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-03-28 22:32:14 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-06-28 02:47:08 +0200 |
commit | b1fffc3a1b2dbbb807213b85f538e59251b9bf35 (patch) | |
tree | c373d3234dcb474bb424371a3d89341bed8a9e07 /module/gui | |
parent | Plugins licensing doc (diff) | |
download | pyload-b1fffc3a1b2dbbb807213b85f538e59251b9bf35.tar.xz |
Remove bad whitespaces
Merged vuolter/pyload@00288e6
Diffstat (limited to 'module/gui')
-rw-r--r-- | module/gui/AccountEdit.py | 34 | ||||
-rw-r--r-- | module/gui/Accounts.py | 44 | ||||
-rw-r--r-- | module/gui/CNLServer.py | 4 | ||||
-rw-r--r-- | module/gui/CaptchaDock.py | 22 | ||||
-rw-r--r-- | module/gui/Collector.py | 58 | ||||
-rw-r--r-- | module/gui/ConnectionManager.py | 56 | ||||
-rw-r--r-- | module/gui/CoreConfigParser.py | 77 | ||||
-rw-r--r-- | module/gui/LinkDock.py | 12 | ||||
-rw-r--r-- | module/gui/MainWindow.py | 158 | ||||
-rw-r--r-- | module/gui/Overview.py | 58 | ||||
-rw-r--r-- | module/gui/PackageDock.py | 14 | ||||
-rw-r--r-- | module/gui/Queue.py | 58 | ||||
-rw-r--r-- | module/gui/SettingsWidget.py | 14 | ||||
-rw-r--r-- | module/gui/XMLParser.py | 8 | ||||
-rw-r--r-- | module/gui/connector.py | 32 |
15 files changed, 323 insertions, 326 deletions
diff --git a/module/gui/AccountEdit.py b/module/gui/AccountEdit.py index b22cfc49f..07a4cdad6 100644 --- a/module/gui/AccountEdit.py +++ b/module/gui/AccountEdit.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -25,16 +25,16 @@ class AccountEdit(QWidget): """ account editor widget """ - + def __init__(self): QMainWindow.__init__(self) self.setWindowTitle(_("Edit account")) self.setWindowIcon(QIcon(join(pypath, "icons","logo.png"))) - + self.setLayout(QGridLayout()) l = self.layout() - + typeLabel = QLabel(_("Type")) loginLabel = QLabel(_("Login")) passwordLabel = QLabel(_("New password")) @@ -49,11 +49,11 @@ class AccountEdit(QWidget): self.login = login acctype = QComboBox() self.acctype = acctype - + save = QPushButton(_("Save")) - + self.connect(changePw, SIGNAL("toggled(bool)"), password, SLOT("setEnabled(bool)")) - + l.addWidget(save, 3, 0, 1, 3) l.addWidget(acctype, 0, 1, 1, 2) l.addWidget(login, 1, 1, 1, 2) @@ -62,9 +62,9 @@ class AccountEdit(QWidget): l.addWidget(passwordLabel, 2, 0) l.addWidget(loginLabel, 1, 0) l.addWidget(typeLabel, 0, 0) - + self.connect(save, SIGNAL("clicked()"), self.slotSave) - + def slotSave(self): """ save entered data @@ -73,7 +73,7 @@ class AccountEdit(QWidget): if self.changePw.isChecked(): data["password"] = str(self.password.text()) self.emit(SIGNAL("done"), data) - + @staticmethod def newAccount(types): """ @@ -81,24 +81,24 @@ class AccountEdit(QWidget): """ w = AccountEdit() w.setWindowTitle(_("Create account")) - + w.changePw.setChecked(True) w.password.setEnabled(True) - + w.acctype.addItems(types) - + return w - + @staticmethod def editAccount(types, base): """ create editor instance with given data """ w = AccountEdit() - + w.acctype.addItems(types) w.acctype.setCurrentIndex(types.index(base["type"])) - + w.login.setText(base["login"]) - + return w diff --git a/module/gui/Accounts.py b/module/gui/Accounts.py index 8db04dfa9..d6bd442f1 100644 --- a/module/gui/Accounts.py +++ b/module/gui/Accounts.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -25,7 +25,7 @@ class AccountModel(QAbstractItemModel): """ model for account view """ - + def __init__(self, view, connector): QAbstractItemModel.__init__(self) self.connector = connector @@ -33,7 +33,7 @@ class AccountModel(QAbstractItemModel): self._data = [] self.cols = 4 self.mutex = QMutex() - + def reloadData(self, force=False): """ reload account list @@ -42,23 +42,23 @@ class AccountModel(QAbstractItemModel): if self._data == accounts: return - + if len(self._data) > 0: self.beginRemoveRows(QModelIndex(), 0, len(self._data)-1) self._data = [] self.endRemoveRows() - + if len(accounts) > 0: self.beginInsertRows(QModelIndex(), 0, len(accounts)-1) self._data = accounts self.endInsertRows() - + def toData(self, index): """ return index pointer """ return index.internalPointer() - + def data(self, index, role=Qt.DisplayRole): """ return cell data @@ -85,7 +85,7 @@ class AccountModel(QAbstractItemModel): # if index.column() == 0: # return QVariant(index.internalPointer().data["name"]) return QVariant() - + def index(self, row, column, parent=QModelIndex()): """ create index with data pointer @@ -99,13 +99,13 @@ class AccountModel(QAbstractItemModel): else: index = QModelIndex() return index - + def parent(self, index): """ no parents, everything on top level """ return QModelIndex() - + def rowCount(self, parent=QModelIndex()): """ account count @@ -113,10 +113,10 @@ class AccountModel(QAbstractItemModel): if parent == QModelIndex(): return len(self._data) return 0 - + def columnCount(self, parent=QModelIndex()): return self.cols - + def hasChildren(self, parent=QModelIndex()): """ everything on top level @@ -125,10 +125,10 @@ class AccountModel(QAbstractItemModel): return True else: return False - + def canFetchMore(self, parent): return False - + def headerData(self, section, orientation, role=Qt.DisplayRole): """ returns column heading @@ -143,29 +143,29 @@ class AccountModel(QAbstractItemModel): elif section == 3: return QVariant(_("Traffic left")) return QVariant() - + def flags(self, index): """ cell flags """ return Qt.ItemIsSelectable | Qt.ItemIsEnabled - + class AccountView(QTreeView): """ view component for accounts """ - + def __init__(self, connector): QTreeView.__init__(self) self.setModel(AccountModel(self, connector)) - + self.setColumnWidth(0, 150) self.setColumnWidth(1, 150) self.setColumnWidth(2, 150) self.setColumnWidth(3, 150) - + self.setEditTriggers(QAbstractItemView.NoEditTriggers) - + self.delegate = AccountDelegate(self, self.model()) self.setItemDelegateForColumn(3, self.delegate) @@ -173,7 +173,7 @@ class AccountDelegate(QItemDelegate): """ used to display a progressbar for the traffic in the traffic cell """ - + def __init__(self, parent, model): QItemDelegate.__init__(self, parent) self.model = model @@ -195,7 +195,7 @@ class AccountDelegate(QItemDelegate): opts.maximum = opts.progress = data.trafficleft if data.maxtraffic: opts.maximum = data.maxtraffic - + opts.rect = option.rect opts.rect.setRight(option.rect.right()-1) opts.rect.setHeight(option.rect.height()-1) diff --git a/module/gui/CNLServer.py b/module/gui/CNLServer.py index 5ecac8277..b55555272 100644 --- a/module/gui/CNLServer.py +++ b/module/gui/CNLServer.py @@ -43,7 +43,7 @@ class CNLServer(Thread): def __init__(self): Thread.__init__(self) self.setDaemon(True) - + self.stop = False self.stopped = False @@ -54,7 +54,7 @@ class CNLServer(Thread): except: self.stopped = True return - + self.stopped = False while self.keep_running(): httpd.handle_request() diff --git a/module/gui/CaptchaDock.py b/module/gui/CaptchaDock.py index b88cb53ca..04e4ac6ad 100644 --- a/module/gui/CaptchaDock.py +++ b/module/gui/CaptchaDock.py @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -24,7 +24,7 @@ class CaptchaDock(QDockWidget): """ dock widget for captcha input """ - + def __init__(self): QDockWidget.__init__(self, _("Captcha")) self.setObjectName("Captcha Dock") @@ -36,10 +36,10 @@ class CaptchaDock(QDockWidget): self.processing = False self.currentID = None self.connect(self, SIGNAL("setTask"), self.setTask) - + def isFree(self): return not self.processing - + def setTask(self, tid, img, imgType): self.processing = True data = QByteArray(img) @@ -52,38 +52,38 @@ class CaptchaDockWidget(QWidget): """ widget for the input widgets """ - + def __init__(self, dock): QWidget.__init__(self) self.dock = dock self.setLayout(QHBoxLayout()) layout = self.layout() - + imgLabel = QLabel() captchaInput = QLineEdit() okayButton = QPushButton(_("OK")) cancelButton = QPushButton(_("Cancel")) - + layout.addStretch() layout.addWidget(imgLabel) layout.addWidget(captchaInput) layout.addWidget(okayButton) layout.addWidget(cancelButton) layout.addStretch() - + self.input = captchaInput - + self.connect(okayButton, SIGNAL("clicked()"), self.slotSubmit) self.connect(captchaInput, SIGNAL("returnPressed()"), self.slotSubmit) self.connect(self, SIGNAL("setImage"), self.setImg) self.connect(self, SIGNAL("setPixmap(const QPixmap &)"), imgLabel, SLOT("setPixmap(const QPixmap &)")) - + def setImg(self, data): pixmap = QPixmap() pixmap.loadFromData(data) self.emit(SIGNAL("setPixmap(const QPixmap &)"), pixmap) self.input.setFocus(Qt.OtherFocusReason) - + def slotSubmit(self): text = self.input.text() tid = self.dock.currentID diff --git a/module/gui/Collector.py b/module/gui/Collector.py index 3ec4262f1..d4cc0832f 100644 --- a/module/gui/Collector.py +++ b/module/gui/Collector.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -32,7 +32,7 @@ class CollectorModel(QAbstractItemModel): """ model for the collector view """ - + def __init__(self, view, connector): QAbstractItemModel.__init__(self) self.connector = connector @@ -41,7 +41,7 @@ class CollectorModel(QAbstractItemModel): self.cols = 4 self.interval = 1 self.mutex = QMutex() - + global translatedStatusMap # workaround because i18n is not running at import time translatedStatusMap = { "finished": _("finished"), @@ -59,13 +59,13 @@ class CollectorModel(QAbstractItemModel): "downloading": _("downloading"), "processing": _("processing") } - + def translateStatus(self, string): """ used to convert to locale specific status """ return translatedStatusMap[string] - + def addEvent(self, event): """ called from main loop, pass events to the correct methods @@ -79,7 +79,7 @@ class CollectorModel(QAbstractItemModel): self.insertEvent(event) elif event.eventname == "update": self.updateEvent(event) - + def fullReload(self): """ reload whole model, used at startup to load initial data @@ -93,7 +93,7 @@ class CollectorModel(QAbstractItemModel): self._data.append(package) self._data = sorted(self._data, key=lambda p: p.data["order"]) self.endInsertRows() - + def removeEvent(self, event): """ remove an element from model @@ -113,7 +113,7 @@ class CollectorModel(QAbstractItemModel): del self._data[k] self.endRemoveRows() break - + def insertEvent(self, event): """ inserts a new element in the model @@ -123,7 +123,7 @@ class CollectorModel(QAbstractItemModel): info = self.connector.getFileData(event.id) except FileDoesNotExists: return - + for k, package in enumerate(self._data): if package.id == info.package: if package.getChild(info.fid): @@ -139,7 +139,7 @@ class CollectorModel(QAbstractItemModel): self.beginInsertRows(QModelIndex(), data.order, data.order) self._data.insert(data.order, package) self.endInsertRows() - + def updateEvent(self, event): """ update an element in the model @@ -167,7 +167,7 @@ class CollectorModel(QAbstractItemModel): package.update(data) self.emit(SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), self.index(p, 0), self.index(p, self.cols)) break - + def data(self, index, role=Qt.DisplayRole): """ return cell data @@ -210,7 +210,7 @@ class CollectorModel(QAbstractItemModel): if index.column() == 0: return QVariant(index.internalPointer().data["name"]) return QVariant() - + def index(self, row, column, parent=QModelIndex()): """ creates a cell index with pointer to the data @@ -227,7 +227,7 @@ class CollectorModel(QAbstractItemModel): else: index = QModelIndex() return index - + def parent(self, index): """ return index of parent element @@ -242,7 +242,7 @@ class CollectorModel(QAbstractItemModel): if pack == link.package: return self.createIndex(k, 0, link.package) return QModelIndex() - + def rowCount(self, parent=QModelIndex()): """ returns row count for the element @@ -263,18 +263,18 @@ class CollectorModel(QAbstractItemModel): return False #files have no children return 0 - + def columnCount(self, parent=QModelIndex()): return self.cols - + def hasChildren(self, parent=QModelIndex()): if not parent.isValid(): return True return self.rowCount(parent) > 0 - + def canFetchMore(self, parent): return False - + def headerData(self, section, orientation, role=Qt.DisplayRole): """ returns column heading @@ -289,7 +289,7 @@ class CollectorModel(QAbstractItemModel): elif section == 3: return QVariant(_("Size")) return QVariant() - + def flags(self, index): """ cell flags @@ -297,7 +297,7 @@ class CollectorModel(QAbstractItemModel): if index.column() == 0 and self.parent(index) == QModelIndex(): return Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled return Qt.ItemIsSelectable | Qt.ItemIsEnabled - + def setData(self, index, value, role=Qt.EditRole): """ called if package name editing is finished, sets new name @@ -310,7 +310,7 @@ class Package(object): """ package object in the model """ - + def __init__(self, pack): self.id = pack.pid self.children = [] @@ -318,7 +318,7 @@ class Package(object): self.addChild(f) self.data = {} self.update(pack) - + def update(self, pack): """ update data dict from thift object @@ -331,14 +331,14 @@ class Package(object): "order": pack.order, } self.data.update(data) - + def addChild(self, f): """ add child (Link) to package """ self.children.insert(f.order, Link(f, self)) self.children = sorted(self.children, key=lambda l: l.data["order"]) - + def getChild(self, fid): """ get child from package @@ -347,7 +347,7 @@ class Package(object): if child.id == int(fid): return child return None - + def getChildKey(self, fid): """ get child index @@ -356,7 +356,7 @@ class Package(object): if child.id == int(fid): return k return None - + def removeChild(self, fid): """ remove child @@ -371,7 +371,7 @@ class Link(object): self.update(f) self.id = f.fid self.package = pack - + def update(self, f): """ update data dict from thift object @@ -394,7 +394,7 @@ class CollectorView(QTreeView): """ view component for collector """ - + def __init__(self, connector): QTreeView.__init__(self) self.setModel(CollectorModel(self, connector)) @@ -402,6 +402,6 @@ class CollectorView(QTreeView): self.setColumnWidth(1, 100) self.setColumnWidth(2, 200) self.setColumnWidth(3, 100) - + self.setEditTriggers(QAbstractItemView.DoubleClicked | QAbstractItemView.EditKeyPressed) diff --git a/module/gui/ConnectionManager.py b/module/gui/ConnectionManager.py index def575abc..41b50df6f 100644 --- a/module/gui/ConnectionManager.py +++ b/module/gui/ConnectionManager.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -43,7 +43,7 @@ class ConnectionManager(QWidget): self.setWindowIcon(QIcon(join(pypath, "icons","logo.png"))) connList = QListWidget() - + new = QPushButton(_("New")) edit = QPushButton(_("Edit")) remove = QPushButton(_("Remove")) @@ -76,13 +76,13 @@ class ConnectionManager(QWidget): mainLayout.addLayout(boxLayout) mainLayout.addLayout(buttonLayout) - + buttonLayout.addWidget(new) buttonLayout.addWidget(edit) buttonLayout.addWidget(remove) buttonLayout.addStretch() buttonLayout.addWidget(connect) - + self.setLayout(mainLayout) self.internal = checkbox @@ -93,9 +93,9 @@ class ConnectionManager(QWidget): self.connList = connList self.edit = self.EditWindow() self.connectSignals() - + self.defaultStates = {} - + def connectSignals(self): self.connect(self, SIGNAL("setConnections"), self.setConnections) self.connect(self.new, SIGNAL("clicked()"), self.slotNew) @@ -105,7 +105,7 @@ class ConnectionManager(QWidget): self.connect(self.edit, SIGNAL("save"), self.slotSave) self.connect(self.connList, SIGNAL("itemDoubleClicked(QListWidgetItem *)"), self.slotItemDoubleClicked) self.connect(self.internal, SIGNAL("clicked()"), self.slotInternal) - + def setConnections(self, connections): self.connList.clear() for conn in connections: @@ -116,25 +116,25 @@ class ConnectionManager(QWidget): if conn["default"]: item.setData(Qt.DisplayRole, QVariant(_("%s (Default)") % conn["name"])) self.connList.setCurrentItem(item) - + def slotNew(self): data = {"id":uuid().hex, "type":"remote", "default":False, "name":"", "host":"", "port":"7228", "user":"admin", "password":""} self.edit.setData(data) self.edit.show() - + def slotEdit(self): item = self.connList.currentItem() data = item.data(Qt.UserRole).toPyObject() data = self.cleanDict(data) self.edit.setData(data) self.edit.show() - + def slotRemove(self): item = self.connList.currentItem() data = item.data(Qt.UserRole).toPyObject() data = self.cleanDict(data) self.emit(SIGNAL("removeConnection"), data) - + def slotConnect(self): if self.internal.checkState() == 2: data = {"type": "internal"} @@ -144,16 +144,16 @@ class ConnectionManager(QWidget): data = item.data(Qt.UserRole).toPyObject() data = self.cleanDict(data) self.emit(SIGNAL("connect"), data) - + def cleanDict(self, data): tmp = {} for k, d in data.items(): tmp[str(k)] = d return tmp - + def slotSave(self, data): self.emit(SIGNAL("saveConnection"), data) - + def slotItemDoubleClicked(self, defaultItem): data = defaultItem.data(Qt.UserRole).toPyObject() self.setDefault(data, True) @@ -170,30 +170,30 @@ class ConnectionManager(QWidget): def slotInternal(self): if self.internal.checkState() == 2: self.connList.clearSelection() - + def setDefault(self, data, state): data = self.cleanDict(data) self.edit.setData(data) data = self.edit.getData() data["default"] = state self.edit.emit(SIGNAL("save"), data) - + class EditWindow(QWidget): def __init__(self): QWidget.__init__(self) self.setWindowTitle(_("pyLoad ConnectionManager")) self.setWindowIcon(QIcon(join(pypath, "icons","logo.png"))) - + grid = QGridLayout() - + nameLabel = QLabel(_("Name:")) hostLabel = QLabel(_("Host:")) localLabel = QLabel(_("Local:")) userLabel = QLabel(_("User:")) pwLabel = QLabel(_("Password:")) portLabel = QLabel(_("Port:")) - + name = QLineEdit() host = QLineEdit() local = QCheckBox() @@ -202,10 +202,10 @@ class ConnectionManager(QWidget): password.setEchoMode(QLineEdit.Password) port = QSpinBox() port.setRange(1,10000) - + save = QPushButton(_("Save")) cancel = QPushButton(_("Cancel")) - + grid.addWidget(nameLabel, 0, 0) grid.addWidget(name, 0, 1) grid.addWidget(localLabel, 1, 0) @@ -220,7 +220,7 @@ class ConnectionManager(QWidget): grid.addWidget(password, 5, 1) grid.addWidget(cancel, 6, 0) grid.addWidget(save, 6, 1) - + self.setLayout(grid) self.controls = {"name": name, "host": host, @@ -234,13 +234,13 @@ class ConnectionManager(QWidget): self.connect(cancel, SIGNAL("clicked()"), self.hide) self.connect(save, SIGNAL("clicked()"), self.slotDone) self.connect(local, SIGNAL("stateChanged(int)"), self.slotLocalChanged) - + self.id = None self.default = None - + def setData(self, data): if not data: return - + self.id = data["id"] self.default = data["default"] self.controls["name"].setText(data["name"]) @@ -266,7 +266,7 @@ class ConnectionManager(QWidget): self.controls["password"].setDisabled(True) self.controls["port"].setDisabled(True) self.controls["host"].setDisabled(True) - + def slotLocalChanged(self, val): if val == 2: self.controls["user"].setDisabled(True) @@ -278,7 +278,7 @@ class ConnectionManager(QWidget): self.controls["password"].setDisabled(False) self.controls["port"].setDisabled(False) self.controls["host"].setDisabled(False) - + def getData(self): d = {} d["id"] = self.id @@ -294,7 +294,7 @@ class ConnectionManager(QWidget): else: d["type"] = "remote" return d - + def slotDone(self): data = self.getData() self.hide() diff --git a/module/gui/CoreConfigParser.py b/module/gui/CoreConfigParser.py index 0d1d298c6..84910da1a 100644 --- a/module/gui/CoreConfigParser.py +++ b/module/gui/CoreConfigParser.py @@ -15,61 +15,60 @@ class ConfigParser: """Constructor""" self.configdir = configdir self.config = {} - + if self.checkVersion(): self.readConfig() - + #---------------------------------------------------------------------- def checkVersion(self): - + if not exists(join(self.configdir, "pyload.conf")): return False f = open(join(self.configdir, "pyload.conf"), "rb") v = f.readline() f.close() v = v[v.find(":")+1:].strip() - + if int(v) < CONF_VERSION: return False - + return True - + #---------------------------------------------------------------------- def readConfig(self): """reads the config file""" - + self.config = self.parseConfig(join(self.configdir, "pyload.conf")) - - + #---------------------------------------------------------------------- def parseConfig(self, config): """parses a given configfile""" - + f = open(config) - + config = f.read() config = config.split("\n")[1:] - + conf = {} - + section, option, value, typ, desc = "","","","","" - + listmode = False - + for line in config: - + line = line.rpartition("#") # removes comments - + if line[1]: line = line[0] else: line = line[2] - + line = line.strip() - + try: - + if line == "": continue elif line.endswith(":"): @@ -79,71 +78,69 @@ class ConfigParser: conf[section] = { "desc" : desc } else: if listmode: - + if line.endswith("]"): listmode = False line = line.replace("]","") - + value += [self.cast(typ, x.strip()) for x in line.split(",") if x] - + if not listmode: conf[section][option] = { "desc" : desc, "type" : typ, "value" : value} - - + else: content, none, value = line.partition("=") - + content, none, desc = content.partition(":") - + desc = desc.replace('"', "").strip() - + typ, option = content.split() - + value = value.strip() - + if value.startswith("["): if value.endswith("]"): listmode = False value = value[:-1] else: listmode = True - + value = [self.cast(typ, x.strip()) for x in value[1:].split(",") if x] else: value = self.cast(typ, value) - + if not listmode: conf[section][option] = { "desc" : desc, "type" : typ, "value" : value} - + except: pass - - + f.close() return conf - + #---------------------------------------------------------------------- def cast(self, typ, value): """cast value to given format""" if type(value) not in (str, unicode): return value - + if typ == "int": return int(value) elif typ == "bool": return True if value.lower() in ("1","true", "on", "an","yes") else False else: return value - + #---------------------------------------------------------------------- def get(self, section, option): """get value""" return self.config[section][option]["value"] - + #---------------------------------------------------------------------- def __getitem__(self, section): """provides dictonary like access: c['section']['option']""" @@ -158,7 +155,7 @@ class Section: """Constructor""" self.parser = parser self.section = section - + #---------------------------------------------------------------------- def __getitem__(self, item): """getitem""" diff --git a/module/gui/LinkDock.py b/module/gui/LinkDock.py index ac2d4aae5..66822218d 100644 --- a/module/gui/LinkDock.py +++ b/module/gui/LinkDock.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -27,7 +27,7 @@ class NewLinkDock(QDockWidget): self.setWidget(self.widget) self.setAllowedAreas(Qt.RightDockWidgetArea|Qt.LeftDockWidgetArea) self.hide() - + def slotDone(self): text = str(self.widget.box.toPlainText()) lines = text.splitlines() @@ -41,16 +41,16 @@ class NewLinkWindow(QWidget): self.dock = dock self.setLayout(QVBoxLayout()) layout = self.layout() - + explanationLabel = QLabel("Select a package and then click Add button.") boxLabel = QLabel("Paste URLs here:") self.box = QTextEdit() - + save = QPushButton("Add") - + layout.addWidget(explanationLabel) layout.addWidget(boxLabel) layout.addWidget(self.box) layout.addWidget(save) - + self.connect(save, SIGNAL("clicked()"), self.dock.slotDone) diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py index c71112e9b..d2e27a7a6 100644 --- a/module/gui/MainWindow.py +++ b/module/gui/MainWindow.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -44,10 +44,10 @@ class MainWindow(QMainWindow): self.setWindowTitle(_("pyLoad Client")) self.setWindowIcon(QIcon(join(pypath, "icons","logo.png"))) self.resize(1000,600) - + #layout version self.version = 3 - + #init docks self.newPackDock = NewPackageDock() self.addDockWidget(Qt.RightDockWidgetArea, self.newPackDock) @@ -57,13 +57,13 @@ class MainWindow(QMainWindow): self.newLinkDock = NewLinkDock() self.addDockWidget(Qt.RightDockWidgetArea, self.newLinkDock) self.connect(self.newLinkDock, SIGNAL("done"), self.slotAddLinksToPackage) - + #central widget, layout self.masterlayout = QVBoxLayout() lw = QWidget() lw.setLayout(self.masterlayout) self.setCentralWidget(lw) - + #status self.statusw = QFrame() self.statusw.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) @@ -74,7 +74,7 @@ class MainWindow(QMainWindow): #self.statusw.setPalette(palette) #self.statusw.setAutoFillBackground(True) l = self.statusw.layout() - + class BoldLabel(QLabel): def __init__(self, text): QLabel.__init__(self, text) @@ -82,33 +82,33 @@ class MainWindow(QMainWindow): f.setBold(True) self.setFont(f) self.setAlignment(Qt.AlignRight) - + class Seperator(QFrame): def __init__(self): QFrame.__init__(self) self.setFrameShape(QFrame.VLine) self.setFrameShadow(QFrame.Sunken) - + l.addWidget(BoldLabel(_("Packages:")), 0, 0) self.packageCount = QLabel("0") l.addWidget(self.packageCount, 0, 1) - + l.addWidget(BoldLabel(_("Files:")), 0, 2) self.fileCount = QLabel("0") l.addWidget(self.fileCount, 0, 3) - + l.addWidget(BoldLabel(_("Status:")), 0, 4) self.status = QLabel("running") l.addWidget(self.status, 0, 5) - + l.addWidget(BoldLabel(_("Space:")), 0, 6) self.space = QLabel("") l.addWidget(self.space, 0, 7) - + l.addWidget(BoldLabel(_("Speed:")), 0, 8) self.speed = QLabel("") l.addWidget(self.speed, 0, 9) - + #l.addWidget(BoldLabel(_("Max. downloads:")), 0, 9) #l.addWidget(BoldLabel(_("Max. chunks:")), 1, 9) #self.maxDownloads = QSpinBox() @@ -124,7 +124,7 @@ class MainWindow(QMainWindow): #self.connect(self.statusbar, SIGNAL("showMsg"), self.statusbar.showMessage) #self.serverStatus = QLabel(_("Status: Not Connected")) #self.statusbar.addPermanentWidget(self.serverStatus) - + #menu self.menus = {"file": self.menubar.addMenu(_("File")), "connections": self.menubar.addMenu(_("Connections"))} @@ -136,11 +136,11 @@ class MainWindow(QMainWindow): #add menu actions self.menus["file"].addAction(self.mactions["exit"]) self.menus["connections"].addAction(self.mactions["manager"]) - + #toolbar self.actions = {} self.init_toolbar() - + #tabs self.tabw = QTabWidget() self.tabs = {"overview": {"w": QWidget()}, @@ -159,30 +159,30 @@ class MainWindow(QMainWindow): self.tabw.addTab(self.tabs["accounts"]["w"], _("Accounts")) self.tabw.addTab(self.tabs["settings"]["w"], _("Settings")) self.tabw.addTab(self.tabs["log"]["w"], _("Log")) - + #init tabs self.init_tabs(connector) - + #context menus self.init_context() - + #layout self.masterlayout.addWidget(self.tabw) self.masterlayout.addWidget(self.statusw) - + #signals.. self.connect(self.mactions["manager"], SIGNAL("triggered()"), self.slotShowConnector) - + self.connect(self.tabs["queue"]["view"], SIGNAL('customContextMenuRequested(const QPoint &)'), self.slotQueueContextMenu) self.connect(self.tabs["collector"]["package_view"], SIGNAL('customContextMenuRequested(const QPoint &)'), self.slotCollectorContextMenu) self.connect(self.tabs["accounts"]["view"], SIGNAL('customContextMenuRequested(const QPoint &)'), self.slotAccountContextMenu) - + self.connect(self.tabw, SIGNAL("currentChanged(int)"), self.slotTabChanged) - + self.lastAddedID = None - + self.connector = connector - + def init_toolbar(self): """ create toolbar @@ -203,7 +203,7 @@ class MainWindow(QMainWindow): self.toolbar.addSeparator() self.actions["clipboard"] = self.toolbar.addAction(QIcon(join(pypath, "icons","clipboard.png")), _("Check Clipboard")) self.actions["clipboard"].setCheckable(True) - + self.connect(self.actions["toggle_status"], SIGNAL("toggled(bool)"), self.slotToggleStatus) self.connect(self.actions["clipboard"], SIGNAL("toggled(bool)"), self.slotToggleClipboard) self.connect(self.actions["status_stop"], SIGNAL("triggered()"), self.slotStatusStop) @@ -217,7 +217,7 @@ class MainWindow(QMainWindow): self.connect(containerAction, SIGNAL("triggered()"), self.slotShowAddContainer) self.connect(accountAction, SIGNAL("triggered()"), self.slotNewAccount) self.connect(linksAction, SIGNAL("triggered()"), self.slotShowAddLinks) - + def init_tabs(self, connector): """ create tabs @@ -227,13 +227,13 @@ class MainWindow(QMainWindow): self.tabs["overview"]["w"].setLayout(self.tabs["overview"]["l"]) self.tabs["overview"]["view"] = OverviewView(connector) self.tabs["overview"]["l"].addWidget(self.tabs["overview"]["view"]) - + #queue self.tabs["queue"]["l"] = QGridLayout() self.tabs["queue"]["w"].setLayout(self.tabs["queue"]["l"]) self.tabs["queue"]["view"] = QueueView(connector) self.tabs["queue"]["l"].addWidget(self.tabs["queue"]["view"]) - + #collector toQueue = QPushButton(_("Push selected packages to queue")) self.tabs["collector"]["l"] = QGridLayout() @@ -244,7 +244,7 @@ class MainWindow(QMainWindow): self.connect(toQueue, SIGNAL("clicked()"), self.slotPushPackageToQueue) self.tabs["collector"]["package_view"].setContextMenuPolicy(Qt.CustomContextMenu) self.tabs["queue"]["view"].setContextMenuPolicy(Qt.CustomContextMenu) - + #log self.tabs["log"]["l"] = QGridLayout() self.tabs["log"]["w"].setLayout(self.tabs["log"]["l"]) @@ -253,7 +253,7 @@ class MainWindow(QMainWindow): self.tabs["log"]["text"].setReadOnly(True) self.connect(self.tabs["log"]["text"], SIGNAL("append(QString)"), self.tabs["log"]["text"].append) self.tabs["log"]["l"].addWidget(self.tabs["log"]["text"]) - + #accounts self.tabs["accounts"]["view"] = AccountView(connector) self.tabs["accounts"]["w"].setLayout(QVBoxLayout()) @@ -262,7 +262,7 @@ class MainWindow(QMainWindow): self.tabs["accounts"]["w"].layout().addWidget(newbutton) self.connect(newbutton, SIGNAL("clicked()"), self.slotNewAccount) self.tabs["accounts"]["view"].setContextMenuPolicy(Qt.CustomContextMenu) - + def init_context(self): """ create context menus @@ -287,7 +287,7 @@ class MainWindow(QMainWindow): self.connect(self.queueContext.buttons["pull"], SIGNAL("triggered()"), self.slotPullOutPackage) self.connect(self.queueContext.buttons["abort"], SIGNAL("triggered()"), self.slotAbortDownload) self.connect(self.queueContext.buttons["edit"], SIGNAL("triggered()"), self.slotEditPackage) - + #collector self.collectorContext = QMenu() self.collectorContext.buttons = {} @@ -316,7 +316,7 @@ class MainWindow(QMainWindow): self.connect(packageAction, SIGNAL("triggered()"), self.slotShowAddPackage) self.connect(containerAction, SIGNAL("triggered()"), self.slotShowAddContainer) self.connect(linkAction, SIGNAL("triggered()"), self.slotShowAddLinks) - + self.accountContext = QMenu() self.accountContext.buttons = {} self.accountContext.buttons["add"] = QAction(QIcon(join(pypath, "icons","add_small.png")), _("Add"), self.accountContext) @@ -328,26 +328,26 @@ class MainWindow(QMainWindow): self.connect(self.accountContext.buttons["add"], SIGNAL("triggered()"), self.slotNewAccount) self.connect(self.accountContext.buttons["edit"], SIGNAL("triggered()"), self.slotEditAccount) self.connect(self.accountContext.buttons["remove"], SIGNAL("triggered()"), self.slotRemoveAccount) - + def slotToggleStatus(self, status): """ pause/start toggle (toolbar) """ self.emit(SIGNAL("setDownloadStatus"), status) - + def slotStatusStop(self): """ stop button (toolbar) """ self.emit(SIGNAL("stopAllDownloads")) - + def slotAdd(self): """ add button (toolbar) show context menu (choice: links/package) """ self.addMenu.exec_(QCursor.pos()) - + def slotShowAddPackage(self): """ action from add-menu @@ -355,7 +355,7 @@ class MainWindow(QMainWindow): """ self.tabw.setCurrentIndex(1) self.newPackDock.show() - + def slotShowAddLinks(self): """ action from add-menu @@ -363,21 +363,21 @@ class MainWindow(QMainWindow): """ self.tabw.setCurrentIndex(1) self.newLinkDock.show() - + def slotShowConnector(self): """ connectionmanager action triggered let main to the stuff """ self.emit(SIGNAL("connector")) - + def slotAddPackage(self, name, links, password=None): """ new package let main to the stuff """ self.emit(SIGNAL("addPackage"), name, links, password) - + def slotAddLinksToPackage(self, links): """ adds links to currently selected package @@ -385,14 +385,14 @@ class MainWindow(QMainWindow): """ if self.tabw.currentIndex() != 1: return - + smodel = self.tabs["collector"]["package_view"].selectionModel() for index in smodel.selectedRows(0): item = index.internalPointer() if isinstance(item, Package): self.connector.proxy.addFiles(item.id, links) break - + def slotShowAddContainer(self): """ action from add-menu @@ -408,7 +408,7 @@ class MainWindow(QMainWindow): fileNames = QFileDialog.getOpenFileNames(self, _("Open container"), "", typeStr) for name in fileNames: self.emit(SIGNAL("addContainer"), str(name)) - + def slotPushPackageToQueue(self): """ push collector pack to queue @@ -422,7 +422,7 @@ class MainWindow(QMainWindow): self.emit(SIGNAL("pushPackageToQueue"), item.id) else: self.emit(SIGNAL("pushPackageToQueue"), item.package.id) - + def saveWindow(self): """ get window state/geometry @@ -430,12 +430,12 @@ class MainWindow(QMainWindow): """ state_raw = self.saveState(self.version) geo_raw = self.saveGeometry() - + state = str(state_raw.toBase64()) geo = str(geo_raw.toBase64()) - + self.emit(SIGNAL("saveMainWindow"), state, geo) - + def closeEvent(self, event): """ somebody wants to close me! @@ -445,24 +445,24 @@ class MainWindow(QMainWindow): event.ignore() self.hide() self.emit(SIGNAL("hidden")) - + # quit when no tray is available if not QSystemTrayIcon.isSystemTrayAvailable(): self.emit(SIGNAL("Quit")) - + def restoreWindow(self, state, geo): """ restore window state/geometry """ state = QByteArray(state) geo = QByteArray(geo) - + state_raw = QByteArray.fromBase64(state) geo_raw = QByteArray.fromBase64(geo) - + self.restoreState(state_raw, self.version) self.restoreGeometry(geo_raw) - + def slotQueueContextMenu(self, pos): """ custom context menu in queue view requested @@ -506,7 +506,7 @@ class MainWindow(QMainWindow): self.queueContext.buttons["pull"].setEnabled(False) self.queueContext.buttons["edit"].setEnabled(False) self.queueContext.exec_(menuPos) - + def slotCollectorContextMenu(self, pos): """ custom context menu in package collector view requested @@ -538,13 +538,13 @@ class MainWindow(QMainWindow): self.collectorContext.buttons["push"].setEnabled(False) self.collectorContext.buttons["restart"].setEnabled(False) self.collectorContext.exec_(menuPos) - + def slotLinkCollectorContextMenu(self, pos): """ custom context menu in link collector view requested """ pass - + def slotRestartDownload(self): """ restart download action is triggered @@ -553,7 +553,7 @@ class MainWindow(QMainWindow): for index in smodel.selectedRows(0): item = index.internalPointer() self.emit(SIGNAL("restartDownload"), item.id, isinstance(item, Package)) - + def slotRemoveDownload(self): """ remove download action is triggered @@ -566,13 +566,13 @@ class MainWindow(QMainWindow): for index in smodel.selectedRows(0): item = index.internalPointer() self.emit(SIGNAL("removeDownload"), item.id, isinstance(item, Package)) - + def slotToggleClipboard(self, status): """ check clipboard (toolbar) """ self.emit(SIGNAL("setClipboardStatus"), status) - + def slotEditPackage(self): # in Queue, only edit name if self.activeMenu == self.queueContext: @@ -583,7 +583,7 @@ class MainWindow(QMainWindow): def slotEditCommit(self, editor): self.emit(SIGNAL("changePackageName"), self.activeMenu.index.internalPointer().id, editor.text()) - + def slotPullOutPackage(self): """ pull package out of the queue @@ -595,14 +595,14 @@ class MainWindow(QMainWindow): self.emit(SIGNAL("pullOutPackage"), item.id) else: self.emit(SIGNAL("pullOutPackage"), item.package.id) - + def slotAbortDownload(self): view = self.tabs["queue"]["view"] smodel = view.selectionModel() for index in smodel.selectedRows(0): item = index.internalPointer() self.emit(SIGNAL("abortDownload"), item.id, isinstance(item, Package)) - + # TODO disabled because changing desktop on linux, main window disappears #def changeEvent(self, e): # if e.type() == QEvent.WindowStateChange and self.isMinimized(): @@ -611,13 +611,13 @@ class MainWindow(QMainWindow): # self.emit(SIGNAL("hidden")) # else: # super(MainWindow, self).changeEvent(e) - + def slotTabChanged(self, index): if index == 2: self.emit(SIGNAL("reloadAccounts")) elif index == 3: self.tabs["settings"]["w"].loadConfig() - + def slotRefreshPackage(self): smodel = self.tabs["collector"]["package_view"].selectionModel() for index in smodel.selectedRows(0): @@ -626,11 +626,11 @@ class MainWindow(QMainWindow): if isinstance(item, Link): pid = item.package.id self.emit(SIGNAL("refreshStatus"), pid) - + def slotNewAccount(self): types = self.connector.proxy.getAccountTypes() self.accountEdit = AccountEdit.newAccount(types) - + #TODO make more easy n1, n2, n3 def save(data): if data["password"]: @@ -639,19 +639,19 @@ class MainWindow(QMainWindow): n2 = data["login"] n3 = data["password"] self.connector.updateAccount(n1, n2, n3, None) - + self.accountEdit.connect(self.accountEdit, SIGNAL("done"), save) self.accountEdit.show() def slotEditAccount(self): types = self.connector.getAccountTypes() - + data = self.tabs["accounts"]["view"].selectedIndexes() if len(data) < 1: return - + data = data[0].internalPointer() - + self.accountEdit = AccountEdit.editAccount(types, data) #TODO make more easy n1, n2, n3 @@ -664,34 +664,34 @@ class MainWindow(QMainWindow): if data["password"]: n3 = data["password"] self.connector.updateAccount(n1, n2, n3, None) - + self.accountEdit.connect(self.accountEdit, SIGNAL("done"), save) self.accountEdit.show() - + def slotRemoveAccount(self): data = self.tabs["accounts"]["view"].selectedIndexes() if len(data) < 1: return - + data = data[0].internalPointer() - + self.connector.removeAccount(data.type, data.login) - + def slotAccountContextMenu(self, pos): globalPos = self.tabs["accounts"]["view"].mapToGlobal(pos) i = self.tabs["accounts"]["view"].indexAt(pos) if not i: return - + data = i.internalPointer() - + if data is None: self.accountContext.buttons["edit"].setEnabled(False) self.accountContext.buttons["remove"].setEnabled(False) else: self.accountContext.buttons["edit"].setEnabled(True) self.accountContext.buttons["remove"].setEnabled(True) - + menuPos = QCursor.pos() menuPos.setX(menuPos.x()+2) self.accountContext.exec_(menuPos) diff --git a/module/gui/Overview.py b/module/gui/Overview.py index 183383b5e..a7c82e7d0 100644 --- a/module/gui/Overview.py +++ b/module/gui/Overview.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -31,24 +31,24 @@ class OverviewModel(QAbstractListModel): CurrentSize = 16 MaxSize = 17 Status = 18 - + def __init__(self, view, connector): QAbstractListModel.__init__(self) - + self.packages = [] - + def queueChanged(self): #dirty.. self.beginResetModel() - + self.packages = [] - + def partsFinished(p): f = 0 for c in p.children: if c.data["status"] == 0: f += 1 return f - + def maxSize(p): ms = 0 cs = 0 @@ -63,13 +63,13 @@ class OverviewModel(QAbstractListModel): cs += s ms += s return ms, cs - + def getProgress(p): for c in p.children: if c.data["status"] == 13: pass # TODO return _("Unpacking"), int(c.data["progress"]) return _("Downloading"), self.queue.getProgress(p) - + d = self.queue._data for p in d: status, progress = getProgress(p) @@ -92,27 +92,27 @@ class OverviewModel(QAbstractListModel): OverviewModel.MaxSize: maxsize, OverviewModel.Status: status, } - + self.packages.append(info) - + self.endResetModel() - + def headerData(self, section, orientation, role=Qt.DisplayRole): return QVariant(_("Package")) - + def rowCount(self, parent=QModelIndex()): return len(self.packages) - + def data(self, index, role=Qt.DisplayRole): if role in [OverviewModel.PackageName, OverviewModel.Progress, OverviewModel.PartsFinished, OverviewModel.Parts, OverviewModel.ETA, OverviewModel.Speed, OverviewModel.CurrentSize, OverviewModel.MaxSize, OverviewModel.Status]: return QVariant(self.packages[index.row()][role]) return QVariant() - + class OverviewView(QListView): def __init__(self, connector): QListView.__init__(self) self.setModel(OverviewModel(self, connector)) - + self.setAlternatingRowColors(True) self.delegate = OverviewDelegate(self) self.setItemDelegate(self.delegate) @@ -122,14 +122,14 @@ class OverviewDelegate(QItemDelegate): QItemDelegate.__init__(self, parent) self.parent = parent self.model = parent.model() - + def paint(self, painter, option, index): option.rect.setHeight(59+16) option.rect.setWidth(self.parent.width()-20) - + #if option.state & QStyle.State_Selected: # painter.fillRect(option.rect, option.palette.color(QPalette.Highlight)) - + packagename = index.data(OverviewModel.PackageName).toString() partsf = index.data(OverviewModel.PartsFinished).toString() parts = index.data(OverviewModel.Parts).toString() @@ -139,13 +139,13 @@ class OverviewDelegate(QItemDelegate): currentSize = int(index.data(OverviewModel.CurrentSize).toString()) maxSize = int(index.data(OverviewModel.MaxSize).toString()) status = index.data(OverviewModel.Status).toString() - + def formatEta(seconds): #TODO add to utils if seconds <= 0: return "" hours, seconds = divmod(seconds, 3600) minutes, seconds = divmod(seconds, 60) return _("ETA: ") + "%.2i:%.2i:%.2i" % (hours, minutes, seconds) - + statusline = QString(_("Parts: ") + "%s/%s" % (partsf, parts)) if partsf == parts: speedline = _("Finished") @@ -153,25 +153,25 @@ class OverviewDelegate(QItemDelegate): speedline = QString(status) else: speedline = QString(formatEta(eta) + " " + _("Speed: %s") % formatSpeed(speed)) - + if progress in (0,100): sizeline = QString(_("Size:") + "%s" % formatSize(maxSize)) else: sizeline = QString(_("Size:") + "%s / %s" % (formatSize(currentSize), formatSize(maxSize))) - + f = painter.font() f.setPointSize(12) f.setBold(True) painter.setFont(f) - + r = option.rect.adjusted(4, 4, -4, -4) painter.drawText(r.left(), r.top(), r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, packagename) newr = painter.boundingRect(r.left(), r.top(), r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, packagename) - + f.setPointSize(10) f.setBold(False) painter.setFont(f) - + painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, statusline) painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignHCenter, sizeline) painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignRight, speedline) @@ -179,10 +179,10 @@ class OverviewDelegate(QItemDelegate): newr.setTop(newr.bottom()+8) newr.setBottom(newr.top()+20) newr.setRight(self.parent.width()-25) - + f.setPointSize(10) painter.setFont(f) - + opts = QStyleOptionProgressBarV2() opts.maximum = 100 opts.minimum = 0 @@ -192,6 +192,6 @@ class OverviewDelegate(QItemDelegate): opts.textAlignment = Qt.AlignCenter opts.text = QString.number(opts.progress) + "%" QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter) - + def sizeHint(self, option, index): return QSize(self.parent.width()-22, 59+16) diff --git a/module/gui/PackageDock.py b/module/gui/PackageDock.py index 73db8f177..f38ffcbfc 100644 --- a/module/gui/PackageDock.py +++ b/module/gui/PackageDock.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ import re @@ -28,7 +28,7 @@ class NewPackageDock(QDockWidget): self.setWidget(self.widget) self.setAllowedAreas(Qt.RightDockWidgetArea|Qt.LeftDockWidgetArea) self.hide() - + def slotDone(self): text = str(self.widget.box.toPlainText()) pw = str(self.widget.passwordInput.text()) @@ -62,21 +62,21 @@ class NewPackageWindow(QWidget): self.dock = dock self.setLayout(QGridLayout()) layout = self.layout() - + nameLabel = QLabel(_("Name")) nameInput = QLineEdit() passwordLabel = QLabel(_("Password")) passwordInput = QLineEdit() - + linksLabel = QLabel(_("Links in this Package")) - + self.box = QTextEdit() self.nameInput = nameInput self.passwordInput = passwordInput - + save = QPushButton(_("Create")) parseUri = QPushButton(_("Filter URLs")) - + layout.addWidget(nameLabel, 0, 0) layout.addWidget(nameInput, 0, 1) layout.addWidget(passwordLabel, 1, 0) diff --git a/module/gui/Queue.py b/module/gui/Queue.py index 0a0cbb810..f3df023a0 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -29,40 +29,40 @@ class QueueModel(CollectorModel): """ model for the queue view, inherits from CollectorModel """ - + def __init__(self, view, connector): CollectorModel.__init__(self, view, connector) self.cols = 6 self.wait_dict = {} - + self.updater = self.QueueUpdater(self.interval) self.connect(self.updater, SIGNAL("update()"), self.update) - + class QueueUpdater(QObject): """ timer which emits signal for a download status reload @TODO: make intervall configurable """ - + def __init__(self, interval): QObject.__init__(self) - + self.interval = interval self.timer = QTimer() self.timer.connect(self.timer, SIGNAL("timeout()"), self, SIGNAL("update()")) - + def start(self): self.timer.start(1000) - + def stop(self): self.timer.stop() - + def start(self): self.updater.start() - + def stop(self): self.updater.stop() - + def fullReload(self): """ reimplements CollectorModel.fullReload, because we want the Queue data @@ -77,28 +77,28 @@ class QueueModel(CollectorModel): self._data = sorted(self._data, key=lambda p: p.data["order"]) self.endInsertRows() self.updateCount() - + def insertEvent(self, event): """ wrap CollectorModel.insertEvent to update the element count """ CollectorModel.insertEvent(self, event) self.updateCount() - + def removeEvent(self, event): """ wrap CollectorModel.removeEvent to update the element count """ CollectorModel.removeEvent(self, event) self.updateCount() - + def updateEvent(self, event): """ wrap CollectorModel.updateEvent to update the element count """ CollectorModel.updateEvent(self, event) self.updateCount() - + def updateCount(self): """ calculate package- and filecount for statusbar, @@ -111,7 +111,7 @@ class QueueModel(CollectorModel): self.mutex.unlock() self.emit(SIGNAL("updateCount"), packageCount, fileCount) self.mutex.lock() - + def update(self): """ update slot for download status updating @@ -142,7 +142,7 @@ class QueueModel(CollectorModel): k = pack.getChildKey(d.fid) self.emit(SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), self.index(k, 0, self.index(p, 0)), self.index(k, self.cols, self.index(p, self.cols))) self.updateCount() - + def headerData(self, section, orientation, role=Qt.DisplayRole): """ returns column heading @@ -161,7 +161,7 @@ class QueueModel(CollectorModel): elif section == 5: return QVariant(_("Progress")) return QVariant() - + def getWaitingProgress(self, item): """ returns time to wait, caches startingtime to provide progress @@ -186,7 +186,7 @@ class QueueModel(CollectorModel): perc = rest*res return perc, rest return None - + def getProgress(self, item, locked=True): """ return download progress, locks by default @@ -216,7 +216,7 @@ class QueueModel(CollectorModel): return 0 return perc_sum/count return 0 - + def getSpeed(self, item): """ calculate download speed @@ -241,7 +241,7 @@ class QueueModel(CollectorModel): return None return speed_sum return None - + def data(self, index, role=Qt.DisplayRole): """ return cell data @@ -271,7 +271,7 @@ class QueueModel(CollectorModel): status = child.data["status"] else: status = item.data["status"] - + if speed is None or status == 7 or status == 10 or status == 5: return QVariant(self.translateStatus(statusMapReverse[status])) else: @@ -318,7 +318,7 @@ class QueueModel(CollectorModel): if index.column() == 0: return QVariant(index.internalPointer().data["name"]) return QVariant() - + def flags(self, index): """ cell flags @@ -326,12 +326,12 @@ class QueueModel(CollectorModel): if index.column() == 0 and self.parent(index) == QModelIndex(): return Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled return Qt.ItemIsSelectable | Qt.ItemIsEnabled - + class QueueView(CollectorView): """ view component for queue """ - + def __init__(self, connector): CollectorView.__init__(self, connector) self.setModel(QueueModel(self, connector)) @@ -341,9 +341,9 @@ class QueueView(CollectorView): self.setColumnWidth(2, 140) self.setColumnWidth(3, 180) self.setColumnWidth(4, 70) - + self.setEditTriggers(QAbstractItemView.NoEditTriggers) - + self.delegate = QueueProgressBarDelegate(self, self.model()) self.setItemDelegateForColumn(5, self.delegate) @@ -351,11 +351,11 @@ class QueueProgressBarDelegate(QItemDelegate): """ used to display a progressbar in the progress cell """ - + def __init__(self, parent, queue): QItemDelegate.__init__(self, parent) self.queue = queue - + def paint(self, painter, option, index): """ paint the progressbar diff --git a/module/gui/SettingsWidget.py b/module/gui/SettingsWidget.py index cd22a7b9e..ebe849d48 100644 --- a/module/gui/SettingsWidget.py +++ b/module/gui/SettingsWidget.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -30,7 +30,7 @@ class SettingsWidget(QWidget): self.data = None self.pdata = None self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) - + def setConnector(self, connector): self.connector = connector @@ -64,7 +64,7 @@ class SettingsWidget(QWidget): tab = QTabWidget() self.tab = tab - + gw = QWidget() gw.setLayout(QVBoxLayout()) gw.layout().addWidget(self.general) @@ -165,18 +165,18 @@ class Section(QGroupBox): self.ctype = ctype layout = QFormLayout(self) self.setLayout(layout) - + sw = QWidget() sw.setLayout(QVBoxLayout()) sw.layout().addWidget(self) - + sa = QScrollArea() sa.setWidgetResizable(True) sa.setWidget(sw) sa.setFrameShape(sa.NoFrame) - + parent.addTab(sa, data.description) - + for option in self.data.items: if option.type == "int": i = QSpinBox(self) diff --git a/module/gui/XMLParser.py b/module/gui/XMLParser.py index 5e3b7bf65..d9adc74f6 100644 --- a/module/gui/XMLParser.py +++ b/module/gui/XMLParser.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ from __future__ import with_statement @@ -33,7 +33,7 @@ class XMLParser(): self.mutex.unlock() self.loadData() self.root = self.xml.documentElement() - + def loadData(self): self.mutex.lock() f = self.file @@ -43,7 +43,7 @@ class XMLParser(): content = fh.read() self.xml.setContent(content) self.mutex.unlock() - + def saveData(self): self.mutex.lock() content = self.xml.toString() @@ -51,7 +51,7 @@ class XMLParser(): fh.write(content) self.mutex.unlock() return content - + def parseNode(self, node, ret_type="list"): if ret_type == "dict": childNodes = {} diff --git a/module/gui/connector.py b/module/gui/connector.py index c16ccd08e..68cc531ce 100644 --- a/module/gui/connector.py +++ b/module/gui/connector.py @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - + @author: mkaay """ @@ -33,9 +33,9 @@ class Connector(QObject): """ manages the connection to the pyload core via thrift """ - + firstAttempt = True - + def __init__(self): QObject.__init__(self) self.mutex = QMutex() @@ -48,7 +48,7 @@ class Connector(QObject): self.running = True self.internal = False self.proxy = self.Dummy() - + def setConnectionData(self, host, port, user, password, ssl=False): """ set connection data for connection attempt, called from slotConnect @@ -58,7 +58,7 @@ class Connector(QObject): self.user = user self.password = password self.ssl = ssl - + def connectProxy(self): """ initialize thrift rpc client, @@ -83,25 +83,25 @@ class Connector(QObject): self.emit(SIGNAL("errorBox"), err) Connector.firstAttempt = False return False - + self.proxy = DispatchRPC(self.mutex, client) self.connect(self.proxy, SIGNAL("connectionLost"), self, SIGNAL("connectionLost")) - + server_version = self.proxy.getServerVersion() self.connectionID = uuid().hex - + if not server_version == SERVER_VERSION: self.emit(SIGNAL("errorBox"), _("server is version %(new)s client accepts version %(current)s") % { "new": server_version, "current": SERVER_VERSION}) return False - + return True - + def __getattr__(self, attr): """ redirect rpc calls to dispatcher """ return getattr(self.proxy, attr) - + class Dummy(object): """ dummy rpc proxy, to prevent errors @@ -119,12 +119,12 @@ class DispatchRPC(QObject): wraps the thrift client, to catch critical exceptions (connection lost) adds thread safety """ - + def __init__(self, mutex, server): QObject.__init__(self) self.mutex = mutex self.server = server - + def __getattr__(self, attr): """ redirect and wrap call in Wrapper instance, locks dispatcher @@ -133,17 +133,17 @@ class DispatchRPC(QObject): self.fname = attr f = self.Wrapper(getattr(self.server, attr), self.mutex, self) return f - + class Wrapper(object): """ represents a rpc call """ - + def __init__(self, f, mutex, dispatcher): self.f = f self.mutex = mutex self.dispatcher = dispatcher - + def __call__(self, *args, **kwargs): """ instance is called, rpc is executed |