-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
2764 lines (2254 loc) · 95.5 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
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
# MIT License
# Copyright (c) [year] [fullname]
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS 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 THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from libgpm import MyGPM # This provides all the main functionalities and database access
import password # This provides the functionality to decrypt data from the database
import threading
from sys import exit
import subprocess # This provides the functionality to open other softwares
import os
import time
import random
# Modules for GUI design
import gi
gi.require_version("Gtk", "3.0")
gi.require_version('Notify', '0.7')
from gi.repository import Gtk, Gio, Gdk, Notify
# CSS styleshee
CSS = b"""
.myNotebook {
background-color: #323232;
}
.myNotebook tab {
color: white;
font-size: 14px;
padding-bottom: 0;
margin: 0
}
.myNotebook tab:checked {
color: white;
transition: 400ms ease-in-out;
background-color: #E95420;
}
.myNotebook tab:hover {
background-color: #3a3a3a;
}
.myNotebook tab:checked:hover {
background-color: #F95620;
}
.home{
background-color: #3a3a3a;
}
"""
app = MyGPM() # Create an object of MyDMS class
unam = '' # A global variable
# Note: the username (GitHub username) is always unique
pword = ''
# Class - Login
# This class creates Login window (Gtk.Window)
# This runs when the user start the app
class Login(Gtk.Window): # Login Window
def __init__(self):
# Create window
Gtk.Window.__init__(self)
self.connect("destroy", Gtk.main_quit)
# Initialise window
self.set_default_size(360,500)
self.set_border_width(5)
self.set_title("GNOME Project Manager")
# Create content
window = self.loginWindow()
self.add(window) # add content to the window
self.show_all()
# Fucntion: create login window
def loginWindow(self): # Create contents
self.window = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20)
# Create widgets
label = Gtk.Label()
label.set_markup("<span size='xx-large'><b>Login</b></span>")
label.set_halign(Gtk.Align.CENTER)
self.window.pack_start(label, True, True, 0)
# A box that containes the login form
form = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
form.set_halign(Gtk.Align.CENTER)
form.set_size_request(250, 300)
# Child elements of the form - username section
username = Gtk.Box(spacing=5)
uname_label = Gtk.Label()
uname_label.set_markup("<b>Username</b>")
uname_input = Gtk.Entry()
uname_input.set_placeholder_text("GitHub Account")
username.pack_start(uname_label, True, True, 0)
username.pack_start(uname_input, True, True, 0)
form.pack_start(username, False, True, 0)
# Child elements of the form - password section
password = Gtk.Box(spacing=8)
pword_label = Gtk.Label()
pword_label.set_markup("<b>Password</b>")
pword_input = Gtk.Entry()
pword_input.set_visibility(False)
pword_input.set_placeholder_text("Password")
password.pack_start(pword_label, True, True, 0)
password.pack_start(pword_input, True, True, 0)
form.pack_start(password, False, True, 0)
# Child elements of the form - Submit button
submit = Gtk.Button(label="Login")
submit.connect("clicked", self.getInfo, uname_input, pword_input)
form.pack_start(submit, False, True, 5)
# Child elements of the form - forgot button linked to `self.forgotPW` method
forgot = Gtk.Button(label="Forgot Password")
forgot.connect("clicked", self.forgotPW)
form.pack_end(forgot, False, True, 0)
# Child elements of the form - register button linked to `self.createAccount` method
register = Gtk.Button(label="Register")
register.set_margin_bottom(10)
register.connect("clicked", self.createAccount)
form.pack_end(register, False, True, 0)
# Add form to the main box
self.window.pack_start(form, True, True, 0)
return self.window
# Function: get the user input and varify the user account for login
def getInfo(self, button, uname_input, pword_input):
global uname
global pword
uname = uname_input.get_text()
pword = pword_input.get_text()
# If the user input correct username and password
if(app.varify(uname, pword)):
self.set_visible(False)
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
else:
# Displat a modal window
dialog = Gtk.MessageDialog(
parent = self,
flags= 0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.CANCEL,
text="Wrong username / password! Please try again!",
)
dialog.run()
dialog.destroy()
# Function: create register window
def createAccount(self, button):
self.register = Gtk.Window(title="GNOME Project Manager - Create Account")
self.register.set_default_size(300, 500)
# Create form
form = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
form.set_halign(Gtk.Align.CENTER)
form.set_size_request(250, 500)
# Child elements of the form - title
label = Gtk.Label()
label.set_markup("<span size='xx-large'>Register</span>")
label.set_size_request(100, 100)
form.pack_start(label, False, True, 0)
# Child elements of the form - username section
username = Gtk.Box(spacing=5)
username.set_valign(Gtk.Align.START)
uname_label = Gtk.Label()
uname_label.set_markup("<b>Username*</b>")
uname_input = Gtk.Entry()
uname_input.set_placeholder_text("GitHub Username")
username.pack_start(uname_label, True, True, 0)
username.pack_start(uname_input, True, True, 0)
form.pack_start(username, False, True, 0)
# A short label with small font under the uname_input
note = Gtk.Label()
note.set_markup("<span size='small'>*Please enter valid GitHub account username*</span>")
# Add box `username` to the form
form.pack_start(note, False, True, 0)
# Child elements of the form - password section
password1 = Gtk.Box(spacing=8)
pword_label1 = Gtk.Label()
pword_label1.set_markup("<b>Password*</b>")
pword_input1 = Gtk.Entry()
pword_input1.set_visibility(False)
pword_input1.set_placeholder_text("Password")
password1.pack_start(pword_label1, True, True, 0)
password1.pack_start(pword_input1, True, True, 0)
password2 = Gtk.Box(spacing=8) # Confirm the password
pword_input2 = Gtk.Entry()
pword_input2.set_visibility(False)
pword_input2.set_placeholder_text("Confirm")
password2.pack_start(pword_input2, True, True, 0)
# Add box `password` to the form
form.pack_start(password1, False, True, 0)
form.pack_start(password2, False, True, 0)
# Add a line break to the form
linebreak = Gtk.Label()
linebreak.set_text("----------------------------------------------------------------")
form.pack_start(linebreak, False, True, 0)
# Other informations: Get the name
name = Gtk.Box(spacing=8)
name_label = Gtk.Label()
name_label.set_markup("<b>Name*</b>")
name_input = Gtk.Entry()
name_input.set_placeholder_text("Name*")
name.pack_start(name_label, True, True, 0)
name.pack_start(name_input, True, True, 0)
form.pack_start(name, False, True, 0)
# Get the email
email = Gtk.Box(spacing=8)
email_label = Gtk.Label()
email_label.set_markup("<b>Email*</b>")
email_input = Gtk.Entry()
email_input.set_placeholder_text("Email Address")
email.pack_start(email_label, True, True, 0)
email.pack_start(email_input, True, True, 0)
form.pack_start(email, False, True, 0)
# Get the GitHub URL
github = Gtk.Box(spacing=8)
glabel = Gtk.Label()
glabel.set_markup("<b>URL</b>")
github_input = Gtk.Entry()
github_input.set_placeholder_text("GitHub Page URL")
github.pack_start(glabel, True, True, 0)
github.pack_start(github_input, True, True, 0)
form.pack_start(github, False, True, 0)
# Child element of the form - submit button linked to `self.recordInfo`
submit = Gtk.Button(label="Confirm")
submit.connect("clicked", self.recordInfo,
uname_input,
pword_input1,
pword_input2,
name_input,
email_input,
github_input
)
form.pack_start(submit, False, True, 0)
# Add the register form to register window
self.register.add(form)
# Display the window
self.register.show_all()
# Function: Take the user input from register window and record them in `main.db`
def recordInfo(self, button, uname_input, pword_input1, pword_input2, name_input, email_input, github_input):
global uname
global pword
uname = uname_input.get_text()
pword1 = pword_input1.get_text()
pword2 = pword_input2.get_text()
name = name_input.get_text()
email = email_input.get_text()
github = github_input.get_text()
# GitHub URL is not required
if (github == ''):
github = None
# Check for the validity of the data
if(uname == '' or pword1 == '' or name == '' or email == ''):
dialog = Gtk.MessageDialog(
parent = self.register,
flags = 0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.CANCEL,
text="Fields with * can not be empty!",
)
dialog.run()
dialog.destroy()
return 0
elif(pword1 != pword2):
dialog = Gtk.MessageDialog(
parent = self.register,
flags = 0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.CANCEL,
text="Please make sure your password matches!",
)
dialog.run()
dialog.destroy()
return 0
elif(len(pword1) <= 6): # Password must be longer than 6 chars (for security)
dialog = Gtk.MessageDialog(
parent = self.register,
flags = 0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.CANCEL,
text="Your password is too short! (length > 6)",
)
dialog.run()
dialog.destroy()
return 0
# Register the account and save the data into `main.db`
check = app.checkAccount(uname)
if check == True:
dialog = Gtk.MessageDialog(
parent = self.register,
flags = 0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.CANCEL,
text="The user account with this GitHub username is registered!",
)
dialog.run()
dialog.destroy()
return 0
app.register(uname, pword1, name, email, github)
pword = pword1
try:
# Note: This requires internet access! An `ApiError` will be raised
app.addUserData(uname)
# Get all the public (open source) repo of the user with his/her GitHub account (username)
app.createRepoDB(uname)
dialog = Gtk.MessageDialog(
parent = self.register,
flags=0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text = "Registered! Please enjoy the app!",
)
except:
dialog = Gtk.MessageDialog(
parent = self.register,
flags=0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text = """
Registered! Please restart the app!
Note: Failed loading repo data (this requires Internet access).
""",
)
dialog.run()
dialog.destroy()
self.set_visible(False)
self.register.set_visible(False)
window = MyWindow()
window.connect("destroy", Gtk.main_quit)
window.show_all()
# Function: Recover the password
def forgotPW(self, button):
# Create window
self.window = Gtk.Window()
# Initialise the window
self.window.set_title("GNOME Project Manager - Forgot Password")
self.window.set_default_size(350, 250)
# Create form (vertical box)
form = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
form.set_halign(Gtk.Align.CENTER)
form.set_size_request(300, 200)
# Child element of the form - label
title = Gtk.Label()
title.set_markup("<span size='xx-large'>Recover Password</span>")
title.set_size_request(100, 100)
form.pack_start(title, False, True, 0)
# Chile element of the form - username section
uname_input = Gtk.Box()
uname_input_label = Gtk.Label(label="Username")
uname_input_field = Gtk.Entry()
uname_input_field.set_placeholder_text("GitHub Account")
uname_input.pack_start(uname_input_label, False, True, 15)
uname_input.pack_start(uname_input_field, True, True, 0)
form.pack_start(uname_input, False, True, 0)
# Child element of the form - email section
email_input = Gtk.Box()
email_input_label = Gtk.Label(label="Registerd Email")
email_input_field = Gtk.Entry()
email_input_field.set_placeholder_text("Email")
email_input.pack_start(email_input_label, False, True, 15)
email_input.pack_start(email_input_field, False, True, 0)
form.pack_start(email_input, False, True, 0)
# Child element of the form - sumbit button linked to `selc.recover` method
submit = Gtk.Button(label="Sumbit")
submit.connect("clicked", self.recover, email_input_field, uname_input_field)
form.pack_start(submit, False, True, 20)
# Add the form to the window and display the window
self.window.add(form)
self.window.show_all()
# Function: Get the user's password with email and username (highly unsecure!)
def recover(self, button, email_input, uname_input):
email = email_input.get_text()
uname = uname_input.get_text()
# Get the password
password = app.recoverAccount(email, uname)
# If there is a password that matches the username and email
if (password != None):
dialog = Gtk.MessageDialog(
parent = self.window,
flags = 0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text=f"Your password is: {password}",
)
else:
dialog = Gtk.MessageDialog(
parent = self.window,
flags = 0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.OK,
text=f"Incorrect email address",
)
dialog.run()
dialog.destroy()
self.window.destroy()
##########################################################################
# Class - MyWindow
# This class creates Main window (Gtk.Window)
# This window contains all the child elements
class MyWindow(Gtk.Window): # Main app
def __init__(self):
varify()
Gtk.Window.__init__(self)
self.set_default_size(1100,650)
# Set stylesheet
cssprovider = Gtk.CssProvider()
cssprovider.load_from_data(CSS)
screen = Gdk.Screen.get_default()
stylecontext = Gtk.StyleContext()
stylecontext.add_provider_for_screen(screen, cssprovider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
# Create headbar
hb = Gtk.HeaderBar()
hb.set_show_close_button(True)
hb.props.title = f"GNOME Project Manager - {uname}"
# Child element of the headbar - about button linked to `self.about`
about_button = Gtk.Button()
about_button.connect("clicked", self.about)
about_icon = Gio.ThemedIcon(name="dialog-information-symbolic")
about_image = Gtk.Image.new_from_gicon(about_icon, Gtk.IconSize.BUTTON)
about_button.add(about_image)
hb.pack_end(about_button)
refresh = Gtk.Button(label="Refresh App")
refresh.connect("clicked", self.refreshApp)
hb.pack_start(refresh)
auto_refresh = Gtk.CheckButton(label="auto refresh")
auto_refresh.connect("toggled", self.autoRefresh)
hb.pack_start(auto_refresh)
status = app.getAutoRefresh(uname)
if status == 1:
auto_refresh.set_active(True)
else:
auto_refresh.set_active(False)
# Set the titlebar of the window to hb
self.set_titlebar(hb)
# Create Notebook
self.notebook = Gtk.Notebook()
self.notebook.set_tab_pos(Gtk.PositionType.LEFT)
self.notebook.set_scrollable(True)
# Add CSS class to Notebook
notebook_style = self.notebook.get_style_context()
notebook_style.add_class("myNotebook")
# Get data
for i in app.getUsersData(uname):
self.data = i
####
# Create self.notebook page(1)
page1 = Home(self.data, self)
# Add CSS class to page1
home_style = page1.get_style_context()
home_style.add_class("home")
# Set the name of the page as `Home`
home = Gtk.Label(label="Home")
home.set_size_request(150, 50)
home.set_xalign(0)
self.notebook.append_page(page1, home)
####
# Create self.notebook page(2)
page2 = Repo(self.data, self)
# Add CSS class to page2
page2_style = page2.get_style_context()
page2_style.add_class("home")
# Set the name of the page as `My Repos`
title = Gtk.Label(label="\nMy Repos\n")
title.set_xalign(0)
self.notebook.append_page(page2, title)
####
# Create self.notebook page(3)
page3 = Working(self)
# Add CSS class to page3
page3_style = page3.get_style_context()
page3_style.add_class("home")
# Set the name of the page as `Working`
title = Gtk.Label(label="\nWorking\n")
title.set_xalign(0)
self.notebook.append_page(page3, title)
####
# Create self.notebook page(4)
page4 = Idea(self.notebook, self)
# Add CSS class to page4
page4_style = page4.get_style_context()
page4_style.add_class("home")
# Set the name of the page as `My Repos`
title = Gtk.Label(label="__________________________\n\nRecord Project Ideas\n")
title.set_xalign(0)
self.notebook.append_page(page4, title)
# Add self.notebook widget to the main window
idea_count = app.getIdeaCount(uname)
for i in range(1, idea_count+1):
for j in app.getIdeaData(i):
data = j
if (data[0]):
page = IdeaPage(data, self)
page_style = page.get_style_context()
page_style.add_class("home")
title = Gtk.Label(label=('\n' + f"Project Idea {i}" + '\n'))
title.set_xalign(0)
self.notebook.append_page(page, title)
self.add(self.notebook)
self.connect("destroy", Gtk.main_quit)
# Function: create AboutDialog that displayed on the title bar
def about(self, button):
aboutdialog = Gtk.AboutDialog()
author = ["MengZe"]
copyright = "© MengZe 2020"
version = "Version 1.0"
# Set info
aboutdialog.set_program_name("GNOME Project Manager")
aboutdialog.set_authors(author)
aboutdialog.set_copyright(copyright)
aboutdialog.set_version(version)
aboutdialog.set_website("https://github.com/openMengZe")
aboutdialog.set_website_label("My GitHub")
aboutdialog.set_title("About")
aboutdialog.show_all()
def refreshApp(self, button, page=''):
if page == '':
page = self.notebook.get_current_page()
self.set_visible(False)
window = MyWindow()
window.connect("destroy", Gtk.main_quit)
window.show_all()
window.set_page(page)
def set_page(self, page):
self.notebook.set_current_page(page)
def autoRefresh(self, checkbutton):
if(checkbutton.get_active()):
status = 1
else:
status = 0
app.updateAutoRefresh(uname, status)
##########################################################################
# Class - Home
# This class creates Home page (Gtk.Box)
class Home(Gtk.Box):
def __init__(self, data, main):
varify()
# Create window (vertical box)
Gtk.Box.__init__(self)
self.main = main
self.set_orientation(Gtk.Orientation.VERTICAL)
self.set_spacing(15)
# Get data from `main.db` using MyDMS class
self.data = data
self.repo_count = app.getRepoCount(uname)
# Set title of the window
title = Gtk.Label()
title.set_markup(f"<span size='xx-large'> Welcome Back, {self.data[4]}! </span>")
title.set_margin_top(40)
self.pack_start(title, False, True, 0)
# Create a vertical box container for containing stack and stack_switcher
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
vbox.set_border_width(10)
# Create a Stack widget
stack = Gtk.Stack()
stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
stack.set_transition_duration(1000)
# Child element of the stack - Profile window
profile = self.profile()
stack.add_titled(profile, "profile", "Profile")
# Child element of the stack - Status window(worling)
edit = self.editProfile(self.data)
stack.add_titled(edit, "edit", "Edit Profile")
# Create a stack_switcher
stack_switcher = Gtk.StackSwitcher()
stack_switcher.set_stack(stack)
hbox = Gtk.Box(spacing=3)
hbox.pack_start(stack_switcher, False, True, 0)
delete = Gtk.Button(label="Delete Account")
delete.connect("clicked", self.deleteWindow, uname)
hbox.pack_end(delete, False, True, 5)
# Add the stack and stack_switcher widgets to the container
vbox.pack_start(hbox, False, True, 0)
vbox.pack_start(stack, True, True, 0)
# Add the container to the window
self.pack_start(vbox, True, True, 0)
def guide(self, button):
Guide()
def deleteWindow(self, button, uname):
window = Gtk.Window()
window.set_title("GNOME Project Manager - Delete Account")
window.set_default_size(550, 350)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
vbox.set_halign(Gtk.Align.CENTER)
title = Gtk.Label()
title.set_markup("<span size='x-large'>Delete Account</span>")
title.set_margin_top(20)
vbox.pack_start(title, False, True, 15)
note = Gtk.Label()
note.set_markup("<i>Are you sure you want to delete this account?\nThis will delete all your data! permanently</i>")
vbox.pack_start(note, False, True, 0)
line_separator = Gtk.Separator()
vbox.pack_start(line_separator, False, True, 5)
confirm_note = Gtk.Label()
confirm_note.set_markup("<b>Please type: 'Delete my account'</b>")
vbox.pack_start(confirm_note, False, True, 5)
message_input = Gtk.Entry()
message_input.set_placeholder_text("Confirm Message")
vbox.pack_start(message_input, False, False, 0)
confirm = Gtk.Button(label="Confirm")
confirm.connect("clicked", self.deleteAccount, message_input, window)
vbox.pack_start(confirm, False, True, 10)
window.add(vbox)
window.show_all()
def deleteAccount(self, button, message_input, window):
message = message_input.get_text()
global run
if message == "Delete my account":
app.deleteAccount(uname)
dialog = Gtk.MessageDialog(
parent=window,
flags=0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text = '''
Account deleted!
'''
)
dialog.run()
dialog.destroy()
run = False
exit()
return run
else:
dialog = Gtk.MessageDialog(
parent=window,
flags=0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text = '''
The confirm message is wrong.
Please try again!
'''
)
dialog.run()
dialog.destroy()
# Function: create Profile window for the Home Page (stack)
def profile(self):
# Create a vertical box container
my_profile = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
# Create a container (listbox) that contains all the data using `self.makeProfile` method
listbox = self.makeProfile(
["GitHub Account:", "GitHub URL:", "Repos:", "Followers:", "Email Address:", "Location:", "Company:", "Register Date:"],
[self.data[0], self.data[1], self.repo_count, self.data[6], self.data[2], self.data[8], self.data[7], self.data[3]]
)
# Add the containerto the box
my_profile.pack_start(listbox, True, True, 0)
return my_profile
# Function: create ListBox and ListBoxRows with given data
def makeProfile(self, item, content):
window = Gtk.ScrolledWindow()
# Create listbox
listbox = Gtk.ListBox()
listbox.set_selection_mode(Gtk.SelectionMode.NONE)
# Create rows for all data provided
for i in range(len(item)):
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=20)
row.add(hbox)
# Set label of the row
item_label = Gtk.Label(label=('\n' + item[i] + '\n'), xalign=0)
content_label = Gtk.Label()
# If the data is a link (app.url_validate == True), display it as a link
if(app.url_validate(str(content[i])) or i == 4):
content_label.set_markup(
f'<a href="/">{content[i]}</a>'
)
else:
content_label.set_label(str(content[i]))
# Add both label and content to the same row
hbox.pack_start(item_label, True, True, 10)
hbox.pack_start(content_label, False, True, 10)
# Add the row to listbox
listbox.add(row)
window.add(listbox)
return window
def editProfile(self, data):
# Create form
form = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
form.set_margin_top(30)
name = Gtk.Box(spacing=8)
name_label = Gtk.Label()
name_label.set_markup("<b>Name* </b>")
name_input = Gtk.Entry()
name_input.set_placeholder_text("Name*")
try:
name_input.set_text(data[4])
except:
pass
name.pack_start(name_label, False, True, 40)
name.pack_start(name_input, True, True, 40)
form.pack_start(name, False, True, 0)
# Get the email
email = Gtk.Box(spacing=8)
email_label = Gtk.Label()
email_label.set_markup("<b>Email* </b>")
email_input = Gtk.Entry()
email_input.set_placeholder_text("Email Address")
try:
email_input.set_text(data[2])
except:
pass
email.pack_start(email_label, False, True, 40)
email.pack_start(email_input, True, True, 40)
form.pack_start(email, False, True, 0)
# Get the GitHub URL
github = Gtk.Box(spacing=8)
github_label = Gtk.Label()
github_label.set_markup("<b>URL </b>")
github_input = Gtk.Entry()
github_input.set_placeholder_text("GitHub Page URL")
try:
github_input.set_text(data[1])
except:
pass
github.pack_start(github_label, False, True, 40)
github.pack_start(github_input, True, True, 40)
form.pack_start(github, False, True, 0)
location = Gtk.Box(spacing=8)
location_label = Gtk.Label()
location_label.set_markup("<b>Location </b>")
location_input = Gtk.Entry()
location_input.set_placeholder_text("Location")
try:
location_input.set_text(data[8])
except:
pass
location.pack_start(location_label, False, True, 40)
location.pack_start(location_input, True, True, 40)
form.pack_start(location, False, True, 0)
company = Gtk.Box(spacing=8)
company_label = Gtk.Label()
company_label.set_markup("<b>Company</b>")
company_input = Gtk.Entry()
company_input.set_placeholder_text("Company")
try:
company_input.set_text(data[7])
except:
pass
company.pack_start(company_label, False, True, 40)
company.pack_start(company_input, True, True, 40)
form.pack_start(company, False, True, 0)
# Child element of the form - submit button linked to `self.recordInfo`
submit = Gtk.Button(label="Confirm")
submit.connect("clicked", self.updateData, name_input, github_input, email_input, location_input, company_input)
form.pack_start(submit, False, True, 0)
return form
def updateData(self, button, name_input, github_input, email_input, location_input, company_input):
name = name_input.get_text()
github = github_input.get_text()
email = email_input.get_text()
location = location_input.get_text()
company = company_input.get_text()
# Check for the validity of the data
if(name == '' or email == ''):
dialog = Gtk.MessageDialog(
parent = MyWindow(),
flags= 0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.CANCEL,
text = "Fields with * can not be empty!",
)
dialog.run()
dialog.destroy()
return 0
try:
app.updateUserData(uname, name, email, github, location, company)
dialog = Gtk.MessageDialog(
parent = MyWindow(),
flags= 0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text = 'Profile Updated!'
)
dialog.run()
dialog.destroy()
MyWindow.refreshApp(self.main, '')
except:
dialog = Gtk.MessageDialog(
parent = MyWindow(),
flags= 0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.CANCEL,
text = "Failed updating data!",
)
dialog.run()
dialog.destroy()
# Class - Repo
# This class creates Repo page (Gtk.Box)
class Repo(Gtk.Box):
# Function: create repo window for My Repos page
def __init__(self, data, main):
varify()
Gtk.Box.__init__(self)
self.main = main
self.set_orientation(Gtk.Orientation.VERTICAL)
self.set_spacing(15)
self.data = data
title = Gtk.Label()
title.set_markup(f"<span size='xx-large'> {self.data[0]}'s Repos! </span>")
title.set_margin_top(40)
self.pack_start(title, False, True, 0)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
vbox.set_border_width(10)
stack = Gtk.Stack()
stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
stack.set_transition_duration(1000)
repo_window = self.createRepoWindow()
stack.add_titled(repo_window, "repo", "Repos")
stack_switcher = Gtk.StackSwitcher()
stack_switcher.set_stack(stack)
button = Gtk.Button()
button.connect("clicked", self.repoNote)
icon = Gio.ThemedIcon(name="dialog-information-symbolic")
image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
button.add(image)
hbox = Gtk.Box(spacing=15)
hbox.pack_start(stack_switcher, False, True, 0)
hbox.pack_start(button, False, True, 0)
self.spinner = Gtk.Spinner()
hbox.pack_end(self.spinner, False, True, 0)
refresh = Gtk.Button(label="Refresh Repo")
refresh.connect("clicked", self.refreshData, uname)
hbox.pack_end(refresh, False, True, 5)
vbox.pack_start(hbox, False, True, 0)
vbox.pack_start(stack, True, True, 0)
self.pack_start(vbox, True, True, 0)
def refreshData(self, button, uname):
self.spinner.start()
try:
app.refreshData(uname)
refresh = app.getAutoRefresh(uname)
if refresh == 1:
self.spinner.stop()
MyWindow.refreshApp(self.main, '')
dialog = Gtk.MessageDialog(
parent = MyWindow(),
flags = 0,
message_type = Gtk.MessageType.INFO,
buttons = Gtk.ButtonsType.OK,
text = '''
Data refreshed!
Please refresh the app to load new data!
'''
)
dialog.run()
dialog.destroy()
except:
dialog = Gtk.MessageDialog(
parent = MyWindow(),
flags = 0,
message_type = Gtk.MessageType.INFO,
buttons = Gtk.ButtonsType.OK,
text = '''
This process requires internet access!
Please try again later!
'''
)
dialog.run()
dialog.destroy()
self.spinner.stop()
def repoNote(self, button):
dialog = Gtk.MessageDialog(
parent=MyWindow(),
flags= 0,