|
5 | 5 | """ Graphical User Interface (GUI) for Nescient. """ |
6 | 6 | # TODO: Options, documentation, better path awareness, working directory changes, non-blocking benchmarking, About |
7 | 7 | import os |
| 8 | +import sys |
8 | 9 | import glob |
9 | 10 | import webbrowser |
10 | 11 | from tkinter import Tk, Label, PhotoImage, OptionMenu, StringVar, Frame, Text, Scrollbar, RIGHT, Y, WORD, DISABLED, \ |
@@ -210,7 +211,7 @@ def close(self): |
210 | 211 |
|
211 | 212 | # The main UI |
212 | 213 | class NescientUI(Tk): |
213 | | - def __init__(self): |
| 214 | + def __init__(self, paths=None): |
214 | 215 | Tk.__init__(self) |
215 | 216 | self.title('Nescient ' + __version__) |
216 | 217 | try: |
@@ -239,6 +240,8 @@ def __init__(self): |
239 | 240 | self.grid_columnconfigure(1, weight=1) |
240 | 241 | # Set up initial variables |
241 | 242 | self.paths = [] |
| 243 | + if paths: |
| 244 | + self.add_files('auto', paths) |
242 | 245 | self.state = 'ready' |
243 | 246 | self.open_dir = os.getcwd() |
244 | 247 |
|
@@ -278,22 +281,24 @@ def threaded_task(self, func, *args, **kwargs): |
278 | 281 | self.state = 'ready' |
279 | 282 | return return_value |
280 | 283 |
|
281 | | - def add_files(self, choice): |
| 284 | + def add_files(self, choice, paths=None): |
282 | 285 | self.status.config(text='Adding files...') |
| 286 | + self.global_widget_state(DISABLED) |
283 | 287 | if choice == 'glob': |
284 | 288 | pattern = self.path_select.entry.get() |
285 | 289 | paths = [path for path in glob.glob(pattern, recursive=True) if os.path.isfile(path)] |
286 | | - else: # choice == 'dialog': |
| 290 | + elif choice == 'dialog': |
287 | 291 | paths = list(filedialog.askopenfilenames(initialdir=self.open_dir, parent=self, title='Add files')) |
288 | 292 | if paths: |
289 | 293 | self.open_dir = os.path.dirname(paths[0]) |
290 | 294 | for path in paths: |
291 | 295 | if not self.paths: |
292 | 296 | self.text.clear() |
293 | 297 | if path not in self.paths: |
294 | | - self.text.insert(path + '\n', path.replace(' ', '?')) |
| 298 | + self.text.insert(path + '\n', 'path%s' % len(self.paths)) |
295 | 299 | self.paths.append(path) |
296 | 300 | self.status.config(text='Ready.') |
| 301 | + self.global_widget_state(NORMAL) |
297 | 302 |
|
298 | 303 | def clear_paths(self): |
299 | 304 | self.status.config(text='Clearing paths...') |
@@ -323,10 +328,10 @@ def password_failed(self, password): |
323 | 328 |
|
324 | 329 | def packing_loop(self, choice, packer): |
325 | 330 | self.title('Nescient %s - %s' % (__version__, 'Packing' if choice == 'pack' else 'Unpacking')) |
326 | | - for path in self.paths: |
| 331 | + for path_num, path in enumerate(self.paths): |
327 | 332 | try: |
328 | 333 | # Color and scroll to the tag |
329 | | - tag = path.replace(' ', '?') |
| 334 | + tag = 'path%s' % path_num |
330 | 335 | self.text.text.see('%s.first' % tag) |
331 | 336 | self.text.tag_config(tag, background='#369a9d') |
332 | 337 | # Fix the out path and set up display text |
@@ -389,8 +394,12 @@ def benchmark_all_modes(self): |
389 | 394 | self.mode_select.display_rate_info() |
390 | 395 | self.status.config(text='Ready') |
391 | 396 | self.title('Nescient ' + __version__) |
| 397 | + |
| 398 | +def main(): |
| 399 | + paths = sys.argv[1:] if len(sys.argv) > 1 else None |
| 400 | + gui = NescientUI(paths) |
| 401 | + gui.mainloop() |
392 | 402 |
|
393 | 403 |
|
394 | 404 | if __name__ == '__main__': |
395 | | - gui = NescientUI() |
396 | | - gui.mainloop() |
| 405 | + main() |
0 commit comments