-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
113 lines (88 loc) · 3.34 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
__author__ = "Mikhail Fedosov <tbs.micle@gmail.com>"
__doc__ = u"Quick share for teams"
import sys
import logging
# PySide
from PySide.QtGui import *
from PySide import QtGui, QtCore
# QSH
from networking.connector import Connector
from config import AppConfig, SCREEN_IMAGE_TYPE, SCREEN_IMAGE_QUALITY
from dialogs import ConfigurationDialog, ScreenViewDialog, MainTrayIcon
logger = logging.getLogger(__name__)
class QSH(QApplication):
def __init__(self, *args, **kwargs):
super(QSH, self).__init__(*args, **kwargs)
self.setQuitOnLastWindowClosed(False)
# signals
self.aboutToQuit.connect(self.beforeQuit)
# dialogs
self.screenViewDialog = ScreenViewDialog(self)
# networking
self.connector = Connector()
# tray
self.trayIcon = MainTrayIcon(self, callbacks=
{
"quit": self.quit,
"configuration": self.showConfigurationDialog,
"incoming": self.showScreenViewDialog
})
self.trayIcon.middle_click_callback = self.trayIconMiddleClick
# networking callbacks
self.connector.known_hosts_updated_callback = self.trayIcon.updateMenu
self.connector.got_image_callback = self.processReceivedImage
self.connector.receiving_start_callback = self.trayIcon.setIconLoading
self.connector.sending_end_callback = self.trayIcon.setIconDefault
# hi there!
self.connector.updateKnownHosts()
# periodically check whether hosts alive
self.helloAllTimer = QtCore.QTimer(self)
self.connect(self.helloAllTimer, QtCore.SIGNAL("timeout()"), self.connector.updateKnownHosts)
self.helloAllTimer.start(AppConfig.get_heartbeat_interval())
def trayIconMiddleClick(self):
self.trayIcon.icon.setContextMenu(None)
if not self.screenViewDialog.isVisible():
if self.trayIcon.incomingTotal:
self.trayIcon.actionShowScreenViewDialog.trigger()
else:
self.screenViewDialog.close()
def processReceivedImage(self, data_uuid=None, data=None):
""" Show received screenshot
"""
if data_uuid and data.size():
receivedImagesCount = self.screenViewDialog.processReceivedImage(data_uuid=data_uuid,
data=data,
known_hosts=self.connector.known_hosts)
self.trayIcon.incomingTotal += receivedImagesCount
if self.screenViewDialog.isVisible():
self.screenViewDialog.showWindow()
else:
self.trayIcon.incomingUnread += receivedImagesCount
self.trayIcon.updateMenu()
self.trayIcon.setIconDefault()
def shareScreen(self, host_data):
""" Send screenshot
"""
self.trayIcon.setIconLoading()
# capture screenshot
screenBA = QtCore.QByteArray()
screenBuf = QtCore.QBuffer(screenBA)
screenBuf.open(QtCore.QBuffer.WriteOnly)
QPixmap.grabWindow(self.desktop().winId()).save(screenBuf, SCREEN_IMAGE_TYPE, SCREEN_IMAGE_QUALITY)
self.connector.submitScreen(host_data["host"], host_data["port"], screenBA)
def showConfigurationDialog(self):
self.config_dialog = ConfigurationDialog(self)
self.config_dialog.showNormal()
self.config_dialog.activateWindow()
self.config_dialog.raise_()
def showScreenViewDialog(self):
self.trayIcon.incomingUnread = 0
self.trayIcon.updateMenu()
self.trayIcon.setIconDefault()
self.screenViewDialog.showWindow()
def beforeQuit(self):
self.connector.byeAll()
if __name__ == '__main__':
app = QSH(sys.argv)
sys.exit(app.exec_())