keepyourhead 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/COPYING.txt +674 -0
  2. data/LICENSE.rdoc +20 -0
  3. data/README.rdoc +3 -0
  4. data/bin/keepyourhead +6 -0
  5. data/data/glade/DialogEditLatex.glade +180 -0
  6. data/data/glade/DialogEditText.glade +66 -0
  7. data/data/glade/DialogTrainStart.glade +101 -0
  8. data/data/glade/WindowEdit.glade +1419 -0
  9. data/data/glade/WindowTrain.glade +271 -0
  10. data/data/images/error_back.png +0 -0
  11. data/data/images/error_front.png +0 -0
  12. data/data/images/loading_back.png +0 -0
  13. data/data/images/loading_front.png +0 -0
  14. data/lib/Keepyourhead.rb +62 -0
  15. data/lib/Keepyourhead/Application.rb +94 -0
  16. data/lib/Keepyourhead/Cache.rb +233 -0
  17. data/lib/Keepyourhead/Compilation.rb +38 -0
  18. data/lib/Keepyourhead/Images.rb +62 -0
  19. data/lib/Keepyourhead/Preferences.rb +52 -0
  20. data/lib/Keepyourhead/Requirements.rb +72 -0
  21. data/lib/Keepyourhead/Resources.rb +45 -0
  22. data/lib/Keepyourhead/Training.rb +132 -0
  23. data/lib/Keepyourhead/Utils.rb +97 -0
  24. data/lib/Keepyourhead/Version.rb +43 -0
  25. data/lib/Keepyourhead/database/Base.rb +77 -0
  26. data/lib/Keepyourhead/database/BaseStatistic.rb +63 -0
  27. data/lib/Keepyourhead/database/BaseTopicFlashcardContainer.rb +43 -0
  28. data/lib/Keepyourhead/database/Collection.rb +43 -0
  29. data/lib/Keepyourhead/database/Database.rb +139 -0
  30. data/lib/Keepyourhead/database/File.rb +224 -0
  31. data/lib/Keepyourhead/database/FileRoot.rb +44 -0
  32. data/lib/Keepyourhead/database/Flashcard.rb +116 -0
  33. data/lib/Keepyourhead/database/Topic.rb +40 -0
  34. data/lib/Keepyourhead/database/Visitor.rb +33 -0
  35. data/lib/Keepyourhead/database/XmlAccessor.rb +315 -0
  36. data/lib/Keepyourhead/gui/Action.rb +91 -0
  37. data/lib/Keepyourhead/gui/DialogEditLatex.rb +132 -0
  38. data/lib/Keepyourhead/gui/DialogEditText.rb +104 -0
  39. data/lib/Keepyourhead/gui/DialogTrainStart.rb +63 -0
  40. data/lib/Keepyourhead/gui/FlashcardViewController.rb +112 -0
  41. data/lib/Keepyourhead/gui/WindowEdit.rb +469 -0
  42. data/lib/Keepyourhead/gui/WindowEditActions.rb +440 -0
  43. data/lib/Keepyourhead/gui/WindowEditAdapters.rb +329 -0
  44. data/lib/Keepyourhead/gui/WindowTrain.rb +167 -0
  45. data/lib/Keepyourhead/style/Style.rb +48 -0
  46. data/lib/Keepyourhead/style/StyleLatex.rb +235 -0
  47. metadata +100 -0
