-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainschedule.py
240 lines (200 loc) · 8.77 KB
/
trainschedule.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#! /usr/bin/env python
#
# GUI module generated by PAGE version 4.7
# In conjunction with Tcl version 8.6
# Apr 23, 2016 04:43:07 AM
import sys
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
import trainschedule_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = Tk()
top = Train_Schedules (root)
trainschedule_support.init(root, top)
root.mainloop()
w = None
def create_Train_Schedules(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = Toplevel (root)
top = Train_Schedules (w)
trainschedule_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Train_Schedules():
global w
w.destroy()
w = None
class Train_Schedules:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#d9d9d9' # X11 color: 'gray85'
font10 = "-family {DejaVu Sans} -size 10 -weight normal -slant" \
" roman -underline 0 -overstrike 0"
font11 = "-family {DejaVu Sans} -size 20 -weight normal -slant" \
" roman -underline 0 -overstrike 0"
self.style = ttk.Style()
if sys.platform == "win32":
self.style.theme_use('winnative')
self.style.configure('.',background=_bgcolor)
self.style.configure('.',foreground=_fgcolor)
self.style.configure('.',font="TkDefaultFont")
self.style.map('.',background=
[('selected', _compcolor), ('active',_ana2color)])
top.geometry("600x450+295+159")
top.title("Train Schedules")
self.Frame1-2 = Frame(top)
self.Frame1-2.place(relx=0.03, rely=0.04, relheight=0.92, relwidth=0.94)
self.Frame1-2.configure(relief=GROOVE)
self.Frame1-2.configure(borderwidth="2")
self.Frame1-2.configure(relief=GROOVE)
self.Frame1-2.configure(width=565)
self.Label3 = Label(self.Frame1-2)
self.Label3.place(relx=0.25, rely=0.17, height=33, width=257)
self.Label3.configure(activebackground="#f9f9f9")
self.Label3.configure(font=font11)
self.Label3.configure(foreground="#ffb600")
self.Label3.configure(text='''View Train Schedule''')
self.Entrytrain#1 = Entry(self.Frame1-2)
self.Entrytrain#1.place(relx=0.16, rely=0.37, relheight=0.0
, relwidth=0.35)
self.Entrytrain#1.configure(background="white")
self.Entrytrain#1.configure(font="TkFixedFont")
self.Entrytrain#1.configure(selectbackground="#c4c4c4")
self.Entrytrain#1.configure(width=196)
self.Entrytrain#2 = Entry(self.Frame1-2)
self.Entrytrain#2.place(relx=0.34, rely=0.41, relheight=0.07
, relwidth=0.38)
self.Entrytrain#2.configure(background="white")
self.Entrytrain#2.configure(font="TkFixedFont")
self.Entrytrain#2.configure(selectbackground="#c4c4c4")
self.Label4 = Label(self.Frame1-2)
self.Label4.place(relx=0.18, rely=0.41, height=38, width=56)
self.Label4.configure(activebackground="#f9f9f9")
self.Label4.configure(font=font10)
self.Label4.configure(text='''Train #''')
self.searchbutton1 = Button(self.Frame1-2)
self.searchbutton1.place(relx=0.32, rely=0.53, height=26, width=68)
self.searchbutton1.configure(activebackground="#d9d9d9")
self.searchbutton1.configure(text='''Search''')
self.Frame2-2 = Frame(self.Frame1-2)
self.Frame2-2.place(relx=0.04, rely=0.27, relheight=0.73, relwidth=0.91)
self.Frame2-2.configure(relief=GROOVE)
self.Frame2-2.configure(borderwidth="2")
self.Frame2-2.configure(relief=GROOVE)
self.Frame2-2.configure(width=515)
self.style.configure('Treeview.Heading', font="TkDefaultFont")
self.Scrolledtreeview1 = ScrolledTreeView(self.Frame2-2)
self.Scrolledtreeview1.place(relx=0.02, rely=0.16, relheight=0.66
, relwidth=0.96)
self.Scrolledtreeview1.configure(columns="Col2 Col3 Col4")
self.Scrolledtreeview1.heading("#0",text="Train")
self.Scrolledtreeview1.heading("#0",anchor="center")
self.Scrolledtreeview1.column("#0",width="123")
self.Scrolledtreeview1.column("#0",minwidth="20")
self.Scrolledtreeview1.column("#0",stretch="1")
self.Scrolledtreeview1.column("#0",anchor="w")
self.Scrolledtreeview1.heading("Col2",text="Arrival Time")
self.Scrolledtreeview1.heading("Col2",anchor="center")
self.Scrolledtreeview1.column("Col2",width="103")
self.Scrolledtreeview1.column("Col2",minwidth="20")
self.Scrolledtreeview1.column("Col2",stretch="1")
self.Scrolledtreeview1.column("Col2",anchor="w")
self.Scrolledtreeview1.heading("Col3",text="Departure time")
self.Scrolledtreeview1.heading("Col3",anchor="center")
self.Scrolledtreeview1.column("Col3",width="103")
self.Scrolledtreeview1.column("Col3",minwidth="20")
self.Scrolledtreeview1.column("Col3",stretch="1")
self.Scrolledtreeview1.column("Col3",anchor="w")
self.Scrolledtreeview1.heading("Col4",text="Station")
self.Scrolledtreeview1.heading("Col4",anchor="center")
self.Scrolledtreeview1.column("Col4",width="153")
self.Scrolledtreeview1.column("Col4",minwidth="20")
self.Scrolledtreeview1.column("Col4",stretch="1")
self.Scrolledtreeview1.column("Col4",anchor="w")
self.backtosearch = Button(self.Frame2-2)
self.backtosearch.place(relx=0.08, rely=0.85, height=26, width=55)
self.backtosearch.configure(activebackground="#d9d9d9")
self.backtosearch.configure(takefocus="0")
self.backtosearch.configure(text='''Back''')
# The following code is added to facilitate the Scrolled widgets you specified.
class AutoScroll(object):
'''Configure the scrollbars for a widget.'''
def __init__(self, master):
# Rozen. Added the try-except clauses so that this class
# could be used for scrolled entry widget for which vertical
# scrolling is not supported. 5/7/14.
try:
vsb = ttk.Scrollbar(master, orient='vertical', command=self.yview)
except:
pass
hsb = ttk.Scrollbar(master, orient='horizontal', command=self.xview)
#self.configure(yscrollcommand=self._autoscroll(vsb),
# xscrollcommand=self._autoscroll(hsb))
try:
self.configure(yscrollcommand=self._autoscroll(vsb))
except:
pass
self.configure(xscrollcommand=self._autoscroll(hsb))
self.grid(column=0, row=0, sticky='nsew')
try:
vsb.grid(column=1, row=0, sticky='ns')
except:
pass
hsb.grid(column=0, row=1, sticky='ew')
master.grid_columnconfigure(0, weight=1)
master.grid_rowconfigure(0, weight=1)
# Copy geometry methods of master (taken from ScrolledText.py)
if py3:
methods = Pack.__dict__.keys() | Grid.__dict__.keys() \
| Place.__dict__.keys()
else:
methods = Pack.__dict__.keys() + Grid.__dict__.keys() \
+ Place.__dict__.keys()
for meth in methods:
if meth[0] != '_' and meth not in ('config', 'configure'):
setattr(self, meth, getattr(master, meth))
@staticmethod
def _autoscroll(sbar):
'''Hide and show scrollbar as needed.'''
def wrapped(first, last):
first, last = float(first), float(last)
if first <= 0 and last >= 1:
sbar.grid_remove()
else:
sbar.grid()
sbar.set(first, last)
return wrapped
def __str__(self):
return str(self.master)
def _create_container(func):
'''Creates a ttk Frame with a given master, and use this new frame to
place the scrollbars and the widget.'''
def wrapped(cls, master, **kw):
container = ttk.Frame(master)
return func(cls, container, **kw)
return wrapped
class ScrolledTreeView(AutoScroll, ttk.Treeview):
'''A standard ttk Treeview widget with scrollbars that will
automatically show/hide as needed.'''
@_create_container
def __init__(self, master, **kw):
ttk.Treeview.__init__(self, master, **kw)
AutoScroll.__init__(self, master)
if __name__ == '__main__':
vp_start_gui()