5
5
Python Version: 3.9.2
6
6
"""
7
7
8
+ import PyPDF2
9
+
8
10
from os .path import basename
9
11
from pathlib import Path
10
12
from tkinter import *
13
15
14
16
# GLOBAL VARIABLES
15
17
file_list = []
18
+
16
19
current_file_index = None
17
20
current_file_dir = None
18
21
current_file_title = None
@@ -24,10 +27,89 @@ def add_files():
24
27
25
28
files = filedialog .askopenfilenames (initialdir = Path .home (), filetypes = [("Compatible Files" , "*.gif *.jpeg *.png *.doc *.docx" ),("All Files" , "*.*" )])
26
29
27
- for file in files :
28
- file_title = basename (file )
29
- file_list .append (dict (title = file_title , file_dir = file ))
30
- file_listbox .insert (END , file_title )
30
+ if files :
31
+ for file in files :
32
+ file_title = basename (file )
33
+ file_list .append (dict (title = file_title , file_dir = file ))
34
+ file_listbox .insert (END , file_title )
35
+
36
+ # Temporary testing
37
+ print (bool (files ))
38
+ print (file_list )
39
+
40
+
41
+ def delete_file ():
42
+ global file_list
43
+
44
+ index = file_listbox .curselection ()
45
+
46
+ if index :
47
+ file_list .pop (index [0 ])
48
+ file_listbox .delete (index [0 ])
49
+ file_listbox .selection_clear (0 , END )
50
+ file_listbox .activate (index [0 ])
51
+ file_listbox .selection_set (index [0 ], last = None )
52
+
53
+ # Temporary testing
54
+ print (bool (index ))
55
+
56
+
57
+ def clear_list ():
58
+ global file_list
59
+
60
+ file_list .clear ()
61
+ file_listbox .delete (0 , END )
62
+
63
+ # Temporary testing
64
+ print (file_list )
65
+
66
+
67
+ def move_up ():
68
+ current_selection = file_listbox .curselection ()
69
+
70
+ if current_selection :
71
+ index = current_selection [0 ]
72
+ if index == 0 :
73
+ pass
74
+ else :
75
+ to_move = file_list [index ]
76
+ file_list .pop (index )
77
+ file_list .insert (index - 1 , to_move )
78
+
79
+ file_listbox .delete (0 , END )
80
+ for file in file_list :
81
+ file_listbox .insert (END , file ['title' ])
82
+
83
+ file_listbox .activate (index - 1 )
84
+ file_listbox .selection_set (index - 1 , last = None )
85
+
86
+ # Temporary testing
87
+ print (file_list )
88
+
89
+
90
+ def move_down ():
91
+ global file_list
92
+
93
+ current_selection = file_listbox .curselection ()
94
+
95
+ if current_selection :
96
+ index = current_selection [0 ]
97
+ if index == len (file_list )- 1 :
98
+ pass
99
+ else :
100
+ to_move = file_list [index ]
101
+ file_list .pop (index )
102
+ file_list .insert (index + 1 , to_move )
103
+
104
+ file_listbox .delete (0 , END )
105
+ for file in file_list :
106
+ file_listbox .insert (END , file ['title' ])
107
+
108
+ file_listbox .activate (index + 1 )
109
+ file_listbox .selection_set (index + 1 , last = None )
110
+
111
+ # Temporary testing
112
+ print (file_list )
31
113
32
114
33
115
# APPLICATION GUI
@@ -37,33 +119,62 @@ def add_files():
37
119
38
120
# GUI frames
39
121
main_frame = Frame (root )
40
- main_frame .pack (pady = 20 )
122
+ main_frame .pack (pady = 10 )
41
123
42
124
files_controls_frame = LabelFrame (main_frame , text = 'File Controls' )
43
125
files_controls_frame .grid (row = 0 , column = 0 , padx = 25 )
44
126
45
127
files_list_frame = LabelFrame (main_frame , text = 'File List' )
46
128
files_list_frame .grid (row = 0 , column = 1 , padx = 25 )
47
129
130
+ list_controls_frame = Frame (files_list_frame )
131
+ list_controls_frame .grid (row = 0 , column = 1 )
132
+
133
+ output_frame = LabelFrame (root , text = 'Output' )
134
+ output_frame .pack (pady = 10 )
135
+
136
+ file_output_frame = Frame (output_frame , padx = 10 , pady = 10 )
137
+ file_output_frame .grid (row = 0 , column = 0 )
138
+
139
+
48
140
# Control buttons for the files_controls_frame
49
- add_file_button = Button (files_controls_frame , text = 'Add File(s)' )
50
- add_file_button .pack (pady = 10 )
141
+ add_file_button = Button (files_controls_frame , text = 'Add File(s)' , command = add_files )
142
+ add_file_button .pack (padx = 10 , pady = 10 )
51
143
52
- delete_file_button = Button (files_controls_frame , text = 'Delete File' )
53
- delete_file_button .pack (pady = 10 )
144
+ delete_file_button = Button (files_controls_frame , text = 'Delete File' , command = delete_file )
145
+ delete_file_button .pack (padx = 10 , pady = 10 )
54
146
55
- clear_list_button = Button (files_controls_frame , text = 'Clear List' )
56
- clear_list_button .pack (pady = 10 )
147
+ clear_list_button = Button (files_controls_frame , text = 'Clear List' , command = clear_list )
148
+ clear_list_button .pack (padx = 10 , pady = 10 )
57
149
58
150
# File listbox and list order controls for the files_list_frame
59
151
file_listbox = Listbox (files_list_frame , width = 40 )
60
152
file_listbox .grid (row = 0 , column = 0 , padx = 10 , pady = 10 )
61
153
154
+ list_control_up = Button (list_controls_frame , text = 'Up' , command = move_up )
155
+ list_control_up .pack (padx = 10 , pady = 10 )
156
+
157
+ list_control_down = Button (list_controls_frame , text = 'Down' , command = move_down )
158
+ list_control_down .pack (padx = 10 , pady = 10 )
62
159
160
+ # Label and entry box for file_name_frame
161
+ file_name_label = Label (file_output_frame , text = 'File Name: ' )
162
+ file_name_label .grid (row = 0 , column = 0 )
63
163
164
+ new_file_name = StringVar ()
165
+ file_name_entry = Entry (file_output_frame , textvariable = new_file_name )
166
+ file_name_entry .grid (row = 0 , column = 1 )
64
167
168
+ # Label, entry, and browse button for file_destination_frame
169
+ file_destination_label = Label (file_output_frame , text = 'Destination: ' )
170
+ file_destination_label .grid (row = 1 , column = 0 )
65
171
172
+ new_file_destination = StringVar ()
173
+ file_destination_entry = Entry (file_output_frame , textvariable = new_file_destination )
174
+ file_destination_entry .grid (row = 1 , column = 1 )
66
175
176
+ file_destination_browse = Button (file_output_frame , text = 'Browse' )
177
+ file_destination_browse .grid (row = 1 , column = 2 )
67
178
68
179
69
180
0 commit comments