@@ -0,0 +1,91 @@
1
+ # Copyright 2008 Burghard Oliver
2
+ #
3
+ # This file is part of KeepYourHead.
4
+ #
5
+ # KeepYourHead is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # KeepYourHead is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with KeepYourHead. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+
20
+ module KeepYourHead
21
+ class Action
22
+ attr_accessor :procExecuteable
23
+ attr_reader :object
24
+ attr_reader :name
25
+
26
+ def initialize(object, name)
27
+ @widgets = []
28
+ @handler_id = {}
29
+ @object = object
30
+ @name = name
31
+ end
32
+
33
+ def widgets
34
+ @handler_id.keys
35
+ end
36
+
37
+ def addActivator(widget)
38
+ assert( @handler_id[widget] == nil )
39
+ @handler_id[widget] =
40
+ case widget
41
+ when Gtk::MenuItem
42
+ widget.signal_connect("activate") {
43
+ self.activate
44
+ }
45
+ when Gtk::ToolButton
46
+ widget.signal_connect("clicked") {
47
+ self.activate
48
+ }
49
+ else
50
+ throw ExceptionNotImplemented
51
+ end
52
+ end
53
+ def removeActivator(widget)
54
+ assert( @handler_id[widget] )
55
+ widget.signal_handler_disconnect @handler_id[widget]
56
+ @handler_id.delete widget
57
+ end
58
+
59
+ def enable
60
+ widgets.each{ |w| w.sensitive = true }
61
+ end
62
+ def disable
63
+ widgets.each{ |w| w.sensitive = false }
64
+ end
65
+
66
+ def executeable?
67
+ (not self.procExecuteable) || self.procExecuteable.call(object)
68
+ end
69
+ def updateEnable
70
+ if executeable? then
71
+ enable
72
+ else
73
+ disable
74
+ end
75
+ end
76
+
77
+ def activate(*args)
78
+ if self.executeable? then
79
+ object.actionBefore
80
+ ret = object.send("onAction#{name}", *args)
81
+ object.actionAfter
82
+ else
83
+ ret = nil
84
+ end
85
+
86
+ ret
87
+ end
88
+ end
89
+
90
+ end
91
+
@@ -0,0 +1,132 @@
1
+ # Copyright 2008 Burghard Oliver
2
+ #
3
+ # This file is part of KeepYourHead.
4
+ #
5
+ # KeepYourHead is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # KeepYourHead is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with KeepYourHead. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ module KeepYourHead
20
+ class DialogEditFlashcardLatex
21
+ RESPONSE_EDIT, RESPONSE_PREVIEW = *(101..102).to_a
22
+
23
+ Widgets = [ "notebook_output", "textview_output", "image_preview", "hscalePage", "hscaleBox",
24
+ "viewport_edit",
25
+ ]
26
+
27
+ # ImageWidth = (Gdk::Screen.default.width * 0.6).to_i
28
+ def initialize( flashcard, type )
29
+ @compilation = nil
30
+
31
+ @glade = GladeXML.new(Resources::system("glade/DialogEditLatex.glade")) { |handler| method(handler) }
32
+
33
+ @window = @glade.get_widget("dialog_edit_latex")
34
+
35
+ @flashcard, @type = flashcard, type
36
+
37
+ Widgets.each { |name|
38
+ widget = @glade.get_widget(name)
39
+ assert widget
40
+ eval("@#{name} = widget")
41
+ }
42
+
43
+ @flashcardViewController = FlashcardViewController.new @image_preview, @hscalePage, @hscaleBox
44
+
45
+ @window.title = "editieren"
46
+
47
+ # @notebook_output.width_request = (ImageWidth * 1.1).to_i
48
+
49
+ language = Gtk::SourceLanguagesManager.new.get_language("text/x-tex")
50
+
51
+ @edit_buffer = Gtk::SourceBuffer.new language
52
+ @edit_buffer.set_property( "check-brackets", true )
53
+ @edit_buffer.set_property( "highlight", true )
54
+ # @edit_buffer.set_property( "max-undo-levels", 20 )
55
+ @textview_latex = Gtk::SourceView.new @edit_buffer
56
+ @textview_latex.set_property( "auto-indent", true)
57
+ @textview_latex.set_property( "insert-spaces-instead-of-tabs", false)
58
+ # @textview_latex.set_property( "margin", 10)
59
+ @textview_latex.set_property( "show-line-markers", true)
60
+ @textview_latex.set_property( "show-line-numbers", true)
61
+ @textview_latex.set_property( "show-margin", true)
62
+ @textview_latex.set_property( "smart-home-end", true)
63
+ @textview_latex.set_property( "tabs-width", 4)
64
+
65
+ @viewport_edit.add @textview_latex
66
+ @textview_latex.show
67
+
68
+ @button_preview = @window.add_button "Vorschau", RESPONSE_PREVIEW
69
+ @button_edit = @window.add_button "editieren", RESPONSE_EDIT
70
+ @window.add_button Gtk::Stock::APPLY, Gtk::Dialog::RESPONSE_APPLY
71
+ @window.add_button Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL
72
+ end
73
+
74
+ def text
75
+ @edit_buffer.text
76
+ end
77
+
78
+ def text=(t)
79
+ @edit_buffer.text = t
80
+ end
81
+
82
+ def makePreview
83
+ style = @flashcard.file.style("latex")
84
+
85
+ @compilation.remove if @compilation
86
+
87
+ @compilation = @flashcard.compileImage(@type, :previewCode => @textview_latex.buffer.text )
88
+
89
+ @flashcardViewController.filenames = Images.fromCompilation @type, @compilation
90
+ if @compilation.success and @compilation.filenames.length > 0 then
91
+ @notebook_output.page = 2
92
+ else
93
+ @notebook_output.page = 1
94
+ end
95
+
96
+ @textview_output.buffer.text = @compilation.output
97
+ end
98
+
99
+
100
+ def run
101
+ @window.show
102
+
103
+ ret = nil
104
+
105
+ while ret == nil do
106
+ response = @window.run
107
+
108
+ case response
109
+ when Gtk::Dialog::RESPONSE_APPLY
110
+ ret = true
111
+ when Gtk::Dialog::RESPONSE_CANCEL
112
+ ret = false
113
+ when RESPONSE_PREVIEW
114
+ makePreview
115
+ when RESPONSE_EDIT
116
+ @notebook_output.page = 0
117
+ else
118
+ # puts response
119
+ end
120
+ end
121
+
122
+ @compilation.remove if @compilation
123
+
124
+ ret
125
+ end
126
+
127
+ def destroy
128
+ @window.destroy
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,104 @@
1
+ # Copyright 2008 Burghard Oliver
2
+ #
3
+ # This file is part of KeepYourHead.
4
+ #
5
+ # KeepYourHead is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # KeepYourHead is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with KeepYourHead. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ module KeepYourHead
20
+ class DialogEditText
21
+ attr_accessor :changeProc
22
+
23
+ Widgets = ["viewport_edit", "labelName" ]
24
+
25
+ def initialize( name )
26
+ @glade = GladeXML.new(Resources::system("glade/DialogEditText.glade")) { |handler| method(handler) }
27
+
28
+ @window = @glade.get_widget("dialog_edit_text")
29
+
30
+ Widgets.each { |name|
31
+ widget = @glade.get_widget(name)
32
+ assert widget
33
+ eval("@#{name} = widget")
34
+ }
35
+
36
+ self.name = name
37
+
38
+ @window.title = "editieren"
39
+
40
+ language = Gtk::SourceLanguagesManager.new.get_language("text/x-tex")
41
+
42
+ @edit_buffer = Gtk::SourceBuffer.new language
43
+ @edit_buffer.set_property( "check-brackets", true )
44
+ @edit_buffer.set_property( "highlight", true )
45
+ # @edit_buffer.set_property( "max-undo-levels", 20 )
46
+ @textview_latex = Gtk::SourceView.new @edit_buffer
47
+ @textview_latex.set_property( "auto-indent", true)
48
+ @textview_latex.set_property( "insert-spaces-instead-of-tabs", false)
49
+ # @textview_latex.set_property( "margin", 10)
50
+ @textview_latex.set_property( "show-line-markers", true)
51
+ @textview_latex.set_property( "show-line-numbers", true)
52
+ @textview_latex.set_property( "show-margin", true)
53
+ @textview_latex.set_property( "smart-home-end", true)
54
+ @textview_latex.set_property( "tabs-width", 4)
55
+
56
+ @viewport_edit.add @textview_latex
57
+ @textview_latex.show
58
+
59
+ @window.add_button Gtk::Stock::APPLY, Gtk::Dialog::RESPONSE_APPLY
60
+ @window.add_button Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL
61
+ end
62
+
63
+ def name
64
+ @labelName.text
65
+ end
66
+ def name=(o)
67
+ @labelName.text=o
68
+ end
69
+
70
+ def text
71
+ @edit_buffer.text
72
+ end
73
+
74
+ def text=(t)
75
+ @edit_buffer.text = t
76
+ end
77
+
78
+
79
+ def run
80
+ @window.show
81
+
82
+ ret = nil
83
+
84
+ while ret == nil do
85
+ response = @window.run
86
+
87
+ case response
88
+ when Gtk::Dialog::RESPONSE_APPLY
89
+ ret = true
90
+ when Gtk::Dialog::RESPONSE_CANCEL
91
+ ret = false
92
+ end
93
+ end
94
+
95
+ ret
96
+ end
97
+
98
+ def destroy
99
+ @window.destroy
100
+ end
101
+ end
102
+
103
+
104
+ end
@@ -0,0 +1,63 @@
1
+ # Copyright 2008 Burghard Oliver
2
+ #
3
+ # This file is part of KeepYourHead.
4
+ #
5
+ # KeepYourHead is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # KeepYourHead is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with KeepYourHead. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ module KeepYourHead
20
+ class DialogQuestionStart
21
+ Widgets = ["spinbutton_max_questions", "spinbutton_max_minutes"]
22
+
23
+ attr_reader :widget
24
+
25
+ def initialize( )
26
+ @glade = GladeXML.new(Resources::system("glade/DialogTrainStart.glade")) { |handler| method(handler) }
27
+
28
+ Widgets.each { |name|
29
+ widget = @glade.get_widget(name)
30
+ assert widget
31
+ eval("@#{name} = widget")
32
+ }
33
+
34
+ @widget = @glade.get_widget("dialog_train_start")
35
+ end
36
+
37
+ def run
38
+ @widget.show
39
+ response = @widget.run
40
+
41
+ case response
42
+ when Gtk::Dialog::RESPONSE_OK
43
+ return true
44
+ else
45
+ end
46
+
47
+ false
48
+ end
49
+
50
+ def destroy
51
+ @widget.destroy
52
+ end
53
+
54
+ def max_questions
55
+ @spinbutton_max_questions.value.to_i
56
+ end
57
+ def max_minutes
58
+ @spinbutton_max_minutes.value.to_i
59
+ end
60
+ end
61
+
62
+
63
+ end
@@ -0,0 +1,112 @@
1
+ # Copyright 2008 Burghard Oliver
2
+ #
3
+ # This file is part of KeepYourHead.
4
+ #
5
+ # KeepYourHead is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # KeepYourHead is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with KeepYourHead. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ module KeepYourHead
20
+ class FlashcardViewController
21
+ attr_reader :filenames, :filename, :page
22
+ attr_reader :pixbuf
23
+
24
+ def initialize( gtkImage, gtkScale, gtkScaleContainer )
25
+ @gtkImage, @gtkScale, @gtkScaleContainer = gtkImage, gtkScale, gtkScaleContainer
26
+
27
+ @width = nil
28
+
29
+ @gtkScale.signal_connect( "value_changed" ) {
30
+ onPageChange
31
+ }
32
+
33
+ @gtkImage.signal_connect( "size-allocate") { |widget, event|
34
+ width_ = @gtkImage.allocation.width
35
+ self.width = (width_ * 0.98 - 5).to_i
36
+ }
37
+ end
38
+
39
+ def onPageChange
40
+ page = @gtkScale.value
41
+ self.filename = self.filenames[page]
42
+ end
43
+
44
+ def filenames=(filenames)
45
+ @filenames = filenames
46
+ if self.filenames.length > 0 then
47
+ if self.filenames.length > 1 then
48
+ @gtkScale.sensitive = true
49
+ @gtkScaleContainer.show
50
+ else
51
+ @gtkScale.sensitive = false
52
+ @gtkScaleContainer.hide
53
+ end
54
+
55
+ @gtkScale.adjustment = Gtk::Adjustment.new( 0, 0, self.filenames.length - 0.001, 1, 1, 0 )
56
+ @gtkImage.show
57
+
58
+ self.filename = self.filenames[0]
59
+ else
60
+ @gtkImage.hide
61
+ end
62
+ end
63
+
64
+ protected
65
+
66
+ def filename=(other)
67
+ return if other == self.filename
68
+
69
+ # print "loading #{filename}|before #{other}"
70
+
71
+ @filename = other
72
+ self.pixbuf = Gdk::Pixbuf.new self.filename
73
+ end
74
+
75
+ attr_reader :width
76
+ def width=(value)
77
+ # print "imageWidth #{value}"
78
+ return if self.width == value
79
+
80
+ @width = [value,1].max
81
+ @pixbufScaled = nil
82
+
83
+ @gtkImage.set self.pixbufScaled if self.pixbufScaled
84
+ end
85
+
86
+ def height
87
+ if self.pixbuf then
88
+ [(1.0 * self.pixbuf.height / self.pixbuf.width * self.width).to_i,1].max
89
+ else
90
+ 1
91
+ end
92
+ end
93
+
94
+ def pixbuf=(other)
95
+ @pixbuf = other
96
+ @pixbufScaled = nil
97
+
98
+ @gtkImage.set self.pixbufScaled if self.pixbufScaled
99
+ end
100
+
101
+ def pixbufScaled
102
+ if not @pixbufScaled and self.pixbuf and self.width then
103
+ # print "scale"
104
+
105
+ @pixbufScaled = self.pixbuf.scale(self.width, self.height)
106
+ end
107
+
108
+ @pixbufScaled
109
+ end
110
+ end
111
+ end
112
+