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.
- data/COPYING.txt +674 -0
- data/LICENSE.rdoc +20 -0
- data/README.rdoc +3 -0
- data/bin/keepyourhead +6 -0
- data/data/glade/DialogEditLatex.glade +180 -0
- data/data/glade/DialogEditText.glade +66 -0
- data/data/glade/DialogTrainStart.glade +101 -0
- data/data/glade/WindowEdit.glade +1419 -0
- data/data/glade/WindowTrain.glade +271 -0
- data/data/images/error_back.png +0 -0
- data/data/images/error_front.png +0 -0
- data/data/images/loading_back.png +0 -0
- data/data/images/loading_front.png +0 -0
- data/lib/Keepyourhead.rb +62 -0
- data/lib/Keepyourhead/Application.rb +94 -0
- data/lib/Keepyourhead/Cache.rb +233 -0
- data/lib/Keepyourhead/Compilation.rb +38 -0
- data/lib/Keepyourhead/Images.rb +62 -0
- data/lib/Keepyourhead/Preferences.rb +52 -0
- data/lib/Keepyourhead/Requirements.rb +72 -0
- data/lib/Keepyourhead/Resources.rb +45 -0
- data/lib/Keepyourhead/Training.rb +132 -0
- data/lib/Keepyourhead/Utils.rb +97 -0
- data/lib/Keepyourhead/Version.rb +43 -0
- data/lib/Keepyourhead/database/Base.rb +77 -0
- data/lib/Keepyourhead/database/BaseStatistic.rb +63 -0
- data/lib/Keepyourhead/database/BaseTopicFlashcardContainer.rb +43 -0
- data/lib/Keepyourhead/database/Collection.rb +43 -0
- data/lib/Keepyourhead/database/Database.rb +139 -0
- data/lib/Keepyourhead/database/File.rb +224 -0
- data/lib/Keepyourhead/database/FileRoot.rb +44 -0
- data/lib/Keepyourhead/database/Flashcard.rb +116 -0
- data/lib/Keepyourhead/database/Topic.rb +40 -0
- data/lib/Keepyourhead/database/Visitor.rb +33 -0
- data/lib/Keepyourhead/database/XmlAccessor.rb +315 -0
- data/lib/Keepyourhead/gui/Action.rb +91 -0
- data/lib/Keepyourhead/gui/DialogEditLatex.rb +132 -0
- data/lib/Keepyourhead/gui/DialogEditText.rb +104 -0
- data/lib/Keepyourhead/gui/DialogTrainStart.rb +63 -0
- data/lib/Keepyourhead/gui/FlashcardViewController.rb +112 -0
- data/lib/Keepyourhead/gui/WindowEdit.rb +469 -0
- data/lib/Keepyourhead/gui/WindowEditActions.rb +440 -0
- data/lib/Keepyourhead/gui/WindowEditAdapters.rb +329 -0
- data/lib/Keepyourhead/gui/WindowTrain.rb +167 -0
- data/lib/Keepyourhead/style/Style.rb +48 -0
- data/lib/Keepyourhead/style/StyleLatex.rb +235 -0
- metadata +100 -0
@@ -0,0 +1,38 @@
|
|
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 Compilation
|
21
|
+
attr_accessor :content, :success, :output, :directory, :filenames
|
22
|
+
|
23
|
+
def initialize( content, success, output, directory, filenames )
|
24
|
+
self.content, self.success, self.output, self.directory, self.filenames =
|
25
|
+
content, success, output, directory, filenames
|
26
|
+
end
|
27
|
+
|
28
|
+
def remove
|
29
|
+
self.filenames.each{ |filename|
|
30
|
+
FileUtils.rm filename if ::File.exist? filename
|
31
|
+
}
|
32
|
+
|
33
|
+
FileUtils.rm_r self.directory if ::File.exist? self.directory
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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 Images
|
21
|
+
def self.typeToName(type)
|
22
|
+
case type
|
23
|
+
when Database::FRONT
|
24
|
+
"front"
|
25
|
+
when Database::BACK
|
26
|
+
"back"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.imageError(type)
|
31
|
+
[Resources::system("images/error_#{typeToName(type)}.png")]
|
32
|
+
end
|
33
|
+
def self.imageLoading(type)
|
34
|
+
[Resources::system("images/loading_#{typeToName(type)}.png")]
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.fromCacheItem( type, cacheItem)
|
38
|
+
if cacheItem then
|
39
|
+
if cacheItem.success then
|
40
|
+
cacheItem.filenames
|
41
|
+
else
|
42
|
+
imageError type
|
43
|
+
end
|
44
|
+
else
|
45
|
+
imageLoading type
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.fromCompilation( type, compilation)
|
50
|
+
if compilation then
|
51
|
+
if compilation.success then
|
52
|
+
compilation.filenames
|
53
|
+
else
|
54
|
+
imageError type
|
55
|
+
end
|
56
|
+
else
|
57
|
+
imageError type
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,52 @@
|
|
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 Preferences
|
21
|
+
Filename = Resources::user "Preferences.yaml"
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
load
|
25
|
+
end
|
26
|
+
|
27
|
+
def load
|
28
|
+
begin
|
29
|
+
@data = YAML::load_file( Filename )
|
30
|
+
rescue
|
31
|
+
@data = {}
|
32
|
+
print "no Preferences not found"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def writeBack
|
37
|
+
::File.open( Filename, "w" ) { |file|
|
38
|
+
YAML::dump(@data, file)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def []( name )
|
44
|
+
@data[name]
|
45
|
+
end
|
46
|
+
def []=( name, value )
|
47
|
+
@data[name] = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module KeepYourHead
|
2
|
+
class Requirement
|
3
|
+
attr_accessor :name, :website, :errorDescription, :checkProc
|
4
|
+
def initialize
|
5
|
+
yield self
|
6
|
+
end
|
7
|
+
def check
|
8
|
+
ret =
|
9
|
+
begin
|
10
|
+
@checkProc.call
|
11
|
+
rescue
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
if not ret then
|
16
|
+
puts <<-END
|
17
|
+
Requiremente failed !
|
18
|
+
-------------------------------
|
19
|
+
#{errorDescription}
|
20
|
+
Please install #{name}
|
21
|
+
#{website}
|
22
|
+
-------------------------------
|
23
|
+
END
|
24
|
+
end
|
25
|
+
|
26
|
+
ret
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
requirements = []
|
32
|
+
requirements << Requirement.new { |r|
|
33
|
+
r.checkProc = proc {
|
34
|
+
system( "gs --version > /dev/null" )
|
35
|
+
}
|
36
|
+
r.name = "ghostscript"
|
37
|
+
r.errorDescription = "'gs' not found"
|
38
|
+
r.website = "http://www.ghostscript.com/awki"
|
39
|
+
}
|
40
|
+
requirements << Requirement.new {|r|
|
41
|
+
r.checkProc = proc {
|
42
|
+
system( "pdflatex --version > /dev/null" )
|
43
|
+
}
|
44
|
+
r.name = "latex"
|
45
|
+
r.errorDescription = "'pdflatex' not found"
|
46
|
+
r.website = "http://www.tug.org/texlive"
|
47
|
+
}
|
48
|
+
requirements << Requirement.new { |r|
|
49
|
+
r.checkProc = proc {
|
50
|
+
require "rubygems"
|
51
|
+
require 'gtk2'
|
52
|
+
require "libglade2"
|
53
|
+
}
|
54
|
+
r.name = "ruby-gnome2"
|
55
|
+
r.errorDescription = "'ruby-gnome2' not found"
|
56
|
+
r.website = "http://ruby-gnome2.sourceforge.jp"
|
57
|
+
}
|
58
|
+
|
59
|
+
requirements << Requirement.new { |r|
|
60
|
+
r.checkProc = proc {
|
61
|
+
require "rubygems"
|
62
|
+
require 'gtk2'
|
63
|
+
require "libglade2"
|
64
|
+
require 'gtksourceview'
|
65
|
+
}
|
66
|
+
r.name = "ruby-gnome2"
|
67
|
+
r.errorDescription = "'ruby-gnome2' compiled without 'gtksourceview'"
|
68
|
+
r.website = "http://ruby-gnome2.sourceforge.jp"
|
69
|
+
}
|
70
|
+
Requirements = requirements
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module KeepYourHead
|
2
|
+
class Resources
|
3
|
+
public
|
4
|
+
|
5
|
+
path = ::File.dirname(__FILE__)
|
6
|
+
path = ::File.expand_path(path)
|
7
|
+
path = ::File.expand_path("../../data", path)
|
8
|
+
PathSystem = path
|
9
|
+
|
10
|
+
# returns a file or folder in the storage for the actual user
|
11
|
+
def self.user(name)
|
12
|
+
path = ::File.expand_path("~/.KeepYourHead")
|
13
|
+
::File.makedirs path unless ::File.directory? path
|
14
|
+
path = ::File.expand_path( name, path )
|
15
|
+
path
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns a folder or file from the gem, that is same for all the system
|
19
|
+
def self.system(name)
|
20
|
+
path = ::File.expand_path(name, PathSystem)
|
21
|
+
path
|
22
|
+
end
|
23
|
+
|
24
|
+
WorkDirectory = user( "work/" )
|
25
|
+
|
26
|
+
# creates a new working directory in the user folder that must be deleted afterwards
|
27
|
+
def self.createWorkingDirectory
|
28
|
+
directory = nil
|
29
|
+
|
30
|
+
@monitorDirectory ||= Monitor.new
|
31
|
+
@monitorDirectory.mon_synchronize {
|
32
|
+
begin
|
33
|
+
val = rand(3000000)
|
34
|
+
directory = ::File.expand_path("tmp_#{val}/", WorkDirectory )
|
35
|
+
end while ::File.directory?(directory) or ::File.exist?(directory)
|
36
|
+
|
37
|
+
::File.makedirs directory unless ::File.directory? directory
|
38
|
+
}
|
39
|
+
|
40
|
+
directory
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
@@ -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 FlashcardTraining
|
21
|
+
attr_reader :flashcard
|
22
|
+
attr_reader :flashcards
|
23
|
+
attr_reader :database
|
24
|
+
|
25
|
+
attr_reader :timeStarted
|
26
|
+
attr_reader :timeMax
|
27
|
+
|
28
|
+
attr_reader :questionsMax
|
29
|
+
attr_reader :flashcardsAsked, :flashcardsKnown, :flashcardsUnknown
|
30
|
+
|
31
|
+
|
32
|
+
# in hours
|
33
|
+
StufenSkipTime = [
|
34
|
+
1, 3, 6,
|
35
|
+
1*24, 2*24, 4*24, 7*24, 14*24,
|
36
|
+
1*30*24, 2*30*24
|
37
|
+
].map{ |h| h * 60 * 60 }
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
# timemax in seconds
|
42
|
+
def initialize( database, questionsMax, timeMax )
|
43
|
+
@stacksize = 7
|
44
|
+
|
45
|
+
@questionsMax, @timeMax = questionsMax, timeMax
|
46
|
+
|
47
|
+
@flashcardsAsked = Set.new
|
48
|
+
@flashcardsKnown = Set.new
|
49
|
+
@flashcardsUnknown = Set.new
|
50
|
+
|
51
|
+
@timeStarted = Time.now
|
52
|
+
|
53
|
+
flashcardsAll = database.collectFlashcards.select { |fc| fc.active? }
|
54
|
+
@flashcards = []
|
55
|
+
questionsMax.times {
|
56
|
+
if flashcardsAll.length > 0 then
|
57
|
+
idx = rand( flashcardsAll.length )
|
58
|
+
@flashcards << flashcardsAll.delete_at(idx)
|
59
|
+
end
|
60
|
+
}
|
61
|
+
|
62
|
+
@countStart = @flashcards.length
|
63
|
+
|
64
|
+
@flashcard = nil
|
65
|
+
|
66
|
+
@database = database
|
67
|
+
|
68
|
+
nextFlashcard
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def onKnown
|
73
|
+
@flashcardsKnown << @flashcard
|
74
|
+
@flashcardsAsked << @flashcard
|
75
|
+
|
76
|
+
@flashcard.nextCheck = Time.now + StufenSkipTime[[@flashcard.level, StufenSkipTime.length-1].min]
|
77
|
+
@flashcard.level = @flashcard.level + 1
|
78
|
+
|
79
|
+
@flashcards.pop
|
80
|
+
|
81
|
+
nextFlashcard
|
82
|
+
end
|
83
|
+
|
84
|
+
def onUnknown
|
85
|
+
@flashcardsUnknown << @flashcard
|
86
|
+
@flashcardsAsked << @flashcard
|
87
|
+
|
88
|
+
|
89
|
+
@flashcard.nextCheck = Time.now - 60
|
90
|
+
@flashcard.level = 0
|
91
|
+
|
92
|
+
nextFlashcard
|
93
|
+
end
|
94
|
+
|
95
|
+
def progressFlashcards
|
96
|
+
if @countStart > 0 then
|
97
|
+
(@countStart - @flashcards.length) / @countStart
|
98
|
+
else
|
99
|
+
1.0
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def timeUsed
|
104
|
+
Time.now - @timeStarted
|
105
|
+
end
|
106
|
+
|
107
|
+
def progressTime
|
108
|
+
(Time.now - @timeStarted) / @timeMax
|
109
|
+
end
|
110
|
+
|
111
|
+
def nextFlashcard
|
112
|
+
# if @flashcards.length > 0 and progressTime < 1.0 then
|
113
|
+
if progressFlashcards < 1.0 and progressTime < 1.0 then
|
114
|
+
assert @flashcards.length > 0
|
115
|
+
|
116
|
+
idx = rand( [@flashcards.length, @stacksize].min )
|
117
|
+
@flashcard = @flashcards.delete_at( @flashcards.length - 1 - idx )
|
118
|
+
@flashcards.push @flashcard
|
119
|
+
else
|
120
|
+
@flashcard = nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def close
|
125
|
+
database.saveAllChanged
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,97 @@
|
|
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
|
+
require 'fileutils.rb'
|
19
|
+
require 'ftools'
|
20
|
+
|
21
|
+
$requireBase = File.expand_path( ".", File.dirname( __FILE__ ) )
|
22
|
+
def requireExp(name)
|
23
|
+
require File.expand_path( name, $requireBase )
|
24
|
+
end
|
25
|
+
requireExp "Requirements.rb"
|
26
|
+
|
27
|
+
if not KeepYourHead::Requirements.inject(true) { |val,r| val = r.check && val } then
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
alias print puts
|
33
|
+
def puts(*args)
|
34
|
+
print args
|
35
|
+
print caller
|
36
|
+
end
|
37
|
+
|
38
|
+
#def system(*cmd)
|
39
|
+
# print "system: #{`pwd`}> #{cmd}"
|
40
|
+
# Kernel::system *cmd
|
41
|
+
#end
|
42
|
+
|
43
|
+
require "rubygems"
|
44
|
+
|
45
|
+
require "set.rb"
|
46
|
+
require "thread.rb" # for queue
|
47
|
+
require 'pp'
|
48
|
+
require 'digest.rb'
|
49
|
+
require "rexml/document"
|
50
|
+
require "yaml"
|
51
|
+
require "date.rb"
|
52
|
+
require "time.rb"
|
53
|
+
require "monitor.rb"
|
54
|
+
require 'getoptlong.rb'
|
55
|
+
|
56
|
+
require 'gtk2'
|
57
|
+
require 'gtksourceview'
|
58
|
+
require "libglade2"
|
59
|
+
|
60
|
+
|
61
|
+
def printSignals(widget)
|
62
|
+
widget.class.signals(false).each do |v|
|
63
|
+
widget.signal_connect(v) do
|
64
|
+
print "#{v} is occured."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
#require "RMagick"
|
71
|
+
#include Magick
|
72
|
+
###require "rghost"
|
73
|
+
|
74
|
+
class ExceptionShouldNotBeReached < Exception
|
75
|
+
def initialize
|
76
|
+
super "should not be reached"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class ExceptionNotImplemented < Exception
|
81
|
+
def initialize
|
82
|
+
super "not implemented"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class ExceptionAssert < Exception
|
87
|
+
def initialize(msg)
|
88
|
+
super msg
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def assert( test, msg = nil )
|
94
|
+
throw ExceptionAssert.new(msg) unless test
|
95
|
+
end
|
96
|
+
|
97
|
+
|