-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
173 lines (130 loc) · 5.85 KB
/
main.py
File metadata and controls
173 lines (130 loc) · 5.85 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import pygtk
import os
import logging, sys
import gtk
pygtk.require('2.0')
# ===DEBUGGING SETTINGS===
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
# ===DEBUGGING SETTINGS===
class AcademicProgram:
course_week = {} # Holds the course name and weeks in the dictionary type
checker = []
def add_course(self, widget): # This method adds the course name and weeks to the table
coursenameText = self.coursenameField.get_text()
weeksText = self.weeksField.get_text()
self.course_week[coursenameText] = weeksText # Adds coursename as the key and weeks as the value to a dictionary
logging.debug("\n" + "Added: " + coursenameText + "," + " Weeks: " + str(weeksText))
self.tree_view(False)
self.checker.append(coursenameText)
def grab_path(self, widget):
path_dialog = gtk.FileChooserDialog("Open..",
None,
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
path_dialog.set_default_response(gtk.RESPONSE_OK)
response = path_dialog.run()
if response == gtk.RESPONSE_OK:
print path_dialog.get_filename(), 'selected'
self.browseLocationLabel.set_text(path_dialog.get_filename())
self.location_directory = path_dialog.get_filename()
path_dialog.destroy()
elif response == gtk.RESPONSE_CANCEL:
path_dialog.destroy()
def check_path(self, widget):
if not os.path.exists(self.location_directory):
logging.debug('Path not found: ' + self.location_directory)
# NEEDS TO BE DIALOG WARNING NO DIR FOUND
else:
logging.debug('Path exists: ' + self.location_directory)
self.create_folder(self.location_directory)
def create_folder(self, folder): # Creates the folder for each subject with the inputted week files
for course, week in self.course_week.iteritems():
path = folder + "\\" + course
if not os.path.exists(path):
os.makedirs(path)
for weeks in range(1, int(week) + 1):
path = folder + "\\" + course + "\\Week " + str(weeks)
if not os.path.exists(path):
os.makedirs(path)
logging.debug("Created subfolder for " + course + " for week " + str(weeks))
def tree_view(self, action):
for a in self.course_week.iteritems():
if a in self.checker:
print("Course name already exists")
else:
self.course_week_list_store.clear()
self.data_tree = [(a, b) for a, b in self.course_week.iteritems()]
for item in self.data_tree:
self.course_week_list_store.append(list(item))
self.course_week_tree_view = gtk.TreeView(self.course_week_list_store)
for i, column_names in enumerate(["Course Name", "Weeks"]):
self.render_cell = gtk.CellRendererText()
self.column = gtk.TreeViewColumn(column_names, self.render_cell, text=i)
self.course_week_tree_view.append_column(self.column)
print(self.data_tree)
def __init__(self):
# Create a new window
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Academic Folder Setup")
window.connect("destroy", lambda d: gtk.main_quit())
window.set_size_request(600, 400)
fixed = gtk.Fixed()
window.add(fixed)
fixed.show()
# Tree View
self.data_tree = ()
self.course_week_list_store = gtk.ListStore(str, str)
self.course_week_tree_view = gtk.TreeView(self.course_week_list_store)
for i, column_names in enumerate(["Course Name", "Weeks"]):
self.render_cell = gtk.CellRendererText()
self.column = gtk.TreeViewColumn(column_names, self.render_cell, text=i)
self.course_week_tree_view.append_column(self.column)
fixed.put(self.course_week_tree_view, 300, 40)
self.course_week_tree_view.show()
# Course Name Label
coursenameLabel = gtk.Label(str)
fixed.put(coursenameLabel, 50, 25)
coursenameLabel.set_text("Course name")
coursenameLabel.show()
# Course Name Text Field
self.coursenameField = gtk.Entry(max=0)
fixed.put(self.coursenameField, 50, 50)
self.coursenameField.show()
# Weeks Label
weeksLabel = gtk.Label(str)
fixed.put(weeksLabel, 50, 80)
weeksLabel.set_text("Weeks")
weeksLabel.show()
# Weeks Text Field
self.weeksField = gtk.Entry(max=2)
fixed.put(self.weeksField, 50, 100)
self.weeksField.show()
# Add Button
add_button = gtk.Button("Add")
add_button.connect("clicked", self.add_course)
fixed.put(add_button, 50, 140)
add_button.show()
# Browse Location Label
self.browseLocationLabel = gtk.Label(str)
fixed.put(self.browseLocationLabel, 50, 230)
self.browseLocationLabel.set_text("")
self.browseLocationLabel.show()
# Create Button
folder_button = gtk.Button("Select Folder Location")
folder_button.connect("clicked", self.grab_path)
fixed.put(folder_button, 50, 200)
folder_button.show()
# Create Button
create_button = gtk.Button("Create Folders")
create_button.connect("clicked", self.check_path)
fixed.put(create_button, 50, 290)
create_button.show()
# Display the window
window.show()
def main():
gtk.main()
return 0
if __name__ == "__main__":
AcademicProgram()
main()