11
11
import socket
12
12
import json
13
13
from jsonschema import validate , ValidationError
14
+ from pathlib import Path
14
15
15
16
load_dotenv ()
16
17
@@ -33,8 +34,6 @@ def __init__(self, root):
33
34
# Frames
34
35
left_frame = ctk .CTkFrame (root )
35
36
left_frame .pack (side = tk .TOP , padx = 10 , pady = 10 , fill = tk .X )
36
- right_frame = ctk .CTkFrame (root )
37
- right_frame .pack (side = tk .TOP , padx = 10 , pady = 10 , fill = tk .X )
38
37
39
38
#buttons
40
39
self .get_files_button = ctk .CTkButton (left_frame , text = "📂 Get Files" , command = self .get_files )
@@ -43,9 +42,9 @@ def __init__(self, root):
43
42
self .save_files_button .pack (side = tk .LEFT )
44
43
45
44
46
- self .add_file_button = ctk .CTkButton (right_frame , text = "➕ Add File" , command = self .add_file )
45
+ self .add_file_button = ctk .CTkButton (left_frame , text = "➕ Add File" , command = self .add_file )
47
46
self .add_file_button .pack (side = tk .RIGHT )
48
- self .delete_file_button = ctk .CTkButton (right_frame , text = "❌ Delete File" , command = self .delete_file )
47
+ self .delete_file_button = ctk .CTkButton (left_frame , text = "❌ Delete File" , command = self .delete_file )
49
48
self .delete_file_button .pack (side = tk .RIGHT )
50
49
51
50
@@ -62,10 +61,9 @@ def __init__(self, root):
62
61
self .file_list .heading ("Filename" , text = "Filename" , anchor = tk .W )
63
62
self .file_list .bind ("<Double-1>" , self .on_file_click )
64
63
self .file_list .pack (fill = tk .BOTH , expand = True , side = tk .BOTTOM )
65
-
66
- self .file_states = {}
67
- self .check_for_changes ()
64
+
68
65
self .populate_list (repo_path )
66
+ self .check_for_changes ()
69
67
70
68
def get_files (self ):
71
69
if not repo_url or not git_access_token :
@@ -116,7 +114,6 @@ def populate_list(self, repo_path):
116
114
folders = ['' ]
117
115
118
116
self .file_list .delete (* self .file_list .get_children ())
119
- self .file_states = {}
120
117
121
118
for folder in folders :
122
119
folder_path = os .path .join (repo_path , folder )
@@ -125,26 +122,24 @@ def populate_list(self, repo_path):
125
122
if any (filename .endswith (ext ) for ext in valid_extensions ):
126
123
file_rel_path = os .path .join (folder , filename )
127
124
file_full_path = os .path .join (folder_path , filename )
128
- self .file_states [file_rel_path ] = os .path .getmtime (file_full_path )
129
125
self .file_list .insert ("" , tk .END , values = ("" , file_rel_path ), tags = ('unchanged' ,))
130
126
# tag for modified files
131
- self .file_list .tag_configure ('modified' , background = 'yellow ' )
127
+ # self.file_list.tag_configure('modified', background='light_yellow ')
132
128
133
129
def check_for_changes (self ):
134
- for filename in self .file_states :
135
- file_path = os .path .join (repo_path , filename )
136
- if os .path .exists (file_path ) and os .path .getmtime (file_path ) != self .file_states [filename ]:
137
- # File has been modified
138
- self .file_states [filename ] = os .path .getmtime (file_path )
139
- self .highlight_modified (filename )
140
-
130
+ repo = Repo (repo_path )
131
+ changed_files = [item .a_path for item in repo .index .diff (None )] + repo .untracked_files
132
+ for filename in changed_files :
133
+ self .highlight_modified (filename )
141
134
# Schedule next check
142
135
self .root .after (5000 , self .check_for_changes )
143
136
144
137
def highlight_modified (self , filename ):
145
138
for item in self .file_list .get_children ():
146
- if self .file_list .item (item , 'values' )[1 ] == filename :
147
- self .file_list .item (item , values = ("⭐" , filename ), tags = ('modified' ,))
139
+ treeview_filelist_item = os .path .normpath (os .path .normpath (self .file_list .item (item , 'values' )[1 ]))
140
+ filename_norm = os .path .normpath (filename )
141
+ if treeview_filelist_item == filename_norm :
142
+ self .file_list .item (item , values = ("✏️" , filename ), tags = ('modified' ,))
148
143
break
149
144
150
145
def on_file_click (self , event ):
@@ -174,6 +169,9 @@ def on_file_click(self, event):
174
169
def show_json_dialog (self , json_data , schema , file_path ):
175
170
dialog = ctk .CTkToplevel (self .root )
176
171
dialog .title (schema .get ('title' , 'JSON Data' ))
172
+
173
+ dialog .transient (self .root )
174
+ dialog .focus_set ()
177
175
178
176
self .widget_references = {}
179
177
@@ -286,7 +284,6 @@ def delete_file(self):
286
284
if os .path .exists (file_path ):
287
285
os .remove (file_path )
288
286
self .file_list .delete (selected_item )
289
- del self .file_states [filename ]
290
287
291
288
def add_file (self ):
292
289
extensions = os .environ .get ('file_extensions' , '' )
@@ -312,17 +309,17 @@ def add_file(self):
312
309
313
310
# Add to Treeview
314
311
self .file_list .insert ("" , tk .END , values = ("➕" , filename ), tags = ('new_file' ,))
315
- self .file_states [filename ] = os .path .getmtime (new_file_path )
316
312
317
313
# Configure tag for new files
318
- self .file_list .tag_configure ('new_file' , background = 'lime green' )
314
+ # self.file_list.tag_configure('new_file', background='lime green')
319
315
320
316
root = ctk .CTk ()
321
317
root .geometry ("1024x768" )
322
318
###Treeview Customisation (theme colors are selected)
323
319
bg_color = root ._apply_appearance_mode (ctk .ThemeManager .theme ["CTkFrame" ]["fg_color" ])
324
320
text_color = root ._apply_appearance_mode (ctk .ThemeManager .theme ["CTkLabel" ]["text_color" ])
325
321
selected_color = root ._apply_appearance_mode (ctk .ThemeManager .theme ["CTkButton" ]["fg_color" ])
322
+
326
323
style = ttk .Style ()
327
324
style .theme_use ("default" )
328
325
0 commit comments