-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
1305 lines (921 loc) · 47.2 KB
/
app.py
File metadata and controls
1305 lines (921 loc) · 47.2 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
# -*- coding: utf-8 -*-
from textual.app import App, ComposeResult
from textual.widgets import Sparkline, Tree, ProgressBar, Input, RadioSet, MarkdownViewer, RadioButton, Log, Rule, Collapsible, Checkbox, SelectionList, LoadingIndicator, DataTable, Sparkline, DirectoryTree, Rule, Label, Button, Static, ListView, ListItem, OptionList, Header, SelectionList, Footer, Markdown, TabbedContent, TabPane, Input, DirectoryTree, Select, Tabs
#from textual.widgets.option_list import Option, Separator
from textual.widgets.selection_list import Selection
from textual.screen import Screen, ModalScreen
from textual.await_complete import AwaitComplete
from textual.await_remove import AwaitRemove
from textual.binding import Binding, BindingType
from textual import events
from textual import work
from textual.containers import Horizontal, Vertical, Container, VerticalScroll
from textual import on
from textual.events import Mount
from textual.message import Message
from textual.reactive import reactive
from textual.await_complete import AwaitComplete
from textual.widgets._directory_tree import DirEntry
from textual.widgets._tree import TreeNode
from textual.errors import TextualError
from textual.widgets._list_item import ListItem
from textual.widget import AwaitMount, Widget
from textual.binding import Binding
#import textual_pyfiglet
from textual_pyfiglet import FigletWidget
from textual_plotext import PlotextPlot
from pathlib import Path
from time import sleep
import multiprocessing
import threading
import traceback
import pyfiglet
import uuid
import sys
import copy
import os
from config import *
from utils.ASPC_Log import ASPC_LOG
from utils.ASPC_Snoop import ASPC_SNOOP
from utils.ASPC_Utils import ASPC_UTILS
from utils.ASPC_GUI import ASPC_GUI
from utils.ASPC_Archive import ASPC_ARCHIVE, ASPC_FILL_ARCHIVE
from modal import ModalASPCFilterScreen
#from utils.ASPC_Widgets import HighlightableDirectoryTree, MultiListItem, MultiListView
from utils.ASPC_Widgets import MultiListView, MultiListItem
from styles.theme_file import *
#IMPORT MAIN CLASSES OF CUSTOMIZED WIDGETS FROM TEXTUAL
class HighlightableDirectoryTree(DirectoryTree):
"""DirectoryTree with path highlighting support."""
class PathNotFoundError(TextualError):
def __init__(self, path: Path) -> None:
self.path = path
def highlight_path(self, path: Path) -> AwaitComplete:
"""Highlight a path in the tree.
Highlights a path that may be nested several levels deep in the tree.
This can be done at all times, even when the tree has never been
expanded and thus the directory contents containing the path have not
been cached yet. This method will walk the tree, expanding nodes when
necessary and waiting on the contents before taking another step until
it arrives at the requested path. The node containing the path is
subsequently highlighted.
Args:
path (Path): the path to highlight.
Returns:
AwaitComplete: An optionally awaitable that ensures the path is
highlighted.
"""
return AwaitComplete(self._highlight_path(path))
async def _highlight_path(self, path: Path) -> None:
"""Highlight a path in the tree, while expanding parents.
Args:
path (Path): the path to highlight.
"""
node = await self._expand_parents_and_find_node(path)
self.move_cursor(node)
async def _expand_parents_and_find_node(self, path: Path) -> TreeNode[DirEntry]:
"""Traverse all parts of the path and expand all parents.
This method will traverse all parts of the path and expand all parents
in the tree when necessary. Finally, the node containing the requested
path is returned.
Args:
path (Path): the requested path that must become visible.
Returns:
TreeNode[DirEntry]: the tree node containing the requested path.
"""
node = self.root
for part in Path(path).parts:
node = self._find_node_from_path(node, part)
if not node.children:
await self.reload_node(node)
node.expand()
return node
def _find_node_from_path(
self, parent: TreeNode[DirEntry], path: str
) -> TreeNode[DirEntry]:
"""Search a node's children for a specific path.
The path must be a direct child of the parent. For example, if the
parent's path is /home/alice, then the path may be /home/alice/work, or
/home/alice/documents, but _not_ /home/alice/work/software since that is
not a direct child of /home/alice.
Args:
parent (TreeNode[DirEntry]): the parent node.
path (str): the path to search for.
Raises:
PathNotFoundError: raised when the path is not found.
Returns:
TreeNode[DirEntry]: the node containing the requested path.
"""
root = parent.data.path.absolute()
for node in parent.children:
if str(node.data.path.relative_to(root)) == path:
return node
raise self.PathNotFoundError(path)
class ASPC_HOMEPAGE(ModalScreen):
CSS_PATH = ["styles/layout.tcss"]
def __init__(self, theme_dictionnary):
super().__init__()
self.THEME = theme_dictionnary
self.welcome_page_text = """
[bold]AUSPICIOUS[/bold] VERSION V%s
Writen by [bold][%s]%s[/%s][/bold]
Github Repository → %s
[bold]Don't hesitate to star the Repository :)[/bold]
[italic][bold]Thank you for downloading AUSPICIOUS
Hope it will be useful to you[/bold][/italic]
"""%(VERSION,self.THEME.primary,AUTHOR,self.THEME.primary,REPO)
def compose(self) -> ComposeResult:
with Horizontal(id= "homepage_horizontal_container"):
with Vertical(id = "homepage_vertical_container"):
#yield Static(pyfiglet.figlet_format("AUSPICIOUS", font=ASCII_FONT_HOMEPAGE), classes="static_title_homepage")
yield FigletWidget("AUSPICIOUS", font=ASCII_FONT_HOMEPAGE, justify="center", colors=["$primary", "$secondary", "$background","$panel"], animate=True, gradient_quality=30, id="homepage_title")
with Vertical(id = "homepage_info_container"):
"""
yield Label(str("AUSPICIOUS v%s"%VERSION), classes="homepage_label_info")
yield Label(str("Writen by %s"%AUTHOR), classes="homepage_label_info")
yield Label(str("Star the repository :\n%s"%REPO), classes="homepage_label_info")
"""
yield Static(self.welcome_page_text, id="static_welcome_text")
yield Button("OPEN ASPC", id="homepage_button_open")
def on_button_pressed(self, event:Button.Pressed) -> None:
if event.button.id == "homepage_button_open":
#kill the screen
self.app.pop_screen()
class ModalASPCCreateArchive(ModalScreen, ASPC_UTILS):
CSS_PATH = ["styles/layout.tcss"]
def __init__(self):
super().__init__()
def compose(self) -> ComposeResult:
with VerticalScroll(id = "modal_archive_vertical_container"):
yield Label("No archive detected for this project\nDo you want to create a new one?", id="label_modal_question")
self.input_modal_archive_path = Input(placeholder = "Archive path", id = "input_modal_archive_path")
#self.input_modal_archivelog_path = Input(placeholder = "Archive log path", id="input_modal_archivelog_path")
yield self.input_modal_archive_path
#yield self.input_modal_archivelog_path
with Horizontal(id = "modal_archive_horizontal_container"):
yield Button("Create", id="button_modal_create_archive")
yield Button("Dismiss", id="button_modal_dismiss_archive")
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "button_modal_dismiss_archive":
self.dismiss(True)
if event.button.id == "button_modal_create_archive":
if self.app.current_project_name == None:
self.app.message_function("You must select a project to create an archive!")
return
#check if the path is correct
if os.path.isdir(self.input_modal_archive_path.value)==False:
self.app.message_function("The path isn't valid!", "error")
else:
try:
self.app.project_data[self.app.current_project_name]["ARCHIVE_PATH"] = os.path.join(self.input_modal_archive_path.value, "ASPC_Archive_%s.zip"%os.path.basename(self.app.current_project_name))
#archive log file located next to the archive
#self.app.project_data[self.app.current_project_name]["ARCHIVE_LOG"] = os.path.join(self.input_modal_archive_path.value, "ASPC_ArchiveLog_%s"%os.path.basename(self.app.current_project_name))
#archive log file located in data
self.app.project_data[self.app.current_project_name]["ARCHIVE_LOG"] = os.path.join(os.getcwd(), "data/ASPC_ArchiveLog_%s.json"%os.path.basename(self.app.current_project_name))
#save the content of the new project dictionnary in file
self.save_dictionnary_function()
except Exception as e:
self.app.message_function("Impossible to save the archive path", "error")
self.app.message_function(traceback.format_exc(), "error")
else:
self.app.message_function(os.path.basename(self.app.current_project_name), "success")
self.dismiss(False)
class ModalASPCRemoveProject(ModalScreen):
CSS_PATH = ["styles/layout.tcss"]
def __init__(self):
super().__init__()
def compose(self) -> ComposeResult:
with Vertical(id = "modal_archive_vertical_container"):
yield Label("Before removing the project\nDo you want to restore the content of the project archive")
with Horizontal(id = "horizontal_modal_removearchive"):
yield Button("YES", id="button_modal_removearchive_true")
yield Button("NO", id="button_modal_removearchive_false")
yield Button("QUIT", id="button_modal_removearchive_quit")
def on_button_pressed(self, event:Button.Pressed) -> None:
if event.button.id == "button_modal_removearchive_quit":
self.app.pop_screen()
elif event.button.id == "button_modal_removearchive_true":
self.dismiss(True)
elif event.button.id == "button_modal_removearchive_false":
self.dismiss(False)
class ModalASPCAddToArchive(ModalScreen, ASPC_ARCHIVE, ASPC_FILL_ARCHIVE, ASPC_UTILS):
CSS_PATH = ["styles/layout.tcss"]
def __init__(self, THEME_DICTIONNARY):
self.THEME_DICTIONNARY = THEME_DICTIONNARY
super().__init__()
def compose(self) -> ComposeResult:
with Vertical(id = "vertical_modal_addarchive"):
self.listview_modal_addarchive_filelog = ListView(id = "listview_modal_addarchive_filelog")
yield self.listview_modal_addarchive_filelog
self.listview_modal_addarchive_filelog.border_title = "Archiving log"
yield Button("QUIT", id="button_modal_quit")
def on_button_pressed(self, event:Button.Pressed) -> None:
if event.button.id == "button_modal_quit":
self.app.pop_screen()
def on_mount(self):
#THREAD MODE
"""
try:
self.thread_archiving = threading.Thread(target=self.archiving_thread, args=())
#call the thread
self.thread_archiving.start()
except Exception as e:
self.app.message_function("Impossible to launch archiving thread", "error")
self.app.message_function(traceback.format_exc(), "error")
else:
self.app.message_function("Archiving thread launched", "success")
"""
self.app.message_function("Archiving process started", "notification")
#MULTIPROCESSING MODE
#create instance of the archiving class
with self.app.suspend():
#fill_archive = ASPC_FILL_ARCHIVE(self.app.content_to_archive, self.app.current_project_name, self.app.current_project_data)
fill_archive = ASPC_FILL_ARCHIVE(self.THEME_DICTIONNARY, self.app.user_settings, self.app.content_to_archive, self.app.current_project_name, self.app.project_data)
returned_dictionnary = fill_archive.run()
os.system("pause")
self.app.message_function("Archiving process terminated", "notification")
#load new project data?
self.app.load_project_data_function()
self.app.pop_screen()
"""
if type(returned_dictionnary)==dict:
self.app.current_project_data = returned_dictionnary
self.app.project_data[self.app.current_project_name] = self.app.current_project_data
self.app.message_function("Dictionnary updated")
self.app.current_project_name = self.app.project_list[self.app.listview_projectlist.index][1]
#get the current project data
self.app.current_project_data = self.app.project_data[self.app.current_project_name]
self.app.message_function(type(self.app.current_project_data))
try:
self.save_dictionnary_function()
except Exception as e:
self.app.message_function("Impossible to update the dictionnary\n%s"%traceback.format_exc(), "error")
else:
self.app.message_function("Archiving changes saved successfully", "success")
else:
pass
"""
class ModalASPCHelpCenter(ModalScreen):
CSS_PATH = ["styles/layout.tcss"]
BINDINGS = [
Binding("enter","binding_leavehelp", description="Binding leave help"),
]
def __init__(self, theme_dictionnary):
super().__init__()
self.theme = theme_dictionnary
self.MARKDOWN_HELP = """
[bold][%s]AUSPICIOUS[/%s][/bold] is a program that helps you list items in your projects/folders that are unnecessary,
that are present in large numbers, take up space and that you would like (at least temporarily)
to archive in a compressed file to limit the space used.\n
These files may be important and useful, but you don't necessarily need to keep them on your main hard disk all the time.
[bold][italic][%s]Github link[/%s][/italic][/bold]
https://github.com/DelaporteRobin/ASPC
[bold][italic][%s]Documentation link[/%s][/italic][/bold]
This documentation is not available yet
"""%(self.theme.primary,self.theme.primary, self.theme.primary,self.theme.primary,self.theme.primary, self.theme.primary)
def compose(self) -> ComposeResult:
with Vertical(id = "vertical_help_container"):
yield FigletWidget("AUSPICIOUS HELP", font=ASCII_FONT_HOMEPAGE, justify="center",colors=["$primary", "$secondary", "$background","$panel"], animate=True, gradient_quality=30, id="help_title")
self.markdown_help = Static(self.MARKDOWN_HELP, id="markdown_help")
yield self.markdown_help
yield Button("Leave help", id="button_leavehelp", classes="button_main")
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "button_leavehelp":
self.app.pop_screen()
class ASPC_MAIN(App, ASPC_LOG, ASPC_SNOOP, ASPC_UTILS, ASPC_GUI, ASPC_ARCHIVE):
CSS_PATH = ["styles/layout.tcss"]
BINDINGS = [
Binding("ctrl+j", "binding_fill", description="Binding Fill Selection"),
Binding("!", "binding_welcome", description="Binding Show Welcome Page"),
Binding(
key="question_mark",
action="binding_help",
description="Show help",
key_display="?"
)
]
def __init__(self):
super().__init__()
self.init_control_value = False
#load visual themes in the application
#apply the theme specified in config file
self.THEME_REGISTRY = THEME_REGISTRY
self.THEME_DICTIONNARY = None
for theme in self.THEME_REGISTRY:
self.register_theme(theme)
if theme.name == THEME:
self.THEME_DICTIONNARY = theme
self.theme = THEME
self.global_root_path = Path("/")
self.global_log = []
self.global_log_backup = []
self.selected_item = None
#define the color theme
self.color_theme = "downtown"
self.build_path = None
self.current_focused_folder = Path("/")
self.current_project_name = None
self.current_folder_selected = None
self.current_folder_children_list = []
self.current_folder_list = []
self.current_file_list = []
self.current_file_list_copy = []
self.current_archive_content = []
self.content_to_archive = []
self.project_data = {}
self.project_list = []
self.stop_event_folder = threading.Event()
self.stop_event_file = threading.Event()
self.thread_update_folder_list = threading.Thread()
self.thread_update_file_list = threading.Thread()
self.markdown_base_content = """
Global project informations
"""
#LOAD USER SETTINGS
#OR CREATE IT
#THAT IS THE QUESTION
#first init user settings dictionnary
self.user_settings = {}
self.color_dictionnary = self.theme_variables
def compose(self) -> ComposeResult:
yield Header(show_clock=True)
with Horizontal(id = "horizontal_container_main"):
with VerticalScroll(id = "verticalscroll_container_left"):
#file / folder explorer
#define the 3d project folder
#locate files in folder structure
with Collapsible(title = "Project List", id="collapsible_project_list", collapsed=False):
self.listview_projectlist = ListView(id="listview_projectlist")
yield self.listview_projectlist
#yield Button("CRASHTEST", id="test_log")
yield Button("Remove project from list", id="button_remove_project")
with VerticalScroll(id = "verticalscroll_bottomcontainer_left"):
self.input_global_root_path = Input(placeholder="Starting folder", id="input_global_root_path")
yield self.input_global_root_path
self.directorytree_main = HighlightableDirectoryTree(self.global_root_path, id="directorytree_main")
yield self.directorytree_main
self.label_global_root_path = Label("", id="label_global_root_path")
yield self.label_global_root_path
yield Button("ADD TO LIST AND\nEXPLORE PROJECT", id="button_explore_project", classes="button_main")
yield Button("TEST",id="button_test")
with Horizontal(id = "horizontal_container_center"):
with Vertical(id = "vertical_container_center_left"):
with Collapsible(title = "Folder Display Settings", id="collapsible_folder_display"):
self.checkbox_folder_highlight_children = Checkbox("Highlight children", id = "checkbox_folder_highlight_children")
self.checkbox_find_folder = Checkbox("Find in DirTree", id="checkbox_find_folder")
self.checkbox_folder_children = Checkbox("Sort by children size", id="checkbox_folder_children")
self.checkbox_folder_items = Checkbox("Sort by items contained size", id="checkbox_folder_items")
self.checkbox_folder_gradient = Checkbox("Display size gradient", id = "checkbox_folder_gradient")
self.checkbox_folder_items_gradient = Checkbox("Display items number gradient", id = "checkbox_folder_items_gradient")
yield self.checkbox_folder_highlight_children
yield self.checkbox_find_folder
yield self.checkbox_folder_children
yield self.checkbox_folder_items
yield self.checkbox_folder_gradient
yield self.checkbox_folder_items_gradient
self.progress_folder = ProgressBar(id="progress_folder")
yield self.progress_folder
self.listview_folders = MultiListView(id="listview_folders")
yield self.listview_folders
self.listview_folders.border_title = "Folders list"
with Vertical(id = "vertical_container_center_right"):
with Collapsible(title="File Display Settings", id="collapsible_file_display"):
self.checkbox_file_size = Checkbox("Sort by size", id="checkbox_file_size")
self.checkbox_file_children = Checkbox("Only folder children's", id="checkbox_file_children")
self.checkbox_file_gradient = Checkbox("Display size gradient", id="checkbox_size_gradient")
self.checkbox_file_similarity = Checkbox("Display by similarity", id="checkbox_file_similarity")
self.checkbox_show_archived = Checkbox("Show archived content", id="checkbox_show_archived")
yield self.checkbox_file_similarity
yield self.checkbox_file_size
yield self.checkbox_file_children
yield self.checkbox_file_gradient
yield self.checkbox_show_archived
self.progress_files = ProgressBar(id="progress_files")
yield self.progress_files
self.listview_files = MultiListView(id = "listview_files")
yield self.listview_files
self.listview_files.border_title = "Files list"
with VerticalScroll(id = "verticalscroll_container_right"):
with TabbedContent(id = "tabbedcontent_right"):
with TabPane(title = "LOG", id = "tabpane_log"):
self.listview_log = ListView(id = "listview_log")
yield self.listview_log
with TabPane(title = "ARCHIVE CONTENT", id = "tabpane_archive"):
with Collapsible(title = "ARCHIVE COMPRESSION SETTINGS", id="collapsible_compression_settings"):
#yield Button("Get extension list in project", id="button_extensionlist_get")
self.listview_extensionlist = MultiListView(id="listview_extensionlist")
yield self.listview_extensionlist
self.listview_extensionlist.border_title = "Extension list in project"
yield Button("TEST COMPRESSION METHODS", id="button_compression_test", classes="button_main")
with Collapsible(title = "MODIFY ARCHIVE", id="collapsible_archive_modify"):
with VerticalScroll(id="verticalscroll_archive_modify"):
with Horizontal(id = "tab_horizontal_archivecontent"):
with VerticalScroll(id = "tab_vertical_archivecontent_left"):
self.listview_addarchive_selected = MultiListView(id="listview_addarchive_selected")
yield self.listview_addarchive_selected
self.listview_addarchive_selected.border_title = "Items to archive"
with VerticalScroll(id = "tab_vertical_archiveoptions"):
yield Button("Clear Items in list", id = "button_addarchive_clearlist", classes="button_main")
yield Rule(line_style="heavy")
yield Button("Add selected folder", id="button_addarchive_selectedfolder")
yield Button("Add selected files", id ="button_addarchive_selectedfiles")
yield Rule(line_style="heavy")
self.checkbox_filter_fromselection = Checkbox("Apply only on folder selection",id="checkbox_filter_fromselection")
yield self.checkbox_filter_fromselection
yield Button("Filter window", id="button_addarchive_applyfilter")
yield Rule(line_style="heavy")
yield Button("Add to archive", id="button_add_to_archive", classes="button_main")
with Vertical(id = "tab_vertical_archivecontent_right"):
with Collapsible(id = "collapsible_archive_settings", title="ARCHIVE SETTINGS"):
#self.checkbox_custom_archivepath = Checkbox("Custom archive path", id="checkbox_custom_archivepath")
self.input_archive_path = Input(placeholder="Archive path", id="input_archive_path")
#yield self.checkbox_custom_archivepath
yield self.input_archive_path
with Horizontal(id="horizontal_archive_features"):
yield Button("Move archive", id="button_archive_move", classes="button_main")
with Collapsible(id = "collapsible_archive_features", title="ARCHIVE TOOLS"):
yield Button("Check for Overheads", id="button_archive_check_overhead")
yield Button("FIX OVERHEADS", id="button_archive_fix_overhead", classes="button_main")
self.checkbox_archive_get_below = Checkbox("Select files below", id="checkbox_archive_get_below")
self.checkbox_archive_get_same = Checkbox("Select files in the same folder", id="checkbox_archive_get_same")
#yield self.checkbox_archive_get_below
#yield self.checkbox_archive_get_same
self.listview_archive_content = MultiListView(id="listview_archive_content")
yield self.listview_archive_content
self.listview_archive_content.border_title = "Archive content"
yield Button("RESTORE FILES", id="button_restore_file", classes="button_main")
with TabPane(title = "GLOBAL INFORMATIONS", id = "tabpane_folderinformation"):
#yield Label("folder informations tab")
#self.markdown = Markdown(self.markdown_base_content, id="markdown")
"""
self.markdown_project = Markdown(id = "markdown_project")
yield self.markdown_project
"""
with Collapsible(title = "Markdown Data", id="collapsible_data_markdown"):
with Collapsible(title = "Markdown update settings", id="collapsible_markdown_settings"):
self.checkbox_update_project = Checkbox("Update when selecting project", id="checkbox_update_project")
self.checkbox_update_folder = Checkbox("Update when selecting folder", id="checkbox_update_folder")
self.checkbox_update_file = Checkbox("Update when selecting file", id = "checkbox_update_file")
self.checkbox_update_archive = Checkbox("Show archive informations", id="checkbox_update_archive")
yield self.checkbox_update_project
yield self.checkbox_update_folder
yield self.checkbox_update_file
yield self.checkbox_update_archive
self.markdown_viewer = MarkdownViewer(self.markdown_base_content, id="markdown_viewer")
yield self.markdown_viewer
with Collapsible(title = "Graph Data", id="collapsible_data_graph"):
with VerticalScroll(id = "verticalscroll_collapsible_graphdata"):
"""
self.plotext_filesize = PlotextPlot(id="plotext_filesize")
yield self.plotext_filesize
with Horizontal(id="horizontal_plotext_filesize"):
self.input_plotext_fileitems = Input(type="number", value="0",placeholder="Number of file to display", id="input_plotext_filesize")
yield self.input_plotext_fileitems
yield Button("Show largest files", id="button_plotext_filesize", classes="button_main")
"""
self.plotext_foldersize = PlotextPlot(id="plotext_foldersize")
yield self.plotext_foldersize
with Horizontal(id="horizontal_plotext_foldersize"):
self.input_plotext_foldersize = Input(type="number", value="0", placeholder="Number of folders to display", id="input_plotext_foldersize")
yield self.input_plotext_foldersize
yield Button("Show largest folders", id="button_plotext_foldersize", classes="button_main")
#self.sparkline_extension = Sparkline(id="sparkline_extension")
#self.sparkline_extension.border_title = "Extension data"
self.plotext_extension = PlotextPlot(id="plotext_extension")
yield self.plotext_extension
yield Button("Show extension Data", id="button_graph_extension", classes="button_main")
self.plotext_archive_compression = PlotextPlot(id="plotext_archive_compression")
yield self.plotext_archive_compression
yield Button("Show Compression\nData", id="button_graph_compression", classes="button_main")
self.plotext_project_extension_size = PlotextPlot(id="plotext_extension_size")
yield self.plotext_project_extension_size
yield Button("Show extension ratio in project", id="button_extension_size", classes="button_main")
yield Footer()
def on_mount(self) -> None:
#self.read_log_thread = threading.Thread(target=self.read_log_function, daemon=True,args=())
#self.read_log_thread.start()
#self.message_function(self.theme.primary)
#self.message_function("Log thread activated", "success")
self.load_project_data_function()
self.refresh_project_list_function()
self.load_user_settings_function()
#self.load_archive_content_function()
for checkbox_id, checkbox_value in self.user_settings["WIDGETS"].items():
try:
self.query_one("#%s"%checkbox_id).value = checkbox_value
except Exception as e:
self.message_function("Impossible to load value for widget : %s"%checkbox_id, "error")
#install screens
self.install_screen(ASPC_HOMEPAGE(self.THEME_DICTIONNARY), name="ASPC_HOMEPAGE")
#push the homepage screen
#show_homepage
#self.push_screen("ASPC_HOMEPAGE")
#self.message_function("possible : %s"%self.query_one("#collapsible_data_markdown").allow_maximize)
self.call_after_refresh(self.enable_events)
def enable_events(self) -> None:
"""Activer les événements après que l'interface soit stable"""
#print("Activation des événements")
self.init_control_value = True
def action_binding_fill(self) -> None:
if self.focused.id == "listview_files":
#get the index of the current index selected
#self.message_function(self.listview_files.index)
#check if the index list isn't empty
if len(self.listview_files.index_list) != 0:
#self.message_function("%s ; %s"%(self.listview_files.index_list[-1], self.listview_files.index))
index_range = sorted([self.listview_files.index_list[-1], self.listview_files.index])
for i in range(index_range[0], index_range[1]):
children_item = self.listview_files.children[i]
children_item.highlight_item(children_item)
self.listview_files.index_list.append(i)
#self.message_function("%s ; %s"%(i,children_item))
if self.focused.id == "listview_extensionlist":
if len(self.listview_extensionlist.index_list) != 0:
index_range = sorted([self.listview_extensionlist.index_list[-1], self.listview_extensionlist.index])
for i in range(index_range[0], index_range[1]):
children_item = self.listview_extensionlist.children[i]
children_item.highlight_item(children_item)
self.listview_extensionlist.index_list.append(i)
if self.focused.id == "listview_archive_content":
#get the index of the current index selected
#self.message_function(self.listview_files.index)
#check if the index list isn't empty
if len(self.listview_archive_content.index_list) != 0:
#self.message_function("%s ; %s"%(self.listview_files.index_list[-1], self.listview_files.index))
index_range = sorted([self.listview_archive_content.index_list[-1], self.listview_archive_content.index])
for i in range(index_range[0], index_range[1]):
children_item = self.listview_archive_content.children[i]
children_item.highlight_item(children_item)
#self.message_function("%s ; %s"%(i,children_item))
self.listview_archive_content.index_list.append(i)
#self.message_function(self.listview_files.index_list)
#self.message_function(self.listview_archive_content.index_list)
def action_binding_help(self) -> None:
self.message_function("Call help center", "notification")
self.push_screen(ModalASPCHelpCenter(self.THEME_DICTIONNARY))
def action_binding_welcome(self) -> None:
self.message_function("Show welcome page", "notification")
self.push_screen(ASPC_HOMEPAGE(self.THEME_DICTIONNARY))
def on_key(self, event:events.Key) -> None:
if (event.key == "enter") and (self.focused.id == "listview_files"):
children_item = self.listview_files.children[self.listview_files.index]
children_item.highlight_item(children_item)
if (event.key == "enter") and (self.focused.id == "listview_folders"):
children_item = self.listview_folders.children[self.listview_folders.index]
children_item.highlight_item(children_item)
if (event.key == "enter") and (self.focused.id == "listview_archive_content"):
children_item = self.listview_archive_content.children[self.listview_archive_content.index]
children_item.highlight_item(children_item)
if (event.key == "enter") and (self.focused.id == "listview_extensionlist"):
children_item = self.listview_extensionlist.children[self.listview_extensionlist.index]
children_item.highlight_item(children_item)
def get_tree_children(self, path):
for children in path.children:
self.message_function(children.label)
self.dir_tree_children(children)
def on_checkbox_changed(self, event: Checkbox.Changed) -> None:
#update the value in the dictionnary
if self.init_control_value == True:
widget_dictionnary = self.user_settings["WIDGETS"]
widget_dictionnary[event.control.id] = event.control.value
self.user_settings["WIDGETS"] = widget_dictionnary
#save the new setting file
self.save_user_settings_function()
if (event.control.id == "checkbox_file_similarity"):
self.checkbox_file_size.disabled = self.checkbox_file_similarity.value
if (event.control.id == "checkbox_folder_items") and (self.checkbox_folder_items.value==True):
self.checkbox_folder_children.value = not self.checkbox_folder_items.value
if (event.control.id == "checkbox_folder_children") and (self.checkbox_folder_children.value==True):
self.checkbox_folder_items.value = not self.checkbox_folder_children.value
if event.control.id in ["checkbox_file_size", "checkbox_file_children", "checkbox_size_gradient", "checkbox_file_similarity"]:
self.check_for_file_process_function(checkbox_change=True)
if event.control.id in ["checkbox_folder_items", "checkbox_folder_gradient", "checkbox_folder_children", "checkbox_folder_items_gradient"]:
self.check_for_folder_process_function(True)
def check_for_archive_create_dismiss_function(self, quit_value: bool | None) -> None:
#self.message_function("dismiss value : %s"%quit_value)
if quit_value == False:
try:
self.push_screen(ModalASPCAddToArchive(self.THEME_DICTIONNARY))
except Exception as e:
self.message_function("Impossible to call screen\n%s"%traceback.format_exc(), "error")
else:
self.message_function("Screen called", "success")
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "button_test":
#self.listview_projectlist.children[1].highlighted=True
#self.listview_projectlist.action_select_cursor
self.listview_projectlist.children[1].highlighted=True
self.listview_projectlist.index=1
self.listview_projectlist.post_message(ListView.Selected(self.listview_projectlist, self.listview_projectlist.children[1],1))
if event.button.id == "test_log":
self.message_function(self.current_folder_selected)
if event.button.id == "button_compression_test":
#launch the class to test extension with multiprocessing
with self.suspend():
ASPC_FILL_ARCHIVE_CLASS = ASPC_FILL_ARCHIVE(self.THEME_DICTIONNARY, self.user_settings, self.listview_extensionlist.index_list, self.current_project_name, self.project_data, None, False, False)
returned_compression_dictionnary = ASPC_FILL_ARCHIVE_CLASS.test_compression_method_function()
#print(returned_compression_dictionnary)
#get the type of the returned dictionnary and add it in user settings file
if "COMPRESSION" in self.user_settings:
user_compression_dictionnary = self.user_settings["COMPRESSION"]
#replace values in dictionnary
for extension_name, compression_method in returned_compression_dictionnary.items():
user_compression_dictionnary[extension_name] = compression_method
else:
self.user_settings["COMPRESSION"] = returned_compression_dictionnary
#save user settings
self.save_user_settings_function()
os.system("pause")
if event.button.id == "button_archive_move":
self.move_archive_function()
if event.button.id == "button_graph_extension":
self.load_data_extension()
if event.button.id == "button_plotext_foldersize":
self.load_graph_foldersize_function()
if event.button.id == "button_plotext_filesize":
self.load_graph_filesize_function()
if event.button.id == "button_graph_compression":
self.load_data_compression()
if event.button.id == "button_extension_size":
self.load_data_project_extension_ratio()
if event.button.id == "button_addarchive_applyfilter":
#launch the screen
self.push_screen(ModalASPCFilterScreen())
if event.button.id == "button_archive_check_overhead":
self.check_for_overhead_function()
if event.button.id == "button_archive_fix_overhead":
self.fix_overhead_function()
if event.button.id == "button_remove_project":
#get the project selected
try:
project = list(self.project_data.keys())[self.listview_projectlist.index]
except:
self.message_function("You have to select a project to remove", "error")
else:
self.message_function("Trying to remove this project from data : %s"%project)
#if there is an archive for this project
#ask if the user want to restore archive in project before
#self.remove_project_function()
if "ARCHIVE_PATH" in self.current_project_data:
self.push_screen(ModalASPCRemoveProject(), self.remove_project_function)
else:
self.remove_project_function(False)
if event.button.id == "button_addarchive_clearlist":
self.content_to_archive.clear()
self.listview_addarchive_selected.clear()
self.message_function("Content to archive cleared", "notification")
if event.button.id == "button_add_to_archive":
#CHECK FOR ARCHIVE PATH
archive_exists = self.check_for_archive_function()
if archive_exists == False:
self.push_screen(ModalASPCCreateArchive(), self.check_for_archive_create_dismiss_function)
else:
#self.push_screen(ModalASPCAddToArchive())
self.message_function("Archiving process started", "notification")
#MULTIPROCESSING MODE
#create instance of the archiving class
with self.app.suspend():
#fill_archive = ASPC_FILL_ARCHIVE(self.app.content_to_archive, self.app.current_project_name, self.app.current_project_data)
fill_archive = ASPC_FILL_ARCHIVE(self.THEME_DICTIONNARY, self.user_settings, self.content_to_archive, self.current_project_name, self.project_data)
returned_dictionnary = fill_archive.run()
os.system("pause")
self.message_function("Archiving process terminated", "notification")
#load new project data?
self.load_project_data_function()
#self.pop_screen()
if event.button.id == "button_restore_file":
self.message_function("Starting restore file process...", "notification")
with self.suspend():
self.restore_file_from_archive_function()
#print("Waiting...")
#sleep(4)
#UPDATE THE DATA FILE
#ASPC_SNOOP(self.current_project_name)
os.system("pause")
#reset all listview
self.listview_folders.clear()
self.listview_files.clear()
self.listview_archive_content.clear()
self.current_file_list.clear()
self.current_archive_content.clear()
self.listview_files.index_list.clear()
self.listview_archive_content.index_list.clear()
#reload project data
self.load_project_data_function()
self.message_function("Restore file process done", "notification")
#add archive buttons
if event.button.id == "button_addarchive_selectedfiles":
#get selected files
selected_files_label = []
selected_index = self.listview_files.index_list