forked from vnitinv/JChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainchatwindow.py
159 lines (143 loc) · 7.23 KB
/
mainchatwindow.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from PyQt4 import QtCore, QtGui
import os
import sys
sys.path.append('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
import chatwin
import deviceconnect
import creategroup
import pickle
from boxes import ConnectedDevice
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainChatWindow(object):
def setupUi(self, MainChatWindow):
self.cd_maincw = ConnectedDevice()
MainChatWindow.setObjectName(_fromUtf8("MainChatWindow"))
MainChatWindow.resize(377, 554)
self.centralWidget = QtGui.QWidget(MainChatWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.gridLayout = QtGui.QGridLayout(self.centralWidget)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.treeView = QtGui.QTreeView(self.centralWidget)
self.treeView.setObjectName(_fromUtf8("treeView"))
self.gridLayout.addWidget(self.treeView, 0, 0, 1, 1)
MainChatWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtGui.QMenuBar(MainChatWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 277, 22))
self.menuBar.setObjectName(_fromUtf8("menuBar"))
self.menuDevice = QtGui.QMenu(self.menuBar)
self.menuDevice.setObjectName(_fromUtf8("menuDevice"))
self.menuGroup = QtGui.QMenu(self.menuBar)
self.menuGroup.setObjectName(_fromUtf8("menuGroup"))
self.menuView = QtGui.QMenu(self.menuBar)
self.menuView.setObjectName(_fromUtf8("menuView"))
MainChatWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtGui.QToolBar(MainChatWindow)
self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
MainChatWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtGui.QStatusBar(MainChatWindow)
self.statusBar.setObjectName(_fromUtf8("statusBar"))
MainChatWindow.setStatusBar(self.statusBar)
self.actionConnect = QtGui.QAction(MainChatWindow)
self.actionConnect.setObjectName(_fromUtf8("actionConnect"))
self.actionExit = QtGui.QAction(MainChatWindow)
self.actionExit.setObjectName(_fromUtf8("actionExit"))
self.actionEdit = QtGui.QAction(MainChatWindow)
self.actionEdit.setObjectName(_fromUtf8("actionEdit"))
self.actionCreate = QtGui.QAction(MainChatWindow)
self.actionCreate.setObjectName(_fromUtf8("actionCreate"))
self.actionOnline = QtGui.QAction(MainChatWindow)
self.actionOnline.setObjectName(_fromUtf8("actionOnline"))
self.menuDevice.addAction(self.actionConnect)
self.menuDevice.addAction(self.actionExit)
self.menuGroup.addAction(self.actionEdit)
self.menuGroup.addAction(self.actionCreate)
self.menuView.addAction(self.actionOnline)
self.menuBar.addAction(self.menuDevice.menuAction())
self.menuBar.addAction(self.menuGroup.menuAction())
self.menuBar.addAction(self.menuView.menuAction())
self.retranslateUi(MainChatWindow)
QtCore.QObject.connect(self.actionConnect, QtCore.SIGNAL(_fromUtf8("triggered()")), self.openDeviceConnect)
QtCore.QObject.connect(self.actionCreate, QtCore.SIGNAL(_fromUtf8("triggered()")), self.openCreateGroup)
QtCore.QObject.connect(self.treeView, QtCore.SIGNAL(_fromUtf8("doubleClicked(QModelIndex)")), self.openChatWindow)
QtCore.QMetaObject.connectSlotsByName(MainChatWindow)
MainChatWindow.closeEvent = self.dumpContact
def retranslateUi(self, MainChatWindow):
MainChatWindow.setWindowTitle(_translate("MainChatWindow", "JChat", None))
self.menuDevice.setTitle(_translate("MainChatWindow", "Device", None))
self.menuGroup.setTitle(_translate("MainChatWindow", "Group", None))
self.menuView.setTitle(_translate("MainChatWindow", "View", None))
self.actionConnect.setText(_translate("MainChatWindow", "Connect", None))
self.actionExit.setText(_translate("MainChatWindow", "Exit", None))
self.actionEdit.setText(_translate("MainChatWindow", "Edit", None))
self.actionCreate.setText(_translate("MainChatWindow", "Create", None))
self.actionOnline.setText(_translate("MainChatWindow", "Online", None))
if os.path.isfile('devices.dat') and os.path.isfile('groups.dat'):
with open('devices.dat', 'rb') as handle:
ConnectedDevice.devices = pickle.load(handle)
ConnectedDevice.devices = {k:(None,v) for k,v in ConnectedDevice.devices.items()}
with open('groups.dat', 'rb') as handle:
ConnectedDevice.groups = pickle.load(handle)
os.remove('devices.dat')
os.remove('groups.dat')
print ConnectedDevice.groups,ConnectedDevice.devices
self.updateTree(clr = False)
def openDeviceConnect(self):
self.DeviceConnect = QtGui.QMainWindow()
self.connect_ui = deviceconnect.Ui_DeviceConnect()
self.connect_ui.setupUi(self.DeviceConnect)
self.DeviceConnect.show()
self.DeviceConnect.closeEvent = self.updateTree
def openCreateGroup(self):
self.CreateGroup = QtGui.QWidget()
self.cg_ui = creategroup.Ui_CreateGroup()
self.cg_ui.setupUi(self.CreateGroup)
self.CreateGroup.show()
self.CreateGroup.closeEvent = self.updateTree
def updateTree(self, event=None, clr=True):
if clr ==True:
paint = (0, 200, 0)
else:
paint = (0, 0, 0)
self.model = QtGui.QStandardItemModel()
self.model.invisibleRootItem()
for grp, devices in self.cd_maincw.groups.items():
rt = QtGui.QStandardItem(grp)
self.model.appendRow(rt)
for device in devices:
dv = QtGui.QStandardItem(device)
dv.setForeground(QtGui.QColor(*paint))
dv.setFont(QtGui.QFont("Courier", 17))
rt.appendRow(dv)
dev_in_grps = []
[dev_in_grps.extend(i) for i in self.cd_maincw.groups.values()]
for device in self.cd_maincw.devices.keys():
if device not in dev_in_grps:
dv = QtGui.QStandardItem(device)
dv.setForeground(QtGui.QColor(*paint))
dv.setFont(QtGui.QFont("Courier", 17))
self.model.appendRow(dv)
self.treeView.setModel(self.model)
self.treeView.expandAll()
def openChatWindow(self, index):
self.JChatMain = QtGui.QMainWindow()
self.chat_ui = chatwin.Ui_JChatMain()
self.chat_ui.setupUi(self.JChatMain, index)
self.JChatMain.show()
def dumpContact(self,event=None):
data = {k:v[1] for k,v in zip(ConnectedDevice.devices.keys(), ConnectedDevice.devices.values())}
print data
with open('devices.dat', 'wb') as handle:
pickle.dump(data, handle)
with open('groups.dat', 'wb') as handle:
pickle.dump(ConnectedDevice.groups, handle)