-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
executable file
·1687 lines (1307 loc) · 60.1 KB
/
gui.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: iso-8859-1 -*-
# Skapat av Christian Davén 2004
import wx
import settings
import guisettings
import calendar
import timetable
import error
from i18n import *
applicationname = u"KTH TimeTable"
applicationversion = u"2.7"
# -----------------------------------------------------------
class MainFrame(wx.Frame):
def __init__(self, maximized, size_x, size_y):
global applicationname
global applicationversion
guisettings.getSystemSettings()
self.timetable = timetable.TimeTable()
self.timetable.load()
self.weeklabel = None
self.datelabel = None
self.daylabels = []
self.currentmonday = None
self.days = []
wx.Frame.__init__(self, None, -1, applicationname + " " + applicationversion)
self.SetBackgroundColour(guisettings.bgcolour_default)
if wx.MINOR_VERSION >= 5: # 2.5
self.ClearBackground()
layout = wx.BoxSizer(wx.VERTICAL)
layout.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
layout.Add(self.AddButtonsAndLabels(), 0, wx.ALL|wx.ALIGN_CENTRE, 10)
layout.Add(self.AddWeekView(), 1, wx.EXPAND)
self.AddMenu()
self.statusbar = wx.StatusBar(self, -1, style=wx.ST_SIZEGRIP)
layout.Add(self.statusbar, 0, wx.EXPAND)
self.SetSizerAndFit(layout)
wx.EVT_CLOSE(self, self.OnClose)
self.SetSize(wx.Size(size_x, size_y))
self.CentreOnScreen()
if maximized: self.Maximize()
self.GoToday(None)
if calendar.Date() - self.timetable.updated > 7:
msg = U_("It's been more than a week since you last fetched the timetable. It could have been\nupdated since. Would you like to fetch the timetable now?")
if wx.MessageDialog(self, msg, U_("The timetable is old"),
style=wx.YES_NO|wx.ICON_QUESTION).ShowModal() == wx.ID_YES:
self.Update(None)
def AddWeekView(self):
weekview = wx.BoxSizer(wx.VERTICAL)
hoursanddays = wx.BoxSizer(wx.HORIZONTAL)
daynames = wx.BoxSizer(wx.HORIZONTAL)
flag = wx.EXPAND
if wx.MINOR_VERSION >= 5: # 2.5
flag |= wx.FIXED_MINSIZE
hoursanddays.Add(HoursPanel(self), 0, flag)
# ritar ut saker för varje veckodag
for i in range(settings.lastweekday + 1):
# själva namnet på dagen (fylls i senare under updateView())
self.daylabels.append(StaticText(self, "Ons 15", size=(60, 15), style=wx.ALIGN_CENTRE|wx.SIMPLE_BORDER))
self.daylabels[-1].SetBackgroundColour(guisettings.bgcolour_daylabel)
daynames.Add(self.daylabels[-1], 1, wx.RIGHT|wx.LEFT, 1)
# schemat för dagen, åtminstone utrymmet för detsamma
self.days.append(DayPanel(self))
hoursanddays.Add(self.days[-1], 1, wx.EXPAND|wx.RIGHT|wx.LEFT, 1)
weekview.Add(daynames, 0, wx.EXPAND|wx.LEFT, 60)
weekview.Add(hoursanddays, 1, wx.EXPAND)
return weekview
def AddButtonsAndLabels(self):
self.weeklabel = StaticText(self, "Vecka 43", size=(-1, -1), style=wx.ALIGN_CENTRE)
self.datelabel = StaticText(self, "Juli 2004", size=(150, 25), style=wx.ALIGN_RIGHT)
guisettings.font_default.SetWeight(wx.BOLD)
guisettings.font_default.SetPointSize(guisettings.font_default.GetPointSize() + 1)
self.datelabel.SetFont(guisettings.font_default)
guisettings.font_default.SetPointSize(guisettings.font_default.GetPointSize() - 1)
guisettings.font_default.SetWeight(wx.NORMAL)
buttons = wx.BoxSizer(wx.HORIZONTAL)
buttons.Add(wx.Button(self, 1, U_("Today"), size=(60, -1)), 0)
buttons.Add(wx.Button(self, 2, "<-", size=(30, -1)), 0, wx.LEFT|wx.RIGHT, 7)
buttons.Add(self.weeklabel, 0, wx.TOP, 5)
buttons.Add(wx.Button(self, 3, "->", size=(30, -1)), 0, wx.LEFT|wx.RIGHT, 7)
buttons.Add(self.datelabel, 0, wx.TOP, 5)
wx.EVT_BUTTON(self, 1, self.GoToday)
wx.EVT_BUTTON(self, 2, self.GoPrevWeek)
wx.EVT_BUTTON(self, 3, self.GoNextWeek)
return buttons
def AddMenu(self):
menubar = wx.MenuBar()
menu = wx.Menu()
menu.Append(110, U_("&Export..."))
menu.AppendSeparator()
menu.Append(120, U_("&Quit"))
menubar.Append(menu, U_("&File"))
wx.EVT_MENU(self, 110, self.ExportEvents)
wx.EVT_MENU(self, 120, self.OnClose)
menu = wx.Menu()
menu.Append(210, U_("Choose &courses..."))
menu.Append(220, U_("&Fetch timetable...\tF5"))
menu.AppendSeparator()
menu.Append(230, U_("Choose &groups..."))
menu.Append(240, U_("&Name courses..."))
menu.AppendSeparator()
menu.Append(250, U_("&Settings..."))
menubar.Append(menu, U_("&Tools"))
wx.EVT_MENU(self, 210, self.ChooseCourses)
wx.EVT_MENU(self, 220, self.Update)
wx.EVT_MENU(self, 230, self.ChooseGroups)
wx.EVT_MENU(self, 240, self.NameCourses)
wx.EVT_MENU(self, 250, self.MakeSettings)
#menu = wx.Menu()
#menu.Append(310, U_("Create &new group..."))
#menu.AppendSeparator()
#menubar.Append(menu, U_("&Subscriptions"))
#wx.EVT_MENU(self, 310, self.CreateSubscription)
#wx.EVT_MENU_RANGE(self, 320, 900, self.SubscriptionGroupMenus)
menu = wx.Menu()
menu.Append(100, U_("&About..."))
menubar.Append(menu, U_("&Help"))
wx.EVT_MENU(self, 100, self.About)
self.SetMenuBar(menubar)
#self.updateGroupMenu()
def OnClose(self, event):
try:
self.timetable.save()
except error.WriteError:
msg = U_("Could not save the timetable. The file may be write-protected.")
wx.MessageDialog(self, msg, U_("File error"), style=wx.OK|wx.ICON_ERROR).ShowModal()
settings.maximized = self.IsMaximized()
settings.size_x = self.GetSizeTuple()[0]
settings.size_y = self.GetSizeTuple()[1]
self.Destroy()
def GoToday(self, event):
self.currentmonday = calendar.Date().getLastMondayOrNextIfWeekend()
self.updateView()
def GoPrevWeek(self, event):
self.currentmonday -= 7
self.updateView()
def GoNextWeek(self, event):
self.currentmonday += 7
self.updateView()
def updateView(self):
date = calendar.Date(self.currentmonday)
self.weeklabel.SetLabel(U_("Week") + " " + str(date.getWeek()))
self.datelabel.SetLabel(date.getMonthName() + " " + str(date.getYear()))
if self.timetable.isEmpty():
statusmsg = U_("The timetable is empty")
else:
diff = calendar.Date() - self.timetable.updated
statusmsg = U_("The timetable was fetched") + " " + str(diff) + " " + U_("days ago")
if diff == 0:
statusmsg = U_("The timetable was fetched") + " " + U_("today")
elif diff == 1:
statusmsg = U_("The timetable was fetched") + " " + U_("yesterday")
self.statusbar.SetStatusText(statusmsg)
for day in self.daylabels:
weekday = date.getWeekDay()
self.days[weekday].colorize(date)
# Skriver ut dagens "namn" om det är en speciell dag,
# exempelvis helg- eller flaggdag
if date.getSpecialName():
day.SetLabel(date.getSpecialName())
else:
day.SetLabel(date.getWeekDayName() + " " + str(date.getDay()))
self.days[weekday].Freeze()
self.days[weekday].clear()
for event in self.timetable.getEventsForDate(date):
self.days[weekday].addEvent(event)
self.days[weekday].showEvents()
self.days[weekday].Thaw()
date += 1
def ExportEvents(self, evt):
ExportDialog(self, self.timetable).ShowModal()
self.SetFocus()
def Update(self, evt):
daisycourses = self.timetable.getAllDaisyCourses()
timeeditcourses = self.timetable.getAllTimeEditCourses()
if not daisycourses and not timeeditcourses:
msg = U_("First you must choose which courses to fetch.")
wx.MessageDialog(self, msg, U_("No courses"), style=wx.OK|wx.ICON_INFORMATION).ShowModal()
return
try:
if daisycourses:
self.updateFromDaisy(daisycourses)
if timeeditcourses:
self.updateFromTimeEdit(timeeditcourses)
self.timetable.save()
except (error.DataError, ValueError):
msg = U_("The timetable fetched from the server is corrupt and unusable.")
wx.MessageDialog(self, msg, U_("Server error"), style=wx.OK|wx.ICON_ERROR).ShowModal()
return
except error.ReadError:
msg = U_("Could not read from") + " " + U_("the timetable server") + ". " + U_("Make sure you have access to the Internet.")
wx.MessageDialog(self, msg, U_("Server error"), style=wx.OK|wx.ICON_ERROR).ShowModal()
return
except error.WriteError:
msg = U_("Could not save the timetable. The file may be write-protected.")
wx.MessageDialog(self, msg, U_("File error"), style=wx.OK|wx.ICON_ERROR).ShowModal()
return
self.updateView()
#if settings.publish:
# import subscription
# progressdialog = ProgressDialog(self, U_("Publishing timetable"), [U_("Uploading to") + " sf.net"])
# progressdialog.startProgress()
# subscription.Subscription(self.timetable).put()
# # TODO: Visa fel om det inte gick
# progressdialog.stopProgress()
def updateFromTimeEdit(self, courses):
import timeedit
ids = []
for course in courses:
ids.append(course.id)
progressdialog = ProgressDialog(self, U_("Fetching TimeEdit timetable"), [U_("Connecting to") + " schema.sys.kth.se...", U_("Receiving timetable...")])
progressdialog.startProgress()
try:
data = timeedit.Conduit(progressdialog.increaseProgress).getvCalendarData(ids)
except:
progressdialog.stopProgress()
raise
#file("dbg-timeedit-vcal", "w+").writelines(data)
self.timetable.importVCalendarData(data, courses)
progressdialog.stopProgress()
def updateFromDaisy(self, courses):
import daisy
ids = []
for course in courses:
ids.append(course.id)
data = []
progressdialog = ProgressDialog(self, U_("Fetching Daisy timetable"))
try:
for id in ids:
course = self.timetable.getCourse(id)
progressdialog.setMessages([U_("Connecting to") + " it.kth.se...",
U_("Receiving ") + course.code, U_("Importing ") + course.code])
progressdialog.startProgress()
try:
data += daisy.Conduit(progressdialog.increaseProgress).getvCalendarData([id])
self.timetable.importVCalendarData(data, [course])
except (error.DataError, ValueError):
msg = U_("The timetable fetched for ") + course.code + U_(" is corrupt and unusable.")
wx.MessageDialog(self, msg, U_("Server error"), style=wx.OK|wx.ICON_ERROR).ShowModal()
progressdialog.stopProgress()
except:
progressdialog.stopProgress()
raise
#file("dbg-daisy-vcal", "w+").writelines(data)
progressdialog.stopProgress()
def About(self, evt):
AboutDialog(self).ShowModal()
def ChooseGroups(self, evt):
if GroupsDialog(self, self.timetable).ShowModal() == wx.ID_OK:
self.updateView()
self.SetFocus()
def NameCourses(self, evt):
if CourseNamesDialog(self, self.timetable).ShowModal() == wx.ID_OK:
self.updateView()
self.SetFocus()
def ChooseCourses(self, evt):
if ChooseCoursesDialog(self, self.timetable).ShowModal() == wx.ID_OK:
self.updateView()
if self.timetable.hasCourses():
msg = U_("Do you want to fetch the timetable now?")
dialog = wx.MessageDialog(self, msg, U_("Fetch timetable?"), style=wx.YES_NO|wx.ICON_QUESTION)
if dialog.ShowModal() == wx.ID_YES:
self.Update(None)
self.SetFocus()
def MakeSettings(self, evt):
if SettingsDialog(self).ShowModal() == wx.ID_OK:
self.updateView()
self.SetFocus()
def CreateSubscription(self, evt = None, name = ""):
if SubscriptionDialog(self, self.timetable, name).ShowModal() == wx.ID_OK:
self.updateView()
self.SetFocus()
def updateGroupMenu(self):
ID_FIRST = 320
ID_MAIN = 1000
ID_STEP = 10
menubar = self.GetMenuBar()
menu = menubar.GetMenu(menubar.FindMenu(U_("&Subscriptions")))
# tar först bort tidigare gruppmenyer
for i in range(menu.GetMenuItemCount() - 2):
id = ID_MAIN + ID_FIRST + ID_STEP * i
menu.Remove(menu.FindItemById(id).GetId())
# lägger till en undermeny för varje grupp
names = self.timetable.getAllSubscriptionGroupNames()
menuid = ID_FIRST
for group in map(self.timetable.getSubscriptionGroup, names):
submenu = wx.Menu()
submenu.AppendCheckItem(menuid, U_("&Show group"))
if group.isVisible():
submenu.FindItemById(menuid).Check()
submenu.Append(menuid + 1, U_("&Edit group"))
submenu.Append(menuid + 2, U_("&Remove group"))
menu.AppendMenu(ID_MAIN + menuid, group.getName(), submenu)
menuid += ID_STEP
def SubscriptionGroupMenus(self, evt):
ID_FIRST = 320
ID_MAIN = 1000
ID_STEP = 10
id = evt.GetId()
menubar = self.GetMenuBar()
menu = menubar.GetMenu(menubar.FindMenu(U_("&Subscriptions")))
if str(id)[-1] == "0": # visa grupp
name = menu.FindItemById(id + ID_MAIN).GetText()
if menu.FindItemById(id).IsChecked():
# hämta och visa grupp
progressdialog = ProgressDialog(self, U_("Fetching timetable"), [U_("Receiving timetable...")])
progressdialog.startProgress()
self.timetable.getSubscriptionGroup(name).show(self.timetable)
# TODO: Visa fel om det inte gick
progressdialog.stopProgress()
else:
# dölj grupp
self.timetable.getSubscriptionGroup(name).hide(self.timetable)
self.updateView()
elif str(id)[-1] == "1": # redigera grupp
name = menu.FindItemById(id + ID_MAIN - 1).GetText()
self.CreateSubscription(name = name)
self.updateGroupMenu()
elif str(id)[-1] == "2": # ta bort grupp
name = menu.FindItemById(id + ID_MAIN - 2).GetText()
# döljer gruppen om den visas
if menu.FindItemById(id - 2).IsChecked():
print "hiding group first", name
self.timetable.getSubscriptionGroup(name).hide(self.timetable)
self.updateView()
self.timetable.removeSubscriptionGroup(name)
self.updateGroupMenu()
# -----------------------------------------------------------
class OKCancelDialog(wx.Dialog):
"Dialogruta med OK- och Avbryt-knappar"
def __init__(self, parent, caption):
wx.Dialog.__init__(self, parent, -1, caption)
self.cancelled = False
self.shown = False
self.parent = parent
self.buttons = wx.BoxSizer(wx.HORIZONTAL)
self.okbtn = wx.Button(self, wx.OK, U_("&OK"))
self.okbtn.SetDefault()
self.buttons.Add(self.okbtn)
self.buttons.Add((10, 0), 0)
self.buttons.Add(wx.Button(self, wx.CANCEL, U_("&Cancel")))
wx.EVT_BUTTON(self, wx.OK, self.SaveAndClose)
wx.EVT_BUTTON(self, wx.CANCEL, self.Cancel)
def SaveAndClose(self, evt):
print "Varning! Ingen data sparas (\"abstrakt\" metod)."
self.EndModal(wx.ID_OK)
def Cancel(self, evt):
"""
Kan anropas under __init__() och då kan dialogrutan
inte stängas eftersom den inte öppnats än...
"""
self.cancelled = True
if self.shown:
self.EndModal(wx.ID_CANCEL)
def ShowModal(self):
"Visar dialogrutan endast om __init__() inte avbröts"
if not self.cancelled:
self.shown = True
return wx.Dialog.ShowModal(self)
else:
return wx.ID_CANCEL
# -----------------------------------------------------------
class GroupsDialog(OKCancelDialog):
"Dialogruta för val av gruppdeltagande i kurser"
def __init__(self, parent, timetable):
OKCancelDialog.__init__(self, parent, U_("Choose groups"))
self.choices = []
self.nogroup = U_("all")
self.timetable = timetable
self.courses = self.timetable.getAllPersistentCourses()
if not self.courses:
msg = U_("There are no courses to choose groups for.")
wx.MessageDialog(self, msg, U_("No courses"), style=wx.OK|wx.ICON_INFORMATION).ShowModal()
self.Cancel(None)
return
allcourses = wx.BoxSizer(wx.VERTICAL)
coursestext = wx.BoxSizer(wx.HORIZONTAL)
centeredtext = wx.BoxSizer(wx.VERTICAL)
layout = wx.BoxSizer(wx.VERTICAL)
for course in self.courses:
try:
groups = self.timetable.getAllGroups(course)
except ValueError:
groups = []
msg = U_("There is no information on which groups") + " " + course.name + "\n" + U_("is divided into. You have to fetch the timetable first.")
wx.MessageDialog(self, msg, U_("Timetable missing"), style=wx.OK|wx.ICON_INFORMATION).ShowModal()
text = StaticText(self, course.name, size=(150, -1))
if groups:
groups.sort()
groups.append(self.nogroup.encode("latin_1"))
rightcomponent = Choice(self, (70, -1), groups, course)
# sätter först "ingen"/"alla" som vald
rightcomponent.SetStringSelection(self.nogroup)
if course.group:
# sätter det val som tidigare gjorts
rightcomponent.SetStringSelection(course.group)
self.choices.append(rightcomponent)
else:
rightcomponent = StaticText(self, U_("(no choice possible)"))
coursesizer = wx.BoxSizer(wx.HORIZONTAL)
coursesizer.Add(text, 0, wx.RIGHT, 10)
coursesizer.Add(rightcomponent)
allcourses.Add(coursesizer, 0, wx.ALL, 10)
noticetext = U_("Please note that the choices you make here\nare not reflected in Daisy. You will NOT be\nassigned to these groups. You have to choose\nyour groups in Daisy as well.")
centeredtext.Add((0, 10), 1)
centeredtext.Add(StaticText(self, noticetext), 0, wx.ALL, 10)
centeredtext.Add((0, 10), 1)
coursestext.Add(allcourses, 0, wx.ALL, 10)
coursestext.Add(wx.StaticLine(self, -1, style=wx.LI_VERTICAL), 0, wx.EXPAND)
coursestext.Add(centeredtext, 0, wx.ALL|wx.EXPAND, 10)
layout.Add(coursestext)
layout.Add(self.buttons, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizerAndFit(layout)
self.Centre()
def SaveAndClose(self, evt):
for course in self.choices:
group = course.GetStringSelection()
if group == self.nogroup: group = ""
self.timetable.setCourseGroup(course.course.id, group)
self.EndModal(wx.ID_OK)
# -----------------------------------------------------------
class CourseNamesDialog(OKCancelDialog):
"Dialogruta för egen namngivning av kurser"
def __init__(self, parent, timetable):
OKCancelDialog.__init__(self, parent, U_("Name courses"))
self.courses = []
self.edits = []
self.timetable = timetable
courses = self.timetable.getAllPersistentCourses()
if not courses:
msg = U_("There are no courses to name. Please choose some first.")
wx.MessageDialog(self, msg, U_("No courses"), style=wx.OK|wx.ICON_INFORMATION).ShowModal()
self.Cancel(None)
return
layout = wx.BoxSizer(wx.VERTICAL)
for course in courses:
self.courses.append(course)
text = StaticText(self, course.code, size=(110, -1))
edit = wx.TextCtrl(self, -1, size=(240, -1))
edit.SetValue(course.name)
self.edits.append(edit)
coursesizer = wx.BoxSizer(wx.HORIZONTAL)
coursesizer.Add(text, 0, wx.RIGHT|wx.TOP, 7)
coursesizer.Add(edit, 0, wx.TOP|wx.BOTTOM, 5)
layout.Add(coursesizer, 0, wx.LEFT|wx.RIGHT, 10)
self.buttons.Prepend((20, 0), 1)
layout.Add(self.buttons, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizerAndFit(layout)
self.Centre()
def SaveAndClose(self, evt):
cache = timetable.CachedCourseList()
for i in range(len(self.courses)):
course = self.courses[i]
name = self.edits[i].GetValue()
if not name:
if course.isDaisy():
name = cache.getCourse(course.id).name
msg = U_("You entered no name for the course ") + course.code + ".\n" +\
U_("The new name will be the official Daisy name.")
else:
name = course.code
msg = U_("You entered no name for the course ") + course.code + ".\n" +\
U_("The new name will be the course code.")
dialog = wx.MessageDialog(self, msg, U_("No name"),
style=wx.OK|wx.CANCEL|wx.ICON_INFORMATION)
if dialog.ShowModal() == wx.ID_OK:
self.timetable.setCourseName(course.id, name)
else:
self.edits[i].SetValue(name)
self.edits[i].SetFocus()
return
else:
self.timetable.setCourseName(course.id, name)
self.EndModal(wx.ID_OK)
# -----------------------------------------------------------
class SettingsDialog(OKCancelDialog):
"Dialogruta för inställningar"
def __init__(self, parent):
OKCancelDialog.__init__(self, parent, U_("Change settings"))
layout = wx.BoxSizer(wx.VERTICAL)
setting1 = wx.BoxSizer(wx.HORIZONTAL)
setting2 = wx.BoxSizer(wx.HORIZONTAL)
setting3 = wx.BoxSizer(wx.HORIZONTAL)
setting4 = wx.BoxSizer(wx.HORIZONTAL)
size = (150,-1)
setting1.Add(StaticText(self, U_("Last day of week:"), size=size), 0, wx.ALL, 10)
self.daysinweek = wx.Choice(self, -1, size=(100,-1), choices=[U_("Fri"), U_("Sat"), U_("Sun")])
self.daysinweek.SetSelection(settings.lastweekday - 4)
setting1.Add(self.daysinweek, 0, wx.LEFT|wx.RIGHT, 10)
setting2.Add(StaticText(self, U_("Program language:"), size=size), 0, wx.ALL, 10)
self.language = wx.Choice(self, -1, size=(100,-1), choices=["English", "Svenska"])
if settings.language == "en": self.language.SetSelection(0)
elif settings.language == "sv": self.language.SetSelection(1)
setting2.Add(self.language, 0, wx.LEFT|wx.RIGHT, 10)
setting3.Add(StaticText(self, U_("Start of day:"), size=size), 0, wx.ALL, 10)
self.daybegin = wx.Choice(self, -1, size=(100,-1), choices=["08:00", "09:00", "10:00"])
if settings.daybegin <= calendar.Time("080000"): self.daybegin.SetSelection(0)
elif settings.daybegin <= calendar.Time("090000"): self.daybegin.SetSelection(1)
else: self.daybegin.SetSelection(2)
setting3.Add(self.daybegin, 0, wx.LEFT|wx.RIGHT, 10)
setting4.Add(StaticText(self, U_("End of day:"), size=size), 0, wx.ALL, 10)
self.dayend = wx.Choice(self, -1, size=(100,-1), choices=["17:00", "18:00", "19:00", "20:00", "21:00"])
if settings.dayend <= calendar.Time("170000"): self.dayend.SetSelection(0)
elif settings.dayend <= calendar.Time("180000"): self.dayend.SetSelection(1)
elif settings.dayend <= calendar.Time("190000"): self.dayend.SetSelection(2)
elif settings.dayend <= calendar.Time("200000"): self.dayend.SetSelection(3)
else: self.dayend.SetSelection(4)
setting4.Add(self.dayend, 0, wx.LEFT|wx.RIGHT, 10)
#boxtitle = wx.StaticBox(self, -1, U_("Publishing"))
#setting5 = wx.StaticBoxSizer(boxtitle, wx.VERTICAL)
#self.radiobtnDoNotPublish = wx.RadioButton(self, -1, U_("Do not publish timetable"))
#self.radiobtnPublish = wx.RadioButton(self, -1, U_("Publish timetable with id:"))
#self.userid = wx.TextCtrl(self, -1, value=settings.publish_userid)
#self.userid.Disable()
#self.radiobtnDoNotPublish.SetValue(True)
#if settings.publish:
# self.userid.Enable(True)
# self.radiobtnPublish.SetValue(True)
#radiotxt = wx.BoxSizer(wx.HORIZONTAL)
#radiotxt.Add(self.radiobtnPublish, 0, wx.ALL, 5)
#radiotxt.Add(self.userid)
#wx.EVT_RADIOBUTTON(self, self.radiobtnDoNotPublish.GetId(), self.OnPublishDeselect)
#wx.EVT_RADIOBUTTON(self, self.radiobtnPublish.GetId(), self.OnPublishSelect)
#setting5.Add(self.radiobtnDoNotPublish, 0, wx.ALL, 5)
#setting5.Add(radiotxt)
layout.Add(StaticText(self, U_("The settings will need a\nprogram restart to take effect.")), 0,
wx.EXPAND|wx.ALL, 10)
layout.Add(setting1, 0, wx.TOP|wx.LEFT|wx.RIGHT, 10)
layout.Add(setting3, 0, wx.TOP|wx.LEFT|wx.RIGHT, 10)
layout.Add(setting4, 0, wx.TOP|wx.LEFT|wx.RIGHT, 10)
layout.Add(setting2, 0, wx.ALL, 10)
#layout.Add(setting5, 0, wx.EXPAND|wx.ALL, 10)
layout.Add(self.buttons, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizerAndFit(layout)
self.CentreOnScreen()
def OnPublishSelect(self, evt):
msg = U_("Publishing your timetable on the Internet will enable anyone,\nincluding you, to view your timetable using a web or WAP browser.\n\nIt will also enable anyone to view your timetable in KTH TimeTable.\n\nYour timetable will be identified by this string, so make sure you\nchoose something unique, e.g. your KTH.se ID.")
if wx.MessageDialog(self, msg, U_("Publish timetable"),
style=wx.OK|wx.CANCEL|wx.ICON_INFORMATION).ShowModal() == wx.ID_OK:
self.userid.Enable(True)
self.userid.SetFocus()
else:
self.radiobtnDoNotPublish.SetValue(True)
def OnPublishDeselect(self, evt):
self.userid.Disable()
def SaveAndClose(self, evt):
settings.dayend = calendar.Time(self.dayend.GetStringSelection()[:2] + "0000")
settings.daybegin = calendar.Time(self.daybegin.GetStringSelection()[:2] + "0000")
settings.language = self.language.GetStringSelection()[:2].lower()
settings.lastweekday = self.daysinweek.GetSelection() + 4
#if self.radiobtnPublish.GetValue() and not self.userid.GetValue() == settings.publish_userid:
# msg = U_("Enter the password for this timetable id:")
# pwdialog = wx.TextEntryDialog(self, msg)
# if pwdialog.ShowModal() == wx.ID_OK:
# settings.publish_pw = pwdialog.GetValue()
# else:
# return
#settings.publish = self.radiobtnPublish.GetValue()
#settings.publish_userid = self.userid.GetValue()
self.EndModal(wx.ID_OK)
# -----------------------------------------------------------
class SubscriptionDialog(OKCancelDialog):
"Dialogruta för hantering av en prenumerationsgrupp"
def __init__(self, parent, ttable, name):
OKCancelDialog.__init__(self, parent, U_("Select group members"))
self.timetable = ttable
self.originalname = name
layout = wx.BoxSizer(wx.VERTICAL)
groupname = wx.BoxSizer(wx.HORIZONTAL)
newuser = wx.BoxSizer(wx.HORIZONTAL)
groupname.Add(StaticText(self, U_("Enter group name:")))
self.groupedit = wx.TextCtrl(self, -1, size=(150, -1))
self.groupedit.SetValue(name)
groupname.Add(self.groupedit, 0, wx.LEFT, 10)
self.useredit = wx.TextCtrl(self, -1, size=(150, -1))
addbtn = wx.Button(self, 90, U_("&Add"))
addbtn.SetDefault()
newuser.Add(self.useredit, 0)
newuser.Add(addbtn, 0, wx.LEFT, 10)
members = []
if name:
members = ttable.getSubscriptionGroup(name).getMembers()
self.userlist = wx.ListBox(self, -1, size=(300,250), choices=members, style=wx.LB_EXTENDED|wx.LB_SORT)
layout.Add(groupname, 0, wx.LEFT|wx.TOP|wx.RIGHT, 10)
layout.Add(StaticText(self, U_("Select the members of this group, one by one. Each member is identified by his or her chosen timetable ID."), wordwrap=True, size=(300,-1)), 0, wx.ALL, 10)
layout.Add(newuser, 0, wx.LEFT|wx.TOP|wx.RIGHT, 10)
# "Ta bort"-knappen högerjusteras
self.buttons.Add(wx.Window(self, -1), 1)
self.buttons.Add(wx.Button(self, 20, U_("&Remove")))
layout.Add(self.userlist, 0, wx.LEFT|wx.TOP|wx.RIGHT, 10)
layout.Add(self.buttons, 0, wx.EXPAND|wx.ALL, 10)
wx.EVT_BUTTON(self, 20, self.RemoveUser)
wx.EVT_BUTTON(self, 90, self.AddUser)
self.SetSizerAndFit(layout)
self.CentreOnScreen()
def AddUser(self, evt):
if not self.useredit.GetValue():
self.SaveAndClose(evt)
return
userid = self.useredit.GetValue()
for i in range(self.userlist.GetCount()):
if userid == self.userlist.GetString(i):
msg = U_("The member") + " " + U_("is already chosen.")
wx.MessageDialog(self, msg, U_("Already chosen"),
style=wx.ICON_INFORMATION).ShowModal()
self.SetFocus()
self.useredit.SetFocus()
return
self.userlist.Append(userid)
self.useredit.SetValue("")
self.SetFocus()
self.useredit.SetFocus()
def RemoveUser(self, evt):
remove = []
for i in self.userlist.GetSelections():
remove.append(self.userlist.GetString(i))
for item in remove:
self.userlist.Delete(self.userlist.FindString(item))
def SaveAndClose(self, evt):
if not self.groupedit.GetValue():
msg = U_("Please enter a name for this group.")
wx.MessageDialog(self, msg, U_("Group name missing"),
style=wx.OK|wx.ICON_WARNING).ShowModal()
return
if self.userlist.GetCount():
members = []
for i in range(self.userlist.GetCount()):
members.append(self.userlist.GetString(i))
self.timetable.addSubscriptionGroup(self.groupedit.GetValue(), members)
original = self.timetable.getSubscriptionGroup(self.originalname)
if original:
self.timetable.getSubscriptionGroup(self.groupedit.GetValue()).copyStatus(original)
self.timetable.removeSubscriptionGroup(self.originalname)
else:
msg = U_("The group is empty. Do you want to remove it?")
dialog = wx.MessageDialog(self, msg, U_("Group name missing"), style=wx.YES_NO|wx.ICON_QUESTION)
if dialog.ShowModal() == wx.ID_YES:
self.timetable.removeSubscriptionGroup(self.groupedit.GetValue())
self.GetParent().updateGroupMenu()
self.EndModal(wx.ID_OK)
# -----------------------------------------------------------
class ChooseCoursesDialog(OKCancelDialog):
"Dialogruta för val av kurser"
def __init__(self, parent, ttable):
OKCancelDialog.__init__(self, parent, U_("Choose courses"))
layout = wx.BoxSizer(wx.VERTICAL)
newcourse = wx.BoxSizer(wx.HORIZONTAL)
self.timetable = ttable
self.courseedit = wx.TextCtrl(self, -1, size=(150, -1))
addbtn = wx.Button(self, 90, U_("&Add"))
addbtn.SetDefault()
newcourse.Add(StaticText(self, U_("Enter one course code at a time:"), size=(200,-1)), 0, wx.TOP, 5)
newcourse.Add(self.courseedit, 0)
newcourse.Add(addbtn, 0, wx.LEFT, 10)
self.chosencourses = []
self.courselist = CourseListBox(self, self.timetable.getAllPersistentCourses(), size=(450,250))
wx.EVT_BUTTON(self, 20, self.RemoveCourse)
wx.EVT_BUTTON(self, 90, self.addCourse)
layout.Add(StaticText(self, U_("Choose the courses you want included in your timetable. Both TimeEdit and Daisy courses can be added. For Daisy courses you can enter parts of the code or name. All matching courses will then be added."), size=(450,-1), wordwrap=True), 0, wx.LEFT|wx.TOP, 10)
layout.Add(newcourse, 0, wx.LEFT|wx.TOP|wx.RIGHT, 10)
self.radiodaisy = wx.RadioButton(self, -1, "Daisy")
self.radiotimeedit = wx.RadioButton(self, -1, "TimeEdit")
self.radiodaisy.SetValue(True)
if settings.preferred_system == "TimeEdit":
self.radiotimeedit.SetValue(True)
layout.Add(StaticText(self, U_("If the course exists in both systems, prefer:")), 0, wx.LEFT|wx.TOP, 10)
layout.Add(self.radiodaisy, 0, wx.LEFT|wx.TOP, 10)
layout.Add(self.radiotimeedit, 0, wx.LEFT, 10)
# "Ta bort"-knappen högerjusteras
self.buttons.Add(wx.Window(self, -1), 1)
self.buttons.Add(wx.Button(self, 20, U_("&Remove")))
layout.Add(self.courselist, 0, wx.LEFT|wx.TOP|wx.RIGHT, 10)
layout.Add(self.buttons, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizerAndFit(layout)
self.CentreOnScreen()
self.daisycourses = timetable.CachedCourseList()
if self.daisycourses.isEmpty():
self.daisycourses.setCourses(self.getDaisyCourses())
self.daisycourses.save()
def getDaisyCourses(self):
import daisy
progressdialog = ProgressDialog(self, U_("Fetching course list"), [U_("Connecting to") + " it.kth.se...",
U_("Receiving data..."), U_("Connecting to") + " it.kth.se...", U_("Receiving data..."), ""])
progressdialog.startProgress()
courses = []
try:
courses = daisy.Conduit().getCourses(progressdialog.increaseProgress)
except error.ReadError:
msg = U_("Could not read from") + " " + U_("the IT University web site.") + "\n" + U_("Make sure you have access to the Internet.")
wx.MessageDialog(self, msg, U_("Server error"), style=wx.OK|wx.ICON_INFORMATION).ShowModal()
except error.DataError:
msg = U_("Got bad and unusable data from") + " " + U_("the IT University web site.")
wx.MessageDialog(self, msg, U_("Server error"), style=wx.OK|wx.ICON_ERROR).ShowModal()
progressdialog.stopProgress()
return courses
def addCourse(self, evt = None):
code = self.courseedit.GetValue()
if not code:
# ingen angiven kod, vill förmodligen
# stänga dialogrutan
self.SaveAndClose(evt)
return
if self.radiotimeedit.GetValue():
# letar i TimeEdit först
courses = self.lookForCourseInTimeEdit(code)
if not courses:
courses = self.lookForCourseInDaisy(code)
else:
# letar i Daisy först
courses = self.lookForCourseInDaisy(code)
if not courses:
courses = self.lookForCourseInTimeEdit(code)
if courses:
self.courselist.InsertItems(courses)
self.courseedit.SetValue("")
else:
msg = U_("No course matching ") + code + U_(" exists in Daisy or TimeEdit.")
wx.MessageDialog(self, msg, U_("The course ") + U_("does not exist"),
style=wx.ICON_WARNING).ShowModal()
self.SetFocus()
self.courseedit.SetFocus()
def lookForCourseInDaisy(self, code):
courses = []
try:
courses = self.daisycourses.getAllMatchingCode(code)
except ValueError:
pass
try:
courses.extend(self.daisycourses.getAllMatchingName(code))
except ValueError:
pass
return courses
def lookForCourseInTimeEdit(self, code):
import timeedit
progressdialog = ProgressDialog(self, U_("Fetching course name"), [U_("Receiving data from") + " schema.sys.kth.se..."])
progressdialog.startProgress()
course = []
try:
course = [timeedit.Conduit().getCourseInfo(code)]
except ValueError:
pass
progressdialog.stopProgress()
return course
def RemoveCourse(self, evt):
self.courselist.DeleteSelected()
def SaveAndClose(self, evt):
settings.preferred_system = "TimeEdit"
if self.radiodaisy.GetValue():
settings.preferred_system = "Daisy"
self.timetable.clearCourses()
for i in range(self.courselist.GetCount()):
self.timetable.addCourse(self.courselist.GetClientData(i))
self.timetable.removeOrphanEvents()
self.EndModal(wx.ID_OK)
# -----------------------------------------------------------
class AboutDialog(wx.Dialog):
def __init__(self, parent):
global applicationname
global applicationversion
wx.Dialog.__init__(self, parent, -1, U_("About") + " " + applicationname)
btn = wx.Button(self, wx.OK, U_("&Close"))
btn.SetDefault()
wx.EVT_BUTTON(self, wx.OK, self.Close)
msg = applicationname + " " + U_("is created by") + u" Christian Davén.\n"
msg += U_("Version:") + " " + applicationversion + "\n\n"
msg += U_("The program and its source code is licensed under the terms of the GNU GPL.\n\nPlease send bug reports and suggestions to") + " <[email protected]>"
layout = wx.BoxSizer(wx.VERTICAL)
layout.Add(StaticText(self, msg, wordwrap=True, size=(300,-1)),
0, wx.LEFT|wx.TOP|wx.RIGHT, 10)
layout.Add(btn, 0, wx.ALL, 10)
self.SetSizerAndFit(layout)
self.Centre()
def Close(self, evt):
self.EndModal(wx.ID_OK)
# -----------------------------------------------------------
class ExportDialog(OKCancelDialog):
"Dialogruta för export av schema"
def __init__(self, parent, ttable):