6
6
from open import Open
7
7
8
8
class FileListApp :
9
- sdk : SourceSDK
10
- root : tk .Tk
11
-
12
9
def __init__ (self , sourceSDK , root ):
13
10
self .sdk = sourceSDK
14
11
self .root = root
15
12
self .current_folder = self .sdk .selected_folder
16
- self .firstfolder = self .sdk .selected_folder
13
+ self .first_folder = self .sdk .selected_folder
17
14
self .thumbnails = {}
18
15
19
16
self .create_widgets ()
20
17
self .load_files (self .current_folder )
21
18
22
19
def create_widgets (self ):
20
+ self .up_button = ttk .Button (self .root , text = "Up" , command = self .go_up )
21
+ self .up_button .pack (side = "top" , pady = 5 )
22
+
23
+ self .open_dir_button = ttk .Button (self .root , text = "Open Directory" , command = self .open_directory )
24
+ self .open_dir_button .pack (side = "top" , pady = 5 )
25
+
23
26
self .canvas = tk .Canvas (self .root , bg = 'white' )
24
27
self .scroll_y = ttk .Scrollbar (self .root , orient = "vertical" , command = self .canvas .yview )
28
+ self .canvas .configure (yscrollcommand = self .scroll_y .set )
25
29
26
30
self .scroll_frame = ttk .Frame (self .canvas )
27
31
self .scroll_frame .bind (
@@ -32,30 +36,33 @@ def create_widgets(self):
32
36
)
33
37
34
38
self .canvas .create_window ((0 , 0 ), window = self .scroll_frame , anchor = "nw" )
35
- self .canvas .configure (yscrollcommand = self .scroll_y .set )
36
-
37
- self .up_button = ttk .Button (self .root , text = "Up" , command = self .go_up )
38
- self .up_button .pack (pady = 5 )
39
-
40
- self .open_dir_button = ttk .Button (self .root , text = "Open Directory" , command = self .open_directory )
41
- self .open_dir_button .pack (pady = 5 )
42
39
43
40
self .canvas .pack (side = "left" , fill = "both" , expand = True )
44
41
self .scroll_y .pack (side = "right" , fill = "y" )
45
42
43
+ # Bind mouse wheel events to the canvas
44
+ self .canvas .bind ("<Enter>" , self .bind_mouse_wheel )
45
+ self .canvas .bind ("<Leave>" , self .unbind_mouse_wheel )
46
+
47
+ def bind_mouse_wheel (self , event ):
48
+ self .canvas .bind_all ("<MouseWheel>" , self .on_mouse_wheel )
49
+
50
+ def unbind_mouse_wheel (self , event ):
51
+ self .canvas .unbind_all ("<MouseWheel>" )
52
+
53
+ def on_mouse_wheel (self , event ):
54
+ self .canvas .yview_scroll (int (- 1 * (event .delta / 120 )), "units" )
55
+
46
56
def load_files (self , folder ):
47
57
for widget in self .scroll_frame .winfo_children ():
48
58
widget .destroy ()
49
59
50
60
self .current_folder = folder
51
- self .files = [f for f in os .listdir (folder ) if os .path .isdir (os .path .join (folder , f )) or f .endswith ((
52
- ".vmf" , ".txt" , ".cfg" , ".vtf" , ".vmt" , ".qc" , ".mdl" , ".vcd" , ".res" , ".bsp" , "dir.vpk" , ".tga" , ".wav" , ".mp3" , ".sln" ))]
61
+ self .files = [f for f in os .listdir (folder ) if os .path .isdir (os .path .join (folder , f )) or f .endswith (
62
+ ( ".vmf" , ".txt" , ".cfg" , ".vtf" , ".vmt" , ".qc" , ".mdl" , ".vcd" , ".res" , ".bsp" , "dir.vpk" , ".tga" , ".wav" , ".mp3" , ".sln" ))]
53
63
54
- columns = int (self .root .winfo_width () / 150 )
55
- if columns < 1 :
56
- columns = 1
57
- row = 0
58
- col = 0
64
+ columns = max (1 , int (self .root .winfo_width () / 150 ))
65
+ row = col = 0
59
66
60
67
for file in self .files :
61
68
file_path = os .path .join (self .current_folder , file )
@@ -73,15 +80,14 @@ def load_files(self, folder):
73
80
thumbnail_label .place (relx = 0.5 , rely = 0.55 , anchor = 'center' )
74
81
75
82
if os .path .isdir (file_path ):
76
- frame .bind ("<Double-Button-1>" , lambda e , path = file_path : self .load_files (path ))
77
- label .bind ("<Double-Button-1>" , lambda e , path = file_path : self .load_files (path ))
78
- if thumbnail :
79
- thumbnail_label .bind ("<Double-Button-1>" , lambda e , path = file_path : self .load_files (path ))
83
+ bind_func = lambda e , path = file_path : self .load_files (path )
80
84
else :
81
- frame .bind ("<Double-Button-1>" , lambda e , path = file_path : self .open_file (path ))
82
- label .bind ("<Double-Button-1>" , lambda e , path = file_path : self .open_file (path ))
83
- if thumbnail :
84
- thumbnail_label .bind ("<Double-Button-1>" , lambda e , path = file_path : self .open_file (path ))
85
+ bind_func = lambda e , path = file_path : self .open_file (path )
86
+
87
+ frame .bind ("<Double-Button-1>" , bind_func )
88
+ label .bind ("<Double-Button-1>" , bind_func )
89
+ if thumbnail :
90
+ thumbnail_label .bind ("<Double-Button-1>" , bind_func )
85
91
86
92
col += 1
87
93
if col >= columns :
@@ -95,24 +101,30 @@ def load_thumbnail(self, file_path):
95
101
image = None
96
102
base_path = os .path .dirname (os .path .abspath (__file__ ))
97
103
98
- if file_path .endswith (".vtf" ):
99
- image = Image .open (os .path .join (base_path , "icons" , "VTFEdit.png" ))
100
- elif file_path .endswith (".mdl" ):
101
- image = Image .open (os .path .join (base_path , "icons" , "hlmv.png" ))
102
- elif file_path .endswith (".tga" ):
103
- image = Image .open (file_path )
104
- elif file_path .endswith (".vmf" ):
105
- image = Image .open (os .path .join (base_path , "icons" , "hammer.png" ))
106
- elif file_path .endswith (".vcd" ):
107
- image = Image .open (os .path .join (base_path , "icons" , "hlposer.png" ))
108
- elif file_path .endswith (".bsp" ):
109
- image = Image .open (os .path .join (base_path , "icons" , "source.png" ))
104
+ file_icons = {
105
+ ".vtf" : "VTFEdit.png" ,
106
+ ".mdl" : "hlmv.png" ,
107
+ ".tga" : None ,
108
+ ".vmf" : "hammer.png" ,
109
+ ".vcd" : "hlposer.png" ,
110
+ ".bsp" : "source.png" ,
111
+ ".txt" : "txt.png" ,
112
+ ".res" : "txt.png" ,
113
+ ".vmt" : "txt.png" ,
114
+ ".qc" : "txt.png" ,
115
+ ".smd" : "txt.png" ,
116
+ ".cfg" : "txt.png" ,
117
+ ".sln" : "Visual_Studio.png"
118
+ }
119
+
120
+ ext = os .path .splitext (file_path )[1 ]
121
+ if ext in file_icons :
122
+ if file_icons [ext ]:
123
+ image = Image .open (os .path .join (base_path , "icons" , file_icons [ext ]))
124
+ else :
125
+ image = Image .open (file_path )
110
126
elif os .path .isdir (file_path ):
111
127
image = Image .open (os .path .join (base_path , "icons" , "fileexplorer.png" ))
112
- elif file_path .endswith (".txt" ) or file_path .endswith (".res" ) or file_path .endswith (".vmt" ) or file_path .endswith (".qc" ) or file_path .endswith (".smd" ) or file_path .endswith (".cfg" ):
113
- image = Image .open (os .path .join (base_path , "icons" , "txt.png" ))
114
- elif file_path .endswith (".sln" ):
115
- image = Image .open (os .path .join (base_path , "icons" , "Visual_Studio.png" ))
116
128
117
129
if image :
118
130
image .thumbnail ((50 , 50 ))
@@ -126,7 +138,7 @@ def load_thumbnail(self, file_path):
126
138
127
139
def go_up (self ):
128
140
parent_dir = os .path .dirname (self .current_folder )
129
- if parent_dir and self .current_folder != self .firstfolder :
141
+ if parent_dir and self .current_folder != self .first_folder :
130
142
self .load_files (parent_dir )
131
143
132
144
def open_directory (self ):
0 commit comments