Jldrill Git C0 Coverage Information - RCov

lib/jldrill/views/gtk/widgets/ExampleWindow.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/jldrill/views/gtk/widgets/ExampleWindow.rb 158 136
16.46%
11.76%

Key

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.

Coverage Details

1 require 'Context/Gtk/Widget'
2 require 'jldrill/views/gtk/widgets/KanjiPopupFactory'
3 require 'jldrill/views/gtk/widgets/VocabPopupFactory'
4 require 'gtk2'
5 
6 module JLDrill::Gtk
7     class ExampleWindow < Gtk::Window
8         include Context::Gtk::Widget
9 
10         def initialize(view)
11             @view = view
12             @context = @view.context
13 			@closed = false
14             super("Examples")
15             @accel = Gtk::AccelGroup.new
16             @kanjiPopupFactory = KanjiPopupFactory.new(view)
17             @vocabPopupFactory = VocabPopupFactory.new(view)
18             @popupFactory = @kanjiPopupFactory
19             @lastEvent = nil
20 
21             sw = Gtk::ScrolledWindow.new
22             sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
23             sw.shadow_type = Gtk::SHADOW_IN
24             self.add(sw)
25             
26             @contents = Gtk::TextView.new
27             @contents.wrap_mode = Gtk::TextTag::WRAP_WORD
28             @contents.editable = false
29             @contents.cursor_visible = false
30             sw.add(@contents)
31             self.set_default_size(400, 360)
32 			connectSignals unless @view.nil?
33             createTags
34         end
35 
36         def createTags
37             @contents.buffer.create_tag("normal", 
38                                "background" => "#ffffff")
39             @contents.buffer.create_tag("checked", 
40                                "background" => "#e0f0ff")
41             @contents.buffer.create_tag("h1",
42                                         "size" => 20 * Pango::SCALE,
43                                         "justification" => Gtk::JUSTIFY_CENTER)
44             @contents.buffer.create_tag("h2",
45                                         "size" => 15 * Pango::SCALE,
46                                         "justification" => Gtk::JUSTIFY_CENTER)
47 
48         end
49 
50 		def connectSignals
51             @accel = Gtk::AccelGroup.new
52             @accel.connect(Gdk::Keyval::GDK_Escape, 0,
53                            Gtk::ACCEL_VISIBLE) do
54                 self.close
55             end
56             add_accel_group(@accel)
57             
58             signal_connect('delete_event') do
59                 # Request that the destroy signal be sent
60                 false
61             end
62             
63             signal_connect('destroy') do
64                 self.close
65             end
66 
67             # Kanji Popup
68             @contents.add_events(Gdk::Event::POINTER_MOTION_MASK)
69             @contents.add_events(Gdk::Event::LEAVE_NOTIFY_MASK)
70             
71             @contents.signal_connect('motion_notify_event') do |widget, motion|
72                 @lastEvent = MotionEvent.new(widget, motion)
73                 @popupFactory.notify(@lastEvent)
74             end
75 
76             @contents.signal_connect('leave_notify_event') do
77                 @popupFactory.closePopup
78             end
79             
80             @accel.connect(Gdk::Keyval::GDK_space, 0, Gtk::ACCEL_VISIBLE) do
81                 @popupFactory.closePopup
82                 if @context.dictionaryLoaded?
83                     if @popupFactory == @kanjiPopupFactory
84                         @popupFactory = @vocabPopupFactory
85                     else
86                         @popupFactory = @kanjiPopupFactory
87                     end
88                     if !@lastEvent.nil?
89                         @popupFactory.notify(@lastEvent)
90                     end
91                 end
92             end
93             
94         end
95         
96         def close
97             if !@closed
98                 @view.close
99             end
100         end
101         
102         def explicitDestroy
103             @closed = true
104             self.destroy
105         end
106 
107         def sortExamples(examples)
108            return examples.sort do |x, y|
109                retVal = x.sense <=> y.sense
110                if y.checked && !x.checked
111                    retVal = 1
112                end
113                if x.checked && !y.checked
114                    retVal = -1
115                end
116                retVal
117            end
118         end
119  
120         def updateContents(examples)
121             @contents.buffer.text = ""
122             if !examples.nil?
123                 section = -2
124                 sortExamples(examples).each do |example|
125                     if example.checked
126                         if section == -2
127                             section = -1
128                             insert("Checked Examples\n", "h1")
129                             insertVSpace
130                         end
131                     else
132                         if section < 0
133                             insert("Unchecked Examples\n", "h1")
134                             insertVSpace
135                         end
136                         if section != example.sense
137                             section = example.sense
138                             if section != 0
139                                 insertVSpace
140                                 insert("Examples for sense ##{section}\n", "h2")
141                             end
142                         end
143                     end
144                     insert(example.to_s + "\n", "normal")
145                     insertVSpace
146                 end
147             end
148         end
149 
150         def insert(text, tag)
151             @contents.buffer.insert(@contents.buffer.end_iter, text, tag)
152         end
153 
154         def insertVSpace
155             insert("\n", "normal")
156         end
157     end
158 end

Generated on Mon May 23 16:17:46 +0900 2011 with rcov 0.9.8