-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathload_window.py
95 lines (80 loc) · 3 KB
/
load_window.py
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
from Tkinter import *
import os
from os.path import isfile, isdir, join
from channel import Channel
class LoadWindow(Frame):
def __init__(self, parent=None, mainwindow=None):
Frame.__init__(self, parent)
self.mainwindow = mainwindow
self.path = 'texts'
self.path_list = []
self.full_list = os.listdir(self.path)
self.pane_width = 500
self.selected = {}
self.directory_pane = self.make_directory_pane()
self.sel_pane = self.make_selection_pane()
self.pack()
def make_selection_pane(self):
sel_pane = Frame(self, borderwidth=1, width = self.pane_width, relief=SOLID)
Label(sel_pane, text = "selected paths").grid(row = 0, column = 0)
sel_pane.pack(side = RIGHT)
i = 0
for path in self.selected:
Label(sel_pane, text = path).grid(row = i+1, column = 0)
i += 1
Button(sel_pane, text = "Load", command = self.addSelectedChannels).grid(row = i+1, column = 0)
return sel_pane
def make_directory_pane(self):
dir_pane = Frame(self, borderwidth=1, width = self.pane_width, relief=SOLID)
self.file_list = self.make_file_list(dir_pane)
self.dir_list = self.make_dir_list(dir_pane)
dir_pane.pack(side = LEFT)
return dir_pane
def make_file_list(self, parent):
f_window = Frame(parent, borderwidth=1, relief=SOLID)
Label(f_window, text = "files in /%s" % self.path).grid(row = 0, column = 0)
onlyfiles = [f for f in self.full_list if isfile(join(self.path, f))]
i = 1
for f in onlyfiles:
full_path = self.path + '/' + f
b = Button(f_window, text = f, bd = 1, relief = SUNKEN, command = lambda selpath = full_path: self.selectFile(selpath))
b.grid(row = i, column = 0, sticky=W)
i += 1
f_window.pack(pady = 5, padx = 10)
return f_window
def make_dir_list(self, parent):
d_window = Frame(parent, borderwidth=2, relief=SOLID)
onlydirs = [d for d in self.full_list if isdir(join(self.path, d))]
Label(d_window, text = "directories in /%s" % self.path).pack()
for d in onlydirs:
full_path = self.path + '/' + d
b = Button(d_window, text = d, command = lambda newpath = full_path: self.changePath(newpath))
b.pack(side = TOP, anchor = W)
Button(d_window, text = "back", command = self.upOneLevel).pack()
d_window.pack(pady = 5, padx = 10)
return d_window
def selectFile(self, selpath):
if not selpath in self.selected:
self.selected[selpath] = 1
else:
del self.selected[selpath]
self.refresh()
return
def upOneLevel(self):
self.path = '/'.join(self.path.split('/')[:-1])
self.refresh()
def refresh(self):
self.full_list = os.listdir(self.path)
self.directory_pane.destroy()
self.directory_pane = self.make_directory_pane()
self.sel_pane.destroy()
self.sel_pane = self.make_selection_pane()
def addSelectedChannels(self):
for key in self.selected:
self.path_list.append(key)
self.mainwindow.channels = self.mainwindow.channels_from_paths(self.path_list, self.mainwindow.channels)
self.mainwindow.refresh_keyboards()
self.master.destroy()
def changePath(self, newpath):
self.path = newpath
self.refresh()