Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/jldrill/oldUI/GtkVocabView.rb | 204 | 168 | 88.24%
|
85.71%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 require 'gtk2' |
2 require 'jldrill/model/items/Vocabulary' |
3 |
4 module JLDrill::Gtk |
5 class GtkVocabView < Gtk::VBox |
6 |
7 def initialize(vocab) |
8 super() |
9 @acceptReadingBlock = nil |
10 @acceptKanjiBlock = nil |
11 @kanjiField = createField("Kanji: ", vocab.kanji) do |
12 @acceptKanjiBlock.call |
13 end |
14 @hintField = createField("Hint: ", vocab.hint) |
15 @readingField = createField("Reading: ", vocab.reading) do |
16 @acceptReadingBlock.call |
17 end |
18 @definitionsBox = createBox("Definitions: ", |
19 vocab.definitionsRaw) |
20 @markersBox = createField("Markers: ", vocab.markers) |
21 |
22 pack_start(@kanjiField, true, false, 5) |
23 pack_start(@hintField, true, false, 5) |
24 pack_start(@readingField, true, false, 5) |
25 pack_start(@definitionsBox, true, true, 5) |
26 pack_start(@markersBox, true, true, 5) |
27 end |
28 |
29 def kanjiWidget |
30 @kanjiField.children[1] |
31 end |
32 |
33 def hintWidget |
34 @hintField.children[1] |
35 end |
36 |
37 def readingWidget |
38 @readingField.children[1] |
39 end |
40 |
41 # For some reason I am losing the entry in my boxes |
42 # I think it's a GTK bug, but I'm not sure. |
43 def definitionsWidget |
44 retVal = nil |
45 a2 = @definitionsBox.children[1] |
46 if !a2.nil? |
47 entry = a2.children[0] |
48 if !entry.nil? |
49 retVal = entry.children[0] |
50 else |
51 print "Error: definitionsWidget Entry is nil!!!\n" |
52 end |
53 else |
54 print "Error: definitionsWidget Alignment is nil!!!\n" |
55 end |
56 return retVal |
57 end |
58 |
59 def markersWidget |
60 @markersBox.children[1] |
61 end |
62 |
63 def kanji |
64 kanjiWidget.text |
65 end |
66 |
67 def kanji=(string) |
68 if string.nil? then string = "" end |
69 kanjiWidget.set_text(string) |
70 end |
71 |
72 def hint |
73 hintWidget.text |
74 end |
75 |
76 def hint=(string) |
77 if string.nil? then string = "" end |
78 hintWidget.set_text(string) |
79 end |
80 |
81 def reading |
82 readingWidget.text |
83 end |
84 |
85 def reading=(string) |
86 if string.nil? then string = "" end |
87 readingWidget.set_text(string) |
88 end |
89 |
90 def definitions |
91 widget = definitionsWidget |
92 if !widget.nil? |
93 return widget.buffer.text |
94 else |
95 return "" |
96 end |
97 end |
98 |
99 def definitions=(string) |
100 if string.nil? then string = "" end |
101 widget = definitionsWidget |
102 if !widget.nil? |
103 widget.buffer.set_text(string) |
104 end |
105 end |
106 |
107 def markers |
108 markersWidget.text |
109 end |
110 |
111 def markers=(string) |
112 if string.nil? then string = "" end |
113 markersWidget.set_text(string) |
114 end |
115 |
116 def getVocab |
117 vocab = JLDrill::Vocabulary.new |
118 vocab.kanji = kanji |
119 vocab.hint = hint |
120 vocab.reading = reading |
121 vocab.definitions = definitions |
122 vocab.markers = markers |
123 return vocab |
124 end |
125 |
126 def setVocab(vocab) |
127 if vocab |
128 self.kanji = vocab.kanjiRaw |
129 self.hint = vocab.hintRaw |
130 self.reading = vocab.readingRaw |
131 self.definitions = vocab.definitionsRaw |
132 self.markers = vocab.markersRaw |
133 end |
134 end |
135 |
136 # Sets the fields to the vocabulary listed, but doesn't |
137 # set the hint. This is used to populate the views from |
138 # a dictionary entry (which doesn't have hints) rather than |
139 # the user's enter. |
140 def setDictionaryVocab(vocab) |
141 if vocab |
142 self.kanji = vocab.kanjiRaw |
143 self.reading = vocab.readingRaw |
144 self.definitions = vocab.definitionsRaw |
145 self.markers = vocab.markersRaw |
146 end |
147 end |
148 |
149 def createField(label, value, &block) |
150 if !label then label = "" end |
151 if !value then value = "" end |
152 |
153 hbox = Gtk::HBox.new() |
154 hbox.pack_start(Gtk::Label.new(label), false, false, 5) |
155 entry = Gtk::Entry.new |
156 entry.editable = true |
157 entry.text = value |
158 hbox.pack_start(entry, true, true, 5) |
159 if !block.nil? |
160 entry.signal_connect('activate') do |widget| |
161 block.call |
162 end |
163 end |
164 return hbox |
165 end |
166 |
167 def createBox(label, value, &block) |
168 if !label then label = "" end |
169 if !value then value = "" end |
170 |
171 hbox = Gtk::HBox.new() |
172 alignment1 = Gtk::Alignment.new(0,0,0,0.5) |
173 alignment1.add(Gtk::Label.new(label)) |
174 hbox.pack_start(alignment1, false, false, 5) |
175 |
176 entry = Gtk::ScrolledWindow.new |
177 entry.shadow_type = Gtk::SHADOW_IN |
178 entry.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) |
179 contents = Gtk::TextView.new |
180 contents.wrap_mode = Gtk::TextTag::WRAP_WORD |
181 contents.editable = true |
182 contents.cursor_visible = true |
183 entry.add(contents) |
184 contents.buffer.text = value |
185 |
186 alignment2 = Gtk::Alignment.new(0,0.5,1,1) |
187 alignment2.add(entry) |
188 |
189 hbox.pack_start(alignment2, true, true, 5) |
190 return hbox |
191 end |
192 |
193 def setAcceptReading(&block) |
194 @acceptReadingBlock = block |
195 end |
196 |
197 def setAcceptKanji(&block) |
198 @acceptKanjiBlock = block |
199 end |
200 def focusReading |
201 readingWidget.grab_focus |
202 end |
203 end |
204 end |
Generated on Mon May 23 16:17:46 +0900 2011 with rcov 0.9.8