示例#1
0
 def __init__(self, app, parent=None):
     super(MainWindow, self).__init__(parent)
     self.setWindowIcon(QIcon(iconPath("apps/spark", 16)))
     self.setWindowTitle("Spark")
     self.setMinimumSize(530, 360)
     self.aboutWindow = AboutWindow(self)
     self.app = app
     self.actions = {}
     self.initMenu()
     self.initToolbar()
     self.initTransferList()
     self.initStatusBar()
     self.initTrayIcon()
     self.initTimer()
     self.sharedFiles = {}
     self.fileIDs = []
     self.selectedID = None
     self.lastUsedFolder = os.path.expanduser("~")
     self.app.listening += self.onStateChanged
     self.app.connected += self.onStateChanged
     self.app.disconnected += self.onStateChanged
     self.app.stateChanged += self.onStateChanged
     self.app.fileListUpdated += self.onStateChanged
     self.app.fileUpdated += self.onFileUpdated
     self.updateStatusBar()
     self.updateToolBar()
示例#2
0
 def initStatusBar(self):
     self.connStatus = QLabel(self.statusBar())
     self.myIP = QLabel(self.statusBar())
     self.transferCount = QLabel(self.statusBar())
     self.uploadSpeedIcon = QLabel(self.statusBar())
     self.uploadSpeedIcon.setPixmap(QPixmap(iconPath("actions/go-up", 24)))
     self.uploadSpeedText = QLabel(self.statusBar())
     self.downloadSpeedIcon = QLabel(self.statusBar())
     self.downloadSpeedIcon.setPixmap(QPixmap(iconPath("actions/go-down", 24)))
     self.downloadSpeedText = QLabel(self.statusBar())
     self.statusBar().addWidget(self.connStatus)
     self.statusBar().addWidget(self.myIP, 2)
     self.statusBar().addWidget(self.transferCount)
     self.statusBar().addWidget(self.uploadSpeedIcon)
     self.statusBar().addWidget(self.uploadSpeedText)
     self.statusBar().addWidget(self.downloadSpeedIcon)
     self.statusBar().addWidget(self.downloadSpeedText)
示例#3
0
 def createAction(self, icon, size, text, help=None):
     path = iconPath(icon, size)
     if path:
         action = QAction(QIcon(path), text, self)
     else:
         action = QAction(text, self)
     if help:
         action.setToolTip(help)
         action.setStatusTip(help)
     return action
示例#4
0
 def updateStatusBar(self):
     if self.app.isConnected:
         connStatus = "Connected to %s:%d" % self.app.connectionAddress
         self.connStatus.setPixmap(QPixmap(iconPath("status/network-idle", 24)))
     else:
         connStatus = "Not connected to a peer"
         self.connStatus.setPixmap(QPixmap(iconPath("status/network-offline", 24)))
     if self.app.isListening:
         listenStatus = "Listening for incoming connections on %s:%d" % self.app.bindAddress
         self.setWindowTitle("Spark - %s:%d" % self.app.bindAddress)
     else:
         self.setWindowTitle("Spark")
         listenStatus = "Not listening for incoming connections"
     self.trayIcon.setToolTip(self.windowTitle())
     self.connStatus.setToolTip(connStatus + "\n" + listenStatus)
     self.myIP.setText("My IP: %s" % self.app.myIPaddress)
     self.transferCount.setText("%d transfer(s)" % self.app.activeTransfers)
     self.uploadSpeedText.setText(formatSize(self.app.uploadSpeed, "%s/s"))
     self.downloadSpeedText.setText(formatSize(self.app.downloadSpeed, "%s/s"))
示例#5
0
 def initTrayIcon(self):
     self.trayIcon = QSystemTrayIcon(self)
     self.trayIcon.setIcon(QIcon(QPixmap(iconPath("apps/spark", 24))))
     self.trayIcon.setToolTip(self.windowTitle())
     self.trayMenu = QMenu(self)
     quit = QAction("Quit", self)
     self.trayMenu.addAction(quit)
     self.trayIcon.setContextMenu(self.trayMenu)
     QObject.connect(self.trayIcon,
         SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.trayIconActivated)
     QObject.connect(quit, SIGNAL("triggered()"), self, SLOT("close()"))
示例#6
0
 def setStatusIcon(self, icon, index):
     statusIcon = self.statusIcons[index]
     if icon:
         statusIcon.setPixmap(QPixmap(iconPath(icon, 16)))
     else:
         statusIcon.setPixmap(QPixmap())
示例#7
0
 def setTypeIcon(self, icon):
     if isinstance(icon, basestring):
         self.typeIconSet = QIcon(iconPath(icon))
         self.typeIcon.setPixmap(self.typeIconSet.pixmap(48, 48))
     else:
         self.typeIcon.setPixmap(icon)