-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBCclient.py
390 lines (334 loc) · 13.2 KB
/
SBCclient.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import sys,base64,threading
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from functools import partial
from PyQt5.QtGui import QFontMetrics
import SBCMainWindow
import time,io
from PyQt5.Qt import QThread
import os,hashlib
from PIL import Image
from ui import SubUi
from pack import SBCRequest
def GetFileMd5(filename):
if not os.path.isfile(filename):
return
myhash = hashlib.md5()
f = open(filename ,"rb")
while True:
b = f.read(8096)
if not b:
break
myhash.update(b)
f.close()
return myhash.hexdigest()
def size_format(size):
if size < 1024:
return '%i' % size + 'size'
elif 1024 <= size < 1024*1024:
return '%.1f' % float(size/1024) + 'KB'
elif 1024*1024 <= size < 1024*1024*1024:
return '%.1f' % float(size/(1024*1024)) + 'MB'
elif 1024*1024*1024 <= size < 1024*1024*1024*1024:
return '%.1f' % float(size/(1024*1024*1024)) + 'GB'
elif 1024*1024*1024*1024 <= size:
return '%.1f' % float(size/(1024*1024*1024*1024)) + 'TB'
class Thread_LoadImg(QThread):
def __init__(self):
super().__init__()
self.ui = ui
# self.Thread_LoadImg = Thread_LoadImg(self.ui)
def func(self,listTemp, n):
for i in range(0, len(listTemp), n):
yield listTemp[i:i + n]
def ShowCon(self,px,base64data):
ba = base64data
pixmap = QtGui.QPixmap()
pixmap.loadFromData(ba)
px.setPixmap(pixmap)
def run(self):
temp = self.func(self.ui.FileCon, 2)
for i in temp:
SendList = [{'fepath':j['fepath']} for j in i]
# print('send',SendList)
ConList = SBCRe.GetFileCon(SendList)
try:
for num in range(len(ConList['src'])):
coninfo = ConList['src'][num]
ConBase64 = coninfo.split(',')[-1]
img_b64decode = base64.b64decode(ConBase64) # [21:]
self.ShowCon(i[num]['con'],img_b64decode)
except:
# print('threderror')
break
class ClickEventDeals():
def __init__(self):
self.ui = ui
def DownDeal(self,e):
pass
def UpDeal(self,e):
pass
def ReameDeal(self,e):
pass
def MoreDeal(self,e):
pass
def ChooseNetDeal(self,e):
pass
def SearchDeal(self,e):
pass
def NetBackDeal(self,e):
pass
def NetRefresh(self,e):
pass
def ClearNavStyle(self):
self.ui.frame_2.setStyleSheet("")
self.ui.frame_3.setStyleSheet("")
self.ui.frame_4.setStyleSheet("")
self.ui.frame_5.setStyleSheet("")
self.ui.frame_6.setStyleSheet("")
def NavChoose(self,WosLabel,e):
if e.buttons() == QtCore.Qt.LeftButton:
if self.ui.CurNavChosed != WosLabel:
self.ClearNavStyle()
print(WosLabel)
if WosLabel == 'Photo':
self.ui.CurNavChosed = 'Photo'
SBCM.ChoseNav_Photo()
self.ui.frame_3.setStyleSheet("background:#7DCEA0;border-radius:20px;opacity:0.5;")
if WosLabel == 'File':
self.ui.CurNavChosed = 'File'
SBCM.ChoseNav_File()
self.ui.frame_2.setStyleSheet("background:#7DCEA0;border-radius:20px;opacity:0.5;")
if WosLabel == 'Video':
self.ui.CurNavChosed = 'Video'
self.ui.frame_4.setStyleSheet("background:#7DCEA0;border-radius:20px;opacity:0.5;")
SBCM.ChoseNav_Video()
if WosLabel == 'Share':
self.ui.CurNavChosed = 'Share'
self.ui.frame_5.setStyleSheet("background:#7DCEA0;border-radius:20px;opacity:0.5;")
if WosLabel == 'Transmit':
self.ui.CurNavChosed = 'Transmit'
self.ui.frame_6.setStyleSheet("background:#7DCEA0;border-radius:20px;opacity:0.5;")
def FileClickDeal(self,FileInfo,e):
if e.buttons() == QtCore.Qt.LeftButton:
self.FileLeftDeal(FileInfo)
elif e.buttons() == QtCore.Qt.RightButton:
self.FileRightDeal(FileInfo)
def FileLeftDeal(self,FileInfo):
print('FileLeft',FileInfo)
SBCM.FileShow(FileInfo['fepath'])
def FileRightDeal(self,FileInfo):
print("右")
SBCM.FileShow('/home/')
def ChoseNet(self,WosLabel,e):
if e.buttons() == QtCore.Qt.LeftButton:
if self.ui.CurNetChosed != WosLabel:
if WosLabel == 'SBC':
pass
if WosLabel == 'BDC':
pass
class ChoseNetNav():
def __init__(self):
pass
def CreatFrame(self):
self.frame_ChoseNet = QtWidgets.QFrame(ui.frame_14)
self.frame_ChoseNet.setGeometry(QtCore.QRect(220, 35, 101, 171))
self.frame_ChoseNet.setStyleSheet("#frame_ChoseNet\n"
"{\n"
" background:#D0D3D4;\n"
"}\n"
"\n"
"#frame_ChoseNet QLabel:hover{\n"
" background:#A2D9CE;\n"
" \n"
" opacity:0.5;\n"
" }")
self.frame_ChoseNet.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_ChoseNet.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_ChoseNet.setObjectName("frame_ChoseNet")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.frame_ChoseNet)
self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_3.setSpacing(0)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.label = QtWidgets.QLabel(self.frame_ChoseNet)
self.label.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.verticalLayout_3.addWidget(self.label)
self.label_2 = QtWidgets.QLabel(self.frame_ChoseNet)
self.label_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.verticalLayout_3.addWidget(self.label_2)
self.label_3 = QtWidgets.QLabel(self.frame_ChoseNet)
self.label_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.label_3.setAlignment(QtCore.Qt.AlignCenter)
self.label_3.setObjectName("label_3")
self.verticalLayout_3.addWidget(self.label_3)
# self.retranslateUi(Form)
# QtCore.QMetaObject.connectSlotsByName(Form)
self.label.setText("小黑云")
self.label_2.setText("百度云")
self.label_3.setText("阿里云")
ui.frame_ChoseNet = self.frame_ChoseNet
ui.choseSBCLabel = self.label
ui.choseBDCLabel = self.label_2
ui.choseALCLabel = self.label_3
ui.frame_ChoseNet.raise_()
ui.frame_ChoseNet.hide()
class SBC(QThread):
signal = pyqtSignal()
def __init__(self):
super().__init__()
# self.ui = ui
# self.Main = Main
# self.Main.resizeEvent = self.MainWindowSizeChange
self.width0 = 900
self.height0 = 700
self.ClickEventDeals = ClickEventDeals()
self.frame_ChoseNetshow = 0
self.initdWindow()
# self.signal.connect(self.Refresh)
def WindowReSize(self):
# if ui.scrollArea.width() < 500:
# w = 760
# else:
# w = ui.scrollArea.width()
w = Main.width() - 150
if ui.CurNavChosed in ui.SBCFilesDict[ui.CurNetChosed]:
CurSBCFilesDict = ui.SBCFilesDict[ui.CurNetChosed][ui.CurNavChosed]['File']
# print(CurSBCFilesDict)
for i in CurSBCFilesDict:
FIleinfo = CurSBCFilesDict[i]
FileName = FIleinfo['fename']
Felabel = FIleinfo['FileNameLabel']
# print(Felabel)
metrics = QFontMetrics(Felabel.font())
# print(metrics)
new_file_name = metrics.elidedText(FileName, Qt.ElideRight, w*0.5)
Felabel.setText(new_file_name)
def MainWindowSizeChange(self,e):
self.WindowReSize()
def initFrame(self):
ui.nav = {}
# ui.nav['SBC'] = {}
# ui.nav['BDC'] = {}
# ui.nav['ALC'] = {}
ui.frameandscroll = {}
ui.frameandscroll['SBC'] = {}
ui.frameandscroll['BDC'] = {}
ui.frameandscroll['ALC'] = {}
ui.SBCFilesDict = {}
ui.SBCFilesDict['SBC'] = {}
ui.SBCFilesDict['BDC'] = {}
ui.SBCFilesDict['ALC'] = {}
ui.FileCons = {}
ui.FileCons['SBC'] = {}
ui.FileCons['BDC'] = {}
ui.FileCons['ALC'] = {}
for i in ui.frameandscroll:
ui.frameandscroll[i]['Photo'] = subui.InitShow()
ui.frameandscroll[i]['Video'] = subui.InitShow()
# ui.frameandscroll[i]['File'] = subui.InitFileShow()
ui.frameandscroll[i]['File'] = subui.initfileshow()
# ui.frameandscroll['Photo'] = subui.InitShow()
# ui.frameandscroll['Video'] = subui.InitShow()
# ui.frameandscroll['File'] = subui.InitFileShow()
def initdWindow(self):
global ui,Main
ui.CurNetChosed = 'SBC'
ui.CurSBCFilesDict = {}
ui.frame_13.deleteLater()
ui.frame_2.mousePressEvent = partial(self.ClickEventDeals.NavChoose,'File')
ui.frame_3.mousePressEvent = partial(self.ClickEventDeals.NavChoose, 'Photo')
ui.frame_4.mousePressEvent = partial(self.ClickEventDeals.NavChoose, 'Video')
ui.frame_5.mousePressEvent = partial(self.ClickEventDeals.NavChoose, 'Share')
ui.frame_6.mousePressEvent = partial(self.ClickEventDeals.NavChoose, 'Transmit')
ui.CurNavChosed = 'File'
ui.frame_2.setStyleSheet("background:#7DCEA0;border-radius:20px;opacity:0.5;")
Main.resize(self.width0, self.height0)
Main.setMinimumSize(QtCore.QSize(800, 700))
# Main.resizeEvent = self.MainWindowSizeChange
ui.PhotoShowFilesDict = {}
ui.VdeoShowFilesDict = {}
ui.DocumenttoShowFilesDict = {}
ui.SharehowFilesDict = {}
# ui.SBCFilesDict = {}
# ui.FileCons = {}
ui.CurShow = ''
Main.resizeEvent = self.MainWindowSizeChange
# ui.frame_12.resizeEvent = self.MainWindowSizeChange
chosenetnav = ChoseNetNav()
chosenetnav.CreatFrame()
ui.choseBDCLabel.mousePressEvent = partial(self.ClickEventDeals.NavChoose, 'File')
ui.label_18.mousePressEvent = self.ChoseNetShow
ui.frame_ChoseNet.leaveEvent = self.ChoseNetHide
ui.choseBDCLabel.mousePressEvent = partial(self.ChoseNet, 'BDC')
self.initFrame()
self.HideFrames()
subui.FileShow()
def ChoseNet(self,chose,e):
print(chose)
def ChoseNetHide(self,e):
ui.frame_ChoseNet.hide()
self.frame_ChoseNetshow = 0
def ChoseNetShow(self,e):
if self.frame_ChoseNetshow:
ui.frame_ChoseNet.hide()
self.frame_ChoseNetshow = 0
else:
ui.frame_ChoseNet.raise_()
ui.frame_ChoseNet.show()
self.frame_ChoseNetshow = 1
# t = threading.Thread(target=self.ThreadRun,args=(path,))
# t.setDaemon(True)
# t.start()
def HideFrames(self):
# ui.frame_12.hide()
for i in ui.frameandscroll:
# print(i)
ui.frameandscroll[i]['Photo']['frame'].hide()
ui.frameandscroll[i]['Video']['frame'].hide()
ui.frameandscroll[i]['File']['frame'].hide()
# ui.frameandscroll['Photo']['frame'].hide()
# ui.frameandscroll['Video']['frame'].hide()
def ChoseNav_Photo(self):
self.HideFrames()
# ui.frame_12.hide()
ui.CurShow = 'Photo'
subui.PhotoShow()
# subui.frame_PhotoShow.resizeEvent = self.MainWindowSizeChange1
def ChoseNav_File(self):
self.HideFrames()
subui.FileShow()
# ui.frame_PhotoShow.hide()
# ui.frame_12.show()
# ui.scrollAreaWidgetContents.raise_()
def ChoseNav_Video(self):
self.HideFrames()
# ui.frame_12.hide()
subui.VideoShow()
# # 加载图片
# self.label_2.setPixmap(QtGui.QPixmap("./res/tay.jpeg"))
# # 图片居中
# self.label_2.setAlignment(Qt.AlignCenter)
# # 图片自适应控件尺寸
# self.label_2.setScaledContents(True)
if __name__ == '__main__':
# clickdeal = EventDeals()
SBCRe = SBCRequest.SBCRe()
app = QApplication(sys.argv)
Main = QMainWindow()
ui = SBCMainWindow.Ui_SBCclient()
ui.setupUi(Main)
subui = SubUi.Ui_PhotoShow(ui)
# ui.frameandscroll = {}
# ui.frameandscroll['Photo'] = subui.InitShow()
# ui.frameandscroll['Video'] = subui.InitShow()
# ui.frameandscroll['File'] = subui.InitFileShow()
SBCM = SBC()
# SBCM.FileShow('/home/')
print(Main.width())
Main.show()
sys.exit(app.exec_())