Jldrill Git C0 Coverage Information - RCov

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

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/jldrill/views/gtk/widgets/ProblemPane.rb 175 135
78.86%
77.04%

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 'gtk2'
3 
4 module JLDrill::Gtk
5 
6     # This is a scrolled window that shows information from
7     # a problem.  There are two kinds of problem pane:
8     # the QuestionPane and the AnswerPane.  The QuestionPane
9     # shows the question for the problem and the AnswerPane
10     # shows the answer
11     class ProblemPane < Gtk::ScrolledWindow
12         include Context::Gtk::Widget
13 
14         NORMAL_COLOR = Gdk::Color.parse("#ffffc0")
15         DISPLAY_ONLY_COLOR = Gdk::Color.parse("#e0f0ff")
16         PREVIEW_COLOR = Gdk::Color.parse("#ffe0ff")
17         EXPIRED_COLOR = Gdk::Color.parse("#f07070")
18 
19         attr_reader :contents
20 
21         def initialize(display)
22             super()
23             @display = display
24             setupWidget
25 
26             self.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
27             self.shadow_type = Gtk::SHADOW_IN
28             @contents = Gtk::TextView.new
29             @contents.wrap_mode = Gtk::TextTag::WRAP_WORD
30             @contents.editable = false
31             @contents.cursor_visible = false
32             @contents.set_pixels_above_lines(5)
33             normalMode
34             self.add(@contents)
35             @buffer = @contents.buffer
36             createTags
37             @images = []
38         end
39 
40         def normalMode
41             @contents.modify_base(Gtk::STATE_NORMAL, NORMAL_COLOR)
42         end
43 
44         def previewMode
45             @contents.modify_base(Gtk::STATE_NORMAL, PREVIEW_COLOR)
46         end
47 
48         def displayOnlyMode
49             @contents.modify_base(Gtk::STATE_NORMAL, DISPLAY_ONLY_COLOR)
50         end
51 
52         def expiredMode
53             @contents.modify_base(Gtk::STATE_NORMAL, EXPIRED_COLOR)
54         end
55 
56         def createTags
57             @buffer.create_tag("kanji", 
58                                "size" => 36 * Pango::SCALE,
59                                "justification" => Gtk::JUSTIFY_CENTER,
60                                "family" => "Kochi Mincho")
61             @buffer.create_tag("reading", 
62                                "size" => 18 * Pango::SCALE,
63                                "justification" => Gtk::JUSTIFY_CENTER,
64                                "family" => "Kochi Mincho",
65                                "foreground" => "blue")
66             @buffer.create_tag("definitions", 
67                                "size" => 16 * Pango::SCALE,
68                                "justification" => Gtk::JUSTIFY_CENTER,
69                                "family" => "Sans")
70             @buffer.create_tag("hint", 
71                                "size" => 14 * Pango::SCALE,
72                                "justification" => Gtk::JUSTIFY_CENTER,
73                                "family" => "Sans",
74                                "foreground" => "red")
75             @buffer.create_tag("image",
76                                "justification" => Gtk::JUSTIFY_CENTER)
77         end
78 
79         # Adds an image to the bottom of the pane
80         def addImage(filename)
81             filename = @display.expandWithSavePath(filename)
82             image = Gtk::Image.new(filename)
83             # inserting spaces on either end of the image centers it
84             @buffer.insert(@buffer.end_iter," ", "image")
85             if !image.pixbuf.nil?
86                 @buffer.insert(@buffer.end_iter, image.pixbuf)
87                 # This simply makes sure the image isn't garbage collected
88                 # because the pixbuf in the image isn't reference counted.
89                 @images.push(image)
90             else
91                 @buffer.insert(@buffer.end_iter, filename + " not found.", 
92                                "image")
93             end
94             @buffer.insert(@buffer.end_iter," ", "image")
95         end
96 
97         def clear(problem)
98             if !problem.nil? && problem.preview?
99                 previewMode
100             elsif !problem.nil? && problem.displayOnly?
101                 displayOnlyMode
102             else
103                 normalMode
104             end
105 
106             @buffer.text = ""
107             @images = []
108         end
109 
110         def text
111             @buffer.text
112         end
113 
114         def receive(type, string)
115             if !string.nil? && !string.empty?
116                 if (string.start_with?("image:"))
117                     addImage(string[6..string.size])
118                 else
119                     @buffer.insert(@buffer.end_iter, string, type)
120                 end
121                 @buffer.insert(@buffer.end_iter, "\n", type)
122             end
123         end
124 
125         # Returns the height of the buffer in buffer coordinates.
126         # Note: This method must be called *after* all drawing
127         # has taken place.  The easiest way to do this is to
128         # put the calculation into an Gtk.idle_add block.
129         def bufferSize
130             # Allow the buffer to be drawn so that we get correct
131             # coordinates
132             iter = @buffer.end_iter
133             y, height = @contents.get_line_yrange(iter)
134             size = y + height
135             windowType = Gtk::TextView::WINDOW_TEXT
136             winx, winy = @contents.buffer_to_window_coords(windowType, 0, size)
137             return winy
138         end
139     end
140 
141     # The pane that displays the question for the problem
142     class QuestionPane < ProblemPane
143         def update(problem)
144             clear(problem)
145             if !problem.nil?
146                 problem.publishQuestion(self)
147             end
148         end
149 
150         def expire
151             expiredMode
152         end
153 
154     end        
155     
156     # The pane that displays the answer for the problem
157     class AnswerPane < ProblemPane
158         def clear(problem)
159             super(problem)
160             @isClear = true
161         end
162         
163         def clear?
164             @isClear
165         end
166         
167         def update(problem)
168             clear(problem)
169             if !problem.nil?
170                 problem.publishAnswer(self)
171                 @isClear = false
172             end
173         end
174     end
175 end

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