From edf9060676ba864118d87518abb697a96ab1d5ad Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 17:26:59 +0100 Subject: renamed gui --- pyLoadGui.py | 1295 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 982 insertions(+), 313 deletions(-) mode change 100755 => 100644 pyLoadGui.py (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py old mode 100755 new mode 100644 index 806c4437c..844a96ef2 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -1,336 +1,1005 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# -#Copyright (C) 2009 KingZero -# -#This program is free software; you can redistribute it and/or modify -#it under the terms of the GNU General Public License as published by -#the Free Software Foundation; either version 3 of the License, -#or (at your option) any later version. -# -#This program is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -#See the GNU General Public License for more details. -# -#You should have received a copy of the GNU General Public License -# along with this program; if not, see . -# -### -import socket -import subprocess -from os import sep -from os.path import abspath, dirname -from time import sleep +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. -import wxversion -wxversion.select('2.8') + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. -import wx -import wx.lib.newevent -import wx.lib.sized_controls as sized_control -from module.remote.ClientSocket import SocketThread - -(DataArrived, EVT_DATA_ARRIVED) = wx.lib.newevent.NewEvent() - -class _Download_Dialog(sized_control.SizedDialog): - def __init__(self, parent, id): - sized_control.SizedDialog.__init__(self, parent, id, "Downloads hinzufügen", - style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) - - pane = self.GetContentsPane() - - self.links = wx.TextCtrl(pane, -1, style=wx.TE_MULTILINE, size=(500, 200)) - self.links.SetSizerProps(expand=True, proportion=1) - - self.SetButtonSizer(self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL)) - - self.Fit() - self.SetMinSize(self.GetSize()) - - #Clipboard - self.data = wx.TextDataObject() - if wx.TheClipboard.Open(): - wx.TheClipboard.GetData(self.data) - for link in self.data.GetText().split('\n'): - if link.startswith("http"): - self.links.write(link + "\n") - wx.TheClipboard.Close() - -class Download_Liste(wx.ListCtrl): - def __init__(self, parent): - wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT | wx.LC_VIRTUAL) - - # columns - self.InsertColumn(0, 'Name', width=300) - self.InsertColumn(1, 'Status', width=120) - self.InsertColumn(2, 'Größe') - self.InsertColumn(3, 'Übertragen', width=100) - self.InsertColumn(4, 'Prozent', width=60) - self.InsertColumn(5, 'Dauer', width=100) - self.InsertColumn(7, 'Geschwindigkeit', width=120) - - - self.itemDataMap = {} - self.itemIndexMap = [] - self.SetItemCount(len(self.itemIndexMap)) - - def reload(self, links, data): - - self.itemIndexMap = data['order'] - - self.create_data(links, data) + You should have received a copy of the GNU General Public License + along with this program; if not, see . + + @author: mkaay + @version: v0.3 +""" + +SERVER_VERSION = "0.3" + +import sys +import os + +from time import sleep, time + +from PyQt4.QtCore import * +from PyQt4.QtGui import * +from PyQt4.QtXml import * + +from xmlrpclib import ServerProxy + +from uuid import uuid4 as uuid + +class main(QObject): + def __init__(self): + """ + main setup + """ + QObject.__init__(self) + self.app = QApplication(sys.argv) + self.mainWindow = mainWindow() + self.pwWindow = PWInputWindow() + self.connWindow = ConnectionManager() + self.connector = connector() + self.mainloop = self.Loop(self) + self.connectSignals() + self.parser = XMLParser("guiconfig.xml", "guiconfig_default.xml") - self.SetItemCount(len(self.itemIndexMap)) - self.Refresh() - - def create_data(self, links, data): - - self.itemDataMap = {} - - for key, value in data.iteritems(): - if key != 'version' and key != 'order': - self.itemDataMap[key] = [value.url] - - for link in links: - self.itemDataMap[link['id']][0] = link['name'] - self.itemDataMap[link['id']].append(link['status']) - self.itemDataMap[link['id']].append(str(link['size']) + " kb") - self.itemDataMap[link['id']].append(str(link['size'] - link['kbleft']) + " kb") - self.itemDataMap[link['id']].append(str(link['percent']) + " %") - self.itemDataMap[link['id']].append(format_time(link['eta'])) - self.itemDataMap[link['id']].append(str(int(link['speed'])) + " kb/s") - - # virtual methods - def OnGetItemText(self, item, col): - index = self.itemIndexMap[item] + self.refreshConnections() + self.connData = None + self.connWindow.show() + + def startMain(self): + self.connector.start() + sleep(1) + self.mainWindow.show() + self.testStuff() + self.mainloop.start() + + def connectSignals(self): + """ + signal and slot stuff, yay! + """ + self.connect(self.connector, SIGNAL("error_box"), self.slotErrorBox) + self.connect(self.connWindow, SIGNAL("saveConnection"), self.slotSaveConnection) + self.connect(self.connWindow, SIGNAL("removeConnection"), self.slotRemoveConnection) + self.connect(self.connWindow, SIGNAL("connect"), self.slotConnect) + self.connect(self.pwWindow, SIGNAL("ok"), self.slotPasswordTyped) + self.connect(self.pwWindow, SIGNAL("cancel"), self.quit) + + def quit(self): + self.app.quit() + + def loop(self): + """ + start exec loop + """ + sys.exit(self.app.exec_()) + + def slotErrorBox(self, msg): + """ + display a nice error box + """ + QMessageBox(QMessageBox.Warning, "Error", msg) + + def testStuff(self): + """ + only for testing ;) + """ + #test for link collector + ids = self.connector.getLinkCollector() + for id in ids: + data = self.connector.getLinkInfo(id) + item = QListWidgetItem() + item.setData(Qt.UserRole, QVariant(data)) + item.setData(Qt.DisplayRole, QVariant(data["url"])) + self.mainWindow.tabs["collector_links"]["listwidget"].addItem(item) + + #test for package collector + packs = self.connector.getPackageCollector() + for data in packs: + item = QTreeWidgetItem() + item.setData(0, Qt.UserRole, QVariant(data)) + item.setData(0, Qt.DisplayRole, QVariant(data["package_name"])) + files = self.connector.getPackageFiles(data["id"]) + for id in files: + info = self.connector.getLinkInfo(id) + sub = QTreeWidgetItem(item) + sub.setData(0, Qt.DisplayRole, QVariant(info["filename"])) + self.mainWindow.tabs["collector_packages"]["treewidget"].addTopLevelItem(item) + + #test for queue + """ + packs = self.connector.getPackageQueue() + for data in packs: + item = QTreeWidgetItem() + item.setData(0, Qt.UserRole, QVariant(data)) + item.setData(0, Qt.DisplayRole, QVariant(data["package_name"])) + files = self.connector.getPackageFiles(data["id"]) + for id in files: + info = self.connector.getLinkInfo(id) + sub = QTreeWidgetItem(item) + sub.setData(0, Qt.DisplayRole, QVariant(info["filename"])) + sub.setData(1, Qt.DisplayRole, QVariant(info["status_type"])) + self.mainWindow.tabs["queue"]["treewidget"].addTopLevelItem(item) + + model = QueueModel(self.connector) + model.setView(self.mainWindow.tabs["queue"]["view"]) + self.mainWindow.tabs["queue"]["view"].setModel(model) + self.mainWindow.tabs["queue"]["view"].setup() + model.startLoop() + """ + view = self.mainWindow.tabs["queue"]["view"] + view.setColumnCount(3) + view.setHeaderLabels(["Name", "Status", "Fortschritt"]) + view.setColumnWidth(0, 300) + view.setColumnWidth(1, 200) + view.setColumnWidth(2, 100) + self.queue = Queue(view, self.connector) + delegate = QueueProgressBarDelegate(view, self.queue) + view.setItemDelegateForColumn(2, delegate) + #view.setup(self.queue) + self.queue.start() + + def refreshServerStatus(self): + status = self.connector.getServerStatus() + if status["pause"]: + status["status"] = "Paused" + else: + status["status"] = "Running" + status["speed"] = int(status["speed"]) + text = "Status: %(status)s | Speed: %(speed)s kb/s" % status + self.mainWindow.serverStatus.setText(text) + + def getConnections(self): + connectionsNode = self.parser.xml.elementsByTagName("connections").item(0) + if connectionsNode.isNull(): + raise Exception("null") + connections = self.parser.parseNode(connectionsNode) + ret = [] + for conn in connections: + data = {} + data["type"] = conn.attribute("type", "remote") + data["default"] = conn.attribute("default", "False") + data["id"] = conn.attribute("id", uuid().hex) + if data["default"] == "True": + data["default"] = True + else: + data["default"] = False + subs = self.parser.parseNode(conn, "dict") + if not subs.has_key("name"): + data["name"] = "Unnamed" + else: + data["name"] = subs["name"].text() + if data["type"] == "remote": + if not subs.has_key("server"): + continue + else: + data["host"] = subs["server"].text() + data["ssl"] = subs["server"].attribute("ssl", "False") + if data["ssl"] == "True": + data["ssl"] = True + else: + data["ssl"] = False + data["user"] = subs["server"].attribute("user", "admin") + data["port"] = int(subs["server"].attribute("port", "7227")) + ret.append(data) + return ret + + def slotSaveConnection(self, data): + connectionsNode = self.parser.xml.elementsByTagName("connections").item(0) + if connectionsNode.isNull(): + raise Exception("null") + connections = self.parser.parseNode(connectionsNode) + connNode = self.parser.xml.createElement("connection") + connNode.setAttribute("default", data["default"]) + connNode.setAttribute("type", data["type"]) + connNode.setAttribute("id", data["id"]) + nameNode = self.parser.xml.createElement("name") + nameText = self.parser.xml.createTextNode(data["name"]) + nameNode.appendChild(nameText) + connNode.appendChild(nameNode) + if data["type"] == "remote": + serverNode = self.parser.xml.createElement("server") + serverNode.setAttribute("ssl", data["ssl"]) + serverNode.setAttribute("user", data["user"]) + serverNode.setAttribute("port", data["port"]) + hostText = self.parser.xml.createTextNode(data["host"]) + serverNode.appendChild(hostText) + connNode.appendChild(serverNode) + found = False + for c in connections: + cid = c.attribute("id", "None") + if str(cid) == str(data["id"]): + found = c + break + if found: + connectionsNode.replaceChild(connNode, found) + else: + connectionsNode.appendChild(connNode) + self.parser.saveData() + self.refreshConnections() + + def slotRemoveConnection(self, data): + connectionsNode = self.parser.xml.elementsByTagName("connections").item(0) + if connectionsNode.isNull(): + raise Exception("null") + connections = self.parser.parseNode(connectionsNode) + found = False + for c in connections: + cid = c.attribute("id", "None") + if str(cid) == str(data["id"]): + found = c + break + if found: + connectionsNode.removeChild(found) + self.parser.saveData() + self.refreshConnections() + + def slotConnect(self, data): + self.connWindow.hide() + self.connData = data + if data["type"] == "local": + self.slotPasswordTyped("") + self.pwWindow.show() + + def slotPasswordTyped(self, pw): + data = self.connData + data["password"] = pw + if data["type"] == "remote": + if data["ssl"]: + data["ssl"] = "s" + else: + data["ssl"] = "" + server_url = "http%(ssl)s://%(user)s:%(password)s@%(host)s:%(port)s/" % data + self.connector.setAddr(server_url) + self.startMain() + else: + print "comming soon ;)" + self.quit() + + def refreshConnections(self): + self.parser.loadData() + conns = self.getConnections() + self.connWindow.emit(SIGNAL("setConnections(connections)"), conns) + + class Loop(QThread): + def __init__(self, parent): + QThread.__init__(self) + self.parent = parent + self.running = True + + def run(self): + while self.running: + sleep(1) + self.update() + + def update(self): + self.parent.refreshServerStatus() + +############################################# +############## Connector Stuff ############## +############################################# + +class connector(QThread): + def __init__(self): + """ + init thread + """ + QThread.__init__(self) + self.mutex = QMutex() + self.running = True + self.proxy = None + self.addr = None + + def setAddr(self, addr): + self.mutex.lock() + self.addr = addr + self.mutex.unlock() + + def run(self): + """ + start thread + (called from thread.start()) + """ + self.connectProxy(self.addr) + while self.running: + sleep(1) + + def stop(self): + """ + stop thread + """ + self.running = False + + def connectProxy(self, addr): + """ + connect to remote server + """ + self.proxy = ServerProxy(addr, allow_none=True) + server_version = self.proxy.get_server_version() + if not server_version == SERVER_VERSION: + self.emit(SIGNAL("error_box"), "server is version %s client accepts version %s" % (server_version, SERVER_VERSION)) + + def getLinkCollector(self): + """ + grab links from collector and return the ids + """ + self.mutex.lock() try: - s = self.itemDataMap[index][col] - except: - s = "" - return s - - def OnGetItemAttr(self, item): - return None - -class _Upper_Panel(wx.Panel): - def __init__(self, parent): - wx.Panel.__init__(self, parent) - sizer = wx.BoxSizer(wx.HORIZONTAL) - self.parent = parent - - self.list = Download_Liste(self) - - sizer.Add(self.list, 1, wx.EXPAND) - self.SetSizer(sizer) - - def refresh(self, links, data): - self.list.reload(links, data) - - def get_selected_ids(self, deselect=False): - """return ids and deselect items""" - item = self.list.GetFirstSelected() - if deselect: self.list.Select(item, on=0) - - if item == -1: - return False - - links = [] - links.append(self.parent.data['order'][item]) - - while self.list.GetNextSelected(item) != -1: - item = self.list.GetNextSelected(item) - if deselect: self.list.Select(item, on=0) - links.append(self.parent.data['order'][item]) - - return links - -class _Lower_Panel(wx.Panel): - def __init__(self, parent): - wx.Panel.__init__(self, parent) - self.SetBackgroundColour(wx.BLACK) + return self.proxy.get_collector_files() + finally: + self.mutex.unlock() + + def getPackageCollector(self): + """ + grab packages from collector and return the data + """ + self.mutex.lock() + try: + return self.proxy.get_collector_packages() + finally: + self.mutex.unlock() + + def getLinkInfo(self, id): + """ + grab file info for the given id and return it + """ + self.mutex.lock() + try: + return self.proxy.get_file_info(id) + finally: + self.mutex.unlock() + + def getPackageInfo(self, id): + """ + grab package info for the given id and return it + """ + self.mutex.lock() + try: + return self.proxy.get_package_data(id) + finally: + self.mutex.unlock() + + def getPackageQueue(self): + """ + grab queue return the data + """ + self.mutex.lock() + try: + return self.proxy.get_queue() + finally: + self.mutex.unlock() + + def getPackageFiles(self, id): + """ + grab package files and return ids + """ + self.mutex.lock() + try: + return self.proxy.get_package_files(id) + finally: + self.mutex.unlock() + + def getDownloadQueue(self): + """ + grab files that are currently downloading and return info + """ + self.mutex.lock() + try: + return self.proxy.status_downloads() + finally: + self.mutex.unlock() + + def getServerStatus(self): + """ + return server status + """ + self.mutex.lock() + try: + return self.proxy.status_server() + finally: + self.mutex.unlock() + +########################################## +############## Window Stuff ############## +########################################## + +class mainWindow(QMainWindow): + def __init__(self): + """ + set up main window + """ + QMainWindow.__init__(self) + #window stuff + self.setWindowTitle("pyLoad Client") + self.setWindowIcon(QIcon("icons/logo.png")) + self.resize(750,500) -class _Host_Dialog(wx.Dialog): - def __init__(self, parent, id, title): - wx.Dialog.__init__(self, parent, id, title, size=(250, 170)) + #central widget, layout + self.masterlayout = QVBoxLayout() + lw = QWidget() + lw.setLayout(self.masterlayout) + self.setCentralWidget(lw) - self.host = wx.TextCtrl(self, -1, '127.0.0.1') - host_name = wx.StaticText(self, -1, 'Host:') - self.port = wx.TextCtrl(self, -1, '7272') - port_name = wx.StaticText(self, -1, 'Port:') - self.password = wx.TextCtrl(self, -1, 'pwhere') - password_name = wx.StaticText(self, -1, 'Password:') - button_ok = wx.Button(self, wx.ID_OK, 'Ok', size=(90, 28)) - button_cancel = wx.Button(self, wx.ID_CANCEL, 'Close', size=(90, 28)) + #set menubar and statusbar + self.menubar = self.menuBar() + self.statusbar = self.statusBar() + self.serverStatus = QLabel("Status: Not Connected") + self.statusbar.addPermanentWidget(self.serverStatus) + #menu + self.menus = {} + self.menus["file"] = self.menubar.addMenu("&File") + self.menus["connections"] = self.menubar.addMenu("&Connections") - fgs = wx.FlexGridSizer(3, 2, 9, 25) + #menu actions + self.mactions = {} + self.mactions["exit"] = QAction("Exit", self.menus["file"]) + self.mactions["manager"] = QAction("Connection manager", self.menus["connections"]) - fgs.AddMany([(host_name), (self.host, 0, wx.EXPAND), (port_name), (self.port, 1, wx.EXPAND), (password_name), (self.password, 1, wx.EXPAND), (button_ok, 1, wx.EXPAND), (button_cancel, 1, wx.EXPAND)]) + #add menu actions + self.menus["file"].addAction(self.mactions["exit"]) + self.menus["connections"].addAction(self.mactions["manager"]) - fgs.AddGrowableCol(1, 1) + #tabs + self.tabw = QTabWidget() + self.tabs = {} + self.tabs["queue"] = {"w":QWidget()} + self.tabs["collector_packages"] = {"w":QWidget()} + self.tabs["collector_links"] = {"w":QWidget()} + self.tabw.addTab(self.tabs["queue"]["w"], "Queue") + self.tabw.addTab(self.tabs["collector_packages"]["w"], "Package collector") + self.tabw.addTab(self.tabs["collector_links"]["w"], "Link collector") - hbox = wx.BoxSizer(wx.HORIZONTAL) - hbox.Add(fgs, 1, wx.ALL | wx.EXPAND, 15) + #init tabs + self.init_tabs() + #layout + self.masterlayout.addWidget(self.tabw) + + def init_tabs(self): + """ + create tabs + """ + #queue + self.tabs["queue"]["l"] = QGridLayout() + self.tabs["queue"]["w"].setLayout(self.tabs["queue"]["l"]) + self.tabs["queue"]["view"] = QTreeWidget() + self.tabs["queue"]["l"].addWidget(self.tabs["queue"]["view"]) - self.SetSizer(hbox) + #collector_packages + self.tabs["collector_packages"]["l"] = QGridLayout() + self.tabs["collector_packages"]["w"].setLayout(self.tabs["collector_packages"]["l"]) + self.tabs["collector_packages"]["treewidget"] = QTreeWidget() + self.tabs["collector_packages"]["l"].addWidget(self.tabs["collector_packages"]["treewidget"]) -class Pyload_Main_Gui(wx.Frame): - def __init__(self, parent, id, title="pyLoad"): - - wx.Frame.__init__(self, parent, id, title, size=(910, 500)) - - app_path = dirname(abspath(__file__)) + sep - - # vars - self.links = [] - self.data = {} - - # Menubar - menubar = wx.MenuBar() - menu_file = wx.Menu() - submenu_exit = menu_file.Append(-1, 'Schliessen', 'pyLoad beenden') - menubar.Append(menu_file, '&Datei') - menu_pyload = wx.Menu() - self.submenu_pyload_connect = menu_pyload.Append(-1, 'Connect', 'Connect to pyLoad') - self.submenu_pyload_disconnect = menu_pyload.Append(-1, 'Disconnect', 'Disconnect') - self.submenu_pyload_shutdown = menu_pyload.Append(-1, 'Shutdown', 'Shutdown pyLoad Core') - menubar.Append(menu_pyload, '&pyLoad') - self.SetMenuBar(menubar) - - # Statusbar - self.CreateStatusBar() - - # icon - icon1 = wx.Icon(app_path + '/icons/pyload.ico', wx.BITMAP_TYPE_ICO) - self.SetIcon(icon1) - - # Toolbar - toolbar = self.CreateToolBar() - toolbar.SetToolBitmapSize((32, 32)) - add = toolbar.AddLabelTool(2, '', wx.Bitmap(app_path + '/icons/add.png')) - delete = toolbar.AddLabelTool(3, '', wx.Bitmap(app_path + '/icons/del.png')) - start = toolbar.AddLabelTool(4, '', wx.Bitmap(app_path + '/icons/start.png')) - pause = toolbar.AddLabelTool(5, '', wx.Bitmap(app_path + '/icons/pause.png')) - stop = toolbar.AddLabelTool(6, '', wx.Bitmap(app_path + '/icons/stop.png')) - up = toolbar.AddLabelTool(7, '', wx.Bitmap(app_path + '/icons/up.png')) - down = toolbar.AddLabelTool(8, '', wx.Bitmap(app_path + '/icons/down.png')) - config = toolbar.AddLabelTool(9, '', wx.Bitmap(app_path + '/icons/setup.png')) - toolbar.Realize() - - #splitter = wx.SplitterWindow(self) - self.panel_up = _Upper_Panel(self) - #panel_down = _Lower_Panel(splitter) - #splitter.SplitHorizontally(panel_up, panel_down, 300) - - # Binds - self.Bind(wx.EVT_MENU, self.exit_button_clicked, submenu_exit) - self.Bind(wx.EVT_MENU, self.connect, self.submenu_pyload_connect) - self.Bind(wx.EVT_MENU, self.disconnect, self.submenu_pyload_disconnect) - self.Bind(wx.EVT_MENU, self.shutdown, self.submenu_pyload_shutdown) - self.Bind(wx.EVT_TOOL, self.add_button_clicked, add) - self.Bind(wx.EVT_TOOL, self.delete_button_clicked, delete) - self.Bind(wx.EVT_TOOL, self.up_button_clicked, up) - self.Bind(wx.EVT_TOOL, self.down_button_clicked, down) - self.Bind(EVT_DATA_ARRIVED, self.onUpdate) - - self.Centre() - self.Show(True) + #collector_links + self.tabs["collector_links"]["l"] = QGridLayout() + self.tabs["collector_links"]["w"].setLayout(self.tabs["collector_links"]["l"]) + self.tabs["collector_links"]["listwidget"] = QListWidget() + self.tabs["collector_links"]["l"].addWidget(self.tabs["collector_links"]["listwidget"]) + +class ConnectionManager(QWidget): + def __init__(self): + QWidget.__init__(self) - - def exit_button_clicked(self, event): - self.Close() + mainLayout = QHBoxLayout() + buttonLayout = QVBoxLayout() + + connList = QListWidget() + + new = QPushButton("New") + edit = QPushButton("Edit") + remove = QPushButton("Remove") + connect = QPushButton("Connect") + + mainLayout.addWidget(connList) + mainLayout.addLayout(buttonLayout) + + buttonLayout.addWidget(new) + buttonLayout.addWidget(edit) + buttonLayout.addWidget(remove) + buttonLayout.addStretch() + buttonLayout.addWidget(connect) + + self.setLayout(mainLayout) + + self.new = new + self.connectb = connect + self.remove = remove + self.editb = edit + self.connList = connList + self.edit = self.EditWindow() + self.connectSignals() - def connect(self, event): - socket_host = _Host_Dialog(self, -1, 'Connect to:') - res_socket = socket_host.ShowModal() - if (res_socket == wx.ID_OK): - try: - self.thread = SocketThread(socket_host.host.GetValue(), int(socket_host.port.GetValue()), socket_host.password.GetValue(), self) - self.SetStatusText('Connected to: %s:%s' % (socket_host.host.GetValue(), socket_host.port.GetValue())) - except socket.error: - if (socket_host.host.GetValue() in ['localhost', '127.0.0.1']): - if (wx.MessageDialog(None, 'Do you want to start pyLoadCore locally?', 'Start pyLoad', wx.OK | wx.CANCEL).ShowModal() == wx.ID_OK): - cmd = ['python', 'pyLoadCore.py'] - subprocess.Popen(cmd) - sleep(2) - self.thread = SocketThread(socket_host.host.GetValue(), int(socket_host.port.GetValue()), socket_host.password.GetValue(), self) - self.SetStatusText('Connected to: %s:%s' % (socket_host.host.GetValue(), socket_host.port.GetValue())) - else: - wx.MessageDialog(None, 'Cant connect to: %s:%s' % (socket_host.host.GetValue(), socket_host.port.GetValue()), 'Error', wx.OK | wx.ICON_ERROR).ShowModal() - else: - wx.MessageDialog(None, 'Cant connect to: %s:%s' % (socket_host.host.GetValue(), socket_host.port.GetValue()), 'Error', wx.OK | wx.ICON_ERROR).ShowModal() - - self.thread.push_exec("get_links") - - def disconnect(self, event): - self.thread.socket.close_when_done() - self.SetStatusText('') - - def shutdown(self, event): - self.thread.push_exec("kill") - - def add_button_clicked(self, event): - #test - #self.thread.push_exec("get_downloads") - - add_download = _Download_Dialog(None, -1) - result = add_download.ShowModal() - add_download.Destroy() - downloads = add_download.links.GetValue().split() - self.thread.push_exec('add_links', [downloads]) - - def delete_button_clicked(self, event): - - links = self.panel_up.get_selected_ids(True) - - self.thread.push_exec('remove_links', [links]) - - def up_button_clicked(self, event): - - links = self.panel_up.get_selected_ids() - self.thread.push_exec('move_links_up', [links]) - - - def down_button_clicked(self, event): - - links = self.panel_up.get_selected_ids() - - self.thread.push_exec('move_links_down', [links]) - - def show_links(self, links): - for link in links: - #wx.MessageDialog(self, str(link), 'info', style=wx.OK).ShowModal() - print str(link) - - def data_arrived(self, rep): - evt = DataArrived(obj=rep) - wx.PostEvent(self, evt) - - def onUpdate(self, evt): - - if evt.obj.function == "get_downloads": - pass - #self.show_links(evt.obj.response) - - if evt.obj.command == "update": - self.links = evt.obj.data - self.panel_up.refresh(self.links, self.data) + def connectSignals(self): + self.connect(self, SIGNAL("setConnections(connections)"), self.setConnections) + self.connect(self.new, SIGNAL("clicked()"), self.slotNew) + self.connect(self.editb, SIGNAL("clicked()"), self.slotEdit) + self.connect(self.remove, SIGNAL("clicked()"), self.slotRemove) + self.connect(self.connectb, SIGNAL("clicked()"), self.slotConnect) + self.connect(self.edit, SIGNAL("save"), self.slotSave) + + def setConnections(self, connections): + self.connList.clear() + for conn in connections: + item = QListWidgetItem() + item.setData(Qt.DisplayRole, QVariant(conn["name"])) + item.setData(Qt.UserRole, QVariant(conn)) + self.connList.addItem(item) + if conn["default"]: + self.connList.setCurrentItem(item) + + def slotNew(self): + data = {"id":uuid().hex, "type":"remote", "default":False, "name":"", "host":"", "ssl":False, "port":"7227", "user":"admin"} + self.edit.setData(data) + self.edit.show() + + def slotEdit(self): + item = self.connList.currentItem() + data = item.data(Qt.UserRole).toPyObject() + tmp = {} + for k, d in data.items(): + tmp[str(k)] = d + data = tmp + self.edit.setData(data) + self.edit.show() + + def slotRemove(self): + item = self.connList.currentItem() + data = item.data(Qt.UserRole).toPyObject() + tmp = {} + for k, d in data.items(): + tmp[str(k)] = d + data = tmp + self.emit(SIGNAL("removeConnection"), data) + + def slotConnect(self): + item = self.connList.currentItem() + data = item.data(Qt.UserRole).toPyObject() + tmp = {} + for k, d in data.items(): + tmp[str(k)] = d + data = tmp + self.emit(SIGNAL("connect"), data) + + def slotSave(self, data): + self.emit(SIGNAL("saveConnection"), data) + + class EditWindow(QWidget): + def __init__(self): + QWidget.__init__(self) - if evt.obj.command == "file_list" or evt.obj.function == "get_links": - self.data = evt.obj.data - self.panel_up.refresh(self.links, self.data) - + grid = QGridLayout() + + nameLabel = QLabel("Name:") + hostLabel = QLabel("Host:") + sslLabel = QLabel("SSL:") + localLabel = QLabel("Local:") + userLabel = QLabel("User:") + portLabel = QLabel("Port:") + + name = QLineEdit() + host = QLineEdit() + ssl = QCheckBox() + local = QCheckBox() + user = QLineEdit() + 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) + grid.addWidget(local, 1, 1) + grid.addWidget(hostLabel, 2, 0) + grid.addWidget(host, 2, 1) + grid.addWidget(sslLabel, 4, 0) + grid.addWidget(ssl, 4, 1) + grid.addWidget(userLabel, 5, 0) + grid.addWidget(user, 5, 1) + grid.addWidget(portLabel, 3, 0) + grid.addWidget(port, 3, 1) + grid.addWidget(cancel, 6, 0) + grid.addWidget(save, 6, 1) + + self.setLayout(grid) + self.controls = {} + self.controls["name"] = name + self.controls["host"] = host + self.controls["ssl"] = ssl + self.controls["local"] = local + self.controls["user"] = user + self.controls["port"] = port + self.controls["save"] = save + self.controls["cancel"] = cancel + + 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): + self.id = data["id"] + self.default = data["default"] + self.controls["name"].setText(data["name"]) + if data["type"] == "local": + data["local"] = True + else: + data["local"] = False + self.controls["local"].setChecked(data["local"]) + if not data["local"]: + self.controls["ssl"].setChecked(data["ssl"]) + self.controls["user"].setText(data["user"]) + self.controls["port"].setValue(int(data["port"])) + self.controls["host"].setText(data["host"]) + self.controls["ssl"].setDisabled(False) + self.controls["user"].setDisabled(False) + self.controls["port"].setDisabled(False) + self.controls["host"].setDisabled(False) + else: + self.controls["ssl"].setChecked(False) + self.controls["user"].setText("") + self.controls["port"].setValue(1) + self.controls["host"].setText("") + self.controls["ssl"].setDisabled(True) + self.controls["user"].setDisabled(True) + self.controls["port"].setDisabled(True) + self.controls["host"].setDisabled(True) + + def slotLocalChanged(self, val): + if val == 2: + self.controls["ssl"].setDisabled(True) + self.controls["user"].setDisabled(True) + self.controls["port"].setDisabled(True) + self.controls["host"].setDisabled(True) + elif val == 0: + self.controls["ssl"].setDisabled(False) + self.controls["user"].setDisabled(False) + self.controls["port"].setDisabled(False) + self.controls["host"].setDisabled(False) + + def getData(self): + d = {} + d["id"] = self.id + d["default"] = self.default + d["name"] = self.controls["name"].text() + d["local"] = self.controls["local"].isChecked() + d["ssl"] = str(self.controls["ssl"].isChecked()) + d["user"] = self.controls["user"].text() + d["host"] = self.controls["host"].text() + d["port"] = self.controls["port"].value() + if d["local"]: + d["type"] = "local" + else: + d["type"] = "remote" + return d + + def slotDone(self): + data = self.getData() + self.hide() + self.emit(SIGNAL("save"), data) + +class PWInputWindow(QWidget): + def __init__(self): + QWidget.__init__(self) + self.input = QLineEdit() + label = QLabel("Password:") + ok = QPushButton("OK") + cancel = QPushButton("Cancel") + grid = QGridLayout() + grid.addWidget(label, 0, 0, 1, 2) + grid.addWidget(self.input, 1, 0, 1, 2) + grid.addWidget(cancel, 2, 0) + grid.addWidget(ok, 2, 1) + self.setLayout(grid) + + self.connect(ok, SIGNAL("clicked()"), self.slotOK) + self.connect(cancel, SIGNAL("clicked()"), self.slotCancel) + self.connect(self.input, SIGNAL("returnPressed()"), self.slotOK) + + def slotOK(self): + self.hide() + self.emit(SIGNAL("ok"), self.input.text()) + + def slotCancel(self): + self.hide() + self.emit(SIGNAL("cancel")) + +######################################### +############## Queue Stuff ############## +######################################### + +class Queue(QThread): + def __init__(self, view, connector): + QThread.__init__(self) + self.view = view + self.connector = connector + self.statusMap = { + "finished": 0, + "checking": 1, + "waiting": 2, + "reconnected": 3, + "downloading": 4, + "failed": 5, + "aborted": 6, + } + self.statusMapReverse = dict((v,k) for k, v in self.statusMap.iteritems()) + self.queue = [] + self.interval = 2 + self.running = True + self.mutex = QMutex() + + def run(self): + while self.running: + self.update() + sleep(self.interval) + + def update(self): + locker = QMutexLocker(self.mutex) + packs = self.connector.getPackageQueue() + downloading_raw = self.connector.getDownloadQueue() + downloading = {} + for d in downloading: + did = d["id"] + del d["id"] + del d["name"] + del d["status"] + downloading[did] = d + for data in packs: + pack = self.getPack(data["id"]) + if not pack: + pack = self.QueuePack(self) + pack.setData(data) + self.addPack(data["id"], pack) + files = self.connector.getPackageFiles(data["id"]) + for fid in files: + info = self.connector.getLinkInfo(fid) + child = pack.getChild(fid) + if not child: + child = self.QueueFile(self, pack) + try: + info["downloading"] = downloading[data["id"]] + except: + info["downloading"] = None + child.setData(info) + pack.addChild(fid, child) + + def addPack(self, pid, newPack): + pos = None + try: + for k, pack in enumerate(self.queue): + if pack.getData()["id"] == pid: + pos = k + break + if pos == None: + raise Exception() + self.queue[pos] = newPack + except: + self.queue.append(newPack) + pos = self.queue.index(newPack) + item = self.view.topLevelItem(pos) + if not item: + item = QTreeWidgetItem() + self.view.insertTopLevelItem(pos, item) + item.setData(0, Qt.DisplayRole, QVariant(newPack.getData()["package_name"])) + status = -1 + for child in newPack.getChildren(): + if self.statusMap.has_key(child.data["status_type"]) and self.statusMap[child.data["status_type"]] > status: + status = self.statusMap[child.data["status_type"]] + if status >= 0: + item.setData(1, Qt.DisplayRole, QVariant(self.statusMapReverse[status])) + item.setData(0, Qt.UserRole, QVariant(pid)) + item.setData(2, Qt.UserRole, QVariant(newPack)) + + def getPack(self, pid): + for k, pack in enumerate(self.queue): + if pack.getData()["id"] == pid: + return pack + return None + + def getProgress(self, q): + locker = QMutexLocker(self.mutex) + if isinstance(q, self.QueueFile): + data = q.getData() + if data["downloading"]: + return int(data["downloading"]["percent"]) + if data["status_type"] == "finished" or \ + data["status_type"] == "failed" or \ + data["status_type"] == "aborted": + return 100 + elif isinstance(q, self.QueuePack): + children = q.getChildren() + count = len(children) + perc_sum = 0 + for child in children: + val = 0 + data = child.getData() + if data["downloading"]: + val = int(data["downloading"]["percent"]) + elif child.data["status_type"] == "finished" or \ + child.data["status_type"] == "failed" or \ + child.data["status_type"] == "aborted": + val = 100 + perc_sum += val + if count == 0: + return 0 + return perc_sum/count + return 0 + + def getSpeed(self, q): + locker = QMutexLocker(self.mutex) + if isinstance(q, self.QueueFile): + data = q.getData() + if data["downloading"]: + return int(data["downloading"]["speed"]) + elif isinstance(q, self.QueuePack): + children = q.getChildren() + count = len(children) + speed_sum = 0 + for child in children: + val = 0 + data = child.getData() + running = False + if data["downloading"]: + val = int(data["downloading"]["speed"]) + running = True + speed_sum += val + if count == 0 or not running: + return None + return speed_sum + return None + + class QueuePack(): + def __init__(self, queue): + self.queue = queue + self.data = [] + self.children = [] + + def addChild(self, cid, newChild): + pos = None + try: + for k, child in enumerate(self.getChildren()): + if child.getData()["id"] == cid: + pos = k + break + if pos == None: + raise Exception() + self.children[pos] = newChild + except: + self.children.append(newChild) + pos = self.children.index(newChild) + ppos = self.queue.queue.index(self) + parent = self.queue.view.topLevelItem(ppos) + item = parent.child(pos) + if not item: + item = QTreeWidgetItem() + parent.insertChild(pos, item) + status = "%s (%s)" % (newChild.getData()["status_type"], newChild.getData()["plugin"]) + item.setData(0, Qt.DisplayRole, QVariant(newChild.getData()["filename"])) + item.setData(1, Qt.DisplayRole, QVariant(status)) + item.setData(0, Qt.UserRole, QVariant(cid)) + item.setData(2, Qt.UserRole, QVariant(newChild)) + + def getChildren(self): + return self.children + + def getChild(self, cid): + try: + return self.children[cid] + except: + return None + + def hasChildren(self, data): + return (len(self.children) > 0) + + def setData(self, data): + self.data = data + + def getData(self): + return self.data -def format_time(seconds): - seconds = int(seconds) - hours, seconds = divmod(seconds, 3600) - minutes, seconds = divmod(seconds, 60) - return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) + class QueueFile(): + def __init__(self, queue, pack): + self.queue = queue + self.pack = pack + + def getData(self): + return self.data + + def setData(self, data): + self.data = data + + def getPack(self): + return self.pack +class QueueProgressBarDelegate(QItemDelegate): + def __init__(self, parent, queue): + QItemDelegate.__init__(self, parent) + self.queue = queue + + def paint(self, painter, option, index): + if index.column() == 2: + qe = index.data(Qt.UserRole).toPyObject() + progress = self.queue.getProgress(qe) + opts = QStyleOptionProgressBarV2() + opts.maximum = 100 + opts.minimum = 0 + opts.progress = progress + opts.rect = option.rect + opts.rect.setRight(option.rect.right()-1) + opts.rect.setHeight(option.rect.height()-1) + opts.textVisible = True + opts.textAlignment = Qt.AlignCenter + speed = self.queue.getSpeed(qe) + if speed == None: + opts.text = QString.number(opts.progress) + "%" + else: + opts.text = QString("%s kb/s - %s" % (speed, opts.progress)) + "%" + QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter) + return + QItemDelegate.paint(self, painter, option, index) + +######################################### +############## Other Stuff ############## +######################################### + +class XMLParser(): + def __init__(self, data, dfile=""): + self.mutex = QMutex() + self.mutex.lock() + self.xml = QDomDocument() + self.file = data + self.dfile = dfile + self.mutex.unlock() + self.loadData() + self.root = self.xml.documentElement() + + def loadData(self): + self.mutex.lock() + f = self.file + if not os.path.exists(f): + f = self.dfile + with open(f, 'r') as fh: + content = fh.read() + self.xml.setContent(content) + self.mutex.unlock() + + def saveData(self): + self.mutex.lock() + content = self.xml.toString() + with open(self.file, 'w') as fh: + fh.write(content) + self.mutex.unlock() + return content + + def parseNode(self, node, ret_type="list"): + if ret_type == "dict": + childNodes = {} + else: + childNodes = [] + child = node.firstChild() + while True: + n = child.toElement() + if n.isNull(): + break + else: + if ret_type == "dict": + childNodes[str(n.tagName())] = n + else: + childNodes.append(n) + child = child.nextSibling() + return childNodes -app = wx.App() -Pyload_Main_Gui(None, -1) -app.MainLoop() +if __name__ == "__main__": + app = main() + app.loop() -- cgit v1.2.3 From ddd93d0e571edbe1a62f928436ea79818466e940 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 17:47:41 +0100 Subject: splited gui file, extended .hgignore --- pyLoadGui.py | 734 +---------------------------------------------------------- 1 file changed, 8 insertions(+), 726 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 844a96ef2..f8ba3efd3 100644 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -19,21 +19,22 @@ @version: v0.3 """ -SERVER_VERSION = "0.3" - import sys -import os from time import sleep, time from PyQt4.QtCore import * from PyQt4.QtGui import * -from PyQt4.QtXml import * - -from xmlrpclib import ServerProxy from uuid import uuid4 as uuid +from module.gui.ConnectionManager import * +from module.gui.connector import * +from module.gui.MainWindow import * +from module.gui.PWInputWindow import * +from module.gui.Queue import * +from module.gui.XMLParser import * + class main(QObject): def __init__(self): """ @@ -41,7 +42,7 @@ class main(QObject): """ QObject.__init__(self) self.app = QApplication(sys.argv) - self.mainWindow = mainWindow() + self.mainWindow = MainWindow() self.pwWindow = PWInputWindow() self.connWindow = ConnectionManager() self.connector = connector() @@ -281,725 +282,6 @@ class main(QObject): def update(self): self.parent.refreshServerStatus() -############################################# -############## Connector Stuff ############## -############################################# - -class connector(QThread): - def __init__(self): - """ - init thread - """ - QThread.__init__(self) - self.mutex = QMutex() - self.running = True - self.proxy = None - self.addr = None - - def setAddr(self, addr): - self.mutex.lock() - self.addr = addr - self.mutex.unlock() - - def run(self): - """ - start thread - (called from thread.start()) - """ - self.connectProxy(self.addr) - while self.running: - sleep(1) - - def stop(self): - """ - stop thread - """ - self.running = False - - def connectProxy(self, addr): - """ - connect to remote server - """ - self.proxy = ServerProxy(addr, allow_none=True) - server_version = self.proxy.get_server_version() - if not server_version == SERVER_VERSION: - self.emit(SIGNAL("error_box"), "server is version %s client accepts version %s" % (server_version, SERVER_VERSION)) - - def getLinkCollector(self): - """ - grab links from collector and return the ids - """ - self.mutex.lock() - try: - return self.proxy.get_collector_files() - finally: - self.mutex.unlock() - - def getPackageCollector(self): - """ - grab packages from collector and return the data - """ - self.mutex.lock() - try: - return self.proxy.get_collector_packages() - finally: - self.mutex.unlock() - - def getLinkInfo(self, id): - """ - grab file info for the given id and return it - """ - self.mutex.lock() - try: - return self.proxy.get_file_info(id) - finally: - self.mutex.unlock() - - def getPackageInfo(self, id): - """ - grab package info for the given id and return it - """ - self.mutex.lock() - try: - return self.proxy.get_package_data(id) - finally: - self.mutex.unlock() - - def getPackageQueue(self): - """ - grab queue return the data - """ - self.mutex.lock() - try: - return self.proxy.get_queue() - finally: - self.mutex.unlock() - - def getPackageFiles(self, id): - """ - grab package files and return ids - """ - self.mutex.lock() - try: - return self.proxy.get_package_files(id) - finally: - self.mutex.unlock() - - def getDownloadQueue(self): - """ - grab files that are currently downloading and return info - """ - self.mutex.lock() - try: - return self.proxy.status_downloads() - finally: - self.mutex.unlock() - - def getServerStatus(self): - """ - return server status - """ - self.mutex.lock() - try: - return self.proxy.status_server() - finally: - self.mutex.unlock() - -########################################## -############## Window Stuff ############## -########################################## - -class mainWindow(QMainWindow): - def __init__(self): - """ - set up main window - """ - QMainWindow.__init__(self) - #window stuff - self.setWindowTitle("pyLoad Client") - self.setWindowIcon(QIcon("icons/logo.png")) - self.resize(750,500) - - #central widget, layout - self.masterlayout = QVBoxLayout() - lw = QWidget() - lw.setLayout(self.masterlayout) - self.setCentralWidget(lw) - - #set menubar and statusbar - self.menubar = self.menuBar() - self.statusbar = self.statusBar() - self.serverStatus = QLabel("Status: Not Connected") - self.statusbar.addPermanentWidget(self.serverStatus) - - #menu - self.menus = {} - self.menus["file"] = self.menubar.addMenu("&File") - self.menus["connections"] = self.menubar.addMenu("&Connections") - - #menu actions - self.mactions = {} - self.mactions["exit"] = QAction("Exit", self.menus["file"]) - self.mactions["manager"] = QAction("Connection manager", self.menus["connections"]) - - #add menu actions - self.menus["file"].addAction(self.mactions["exit"]) - self.menus["connections"].addAction(self.mactions["manager"]) - - #tabs - self.tabw = QTabWidget() - self.tabs = {} - self.tabs["queue"] = {"w":QWidget()} - self.tabs["collector_packages"] = {"w":QWidget()} - self.tabs["collector_links"] = {"w":QWidget()} - self.tabw.addTab(self.tabs["queue"]["w"], "Queue") - self.tabw.addTab(self.tabs["collector_packages"]["w"], "Package collector") - self.tabw.addTab(self.tabs["collector_links"]["w"], "Link collector") - - #init tabs - self.init_tabs() - - #layout - self.masterlayout.addWidget(self.tabw) - - def init_tabs(self): - """ - create tabs - """ - #queue - self.tabs["queue"]["l"] = QGridLayout() - self.tabs["queue"]["w"].setLayout(self.tabs["queue"]["l"]) - self.tabs["queue"]["view"] = QTreeWidget() - self.tabs["queue"]["l"].addWidget(self.tabs["queue"]["view"]) - - #collector_packages - self.tabs["collector_packages"]["l"] = QGridLayout() - self.tabs["collector_packages"]["w"].setLayout(self.tabs["collector_packages"]["l"]) - self.tabs["collector_packages"]["treewidget"] = QTreeWidget() - self.tabs["collector_packages"]["l"].addWidget(self.tabs["collector_packages"]["treewidget"]) - - #collector_links - self.tabs["collector_links"]["l"] = QGridLayout() - self.tabs["collector_links"]["w"].setLayout(self.tabs["collector_links"]["l"]) - self.tabs["collector_links"]["listwidget"] = QListWidget() - self.tabs["collector_links"]["l"].addWidget(self.tabs["collector_links"]["listwidget"]) - -class ConnectionManager(QWidget): - def __init__(self): - QWidget.__init__(self) - - mainLayout = QHBoxLayout() - buttonLayout = QVBoxLayout() - - connList = QListWidget() - - new = QPushButton("New") - edit = QPushButton("Edit") - remove = QPushButton("Remove") - connect = QPushButton("Connect") - - mainLayout.addWidget(connList) - mainLayout.addLayout(buttonLayout) - - buttonLayout.addWidget(new) - buttonLayout.addWidget(edit) - buttonLayout.addWidget(remove) - buttonLayout.addStretch() - buttonLayout.addWidget(connect) - - self.setLayout(mainLayout) - - self.new = new - self.connectb = connect - self.remove = remove - self.editb = edit - self.connList = connList - self.edit = self.EditWindow() - self.connectSignals() - - def connectSignals(self): - self.connect(self, SIGNAL("setConnections(connections)"), self.setConnections) - self.connect(self.new, SIGNAL("clicked()"), self.slotNew) - self.connect(self.editb, SIGNAL("clicked()"), self.slotEdit) - self.connect(self.remove, SIGNAL("clicked()"), self.slotRemove) - self.connect(self.connectb, SIGNAL("clicked()"), self.slotConnect) - self.connect(self.edit, SIGNAL("save"), self.slotSave) - - def setConnections(self, connections): - self.connList.clear() - for conn in connections: - item = QListWidgetItem() - item.setData(Qt.DisplayRole, QVariant(conn["name"])) - item.setData(Qt.UserRole, QVariant(conn)) - self.connList.addItem(item) - if conn["default"]: - self.connList.setCurrentItem(item) - - def slotNew(self): - data = {"id":uuid().hex, "type":"remote", "default":False, "name":"", "host":"", "ssl":False, "port":"7227", "user":"admin"} - self.edit.setData(data) - self.edit.show() - - def slotEdit(self): - item = self.connList.currentItem() - data = item.data(Qt.UserRole).toPyObject() - tmp = {} - for k, d in data.items(): - tmp[str(k)] = d - data = tmp - self.edit.setData(data) - self.edit.show() - - def slotRemove(self): - item = self.connList.currentItem() - data = item.data(Qt.UserRole).toPyObject() - tmp = {} - for k, d in data.items(): - tmp[str(k)] = d - data = tmp - self.emit(SIGNAL("removeConnection"), data) - - def slotConnect(self): - item = self.connList.currentItem() - data = item.data(Qt.UserRole).toPyObject() - tmp = {} - for k, d in data.items(): - tmp[str(k)] = d - data = tmp - self.emit(SIGNAL("connect"), data) - - def slotSave(self, data): - self.emit(SIGNAL("saveConnection"), data) - - class EditWindow(QWidget): - def __init__(self): - QWidget.__init__(self) - - grid = QGridLayout() - - nameLabel = QLabel("Name:") - hostLabel = QLabel("Host:") - sslLabel = QLabel("SSL:") - localLabel = QLabel("Local:") - userLabel = QLabel("User:") - portLabel = QLabel("Port:") - - name = QLineEdit() - host = QLineEdit() - ssl = QCheckBox() - local = QCheckBox() - user = QLineEdit() - 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) - grid.addWidget(local, 1, 1) - grid.addWidget(hostLabel, 2, 0) - grid.addWidget(host, 2, 1) - grid.addWidget(sslLabel, 4, 0) - grid.addWidget(ssl, 4, 1) - grid.addWidget(userLabel, 5, 0) - grid.addWidget(user, 5, 1) - grid.addWidget(portLabel, 3, 0) - grid.addWidget(port, 3, 1) - grid.addWidget(cancel, 6, 0) - grid.addWidget(save, 6, 1) - - self.setLayout(grid) - self.controls = {} - self.controls["name"] = name - self.controls["host"] = host - self.controls["ssl"] = ssl - self.controls["local"] = local - self.controls["user"] = user - self.controls["port"] = port - self.controls["save"] = save - self.controls["cancel"] = cancel - - 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): - self.id = data["id"] - self.default = data["default"] - self.controls["name"].setText(data["name"]) - if data["type"] == "local": - data["local"] = True - else: - data["local"] = False - self.controls["local"].setChecked(data["local"]) - if not data["local"]: - self.controls["ssl"].setChecked(data["ssl"]) - self.controls["user"].setText(data["user"]) - self.controls["port"].setValue(int(data["port"])) - self.controls["host"].setText(data["host"]) - self.controls["ssl"].setDisabled(False) - self.controls["user"].setDisabled(False) - self.controls["port"].setDisabled(False) - self.controls["host"].setDisabled(False) - else: - self.controls["ssl"].setChecked(False) - self.controls["user"].setText("") - self.controls["port"].setValue(1) - self.controls["host"].setText("") - self.controls["ssl"].setDisabled(True) - self.controls["user"].setDisabled(True) - self.controls["port"].setDisabled(True) - self.controls["host"].setDisabled(True) - - def slotLocalChanged(self, val): - if val == 2: - self.controls["ssl"].setDisabled(True) - self.controls["user"].setDisabled(True) - self.controls["port"].setDisabled(True) - self.controls["host"].setDisabled(True) - elif val == 0: - self.controls["ssl"].setDisabled(False) - self.controls["user"].setDisabled(False) - self.controls["port"].setDisabled(False) - self.controls["host"].setDisabled(False) - - def getData(self): - d = {} - d["id"] = self.id - d["default"] = self.default - d["name"] = self.controls["name"].text() - d["local"] = self.controls["local"].isChecked() - d["ssl"] = str(self.controls["ssl"].isChecked()) - d["user"] = self.controls["user"].text() - d["host"] = self.controls["host"].text() - d["port"] = self.controls["port"].value() - if d["local"]: - d["type"] = "local" - else: - d["type"] = "remote" - return d - - def slotDone(self): - data = self.getData() - self.hide() - self.emit(SIGNAL("save"), data) - -class PWInputWindow(QWidget): - def __init__(self): - QWidget.__init__(self) - self.input = QLineEdit() - label = QLabel("Password:") - ok = QPushButton("OK") - cancel = QPushButton("Cancel") - grid = QGridLayout() - grid.addWidget(label, 0, 0, 1, 2) - grid.addWidget(self.input, 1, 0, 1, 2) - grid.addWidget(cancel, 2, 0) - grid.addWidget(ok, 2, 1) - self.setLayout(grid) - - self.connect(ok, SIGNAL("clicked()"), self.slotOK) - self.connect(cancel, SIGNAL("clicked()"), self.slotCancel) - self.connect(self.input, SIGNAL("returnPressed()"), self.slotOK) - - def slotOK(self): - self.hide() - self.emit(SIGNAL("ok"), self.input.text()) - - def slotCancel(self): - self.hide() - self.emit(SIGNAL("cancel")) - -######################################### -############## Queue Stuff ############## -######################################### - -class Queue(QThread): - def __init__(self, view, connector): - QThread.__init__(self) - self.view = view - self.connector = connector - self.statusMap = { - "finished": 0, - "checking": 1, - "waiting": 2, - "reconnected": 3, - "downloading": 4, - "failed": 5, - "aborted": 6, - } - self.statusMapReverse = dict((v,k) for k, v in self.statusMap.iteritems()) - self.queue = [] - self.interval = 2 - self.running = True - self.mutex = QMutex() - - def run(self): - while self.running: - self.update() - sleep(self.interval) - - def update(self): - locker = QMutexLocker(self.mutex) - packs = self.connector.getPackageQueue() - downloading_raw = self.connector.getDownloadQueue() - downloading = {} - for d in downloading: - did = d["id"] - del d["id"] - del d["name"] - del d["status"] - downloading[did] = d - for data in packs: - pack = self.getPack(data["id"]) - if not pack: - pack = self.QueuePack(self) - pack.setData(data) - self.addPack(data["id"], pack) - files = self.connector.getPackageFiles(data["id"]) - for fid in files: - info = self.connector.getLinkInfo(fid) - child = pack.getChild(fid) - if not child: - child = self.QueueFile(self, pack) - try: - info["downloading"] = downloading[data["id"]] - except: - info["downloading"] = None - child.setData(info) - pack.addChild(fid, child) - - def addPack(self, pid, newPack): - pos = None - try: - for k, pack in enumerate(self.queue): - if pack.getData()["id"] == pid: - pos = k - break - if pos == None: - raise Exception() - self.queue[pos] = newPack - except: - self.queue.append(newPack) - pos = self.queue.index(newPack) - item = self.view.topLevelItem(pos) - if not item: - item = QTreeWidgetItem() - self.view.insertTopLevelItem(pos, item) - item.setData(0, Qt.DisplayRole, QVariant(newPack.getData()["package_name"])) - status = -1 - for child in newPack.getChildren(): - if self.statusMap.has_key(child.data["status_type"]) and self.statusMap[child.data["status_type"]] > status: - status = self.statusMap[child.data["status_type"]] - if status >= 0: - item.setData(1, Qt.DisplayRole, QVariant(self.statusMapReverse[status])) - item.setData(0, Qt.UserRole, QVariant(pid)) - item.setData(2, Qt.UserRole, QVariant(newPack)) - - def getPack(self, pid): - for k, pack in enumerate(self.queue): - if pack.getData()["id"] == pid: - return pack - return None - - def getProgress(self, q): - locker = QMutexLocker(self.mutex) - if isinstance(q, self.QueueFile): - data = q.getData() - if data["downloading"]: - return int(data["downloading"]["percent"]) - if data["status_type"] == "finished" or \ - data["status_type"] == "failed" or \ - data["status_type"] == "aborted": - return 100 - elif isinstance(q, self.QueuePack): - children = q.getChildren() - count = len(children) - perc_sum = 0 - for child in children: - val = 0 - data = child.getData() - if data["downloading"]: - val = int(data["downloading"]["percent"]) - elif child.data["status_type"] == "finished" or \ - child.data["status_type"] == "failed" or \ - child.data["status_type"] == "aborted": - val = 100 - perc_sum += val - if count == 0: - return 0 - return perc_sum/count - return 0 - - def getSpeed(self, q): - locker = QMutexLocker(self.mutex) - if isinstance(q, self.QueueFile): - data = q.getData() - if data["downloading"]: - return int(data["downloading"]["speed"]) - elif isinstance(q, self.QueuePack): - children = q.getChildren() - count = len(children) - speed_sum = 0 - for child in children: - val = 0 - data = child.getData() - running = False - if data["downloading"]: - val = int(data["downloading"]["speed"]) - running = True - speed_sum += val - if count == 0 or not running: - return None - return speed_sum - return None - - class QueuePack(): - def __init__(self, queue): - self.queue = queue - self.data = [] - self.children = [] - - def addChild(self, cid, newChild): - pos = None - try: - for k, child in enumerate(self.getChildren()): - if child.getData()["id"] == cid: - pos = k - break - if pos == None: - raise Exception() - self.children[pos] = newChild - except: - self.children.append(newChild) - pos = self.children.index(newChild) - ppos = self.queue.queue.index(self) - parent = self.queue.view.topLevelItem(ppos) - item = parent.child(pos) - if not item: - item = QTreeWidgetItem() - parent.insertChild(pos, item) - status = "%s (%s)" % (newChild.getData()["status_type"], newChild.getData()["plugin"]) - item.setData(0, Qt.DisplayRole, QVariant(newChild.getData()["filename"])) - item.setData(1, Qt.DisplayRole, QVariant(status)) - item.setData(0, Qt.UserRole, QVariant(cid)) - item.setData(2, Qt.UserRole, QVariant(newChild)) - - def getChildren(self): - return self.children - - def getChild(self, cid): - try: - return self.children[cid] - except: - return None - - def hasChildren(self, data): - return (len(self.children) > 0) - - def setData(self, data): - self.data = data - - def getData(self): - return self.data - - class QueueFile(): - def __init__(self, queue, pack): - self.queue = queue - self.pack = pack - - def getData(self): - return self.data - - def setData(self, data): - self.data = data - - def getPack(self): - return self.pack - -class QueueProgressBarDelegate(QItemDelegate): - def __init__(self, parent, queue): - QItemDelegate.__init__(self, parent) - self.queue = queue - - def paint(self, painter, option, index): - if index.column() == 2: - qe = index.data(Qt.UserRole).toPyObject() - progress = self.queue.getProgress(qe) - opts = QStyleOptionProgressBarV2() - opts.maximum = 100 - opts.minimum = 0 - opts.progress = progress - opts.rect = option.rect - opts.rect.setRight(option.rect.right()-1) - opts.rect.setHeight(option.rect.height()-1) - opts.textVisible = True - opts.textAlignment = Qt.AlignCenter - speed = self.queue.getSpeed(qe) - if speed == None: - opts.text = QString.number(opts.progress) + "%" - else: - opts.text = QString("%s kb/s - %s" % (speed, opts.progress)) + "%" - QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter) - return - QItemDelegate.paint(self, painter, option, index) - -######################################### -############## Other Stuff ############## -######################################### - -class XMLParser(): - def __init__(self, data, dfile=""): - self.mutex = QMutex() - self.mutex.lock() - self.xml = QDomDocument() - self.file = data - self.dfile = dfile - self.mutex.unlock() - self.loadData() - self.root = self.xml.documentElement() - - def loadData(self): - self.mutex.lock() - f = self.file - if not os.path.exists(f): - f = self.dfile - with open(f, 'r') as fh: - content = fh.read() - self.xml.setContent(content) - self.mutex.unlock() - - def saveData(self): - self.mutex.lock() - content = self.xml.toString() - with open(self.file, 'w') as fh: - fh.write(content) - self.mutex.unlock() - return content - - def parseNode(self, node, ret_type="list"): - if ret_type == "dict": - childNodes = {} - else: - childNodes = [] - child = node.firstChild() - while True: - n = child.toElement() - if n.isNull(): - break - else: - if ret_type == "dict": - childNodes[str(n.tagName())] = n - else: - childNodes.append(n) - child = child.nextSibling() - return childNodes - if __name__ == "__main__": app = main() app.loop() -- cgit v1.2.3 From d08271cbb66f3ccbd8f3c5cf707008388ff4297e Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 21:33:13 +0100 Subject: new xml config for core --- pyLoadGui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index f8ba3efd3..3b8658e1b 100644 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -48,7 +48,7 @@ class main(QObject): self.connector = connector() self.mainloop = self.Loop(self) self.connectSignals() - self.parser = XMLParser("guiconfig.xml", "guiconfig_default.xml") + self.parser = XMLParser("module/config/gui.xml", "module/config/gui_default.xml") self.refreshConnections() self.connData = None -- cgit v1.2.3 From 56580326ede51efe9369858636b97dadbff52a5c Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 22:10:29 +0100 Subject: GUI: local connection support --- pyLoadGui.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 3b8658e1b..c213b4fa7 100644 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -246,22 +246,32 @@ class main(QObject): self.connData = data if data["type"] == "local": self.slotPasswordTyped("") - self.pwWindow.show() + else: + self.pwWindow.show() def slotPasswordTyped(self, pw): data = self.connData data["password"] = pw - if data["type"] == "remote": - if data["ssl"]: - data["ssl"] = "s" + if not data["type"] == "remote": + coreparser = XMLParser("module/config/core.xml") + sections = coreparser.parseNode(coreparser.root, "dict") + conf = coreparser.parseNode(sections["remote"], "dict") + ssl = coreparser.parseNode(sections["ssl"], "dict") + data["port"] = conf["port"].text() + data["user"] = conf["username"].text() + data["password"] = conf["password"].text() + data["host"] = "127.0.0.1" + if str(ssl["activated"].text()).lower() == "true": + data["ssl"] = True else: - data["ssl"] = "" - server_url = "http%(ssl)s://%(user)s:%(password)s@%(host)s:%(port)s/" % data - self.connector.setAddr(server_url) - self.startMain() + data["ssl"] = False + if data["ssl"]: + data["ssl"] = "s" else: - print "comming soon ;)" - self.quit() + data["ssl"] = "" + server_url = "http%(ssl)s://%(user)s:%(password)s@%(host)s:%(port)s/" % data + self.connector.setAddr(server_url) + self.startMain() def refreshConnections(self): self.parser.loadData() -- cgit v1.2.3 From ea1f10454e8a5d28785abb4366fbc9067d505ae2 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 17 Dec 2009 23:56:24 +0100 Subject: set +x mode --- pyLoadGui.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 pyLoadGui.py (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py old mode 100644 new mode 100755 -- cgit v1.2.3 From ab5d907f48a8879f717e0c6482695ef1afe280a0 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 20 Dec 2009 18:25:19 +0100 Subject: gui can return to connection manager, new collector --- pyLoadGui.py | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index c213b4fa7..7ac576f4e 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -42,6 +42,9 @@ class main(QObject): """ QObject.__init__(self) self.app = QApplication(sys.argv) + self.init() + + def init(self): self.mainWindow = MainWindow() self.pwWindow = PWInputWindow() self.connWindow = ConnectionManager() @@ -58,9 +61,19 @@ class main(QObject): self.connector.start() sleep(1) self.mainWindow.show() + self.initQueue() self.testStuff() self.mainloop.start() + def stopMain(self): + self.mainloop.stop() + self.connector.stop() + self.mainWindow.hide() + self.queue.stop() + self.mainloop.wait() + self.connector.wait() + self.queue.wait() + def connectSignals(self): """ signal and slot stuff, yay! @@ -71,6 +84,11 @@ class main(QObject): self.connect(self.connWindow, SIGNAL("connect"), self.slotConnect) self.connect(self.pwWindow, SIGNAL("ok"), self.slotPasswordTyped) self.connect(self.pwWindow, SIGNAL("cancel"), self.quit) + self.connect(self.mainWindow, SIGNAL("connector"), self.slotShowConnector) + + def slotShowConnector(self): + self.stopMain() + self.init() def quit(self): self.app.quit() @@ -112,28 +130,8 @@ class main(QObject): sub = QTreeWidgetItem(item) sub.setData(0, Qt.DisplayRole, QVariant(info["filename"])) self.mainWindow.tabs["collector_packages"]["treewidget"].addTopLevelItem(item) - - #test for queue - """ - packs = self.connector.getPackageQueue() - for data in packs: - item = QTreeWidgetItem() - item.setData(0, Qt.UserRole, QVariant(data)) - item.setData(0, Qt.DisplayRole, QVariant(data["package_name"])) - files = self.connector.getPackageFiles(data["id"]) - for id in files: - info = self.connector.getLinkInfo(id) - sub = QTreeWidgetItem(item) - sub.setData(0, Qt.DisplayRole, QVariant(info["filename"])) - sub.setData(1, Qt.DisplayRole, QVariant(info["status_type"])) - self.mainWindow.tabs["queue"]["treewidget"].addTopLevelItem(item) - - model = QueueModel(self.connector) - model.setView(self.mainWindow.tabs["queue"]["view"]) - self.mainWindow.tabs["queue"]["view"].setModel(model) - self.mainWindow.tabs["queue"]["view"].setup() - model.startLoop() - """ + + def initQueue(self): view = self.mainWindow.tabs["queue"]["view"] view.setColumnCount(3) view.setHeaderLabels(["Name", "Status", "Fortschritt"]) @@ -197,7 +195,7 @@ class main(QObject): raise Exception("null") connections = self.parser.parseNode(connectionsNode) connNode = self.parser.xml.createElement("connection") - connNode.setAttribute("default", data["default"]) + connNode.setAttribute("default", str(data["default"])) connNode.setAttribute("type", data["type"]) connNode.setAttribute("id", data["id"]) nameNode = self.parser.xml.createElement("name") @@ -291,6 +289,9 @@ class main(QObject): def update(self): self.parent.refreshServerStatus() + + def stop(self): + self.running = False if __name__ == "__main__": app = main() -- cgit v1.2.3 From 9f342ea3f73148154054515c4a3d3fa8ab35bf51 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 21 Dec 2009 00:41:08 +0100 Subject: GUI: new docks --- pyLoadGui.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 7ac576f4e..77fe54ca0 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -110,6 +110,8 @@ class main(QObject): only for testing ;) """ #test for link collector + self.mainWindow.tabs["collector"]["package_view"].setColumnCount(1) + self.mainWindow.tabs["collector"]["package_view"].setHeaderLabels(["Name"]) ids = self.connector.getLinkCollector() for id in ids: data = self.connector.getLinkInfo(id) -- cgit v1.2.3 From 20f7c0e65607f2fb8607ed0e5e96181a36be76ca Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 21 Dec 2009 14:24:51 +0100 Subject: new update threads, link dock works now --- pyLoadGui.py | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 77fe54ca0..2afd63033 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -33,6 +33,7 @@ from module.gui.connector import * from module.gui.MainWindow import * from module.gui.PWInputWindow import * from module.gui.Queue import * +from module.gui.Collector import * from module.gui.XMLParser import * class main(QObject): @@ -62,7 +63,8 @@ class main(QObject): sleep(1) self.mainWindow.show() self.initQueue() - self.testStuff() + self.initPackageCollector() + self.initLinkCollector() self.mainloop.start() def stopMain(self): @@ -85,6 +87,7 @@ class main(QObject): self.connect(self.pwWindow, SIGNAL("ok"), self.slotPasswordTyped) self.connect(self.pwWindow, SIGNAL("cancel"), self.quit) self.connect(self.mainWindow, SIGNAL("connector"), self.slotShowConnector) + self.connect(self.mainWindow, SIGNAL("addLinks"), self.slotAddLinks) def slotShowConnector(self): self.stopMain() @@ -105,33 +108,19 @@ class main(QObject): """ QMessageBox(QMessageBox.Warning, "Error", msg) - def testStuff(self): - """ - only for testing ;) - """ - #test for link collector - self.mainWindow.tabs["collector"]["package_view"].setColumnCount(1) - self.mainWindow.tabs["collector"]["package_view"].setHeaderLabels(["Name"]) - ids = self.connector.getLinkCollector() - for id in ids: - data = self.connector.getLinkInfo(id) - item = QListWidgetItem() - item.setData(Qt.UserRole, QVariant(data)) - item.setData(Qt.DisplayRole, QVariant(data["url"])) - self.mainWindow.tabs["collector_links"]["listwidget"].addItem(item) - - #test for package collector - packs = self.connector.getPackageCollector() - for data in packs: - item = QTreeWidgetItem() - item.setData(0, Qt.UserRole, QVariant(data)) - item.setData(0, Qt.DisplayRole, QVariant(data["package_name"])) - files = self.connector.getPackageFiles(data["id"]) - for id in files: - info = self.connector.getLinkInfo(id) - sub = QTreeWidgetItem(item) - sub.setData(0, Qt.DisplayRole, QVariant(info["filename"])) - self.mainWindow.tabs["collector_packages"]["treewidget"].addTopLevelItem(item) + def initPackageCollector(self): + view = self.mainWindow.tabs["collector"]["package_view"] + view.setColumnCount(1) + view.setHeaderLabels(["Name"]) + self.packageCollector = PackageCollector(view, self.connector) + self.packageCollector.start() + + def initLinkCollector(self): + view = self.mainWindow.tabs["collector"]["link_view"] + view.setColumnCount(1) + view.setHeaderLabels(["Name"]) + self.linkCollector = LinkCollector(view, self.connector) + self.linkCollector.start() def initQueue(self): view = self.mainWindow.tabs["queue"]["view"] @@ -143,7 +132,6 @@ class main(QObject): self.queue = Queue(view, self.connector) delegate = QueueProgressBarDelegate(view, self.queue) view.setItemDelegateForColumn(2, delegate) - #view.setup(self.queue) self.queue.start() def refreshServerStatus(self): @@ -278,6 +266,9 @@ class main(QObject): conns = self.getConnections() self.connWindow.emit(SIGNAL("setConnections(connections)"), conns) + def slotAddLinks(self, links): + self.connector.addURLs(links) + class Loop(QThread): def __init__(self, parent): QThread.__init__(self) -- cgit v1.2.3 From 4c98db9a0eb0ca1ca70c4886b907e79682bfad82 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 21 Dec 2009 14:41:23 +0100 Subject: pause/start button works --- pyLoadGui.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 2afd63033..6c3bae1dd 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -88,6 +88,7 @@ class main(QObject): self.connect(self.pwWindow, SIGNAL("cancel"), self.quit) self.connect(self.mainWindow, SIGNAL("connector"), self.slotShowConnector) self.connect(self.mainWindow, SIGNAL("addLinks"), self.slotAddLinks) + self.connect(self.mainWindow, SIGNAL("setDownloadStatus"), self.slotSetDownloadStatus) def slotShowConnector(self): self.stopMain() @@ -142,6 +143,7 @@ class main(QObject): status["status"] = "Running" status["speed"] = int(status["speed"]) text = "Status: %(status)s | Speed: %(speed)s kb/s" % status + self.mainWindow.actions["toggle_status"].setChecked(not status["pause"]) self.mainWindow.serverStatus.setText(text) def getConnections(self): @@ -269,6 +271,9 @@ class main(QObject): def slotAddLinks(self, links): self.connector.addURLs(links) + def slotSetDownloadStatus(self, status): + self.connector.setPause(not status) + class Loop(QThread): def __init__(self, parent): QThread.__init__(self) -- cgit v1.2.3 From ff7fa4a0d1aa1c09e563d2086704aa7e2acea716 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 21 Dec 2009 17:07:16 +0100 Subject: package creation works --- pyLoadGui.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 6c3bae1dd..ccab8ba64 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -88,6 +88,7 @@ class main(QObject): self.connect(self.pwWindow, SIGNAL("cancel"), self.quit) self.connect(self.mainWindow, SIGNAL("connector"), self.slotShowConnector) self.connect(self.mainWindow, SIGNAL("addLinks"), self.slotAddLinks) + self.connect(self.mainWindow, SIGNAL("addPackage"), self.slotAddPackage) self.connect(self.mainWindow, SIGNAL("setDownloadStatus"), self.slotSetDownloadStatus) def slotShowConnector(self): @@ -120,6 +121,19 @@ class main(QObject): view = self.mainWindow.tabs["collector"]["link_view"] view.setColumnCount(1) view.setHeaderLabels(["Name"]) + view.setSelectionBehavior(QAbstractItemView.SelectRows) + view.setSelectionMode(QAbstractItemView.SingleSelection) + def event(klass, event): + event.setDropAction(Qt.CopyAction) + event.accept() + view = event.source() + row = view.currentIndex().row() + view.takeTopLevelItem(row) + view.dropEvent = event + view.setDragEnabled(True) + view.setDragDropMode(QAbstractItemView.DragDrop) + view.setDropIndicatorShown(True) + view.setDragDropOverwriteMode(True) self.linkCollector = LinkCollector(view, self.connector) self.linkCollector.start() @@ -274,6 +288,11 @@ class main(QObject): def slotSetDownloadStatus(self, status): self.connector.setPause(not status) + def slotAddPackage(self, name, ids): + packid = self.connector.newPackage(str(name)) + for fileid in ids: + self.connector.addFileToPackage(fileid, packid) + class Loop(QThread): def __init__(self, parent): QThread.__init__(self) -- cgit v1.2.3 From 59eaacc4228707f715be147350adb0a670de6985 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 21 Dec 2009 17:57:17 +0100 Subject: save window state --- pyLoadGui.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index ccab8ba64..a21c27cb9 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -61,6 +61,7 @@ class main(QObject): def startMain(self): self.connector.start() sleep(1) + self.restoreMainWindow() self.mainWindow.show() self.initQueue() self.initPackageCollector() @@ -90,6 +91,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("addLinks"), self.slotAddLinks) self.connect(self.mainWindow, SIGNAL("addPackage"), self.slotAddPackage) self.connect(self.mainWindow, SIGNAL("setDownloadStatus"), self.slotSetDownloadStatus) + self.connect(self.mainWindow, SIGNAL("saveMainWindow"), self.slotSaveMainWindow) def slotShowConnector(self): self.stopMain() @@ -293,6 +295,33 @@ class main(QObject): for fileid in ids: self.connector.addFileToPackage(fileid, packid) + def slotSaveMainWindow(self, state, geo): + mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) + if mainWindowNode.isNull(): + raise Exception("null") + stateNode = mainWindowNode.toElement().elementsByTagName("state").item(0) + geoNode = mainWindowNode.toElement().elementsByTagName("geometry").item(0) + newStateNode = self.parser.xml.createTextNode(state) + newGeoNode = self.parser.xml.createTextNode(geo) + + stateNode.removeChild(stateNode.firstChild()) + geoNode.removeChild(geoNode.firstChild()) + stateNode.appendChild(newStateNode) + geoNode.appendChild(newGeoNode) + + self.parser.saveData() + + def restoreMainWindow(self): + mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) + if mainWindowNode.isNull(): + raise Exception("null") + nodes = self.parser.parseNode(mainWindowNode, "dict") + + state = str(nodes["state"].text()) + geo = str(nodes["geometry"].text()) + + self.mainWindow.restoreWindow(state, geo) + class Loop(QThread): def __init__(self, parent): QThread.__init__(self) -- cgit v1.2.3 From ed36dd5988907019cc9cc5b98265f00a52462c85 Mon Sep 17 00:00:00 2001 From: mkaay Date: Tue, 22 Dec 2009 17:07:35 +0100 Subject: more docstrings, small design changes --- pyLoadGui.py | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 6 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index a21c27cb9..9ff070027 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -46,6 +46,9 @@ class main(QObject): self.init() def init(self): + """ + set main things up + """ self.mainWindow = MainWindow() self.pwWindow = PWInputWindow() self.connWindow = ConnectionManager() @@ -59,6 +62,9 @@ class main(QObject): self.connWindow.show() def startMain(self): + """ + start all refresh threads and show main window + """ self.connector.start() sleep(1) self.restoreMainWindow() @@ -69,13 +75,21 @@ class main(QObject): self.mainloop.start() def stopMain(self): + """ + stop all refresh threads and hide main window + """ self.mainloop.stop() self.connector.stop() + self.mainWindow.saveWindow() self.mainWindow.hide() self.queue.stop() + self.linkCollector.stop() + self.packageCollector.stop() self.mainloop.wait() self.connector.wait() self.queue.wait() + self.linkCollector.wait() + self.packageCollector.wait() def connectSignals(self): """ @@ -92,17 +106,26 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("addPackage"), self.slotAddPackage) self.connect(self.mainWindow, SIGNAL("setDownloadStatus"), self.slotSetDownloadStatus) self.connect(self.mainWindow, SIGNAL("saveMainWindow"), self.slotSaveMainWindow) + self.connect(self.mainWindow, SIGNAL("pushPackageToQueue"), self.slotPushPackageToQueue) def slotShowConnector(self): + """ + emitted from main window (menu) + hide the main window and show connection manager + (to switch to other core) + """ self.stopMain() self.init() def quit(self): + """ + quit gui + """ self.app.quit() def loop(self): """ - start exec loop + start application loop """ sys.exit(self.app.exec_()) @@ -113,13 +136,27 @@ class main(QObject): QMessageBox(QMessageBox.Warning, "Error", msg) def initPackageCollector(self): + """ + init the package collector view + * columns + * selection + * refresh thread + """ view = self.mainWindow.tabs["collector"]["package_view"] view.setColumnCount(1) view.setHeaderLabels(["Name"]) + view.setSelectionMode(QAbstractItemView.ExtendedSelection) self.packageCollector = PackageCollector(view, self.connector) self.packageCollector.start() def initLinkCollector(self): + """ + init the link collector view + * columns + * selection + * drag'n'drop + * refresh thread + """ view = self.mainWindow.tabs["collector"]["link_view"] view.setColumnCount(1) view.setHeaderLabels(["Name"]) @@ -140,18 +177,28 @@ class main(QObject): self.linkCollector.start() def initQueue(self): + """ + init the queue view + * columns + * refresh thread + * progressbar + """ view = self.mainWindow.tabs["queue"]["view"] - view.setColumnCount(3) - view.setHeaderLabels(["Name", "Status", "Fortschritt"]) + view.setColumnCount(4) + view.setHeaderLabels(["Name", "Plugin", "Status", "Fortschritt"]) view.setColumnWidth(0, 300) - view.setColumnWidth(1, 200) - view.setColumnWidth(2, 100) + view.setColumnWidth(1, 100) + view.setColumnWidth(2, 200) + view.setColumnWidth(3, 100) self.queue = Queue(view, self.connector) delegate = QueueProgressBarDelegate(view, self.queue) - view.setItemDelegateForColumn(2, delegate) + view.setItemDelegateForColumn(3, delegate) self.queue.start() def refreshServerStatus(self): + """ + refresh server status and overall speed in the status bar + """ status = self.connector.getServerStatus() if status["pause"]: status["status"] = "Paused" @@ -163,6 +210,9 @@ class main(QObject): self.mainWindow.serverStatus.setText(text) def getConnections(self): + """ + parse all connections in the config file + """ connectionsNode = self.parser.xml.elementsByTagName("connections").item(0) if connectionsNode.isNull(): raise Exception("null") @@ -198,6 +248,9 @@ class main(QObject): return ret def slotSaveConnection(self, data): + """ + save connection to config file + """ connectionsNode = self.parser.xml.elementsByTagName("connections").item(0) if connectionsNode.isNull(): raise Exception("null") @@ -232,6 +285,9 @@ class main(QObject): self.refreshConnections() def slotRemoveConnection(self, data): + """ + remove connection from config file + """ connectionsNode = self.parser.xml.elementsByTagName("connections").item(0) if connectionsNode.isNull(): raise Exception("null") @@ -248,6 +304,10 @@ class main(QObject): self.refreshConnections() def slotConnect(self, data): + """ + slot: connect button in connectionmanager + show password window if remote connection or start connecting + """ self.connWindow.hide() self.connData = data if data["type"] == "local": @@ -256,6 +316,11 @@ class main(QObject): self.pwWindow.show() def slotPasswordTyped(self, pw): + """ + connect to a core + if connection is local, parse the core config file for data + set up connector, show main window + """ data = self.connData data["password"] = pw if not data["type"] == "remote": @@ -280,22 +345,39 @@ class main(QObject): self.startMain() def refreshConnections(self): + """ + reload connetions and display them + """ self.parser.loadData() conns = self.getConnections() self.connWindow.emit(SIGNAL("setConnections(connections)"), conns) def slotAddLinks(self, links): + """ + emitted from main window + add urls to the collector + """ self.connector.addURLs(links) def slotSetDownloadStatus(self, status): + """ + toolbar start/pause slot + """ self.connector.setPause(not status) def slotAddPackage(self, name, ids): + """ + emitted from main window + add package to the collector + """ packid = self.connector.newPackage(str(name)) for fileid in ids: self.connector.addFileToPackage(fileid, packid) def slotSaveMainWindow(self, state, geo): + """ + save the window geometry and toolbar/dock position to config file + """ mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) if mainWindowNode.isNull(): raise Exception("null") @@ -312,6 +394,9 @@ class main(QObject): self.parser.saveData() def restoreMainWindow(self): + """ + load and restore main window geometry and toolbar/dock position from config + """ mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) if mainWindowNode.isNull(): raise Exception("null") @@ -322,7 +407,18 @@ class main(QObject): self.mainWindow.restoreWindow(state, geo) + def slotPushPackageToQueue(self, id): + """ + emitted from main window + push the collector package to queue + """ + self.connector.pushPackageToQueue(id) + class Loop(QThread): + """ + main loop (not application loop) + """ + def __init__(self, parent): QThread.__init__(self) self.parent = parent @@ -334,6 +430,9 @@ class main(QObject): self.update() def update(self): + """ + methods to call + """ self.parent.refreshServerStatus() def stop(self): -- cgit v1.2.3 From a5ff0482ede8bd7bd932482887f2f7cdae5039d9 Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 23 Dec 2009 00:04:36 +0100 Subject: core: downloadlimit is not far away ;) gui: restart download action --- pyLoadGui.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 9ff070027..997a2f781 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -107,6 +107,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("setDownloadStatus"), self.slotSetDownloadStatus) self.connect(self.mainWindow, SIGNAL("saveMainWindow"), self.slotSaveMainWindow) self.connect(self.mainWindow, SIGNAL("pushPackageToQueue"), self.slotPushPackageToQueue) + self.connect(self.mainWindow, SIGNAL("restartDownload"), self.slotRestartDownload) def slotShowConnector(self): """ @@ -380,7 +381,8 @@ class main(QObject): """ mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) if mainWindowNode.isNull(): - raise Exception("null") + mainWindowNode = self.parser.xml.createElement("mainWindow") + self.parser.root.appendChild(mainWindowNode) stateNode = mainWindowNode.toElement().elementsByTagName("state").item(0) geoNode = mainWindowNode.toElement().elementsByTagName("geometry").item(0) newStateNode = self.parser.xml.createTextNode(state) @@ -399,7 +401,7 @@ class main(QObject): """ mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) if mainWindowNode.isNull(): - raise Exception("null") + return nodes = self.parser.parseNode(mainWindowNode, "dict") state = str(nodes["state"].text()) @@ -414,6 +416,16 @@ class main(QObject): """ self.connector.pushPackageToQueue(id) + def slotRestartDownload(self, id, isPack): + """ + emitted from main window + restart download + """ + if isPack: + self.connector.restartPackage(id) + else: + self.connector.restartFile(id) + class Loop(QThread): """ main loop (not application loop) -- cgit v1.2.3 From ea04c11ce1fb52895449a56e862eff5448ea456a Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 24 Dec 2009 01:28:08 +0100 Subject: downloads are now aborted correctly, gui: remove downloads, new icons --- pyLoadGui.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 997a2f781..d5fb02bc0 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -108,6 +108,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("saveMainWindow"), self.slotSaveMainWindow) self.connect(self.mainWindow, SIGNAL("pushPackageToQueue"), self.slotPushPackageToQueue) self.connect(self.mainWindow, SIGNAL("restartDownload"), self.slotRestartDownload) + self.connect(self.mainWindow, SIGNAL("removeDownload"), self.slotRemoveDownload) def slotShowConnector(self): """ @@ -426,6 +427,16 @@ class main(QObject): else: self.connector.restartFile(id) + def slotRemoveDownload(self, id, isPack): + """ + emitted from main window + remove download + """ + if isPack: + self.connector.removePackage(id) + else: + self.connector.removeFile(id) + class Loop(QThread): """ main loop (not application loop) -- cgit v1.2.3 From 504b313112be6a82d6eee418ae059646ecfc4b30 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 26 Dec 2009 20:18:11 +0100 Subject: fixed ddl-music, cleaned up, new status (starting), some more fixes --- pyLoadGui.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index d5fb02bc0..5e13dd080 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -135,7 +135,8 @@ class main(QObject): """ display a nice error box """ - QMessageBox(QMessageBox.Warning, "Error", msg) + msgb = QMessageBox(QMessageBox.Warning, "Error", msg) + msgb.exec_() def initPackageCollector(self): """ @@ -326,7 +327,7 @@ class main(QObject): data = self.connData data["password"] = pw if not data["type"] == "remote": - coreparser = XMLParser("module/config/core.xml") + coreparser = XMLParser("module/config/core.xml", "module/config/core_default.xml") sections = coreparser.parseNode(coreparser.root, "dict") conf = coreparser.parseNode(sections["remote"], "dict") ssl = coreparser.parseNode(sections["ssl"], "dict") -- cgit v1.2.3 From b5d1c47ac2590fe4314d7e96d58443c30463746c Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 26 Dec 2009 22:35:20 +0100 Subject: gui contaoner upload, closes #39 --- pyLoadGui.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 5e13dd080..f075db710 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -28,6 +28,8 @@ from PyQt4.QtGui import * from uuid import uuid4 as uuid +from os.path import basename + from module.gui.ConnectionManager import * from module.gui.connector import * from module.gui.MainWindow import * @@ -109,6 +111,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("pushPackageToQueue"), self.slotPushPackageToQueue) self.connect(self.mainWindow, SIGNAL("restartDownload"), self.slotRestartDownload) self.connect(self.mainWindow, SIGNAL("removeDownload"), self.slotRemoveDownload) + self.connect(self.mainWindow, SIGNAL("addContainer"), self.slotAddContainer) def slotShowConnector(self): """ @@ -377,6 +380,18 @@ class main(QObject): for fileid in ids: self.connector.addFileToPackage(fileid, packid) + def slotAddContainer(self, path): + """ + emitted from main window + add container + """ + filename = basename(path) + type = "".join(filename.split(".")[-1]) + fh = open(path, "r") + content = fh.read() + fh.close() + self.connector.uploadContainer(filename, type, content) + def slotSaveMainWindow(self, state, geo): """ save the window geometry and toolbar/dock position to config file -- cgit v1.2.3 From 757f025247d77b085b6168d5f625d2bbfa7c4c0d Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 27 Dec 2009 14:45:22 +0100 Subject: stop button works, closes #59 --- pyLoadGui.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index f075db710..0f76e6429 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -112,6 +112,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("restartDownload"), self.slotRestartDownload) self.connect(self.mainWindow, SIGNAL("removeDownload"), self.slotRemoveDownload) self.connect(self.mainWindow, SIGNAL("addContainer"), self.slotAddContainer) + self.connect(self.mainWindow, SIGNAL("stopAllDownloads"), self.slotStopAllDownloads) def slotShowConnector(self): """ @@ -215,6 +216,18 @@ class main(QObject): self.mainWindow.actions["toggle_status"].setChecked(not status["pause"]) self.mainWindow.serverStatus.setText(text) + def refreshLog(self): + offset = self.mainWindow.tabs["log"]["text"].logOffset + lines = self.connector.getLog(offset) + if not lines: + return + self.mainWindow.tabs["log"]["text"].logOffset += len(lines) + for line in lines: + self.mainWindow.tabs["log"]["text"].emit(SIGNAL("append(QString)"), line) + cursor = self.mainWindow.tabs["log"]["text"].textCursor() + cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor) + self.mainWindow.tabs["log"]["text"].setTextCursor(cursor) + def getConnections(self): """ parse all connections in the config file @@ -453,6 +466,13 @@ class main(QObject): else: self.connector.removeFile(id) + def slotStopAllDownloads(self): + """ + emitted from main window + stop all running downloads + """ + self.connector.stopAllDownloads() + class Loop(QThread): """ main loop (not application loop) @@ -473,6 +493,7 @@ class main(QObject): methods to call """ self.parent.refreshServerStatus() + self.parent.refreshLog() def stop(self): self.running = False -- cgit v1.2.3 From ff7d4f1a13db0f4a9d6c427dcccbb0d1faf6c577 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 27 Dec 2009 15:26:33 +0100 Subject: closes #51 --- pyLoadGui.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 0f76e6429..ea106c516 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -217,6 +217,9 @@ class main(QObject): self.mainWindow.serverStatus.setText(text) def refreshLog(self): + """ + update log window + """ offset = self.mainWindow.tabs["log"]["text"].logOffset lines = self.connector.getLog(offset) if not lines: @@ -228,6 +231,16 @@ class main(QObject): cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor) self.mainWindow.tabs["log"]["text"].setTextCursor(cursor) + def updateAvailable(self): + """ + update notification + """ + status = self.connector.updateAvailable() + if status: + self.mainWindow.statusbar.emit(SIGNAL("showMsg"), "Update Available") + else: + self.mainWindow.statusbar.emit(SIGNAL("showMsg"), "") + def getConnections(self): """ parse all connections in the config file @@ -494,6 +507,7 @@ class main(QObject): """ self.parent.refreshServerStatus() self.parent.refreshLog() + self.parent.updateAvailable() def stop(self): self.running = False -- cgit v1.2.3 From 090c9d2abdac07025fe6d7351e376e85aabc0891 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 27 Dec 2009 22:16:51 +0100 Subject: fixed uploaded.to and netload.in, gui clipboard check --- pyLoadGui.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index ea106c516..681feec8a 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -27,7 +27,7 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * from uuid import uuid4 as uuid - +import re from os.path import basename from module.gui.ConnectionManager import * @@ -59,6 +59,7 @@ class main(QObject): self.connectSignals() self.parser = XMLParser("module/config/gui.xml", "module/config/gui_default.xml") + self.checkClipboard = False self.refreshConnections() self.connData = None self.connWindow.show() @@ -75,11 +76,15 @@ class main(QObject): self.initPackageCollector() self.initLinkCollector() self.mainloop.start() + self.clipboard = self.app.clipboard() + self.connect(self.clipboard, SIGNAL('dataChanged()'), self.slotClipboardChange) + self.mainWindow.actions["clipboard"].setChecked(self.checkClipboard) def stopMain(self): """ stop all refresh threads and hide main window """ + self.disconnect(self.clipboard, SIGNAL('dataChanged()'), self.slotClipboardChange) self.mainloop.stop() self.connector.stop() self.mainWindow.saveWindow() @@ -113,6 +118,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("removeDownload"), self.slotRemoveDownload) self.connect(self.mainWindow, SIGNAL("addContainer"), self.slotAddContainer) self.connect(self.mainWindow, SIGNAL("stopAllDownloads"), self.slotStopAllDownloads) + self.connect(self.mainWindow, SIGNAL("setClipboardStatus"), self.slotSetClipboardStatus) def slotShowConnector(self): """ @@ -486,6 +492,23 @@ class main(QObject): """ self.connector.stopAllDownloads() + def slotClipboardChange(self): + """ + called if clipboard changes + """ + if self.checkClipboard: + text = self.clipboard.text() + pattern = re.compile(r"(http|https)://[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?/.*)?") + matches = pattern.finditer(text) + for match in matches: + self.slotAddLinks([str(match.group(0))]) + + def slotSetClipboardStatus(self, status): + """ + set clipboard checking + """ + self.checkClipboard = status + class Loop(QThread): """ main loop (not application loop) -- cgit v1.2.3 From da359f8c770bac754234e0f899058b25126cd476 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 28 Dec 2009 19:51:37 +0100 Subject: gui: easier package management --- pyLoadGui.py | 57 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 681feec8a..5ce098fa0 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -154,39 +154,53 @@ class main(QObject): * columns * selection * refresh thread - """ - view = self.mainWindow.tabs["collector"]["package_view"] - view.setColumnCount(1) - view.setHeaderLabels(["Name"]) - view.setSelectionMode(QAbstractItemView.ExtendedSelection) - self.packageCollector = PackageCollector(view, self.connector) - self.packageCollector.start() - - def initLinkCollector(self): - """ - init the link collector view - * columns - * selection * drag'n'drop - * refresh thread """ - view = self.mainWindow.tabs["collector"]["link_view"] + view = self.mainWindow.tabs["collector"]["package_view"] view.setColumnCount(1) view.setHeaderLabels(["Name"]) view.setSelectionBehavior(QAbstractItemView.SelectRows) - view.setSelectionMode(QAbstractItemView.SingleSelection) - def event(klass, event): + view.setSelectionMode(QAbstractItemView.ExtendedSelection) + def dropEvent(klass, event): event.setDropAction(Qt.CopyAction) event.accept() view = event.source() - row = view.currentIndex().row() - view.takeTopLevelItem(row) - view.dropEvent = event + if view == klass: + event.ignore() + return + items = view.selectedItems() + for item in items: + row = view.indexOfTopLevelItem(item) + view.takeTopLevelItem(row) + def dragEvent(klass, event): + view = event.source() + dragOkay = False + items = view.selectedItems() + for item in items: + if hasattr(item, "_data"): + if item._data["id"] == "fixed" or item.parent()._data["id"] == "fixed": + dragOkay = True + else: + dragOkay = True + if dragOkay: + event.accept() + else: + event.ignore() + view.dropEvent = dropEvent + view.dragEnterEvent = dragEvent view.setDragEnabled(True) view.setDragDropMode(QAbstractItemView.DragDrop) view.setDropIndicatorShown(True) view.setDragDropOverwriteMode(True) - self.linkCollector = LinkCollector(view, self.connector) + self.packageCollector = PackageCollector(view, self.connector) + self.packageCollector.start() + + def initLinkCollector(self): + """ + init the link collector + * refresh thread + """ + self.linkCollector = LinkCollector(self.mainWindow.tabs["collector"]["package_view"], self.packageCollector.linkCollector, self.connector) self.linkCollector.start() def initQueue(self): @@ -411,6 +425,7 @@ class main(QObject): packid = self.connector.newPackage(str(name)) for fileid in ids: self.connector.addFileToPackage(fileid, packid) + self.mainWindow.lastAddedID = packid def slotAddContainer(self, path): """ -- cgit v1.2.3 From c225a31e70e85c6e400a7ed4407a1fa53de29689 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 28 Dec 2009 20:44:49 +0100 Subject: you can now drop single links directly into a package --- pyLoadGui.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 5ce098fa0..7ef267fcb 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -166,7 +166,15 @@ class main(QObject): event.accept() view = event.source() if view == klass: - event.ignore() + items = view.selectedItems() + for item in items: + if not hasattr(item.parent(), "getPackData"): + continue + target = view.itemAt(event.pos()) + if not hasattr(target, "getPackData"): + target = target.parent() + klass.emit(SIGNAL("droppedToPack"), target.getPackData()["id"], item.getFileData()["id"]) + event.accept() return items = view.selectedItems() for item in items: @@ -192,6 +200,7 @@ class main(QObject): view.setDragDropMode(QAbstractItemView.DragDrop) view.setDropIndicatorShown(True) view.setDragDropOverwriteMode(True) + self.connect(view, SIGNAL("droppedToPack"), self.slotAddFileToPackage) self.packageCollector = PackageCollector(view, self.connector) self.packageCollector.start() @@ -427,6 +436,12 @@ class main(QObject): self.connector.addFileToPackage(fileid, packid) self.mainWindow.lastAddedID = packid + def slotAddFileToPackage(self, pid, fid): + """ + emitted from collector view after a drop action + """ + self.connector.addFileToPackage(fid, pid) + def slotAddContainer(self, path): """ emitted from main window -- cgit v1.2.3 From 86949a6240bc6d5a5fd5e5677925e0d945686d3e Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 28 Dec 2009 22:21:35 +0100 Subject: package renaming in collector works --- pyLoadGui.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 7ef267fcb..38013cd4c 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -78,6 +78,7 @@ class main(QObject): self.mainloop.start() self.clipboard = self.app.clipboard() self.connect(self.clipboard, SIGNAL('dataChanged()'), self.slotClipboardChange) + self.connect(self.mainWindow, SIGNAL("pauseItemUpdate"), self.packageCollector.pauseItemUpdate) self.mainWindow.actions["clipboard"].setChecked(self.checkClipboard) def stopMain(self): @@ -85,6 +86,7 @@ class main(QObject): stop all refresh threads and hide main window """ self.disconnect(self.clipboard, SIGNAL('dataChanged()'), self.slotClipboardChange) + self.disconnect(self.mainWindow, SIGNAL("pauseItemUpdate"), self.packageCollector.pauseItemUpdate) self.mainloop.stop() self.connector.stop() self.mainWindow.saveWindow() @@ -119,6 +121,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("addContainer"), self.slotAddContainer) self.connect(self.mainWindow, SIGNAL("stopAllDownloads"), self.slotStopAllDownloads) self.connect(self.mainWindow, SIGNAL("setClipboardStatus"), self.slotSetClipboardStatus) + self.connect(self.mainWindow, SIGNAL("changePackageName"), self.slotChangePackageName) def slotShowConnector(self): """ @@ -539,6 +542,12 @@ class main(QObject): """ self.checkClipboard = status + def slotChangePackageName(self, pid, name): + """ + package name edit finished + """ + self.connector.setPackageName(pid, str(name)) + class Loop(QThread): """ main loop (not application loop) -- cgit v1.2.3 From fa9cce4987da585f5bf21274cfbe5f046f46f703 Mon Sep 17 00:00:00 2001 From: mkaay Date: Tue, 29 Dec 2009 16:50:13 +0100 Subject: : Bitte gib eine Versions-Meldung ein. Zeilen beginnend mit 'HG:' werden entfernt. --- pyLoadGui.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 38013cd4c..9db4e5630 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -45,9 +45,9 @@ class main(QObject): """ QObject.__init__(self) self.app = QApplication(sys.argv) - self.init() + self.init(True) - def init(self): + def init(self, first=False): """ set main things up """ @@ -60,14 +60,22 @@ class main(QObject): self.parser = XMLParser("module/config/gui.xml", "module/config/gui_default.xml") self.checkClipboard = False - self.refreshConnections() + default = self.refreshConnections() self.connData = None - self.connWindow.show() + if not first: + self.connWindow.show() + else: + self.connWindow.edit.setData(default) + data = self.connWindow.edit.getData() + self.slotConnect(data) def startMain(self): """ start all refresh threads and show main window """ + if not self.connector.canConnect(): + self.init() + return self.connector.start() sleep(1) self.restoreMainWindow() @@ -122,6 +130,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("stopAllDownloads"), self.slotStopAllDownloads) self.connect(self.mainWindow, SIGNAL("setClipboardStatus"), self.slotSetClipboardStatus) self.connect(self.mainWindow, SIGNAL("changePackageName"), self.slotChangePackageName) + self.connect(self.mainWindow, SIGNAL("pullOutPackage"), self.slotPullOutPackage) def slotShowConnector(self): """ @@ -405,7 +414,7 @@ class main(QObject): else: data["ssl"] = "" server_url = "http%(ssl)s://%(user)s:%(password)s@%(host)s:%(port)s/" % data - self.connector.setAddr(server_url) + self.connector.setAddr(str(server_url)) self.startMain() def refreshConnections(self): @@ -415,6 +424,10 @@ class main(QObject): self.parser.loadData() conns = self.getConnections() self.connWindow.emit(SIGNAL("setConnections(connections)"), conns) + for conn in conns: + if conn["default"]: + return conn + return None def slotAddLinks(self, links): """ @@ -548,6 +561,13 @@ class main(QObject): """ self.connector.setPackageName(pid, str(name)) + def slotPullOutPackage(self, pid, isPack): + """ + pull package out of the queue + """ + if isPack: + self.connector.slotPullOutPackage(pid) + class Loop(QThread): """ main loop (not application loop) -- cgit v1.2.3 From 2685db965d5ef84a4f38517e0d2df55a52a5fd10 Mon Sep 17 00:00:00 2001 From: mkaay Date: Tue, 29 Dec 2009 16:55:27 +0100 Subject: messed up last commit message; added new icons, default connection in gui, pull out packages from queue --- pyLoadGui.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 9db4e5630..dab3ef18b 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -597,3 +597,4 @@ class main(QObject): if __name__ == "__main__": app = main() app.loop() + -- cgit v1.2.3 From c1516088e4e7f76dddd68ef71f58c6413862e31c Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 30 Dec 2009 12:35:03 +0100 Subject: show captchas in gui, SerienjunkiesOrg plugin --- pyLoadGui.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index dab3ef18b..8fff8e8c9 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -62,6 +62,7 @@ class main(QObject): self.checkClipboard = False default = self.refreshConnections() self.connData = None + self.captchaProcessing = False if not first: self.connWindow.show() else: @@ -131,6 +132,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("setClipboardStatus"), self.slotSetClipboardStatus) self.connect(self.mainWindow, SIGNAL("changePackageName"), self.slotChangePackageName) self.connect(self.mainWindow, SIGNAL("pullOutPackage"), self.slotPullOutPackage) + self.connect(self.mainWindow.captchaDock, SIGNAL("done"), self.slotCaptchaDone) def slotShowConnector(self): """ @@ -503,6 +505,7 @@ class main(QObject): geo = str(nodes["geometry"].text()) self.mainWindow.restoreWindow(state, geo) + self.mainWindow.captchaDock.hide() def slotPushPackageToQueue(self, id): """ @@ -566,7 +569,15 @@ class main(QObject): pull package out of the queue """ if isPack: - self.connector.slotPullOutPackage(pid) + self.connector.pullOutPackage(pid) + + def checkCaptcha(self): + if self.connector.captchaWaiting() and self.mainWindow.captchaDock.isFree(): + cid, img, imgType = self.connector.getCaptcha() + self.mainWindow.captchaDock.setTask(cid, str(img), imgType) + + def slotCaptchaDone(self, cid, result): + print self.connector.setCaptchaResult(str(cid), str(result)) class Loop(QThread): """ @@ -590,6 +601,7 @@ class main(QObject): self.parent.refreshServerStatus() self.parent.refreshLog() self.parent.updateAvailable() + self.parent.checkCaptcha() def stop(self): self.running = False -- cgit v1.2.3 From 08f12b089eb6fade689134b8170aa2b81218ddf7 Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 30 Dec 2009 12:50:10 +0100 Subject: signal slot stuff --- pyLoadGui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyLoadGui.py') diff --git a/pyLoadGui.py b/pyLoadGui.py index 8fff8e8c9..9e04cc003 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -574,10 +574,10 @@ class main(QObject): def checkCaptcha(self): if self.connector.captchaWaiting() and self.mainWindow.captchaDock.isFree(): cid, img, imgType = self.connector.getCaptcha() - self.mainWindow.captchaDock.setTask(cid, str(img), imgType) + self.mainWindow.captchaDock.emit(SIGNAL("setTask"), cid, str(img), imgType) def slotCaptchaDone(self, cid, result): - print self.connector.setCaptchaResult(str(cid), str(result)) + self.connector.setCaptchaResult(str(cid), str(result)) class Loop(QThread): """ -- cgit v1.2.3