-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
1129 lines (929 loc) · 60.8 KB
/
Copy pathmain.py
File metadata and controls
1129 lines (929 loc) · 60.8 KB
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2020, Md Imam Hossain (emamhd at gmail dot com)
# see LICENSE.txt for details
import os
import sys
import math
import re
import subprocess
import json
import requests
import requests.exceptions
import urllib.request
import threading
import io
import wx
import wx.lib.agw.hyperlink as hl
class SnapImageShare():
def __init__(self):
self.sis_app = wx.App()
self.main_window = MainWindow()
self.back_image = wx.Bitmap("./data/back.png", wx.BITMAP_TYPE_PNG)
def run(self):
self.sis_app.MainLoop()
class MainWindow(wx.Frame):
def __init__(self):
self.saved_options = dict()
self.load_saved_options()
self.main_window_title = "Snap Image Share Desktop (New possibilities)"
self.main_window_width = 820
self.main_window_height = 700
self.main_window_icon_file = './data/logo.png'
self.main_window_icon = wx.Icon(self.main_window_icon_file, wx.BITMAP_TYPE_PNG)
super(MainWindow, self).__init__(None, title=self.main_window_title, size=(self.main_window_width, self.main_window_height))
self.SetSizeHints((self.main_window_width, self.main_window_height), maxSize=(self.main_window_width, self.main_window_height))
self.SetIcon(self.main_window_icon)
self.Bind(wx.EVT_CLOSE, self.on_window_close)
self.main_window_screen = SplashScreen(self)
self.Center()
self.Show()
def load_saved_options(self):
global download_selection, files_selection, share_goals, platform
if os.path.isfile('./data/options.json'):
options_conf_file = open("./data/options.json", "r")
self.saved_options.clear()
try:
self.saved_options = json.load(options_conf_file)
except ValueError:
print('Snap Image Share:', 'could not load options')
else:
pass
options_conf_file.close()
if len(self.saved_options) > 0:
if self.saved_options['download_dir'] != "":
download_selection.download_directory = self.saved_options["download_dir"]
else:
if platform == "posix":
download_selection.download_directory = os.path.expanduser('~') + "/"
else:
download_selection.download_directory = os.path.expanduser('~') + "\\"
if self.saved_options['browse_dir'] != "":
files_selection.browse_directory = self.saved_options["browse_dir"]
else:
if platform == "posix":
files_selection.browse_directory = os.path.expanduser('~') + "/"
else:
files_selection.browse_directory = os.path.expanduser('~') + "\\"
share_goals.downloads = self.saved_options["downloads_limit"]
share_goals.time = self.saved_options["time_limit"]
def save_options(self):
options_conf_file = open("./data/options.json", "w")
json.dump(self.saved_options, options_conf_file)
options_conf_file.close()
def on_window_close(self, e):
global files_selection, download_selection, share_goals
if e.CanVeto():
self.saved_options["downloads_limit"] = share_goals.downloads
self.saved_options["time_limit"] = share_goals.time
self.saved_options["browse_dir"] = files_selection.browse_directory
self.saved_options["download_dir"] = download_selection.download_directory
self.save_options()
self.Destroy()
class SplashScreen():
def __init__(self, _window):
self.main_window = _window
self.splash_screen_panel = wx.Panel(self.main_window, size=(self.main_window.Size[0], self.main_window.Size[1]))
self.splash_screen_panel.SetBackgroundColour(wx.Colour(250, 250, 250))
self.splash_screen_vbox = wx.BoxSizer(wx.VERTICAL)
self.splash_screen_panel.SetSizer(self.splash_screen_vbox)
self.splash_screen_intro_image = wx.StaticBitmap(self.splash_screen_panel, wx.ID_ANY, wx.Bitmap('./data/intro.png', wx.BITMAP_TYPE_PNG))
self.splash_screen_vbox.Add(self.splash_screen_intro_image, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border=80)
self.splash_screen_intro_text = wx.StaticText(self.splash_screen_panel, style=wx.ALIGN_CENTER)
self.splash_screen_intro_text.SetFont(wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_SLANT, wx.FONTWEIGHT_LIGHT))
self.splash_screen_intro_text.SetLabel("Share file without Sign Up\nLimit file download\nSafe and secure free file sharing")
self.splash_screen_intro_text.SetForegroundColour((103, 103, 103))
#self.splash_screen_intro_text.SetSize(self.splash_screen_intro_text.GetTextExtent(self.splash_screen_intro_text.GetLabel()))
self.splash_screen_vbox.Add(self.splash_screen_intro_text, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border=100)
self.splash_screen_intro_message_text = wx.StaticText(self.splash_screen_panel, style=wx.ALIGN_CENTER)
self.splash_screen_intro_message_text.SetLabel("Click to continue")
self.splash_screen_intro_message_text.SetForegroundColour((105, 105, 105))
self.splash_screen_intro_message_text.Bind(wx.EVT_LEFT_DOWN, self.mouse_click_callback)
self.splash_screen_vbox.Add(self.splash_screen_intro_message_text, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border=20)
#self.splash_screen_panel.Layout()
#self.splash_screen_panel.SetSizerAndFit(self.splash_screen_vbox)
def mouse_click_callback(self, e):
self.splash_screen_panel.Hide()
MainScreen(self.main_window)
class MainScreen():
def __init__(self, _window):
self.main_window = _window
self.main_screen_panel = wx.Notebook(self.main_window, size=(self.main_window.Size[0], self.main_window.Size[1]), style=wx.NB_TOP)
self.main_screen_panel.SetBackgroundColour((120, 150, 150))
self.main_screen_panel.SetFont(wx.Font(16, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.main_screen_panel.SetForegroundColour((250, 250, 200))
self.main_screen_panel.AddPage(SharePage(self.main_screen_panel).share_panel, "Share")
self.main_screen_panel.AddPage(DownloadPage(self.main_screen_panel).download_panel, "Download")
self.main_screen_panel.AddPage(AboutPage(self.main_screen_panel).about_panel, "About")
self.main_screen_panel.SetPadding((80,-1))
#self.main_screen_panel.Layout()
#self.main_screen_panel.SetSizerAndFit(self.main_screen_vbox)
class SharePage():
def __init__(self, _window):
self.main_window = _window
self.share_panel = wx.Panel(self.main_window, size=(self.main_window.Size[0], self.main_window.Size[1]))
self.share_panel_vbox = wx.BoxSizer(wx.VERTICAL)
self.share_panel.SetSizer(self.share_panel_vbox)
self.share_panel_vbox.Add(ShareSettingPage(self.share_panel, self.share_panel_vbox).share_setting_panel, flag=wx.EXPAND)
self.share_panel.Bind(wx.EVT_ERASE_BACKGROUND, self.on_erase_background)
def on_erase_background(self, e):
global snap_image_share
dc = e.GetDC()
if not dc:
dc = wx.ClientDC(self.share_panel)
rect = self.share_panel.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
dc.DrawBitmap(snap_image_share.back_image, 0, 0)
class ShareSettingPage():
def __init__(self, _window, _box):
global share_goals
self.main_window = _window
self.main_window_box = _box
self.share_setting_panel = wx.Panel(self.main_window, size=(self.main_window.Size[0], self.main_window.Size[1]))
self.share_setting_panel_vbox = wx.BoxSizer(wx.VERTICAL)
self.share_setting_panel.SetSizer(self.share_setting_panel_vbox)
self.share_setting_panel_vbox.AddSpacer(50)
self.share_setting_name_message = wx.StaticText(self.share_setting_panel, style=wx.ALIGN_CENTER)
self.share_setting_name_message.SetFont(wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.share_setting_name_message.SetLabel("Enter a title for your file")
self.share_setting_name_message.SetForegroundColour((100, 100, 100))
self.share_setting_panel_vbox.Add(self.share_setting_name_message, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.share_setting_panel_vbox.AddSpacer(30)
self.share_setting_name_text = wx.TextCtrl(self.share_setting_panel, style=wx.TE_LEFT | wx.TE_NO_VSCROLL | wx.TE_BESTWRAP)
self.share_setting_name_text.SetFont(wx.Font(12, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_LIGHT))
self.share_setting_name_text.SetForegroundColour((105, 105, 105))
self.share_setting_name_text.SetValue(share_goals.title)
self.share_setting_panel_vbox.Add(self.share_setting_name_text, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.share_setting_panel_vbox.AddSpacer(60)
self.share_setting_downloads_message = wx.StaticText(self.share_setting_panel, style=wx.ALIGN_CENTER)
self.share_setting_downloads_message.SetFont(wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.share_setting_downloads_message.SetLabel("Limit number of downloads")
self.share_setting_downloads_message.SetForegroundColour((100, 100, 100))
self.share_setting_panel_vbox.Add(self.share_setting_downloads_message, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.share_setting_panel_vbox.AddSpacer(30)
self.share_setting_downloads_select = wx.Slider(self.share_setting_panel, value=share_goals.downloads, minValue=1, maxValue=1000, style=wx.SL_HORIZONTAL)
self.share_setting_panel_vbox.Add(self.share_setting_downloads_select, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.share_setting_downloads_select.Bind(wx.EVT_SCROLL, self.on_downloads_scroll)
self.share_setting_panel_vbox.AddSpacer(20)
self.share_setting_downloads_number = wx.StaticText(self.share_setting_panel, style=wx.ALIGN_LEFT)
self.share_setting_downloads_number.SetFont(wx.Font(12, wx.FONTFAMILY_DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.share_setting_downloads_number.SetForegroundColour((50, 50, 50))
self.share_setting_downloads_number.SetLabel(self.get_downloads_text(self.share_setting_downloads_select.GetValue()))
self.share_setting_panel_vbox.Add(self.share_setting_downloads_number, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.share_setting_panel_vbox.AddSpacer(60)
self.share_setting_time_message = wx.StaticText(self.share_setting_panel, style=wx.ALIGN_CENTER)
self.share_setting_time_message.SetFont(wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.share_setting_time_message.SetLabel("Limit time to expiry")
self.share_setting_time_message.SetForegroundColour((100, 100, 100))
self.share_setting_panel_vbox.Add(self.share_setting_time_message, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.share_setting_panel_vbox.AddSpacer(30)
self.share_setting_time_select = wx.Slider(self.share_setting_panel, value=share_goals.time, minValue=1, maxValue=10080, style=wx.SL_HORIZONTAL)
self.share_setting_panel_vbox.Add(self.share_setting_time_select, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.share_setting_time_select.Bind(wx.EVT_SCROLL, self.on_time_scroll)
self.share_setting_panel_vbox.AddSpacer(20)
self.share_setting_time_number = wx.StaticText(self.share_setting_panel, style=wx.ALIGN_LEFT)
self.share_setting_time_number.SetFont(wx.Font(12, wx.FONTFAMILY_DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.share_setting_time_number.SetForegroundColour((50, 50, 50))
self.share_setting_time_number.SetLabel(self.get_time_text(self.share_setting_time_select.GetValue()))
self.share_setting_panel_vbox.Add(self.share_setting_time_number, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.share_setting_panel_vbox.AddSpacer(60)
self.share_setting_select_file = wx.Button(self.share_setting_panel, label='Next')
self.share_setting_select_file.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.share_setting_panel_vbox.Add(self.share_setting_select_file, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.share_setting_select_file.Bind(wx.EVT_BUTTON, self.on_select_file_click)
def get_downloads_text(self, v):
if v > 1:
return str(v) + " times"
else:
return str(v) + " time"
def on_downloads_scroll(self, e):
global share_goals
obj = e.GetEventObject()
vald = obj.GetValue()
self.share_setting_downloads_number.SetLabel(self.get_downloads_text(vald))
share_goals.downloads = vald
def get_time_text(self, v):
time_m = v
days_value = (time_m / 60) / 24
hr_value = (days_value % 1) * 24
min_value = (hr_value % 1) * 60
days_value = int(round(days_value, 3))
hr_value = int(round(hr_value, 3))
min_value = int(round(min_value, 3))
time_text = ""
if (days_value > 0):
if (days_value > 1):
time_text += str(days_value) + " days"
else:
time_text += str(days_value) + " day"
if (hr_value > 0):
if (days_value > 0):
time_text += ", "
if (hr_value > 1):
time_text += str(hr_value) + " hours"
else:
time_text += str(hr_value) + " hour"
if (min_value > 0):
if (days_value == 0 and hr_value > 0):
time_text += ", "
if (days_value > 0 and hr_value == 0):
time_text += ", "
if (days_value > 0 and hr_value > 0):
time_text += ", "
if (min_value > 1):
time_text += str(min_value) + " minutes"
else:
time_text += str(min_value) + " minute"
return time_text
def on_time_scroll(self, e):
global share_goals
obj = e.GetEventObject()
valt = obj.GetValue()
self.share_setting_time_number.SetLabel(self.get_time_text(valt))
share_goals.time = valt
def on_select_file_click(self, e):
global share_goals
share_goals.title = self.share_setting_name_text.GetValue()
self.share_setting_panel.Hide()
self.main_window_box.Clear()
self.main_window_box.Add(FileSelectionPage(self.main_window, self.main_window_box).file_selection_panel, flag=wx.EXPAND)
class FileSelectionPage():
def __init__(self, _window, _box):
global files_selection
self.main_window = _window
self.main_window_box = _box
self.file_selection_panel = wx.Panel(self.main_window, size=(self.main_window.Size[0], self.main_window.Size[1]))
self.file_selection_panel_vbox = wx.BoxSizer(wx.VERTICAL)
self.file_selection_panel.SetSizer(self.file_selection_panel_vbox)
self.file_selection_panel_vbox.AddSpacer(50)
self.file_selection_browse_file = wx.Button(self.file_selection_panel, label='Browse files to share')
self.file_selection_browse_file.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.file_selection_panel_vbox.Add(self.file_selection_browse_file, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.file_selection_browse_file.Bind(wx.EVT_BUTTON, self.on_select_browse_click)
self.file_selection_panel_vbox.AddSpacer(60)
self.file_selection_selection_message = wx.StaticText(self.file_selection_panel, style=wx.ALIGN_CENTER)
self.file_selection_selection_message.SetFont(wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.file_selection_selection_message.SetLabel("The following files are selected")
self.file_selection_selection_message.SetForegroundColour((100, 100, 100))
self.file_selection_panel_vbox.Add(self.file_selection_selection_message, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.file_selection_panel_vbox.AddSpacer(30)
self.file_selection_selected_files = wx.ListCtrl(self.file_selection_panel, style = wx.LC_REPORT, size=(-1, 220))
self.file_selection_selected_files.InsertColumn(0, 'File name', width=200)
self.file_selection_selected_files.InsertColumn(1, 'Size (MB)', wx.LIST_FORMAT_LEFT, 100)
self.file_selection_selected_files.InsertColumn(2, 'Location', wx.LIST_FORMAT_LEFT, 300)
self.file_selection_selected_files.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
for i in range(files_selection.files_count):
list_row = self.file_selection_selected_files.InsertItem(i, files_selection.files[i][0])
self.file_selection_selected_files.SetItem(list_row, 1, str(files_selection.files[i][1]))
self.file_selection_selected_files.SetItem(list_row, 2, files_selection.files[i][2])
self.file_selection_panel_vbox.Add(self.file_selection_selected_files, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.file_selection_panel_vbox.AddSpacer(10)
self.file_selection_selected_statistics = wx.StaticText(self.file_selection_panel, style=wx.ALIGN_LEFT)
self.file_selection_selected_statistics.SetFont(wx.Font(12, wx.FONTFAMILY_DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.file_selection_selected_statistics.SetForegroundColour((50, 50, 50))
if files_selection.files_count == 0:
self.file_selection_selected_statistics.SetLabel("No file selected")
elif files_selection.files_count > 1:
self.file_selection_selected_statistics.SetLabel("A total of " + str(round(files_selection.total_size, 2)) + " MB for " + str(
files_selection.files_count) + " selected files")
else:
self.file_selection_selected_statistics.SetLabel("A total of " + str(round(files_selection.total_size, 2)) + " MB for " + str(
files_selection.files_count) + " selected file")
self.file_selection_panel_vbox.Add(self.file_selection_selected_statistics, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.file_selection_droped_files = FileDrop(self.file_selection_selected_files, self.file_selection_selected_statistics)
self.file_selection_selected_files.SetDropTarget(self.file_selection_droped_files)
self.file_selection_panel_vbox.AddSpacer(60)
self.file_selection_clear_selections = wx.Button(self.file_selection_panel, label='Empty file selection')
self.file_selection_clear_selections.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.file_selection_panel_vbox.Add(self.file_selection_clear_selections, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.file_selection_clear_selections.Bind(wx.EVT_BUTTON, self.on_clear_selection_click)
self.file_selection_upload_selections = wx.Button(self.file_selection_panel, label='Upload files')
self.file_selection_upload_selections.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.file_selection_panel_vbox.Add(self.file_selection_upload_selections, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.file_selection_upload_selections.Bind(wx.EVT_BUTTON, self.on_upload_selection_click)
self.file_selection_panel_vbox.AddSpacer(10)
self.file_selection_share_settings = wx.Button(self.file_selection_panel, label='Change share settings')
self.file_selection_share_settings.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.file_selection_panel_vbox.Add(self.file_selection_share_settings, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.file_selection_share_settings.Bind(wx.EVT_BUTTON, self.on_share_settings_click)
def on_select_browse_click(self, e):
global files_selection
FileBrowser = wx.FileDialog(self.file_selection_panel, "Open", "", "", "All files (*.*)|*.*", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE)
FileBrowser.SetDirectory(files_selection.browse_directory)
if FileBrowser.ShowModal() == wx.ID_OK:
filenames = FileBrowser.GetFilenames()
pathname = os.path.abspath(FileBrowser.GetDirectory())
for i in range(len(filenames)):
filepath = os.path.join(pathname, filenames[i])
message_buffer = None
file_s = round((os.path.getsize(filepath) / float(1 << 20)), 2)
if file_s > 99.99:
wx.MessageBox("A file larger than " + str(files_selection.FILE_SIZE_LIMIT) + " MB is not accepted by the server", 'Information', wx.OK | wx.ICON_INFORMATION)
continue
list_row = self.file_selection_selected_files.InsertItem(files_selection.files_count, filenames[i])
self.file_selection_selected_files.SetItem(list_row, 1, str(file_s))
self.file_selection_selected_files.SetItem(list_row, 2, pathname)
if platform == "posix":
files_selection.browse_directory = pathname + "/"
else:
files_selection.browse_directory = pathname + "\\"
files_selection.files[files_selection.files_count] = [filenames[i], file_s, pathname]
files_selection.files_count += 1
files_selection.total_size += file_s
if files_selection.files_count > 1:
message_buffer = "A total of " + str(round(files_selection.total_size, 2)) + " MB for " + str(files_selection.files_count) + " selected files"
else:
message_buffer = "A total of " + str(round(files_selection.total_size, 2)) + " MB for " + str(files_selection.files_count) + " selected file"
self.file_selection_selected_statistics.SetLabel(message_buffer)
FileBrowser.Destroy()
def on_clear_selection_click(self, e):
global files_selection
self.file_selection_selected_files.DeleteAllItems()
files_selection.total_size = 0
files_selection.files_count = 0
files_selection.files.clear()
self.file_selection_selected_statistics.SetLabel("No file selected")
def on_share_settings_click(self, e):
self.file_selection_panel.Hide()
self.main_window_box.Clear()
self.main_window_box.Add(ShareSettingPage(self.main_window, self.main_window_box).share_setting_panel, flag=wx.EXPAND)
def on_upload_selection_click(self, e):
global files_selection
if files_selection.files_count:
self.file_selection_panel.Hide()
self.main_window_box.Clear()
self.main_window_box.Add(UploadPage(self.main_window, self.main_window_box).upload_panel, flag=wx.EXPAND)
else:
wx.MessageBox("Please select one or more files to upload", 'Information', wx.OK | wx.ICON_INFORMATION)
class UploadPage():
def __init__(self, _window, _box):
global files_selection
self.main_window = _window
self.main_window_box = _box
self.upload_panel = wx.Panel(self.main_window, size=(self.main_window.Size[0], self.main_window.Size[1]))
self.upload_panel_vbox = wx.BoxSizer(wx.VERTICAL)
self.upload_panel.SetSizer(self.upload_panel_vbox)
self.upload_panel_vbox.AddSpacer(50)
self.upload_file_message = wx.StaticText(self.upload_panel, style=wx.ALIGN_CENTER)
self.upload_file_message.SetFont(wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.upload_file_message.SetForegroundColour((100, 100, 100))
if files_selection.files_count > 1:
self.upload_file_message.SetLabel("Trying to upload " + str(files_selection.files_count) + " files to cloud")
else:
self.upload_file_message.SetLabel("Trying to upload one file to cloud")
self.upload_panel_vbox.Add(self.upload_file_message, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.upload_panel_vbox.AddSpacer(30)
self.upload_progress_bar = wx.Gauge(self.upload_panel, range=100)
self.upload_panel_vbox.Add(self.upload_progress_bar, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.upload_panel_vbox.AddSpacer(60)
self.upload_files_report = wx.ListCtrl(self.upload_panel, style = wx.LC_REPORT, size=(-1, 220))
self.upload_files_report.InsertColumn(0, 'File', width=200)
self.upload_files_report.InsertColumn(1, 'Upload status', wx.LIST_FORMAT_LEFT, 220)
self.upload_files_report.InsertColumn(2, 'Share code', wx.LIST_FORMAT_LEFT, 300)
self.upload_files_report.InsertColumn(3, 'Share name', wx.LIST_FORMAT_LEFT, 200)
self.upload_files_report.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.upload_panel_vbox.Add(self.upload_files_report, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.upload_panel_vbox.AddSpacer(20)
self.upload_files_statistics = wx.StaticText(self.upload_panel, style=wx.ALIGN_LEFT)
self.upload_files_statistics.SetFont(wx.Font(12, wx.FONTFAMILY_DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.upload_files_statistics.SetForegroundColour((50, 50, 50))
self.upload_files_statistics.SetLabel("Uploaded zero files")
self.upload_panel_vbox.Add(self.upload_files_statistics, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.upload_panel_vbox.AddSpacer(60)
self.upload_stop = wx.Button(self.upload_panel, label='Stop uploading')
self.upload_stop.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.upload_panel_vbox.Add(self.upload_stop, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.upload_stop.Bind(wx.EVT_BUTTON, self.on_stop_upload_click)
self.upload_stopped = False
self.upload_copy_link = wx.Button(self.upload_panel, label='Copy the sharing links')
self.upload_copy_link.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.upload_panel_vbox.Add(self.upload_copy_link, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.upload_copy_link.Bind(wx.EVT_BUTTON, self.on_upload_copy_link_click)
self.upload_copy_link.Disable()
self.upload_panel_vbox.AddSpacer(10)
self.upload_share_new = wx.Button(self.upload_panel, label='Share new files')
self.upload_share_new.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.upload_panel_vbox.Add(self.upload_share_new, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.upload_share_new.Bind(wx.EVT_BUTTON, self.on_share_new_click)
self.file_uploads_required = files_selection.files_count
self.file_upload_number = 0
self.file_upload_thread = None
self.upload_timer = wx.Timer(self.upload_panel)
self.upload_panel.Bind(wx.EVT_TIMER, self.on_upload_timer, self.upload_timer)
self.upload_timer.Start(1000)
def on_upload_timer(self, event):
global server_error
if self.file_upload_number == 0:
self.file_upload_thread = threading.Thread(target=self.upload_file, name='file_upload_thread' + str(self.file_upload_number + 1), args=(self.file_upload_number,))
self.file_upload_thread.daemon = True
self.file_upload_thread.start()
self.file_upload_number += 1
self.upload_stop.Enable()
else:
if self.file_upload_thread.isAlive() == False:
if server_error.occured == True:
wx.MessageBox(server_error.last_message, 'Connection error', wx.OK | wx.ICON_ERROR)
if self.file_upload_number < self.file_uploads_required:
self.file_upload_thread = threading.Thread(target=self.upload_file, name='file_upload_thread' + str(self.file_upload_number + 1), args=(self.file_upload_number,))
self.file_upload_thread.daemon = True
self.file_upload_thread.start()
self.file_upload_number += 1
else:
self.upload_timer.Stop()
self.file_upload_number = 0
self.file_upload_thread = None
self.upload_stop.Disable()
self.upload_file_message.SetLabel("Uploading completed")
self.upload_progress_bar.SetValue(100)
def on_stop_upload_click(self, e):
if self.upload_stopped == False:
self.upload_timer.Stop()
self.upload_stop.SetLabel("Resume uploading")
self.upload_stopped = True
else:
self.upload_timer.Start(1000)
self.upload_stop.SetLabel("Stop uploading")
self.upload_stopped = False
def on_upload_copy_link_click(self, e):
global files_selection, share_server_link
copy_link_buffer = ""
links_count = 0
count = self.upload_files_report.GetItemCount()
if count == 1:
file_c = self.upload_files_report.GetItem(0, col=2)
if file_c.GetText() != "":
file_n = self.upload_files_report.GetItem(0, col=0)
copy_link_buffer += file_n.GetText() + " : " + share_server_link + file_c.GetText()
links_count += 1
else:
for row in range(count):
file_c = self.upload_files_report.GetItem(row, col=2)
if file_c.GetText() != "":
file_n = self.upload_files_report.GetItem(row, col=0)
copy_link_buffer += file_n.GetText() + " : " + share_server_link + file_c.GetText() + "\n"
links_count += 1
if wx.TheClipboard.Open():
wx.TheClipboard.SetData(wx.TextDataObject(copy_link_buffer))
wx.TheClipboard.Close()
wx.MessageBox("Copied " + str(links_count) + " share links to the clipboard", 'Information', wx.OK | wx.ICON_INFORMATION)
else:
wx.MessageBox("Can not access the system clipboard", 'Error', wx.OK | wx.ICON_ERROR)
def on_share_new_click(self, e):
if self.file_upload_thread == None:
global share_goals, files_selection
share_goals.upload_completed = 0
share_goals.upload_size = 0
share_goals.upload_threads_count = 0
files_selection.total_size = 0
files_selection.files_count = 0
files_selection.files.clear()
self.upload_panel.Hide()
self.main_window_box.Clear()
self.main_window_box.Add(FileSelectionPage(self.main_window, self.main_window_box).file_selection_panel,flag=wx.EXPAND)
else:
wx.MessageBox("Please wait for the uploading process to finish", 'Information', wx.OK | wx.ICON_INFORMATION)
def upload_file(self, _file_index):
global share_goals, files_selection, server_error
server_url = 'https://snapshare.salhosengineering.com/shareimage_upload_image.php'
upload_data = {'image_data': (files_selection.files[_file_index][0], open(os.path.join(files_selection.files[_file_index][2], files_selection.files[_file_index][0]), 'rb').read())}
file_n = files_selection.files[_file_index][0]
file_s = files_selection.files[_file_index][1]
files_count = files_selection.files_count
share_title = None
if files_count > 1:
share_title = str(share_goals.title) + " file " + str(_file_index+1)
upload_data['title'] = share_title
upload_data['number_of_downloads'] = str(share_goals.downloads)
upload_data['availability'] = str(share_goals.time)
else:
share_title = str(share_goals.title)
upload_data['title'] = share_title
upload_data['number_of_downloads'] = str(share_goals.downloads)
upload_data['availability'] = str(share_goals.time)
share_code = None
(data, ctype) = requests.packages.urllib3.filepost.encode_multipart_formdata(upload_data)
post_headers = {
"Content-Type": ctype
}
post_data = BufferReader(data, upload_progress, progressbar=self.upload_progress_bar)
try:
r = requests.post(server_url, data=post_data, headers=post_headers, timeout=30)
if r.status_code == requests.codes.ok:
if len(r.text) > 0:
server_reply = r.text.split('.')
if int(server_reply[0]) == 0:
share_code = str(server_reply[2])
job_status = "Completed"
server_error.occured = False
server_error.last_message = "Upload completed"
else:
share_code = ""
share_title = ""
server_error.occured = False
server_error.last_message = str(server_reply[1])
else:
share_code = ""
share_title = ""
server_error.occured = True
server_error.last_message = str("Can not reach to Snap Image Share server")
job_status = server_error.occured == False and server_error.last_message == "Upload completed"
if job_status:
share_goals.upload_size += file_s
share_goals.upload_completed += 1
upload_size = share_goals.upload_size
upload_completed = share_goals.upload_completed
list_row = self.upload_files_report.InsertItem(0, file_n)
if job_status:
self.upload_files_report.SetItem(list_row, 1, "Completed")
self.upload_files_report.SetItem(list_row, 2, share_code)
self.upload_files_report.SetItem(list_row, 3, share_title)
else:
self.upload_files_report.SetItem(list_row, 1, server_error.last_message)
self.upload_files_report.SetItem(list_row, 2, share_code)
self.upload_files_report.SetItem(list_row, 3, share_title)
if upload_completed > 1:
self.upload_files_statistics.SetLabel("Uploaded " + str(round(upload_size, 2)) + " MB of data from " + str(upload_completed) + " files")
else:
self.upload_files_statistics.SetLabel("Uploaded " + str(round(upload_size, 2)) + " MB of data from " + str(upload_completed) + " file")
if upload_completed > 0:
self.upload_copy_link.Enable()
except Exception as e:
server_error.occured = True
server_error.last_message = str(e)
return False
return True
class DownloadPage():
def __init__(self, _window):
global download_selection
self.main_window = _window
self.download_panel = wx.Panel(self.main_window, size=(self.main_window.Size[0], self.main_window.Size[1]))
self.download_panel_vbox = wx.BoxSizer(wx.VERTICAL)
self.download_panel.SetSizer(self.download_panel_vbox)
self.download_panel_vbox.AddSpacer(50)
self.download_file_message = wx.StaticText(self.download_panel, style=wx.ALIGN_CENTER)
self.download_file_message.SetFont(wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.download_file_message.SetForegroundColour((100, 100, 100))
self.download_file_message.SetLabel("Downloads will be saved in the following directory")
self.download_panel_vbox.Add(self.download_file_message, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.download_panel_vbox.AddSpacer(30)
self.download_file_save_location = wx.TextCtrl(self.download_panel, style=wx.TE_LEFT | wx.TE_READONLY | wx.TE_NO_VSCROLL | wx.BORDER_SIMPLE)
self.download_file_save_location.SetFont(wx.Font(12, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_LIGHT))
self.download_file_save_location.SetForegroundColour((100, 100, 100))
self.download_file_save_location.SetBackgroundColour((250, 250, 250))
self.download_file_save_location.SetCursor(wx.STANDARD_CURSOR)
self.download_file_save_location.SetValue(download_selection.download_directory)
self.download_panel_vbox.Add(self.download_file_save_location, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.download_save_location_select = wx.DirPickerCtrl(self.download_panel, path=download_selection.download_directory, message="Select a directory where the downloads will be saved", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DIRP_DEFAULT_STYLE, validator=wx.DefaultValidator)
self.download_save_location_select.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.download_panel_vbox.Add(self.download_save_location_select, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.download_save_location_select.Bind(wx.EVT_DIRPICKER_CHANGED, self.on_location_select_click)
# self.download_panel_vbox.AddSpacer(20)
# self.download_save_location_select = wx.Button(self.download_panel, label='Select different download destination')
# self.download_save_location_select.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
# self.download_panel_vbox.Add(self.download_save_location_select, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
# self.download_save_location_select.Bind(wx.EVT_BUTTON, self.on_location_select_click)
self.download_panel_vbox.AddSpacer(5)
self.download_paste_links = wx.Button(self.download_panel, label='Paste share links')
self.download_paste_links.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.download_panel_vbox.Add(self.download_paste_links, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.download_paste_links.Bind(wx.EVT_BUTTON, self.on_paste_links_click)
self.download_panel_vbox.AddSpacer(60)
self.download_paste_message = wx.StaticText(self.download_panel, style=wx.ALIGN_CENTER)
self.download_paste_message.SetFont(wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.download_paste_message.SetLabel("The following files are available to download")
self.download_paste_message.SetForegroundColour((100, 100, 100))
self.download_panel_vbox.Add(self.download_paste_message, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.download_panel_vbox.AddSpacer(30)
self.download_available_files = wx.ListCtrl(self.download_panel, style=wx.LC_REPORT, size=(-1, 140))
self.download_available_files.InsertColumn(0, 'File title', width=200)
self.download_available_files.InsertColumn(1, 'Downloaded', width=150)
self.download_available_files.InsertColumn(2, 'Downloads remaining', wx.LIST_FORMAT_LEFT, 190)
self.download_available_files.InsertColumn(3, 'Time to expiry', wx.LIST_FORMAT_LEFT, 190)
self.download_available_files.InsertColumn(4, 'Share code', wx.LIST_FORMAT_LEFT, 200)
self.download_available_files.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.download_panel_vbox.Add(self.download_available_files, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.download_panel_vbox.AddSpacer(10)
# self.download_statistics = wx.StaticText(self.download_panel, style=wx.ALIGN_LEFT)
# self.download_statistics.SetFont(wx.Font(12, wx.FONTFAMILY_DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
# self.download_statistics.SetForegroundColour((50, 50, 50))
# self.download_statistics.SetLabel("No file downloaded yet")
# self.download_panel_vbox.Add(self.download_statistics, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.download_progress_bar = wx.Gauge(self.download_panel, range=100)
self.download_panel_vbox.Add(self.download_progress_bar, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=100)
self.download_panel_vbox.AddSpacer(40)
self.download_empty_selection = wx.Button(self.download_panel, label='Empty downloads selection')
self.download_empty_selection.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.download_panel_vbox.Add(self.download_empty_selection, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.download_empty_selection.Bind(wx.EVT_BUTTON, self.on_empty_selection_click)
self.download_panel_vbox.AddSpacer(10)
self.download_the_selection = wx.Button(self.download_panel, label='Download')
self.download_the_selection.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.download_panel_vbox.Add(self.download_the_selection, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=120)
self.download_the_selection.Bind(wx.EVT_BUTTON, self.on_download_click)
self.download_timer = wx.Timer(self.download_panel)
self.download_panel.Bind(wx.EVT_TIMER, self.on_download_info_timer, self.download_timer)
self.download_panel.Bind(wx.EVT_ERASE_BACKGROUND, self.on_erase_background)
def on_download_timer(self, event):
global server_error, download_selection
if self.file_download_number < self.downloads_required:
if self.file_download_thread == None:
self.file_download_thread = threading.Thread(target=self.file_download, name='file_download_thread' + str(self.file_download_number + 1), args=(self.file_download_number,))
self.file_download_thread.daemon = True
self.file_download_thread.start()
self.file_download_number += 1
else:
if self.file_download_thread.isAlive() == False:
if server_error.occured == True:
wx.MessageBox(server_error.last_message, 'Connection error', wx.OK | wx.ICON_ERROR)
self.file_download_thread = threading.Thread(target=self.file_download, name='file_download_thread' + str(self.file_download_number + 1), args=(self.file_download_number,))
self.file_download_thread.daemon = True
self.file_download_thread.start()
self.file_download_number += 1
else:
self.download_timer.Stop()
self.download_panel.Bind(wx.EVT_TIMER, self.on_download_info_timer, self.download_timer)
self.download_the_selection.SetLabel("Download")
self.download_the_selection.Enable()
self.download_paste_links.Enable()
self.download_save_location_select.Enable()
wx.MessageBox("Number of files downloaded: " + str(download_selection.downloads_count), 'Downloading completed', wx.OK | wx.ICON_INFORMATION)
if sys.platform == 'darwin':
subprocess.check_call(['open', download_selection.download_directory])
elif sys.platform == 'linux':
subprocess.check_call(['xdg-open', download_selection.download_directory])
elif sys.platform == 'win32':
subprocess.check_call(['explorer', download_selection.download_directory])
def on_download_info_timer(self, event):
global server_error
# urllib.request.urlopen("https://snapshare.salhosengineering.com/").getcode()
if self.link_thread.isAlive() == False:
if server_error.occured == True:
wx.MessageBox(server_error.last_message, 'Connection error', wx.OK | wx.ICON_ERROR)
self.download_paste_links.SetLabel("Paste share links")
self.download_paste_links.Enable()
self.download_timer.Stop()
def file_download(self, _file_index):
global download_selection, server_error
if download_selection.files[_file_index][4] == False:
return False
try:
r = requests.get('https://snapshare.salhosengineering.com/shareimage_image_download.php', params={'urlcode': str(download_selection.files[_file_index][0])}, stream=True)
if (r.status_code == requests.codes.ok):
if (r.headers.get('content-type') == 'application/octet-stream'):
filename = re.findall(r'"(.*?)"', r.headers.get('content-disposition'))
file_size = float(r.headers.get('content-length'))
downloaded = 0.0
with open(download_selection.download_directory + filename[0], 'wb') as fd:
for chunk in r.iter_content(chunk_size=4096):
fd.write(chunk)
downloaded += float(len(chunk))
percent = int((downloaded / file_size) * 100)
self.download_progress_bar.SetValue(percent)
self.download_available_files.SetItem(_file_index, 1, "Yes")
download_selection.downloads_count += 1
else:
server_error.occured = True
server_error.last_message = "Can not reach to Snap Image Share server"
except Exception as e:
server_error.occured = True
server_error.last_message = str(e)
return False
return True
def on_download_click(self, e):
global download_selection
self.file_download_number = 0
self.downloads_required = download_selection.files_count
self.file_download_thread = None
self.download_paste_links.Disable()
self.download_save_location_select.Disable()
self.download_the_selection.Disable()
self.download_the_selection.SetLabel("Downloading...")
self.download_panel.Bind(wx.EVT_TIMER, self.on_download_timer, self.download_timer)
self.download_timer.Start(1000)
def on_empty_selection_click(self, e):
global download_selection
download_selection.files.clear()
download_selection.files_count = 0
download_selection.downloads_count = 0
self.download_available_files.DeleteAllItems()
def on_paste_links_click(self, e):
text_data = wx.TextDataObject()
if wx.TheClipboard.Open():
success = wx.TheClipboard.GetData(text_data)
wx.TheClipboard.Close()
if success:
self.links = text_data.GetText().splitlines()
if len(self.links) > 0:
self.link_thread = threading.Thread(target=self.link_information, name='link_information_thread')
self.link_thread.daemon = True
self.link_thread.start()
self.download_paste_links.Disable()
self.download_paste_links.SetLabel("Retrieving link details...")
self.download_timer.Start(1000)
else:
wx.MessageBox("Please copy one or more sharing links to the Clipboard", 'Information', wx.OK | wx.ICON_INFORMATION)
else:
wx.MessageBox("Can't paste from the Clipboard\nPlease check the clipboard", 'Clipboard error', wx.OK | wx.ICON_ERROR)
def link_information(self):
global download_selection, server_error
files_found = 0
list_row = download_selection.files_count
for i in range(len(self.links)):
share_code = ""
if (len(self.links[i]) == 55):
share_code = self.links[i]
elif (len(self.links[i]) >= 110):
if self.links[i].find("https") > 0 and self.links[i].find("file=") > 0:
si = self.links[i].find("file=")
share_code = self.links[i][si+5:]
else:
continue
else:
continue
if share_code != "":
try:
r = requests.post('https://snapshare.salhosengineering.com/shareimage_image_link.php', data={'urlcode': str(share_code)}, timeout=30)
if (r.status_code == requests.codes.ok):
server_reply = json.loads(r.text)
if (server_reply['response_code'] == '1'):
download_selection.files[download_selection.files_count] = [share_code, str(server_reply['response']), 0, 0, False]
download_selection.files_count += 1
files_found += 1
else:
download_selection.files[download_selection.files_count] = [share_code, str(server_reply['title']), int(server_reply['downloads']), round(float(server_reply['time_remaining']) / 60, 2) * (60 * 1000), True]
download_selection.files_count += 1
files_found += 1
else:
server_error.occured = True
server_error.last_message = "Can not reach to Snap Image Share server"
except Exception as e:
server_error.occured = True
server_error.last_message = str(e)
return False
for i in range(files_found):
self.download_available_files.InsertItem(list_row, download_selection.files[i][1])
self.download_available_files.SetItem(list_row, 2, str(download_selection.files[i][2]))
et_m = int(download_selection.files[i][3] / 60000)
et_s = math.ceil(((download_selection.files[i][3] / 60000) % 1) * 60)
self.download_available_files.SetItem(list_row, 3, str(int(et_m)) + ":" + str(int(et_s)))
self.download_available_files.SetItem(list_row, 4, download_selection.files[i][0])
return True
def on_location_select_click(self, e):
global download_selection, platform
download_selection.download_directory = self.download_save_location_select.GetPath()
if platform == "posix":
download_selection.download_directory += "/"
else:
download_selection.download_directory += "\\"
self.download_file_save_location.SetValue(download_selection.download_directory)
def on_erase_background(self, e):
global snap_image_share
dc = e.GetDC()
if not dc:
dc = wx.ClientDC(self.share_panel)
rect = self.share_panel.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
dc.DrawBitmap(snap_image_share.back_image, 0, 0)
class AboutPage():
def __init__(self, _window):
global snap_image_share
self.main_window = _window
self.about_panel = wx.Panel(self.main_window, size=(self.main_window.Size[0], self.main_window.Size[1]))
self.about_panel.SetBackgroundColour(wx.WHITE)
self.about_panel_vbox = wx.BoxSizer(wx.VERTICAL)
self.about_panel.SetSizer(self.about_panel_vbox)
self.about_panel_vbox.AddSpacer(50)
self.about_panel_name_text = wx.StaticText(self.about_panel, style=wx.ALIGN_CENTER)
self.about_panel_name_text.SetFont(wx.Font(20, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.about_panel_name_text.SetLabel(snap_image_share.main_window.main_window_title)
self.about_panel_name_text.SetForegroundColour((50, 50, 50))
self.about_panel_vbox.Add(self.about_panel_name_text, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border=40)
self.about_panel_about_text = wx.StaticText(self.about_panel, style=wx.ALIGN_CENTER)
self.about_panel_about_text.SetFont(wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_LIGHT))
self.about_panel_about_text.SetLabel("Snap Image Share is a secure file sharing service provided by\n SALHOS Engineering for easy file sharing")
self.about_panel_about_text.SetForegroundColour((105, 105, 105))
self.about_panel_vbox.Add(self.about_panel_about_text, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border=60)
self.about_panel_license_text = wx.TextCtrl(self.about_panel, style=wx.TE_LEFT | wx.TE_READONLY | wx.TE_MULTILINE | wx.TE_NO_VSCROLL | wx.TE_BESTWRAP | wx.BORDER_NONE, size=(-1, 120))
self.about_panel_license_text.SetFont(wx.Font(12, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_LIGHT))
self.about_panel_license_text.SetForegroundColour((105, 105, 105))
self.about_panel_license_text.SetBackgroundColour((250, 250, 250))
self.about_panel_license_text.SetCursor(wx.STANDARD_CURSOR)
self.about_panel_license_text.SetValue("File hosting online service provided by Snap Image Share is provided for use \"as is\" and is without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall Snap Image Share be liable to any party for any direct or indirect damages.")
self.about_panel_vbox.Add(self.about_panel_license_text, flag=wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=60)
self.about_panel_vbox.AddSpacer(100)
self.about_panel_contact_line = wx.BoxSizer(wx.HORIZONTAL)
self.about_panel_contact_textA = wx.StaticText(self.about_panel, style=wx.ALIGN_CENTER)
self.about_panel_contact_textA.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL))
self.about_panel_contact_textA.SetLabel('Please use ')
self.about_panel_contact_textA.SetForegroundColour((105, 105, 105))
self.about_panel_salhos_email = hl.HyperLinkCtrl(self.about_panel, -1, "salhosengineering@gmail.com", URL="mailto:salhosengineering@gmail.com")
self.about_panel_salhos_email.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL))
self.about_panel_contact_textB = wx.StaticText(self.about_panel, style=wx.ALIGN_CENTER)
self.about_panel_contact_textB.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL))
self.about_panel_contact_textB.SetLabel(' to reach out to us.')
self.about_panel_contact_textB.SetForegroundColour((105, 105, 105))