Jldrill Git C0 Coverage Information - RCov

lib/Context/Gtk/Widget.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/Context/Gtk/Widget.rb 163 87
82.21%
66.67%

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/Widget'
2 require 'Context/Log'
3 require 'gtk2'
4 
5 module Context::Gtk
6     include Context::Widget
7 
8     # This is a set of routines for translating the requests
9     # from Context to the specific widgit set.
10     #
11     # Note: If you wish your widget to be able to add and removed
12     #       other widgets (i.e. if it can act as a container), then
13     #       please define the following two methods on your object.
14     #
15     #       gtkAddWidget(widget) -- simply adds the passed widget to
16     #                               the correct Gtk container.  Normally
17     #                               this can be implemented using add().
18     #                               However, for some things like tables
19     #                               you will have to use other methods.
20     #       gtkRemoveWidget(widget) -- removes the passed widget from
21     #                                  the correct Gtk container.  Again
22     #                                  you will normally implement this
23     #                                  with remove().
24     #
25     #       The following also need to be defined if your widget is
26     #       not derived from a Gtk:Widget.
27     #
28     #       show_all() -- Displays the widgets.
29 
30 	module Widget
31 	    attr_reader :gtkWidgetMainWindow
32 	    attr_writer :gtkWidgetMainWindow
33 	    
34 	    def setupWidget
35 	        @gtkWidgetMainWindow = nil
36 	        # Packing hints for the container
37 	        @gtkWidgetExpandHeight = false
38 	        @gtkWidgetExpandWidth = false
39             @gtkWidgetAddedToCallback = nil
40             @gtkWidgetRemovedFromCallback = nil
41 	    end
42 	    
43         # Declares that this widget is a main Window
44         # Normally, this will get set for you if the widget you are
45         # adding is derived from Gtk::Window.  But you can set it
46         # explicitly for certain effects if you know what you are doing.
47 	    def isAMainWindow
48 	        @gtkWidgetMainWindow = self
49 	    end
50 
51         # When adding the widget, expand it to take up all the allocated
52         # vertical height.
53         def expandWidgetHeight
54 	        @gtkWidgetExpandHeight = true
55         end
56 
57         # Returns true when the the widget should take up all the allocated
58         # vertical height.
59         def expandWidgetHeight?
60             @gtkWidgetExpandHeight
61         end
62 
63         # When adding the widget, expand it to take up all the allocated
64         # horizontal width.
65         def expandWidgetWidth
66 	        @gtkWidgetExpandWidth = true
67         end
68 	
69         # Returns true when the the widget should take up all the allocated
70         # horizontal width.
71         def expandWidgetWidth?
72             @gtkWidgetExpandWidth
73         end
74 
75         # Use this widget as a container for the passed widget.
76         # Calls gtkAddWidget, which you must define on the object.
77         # Normally this will simply call add() in the correct container.
78         # Also calls show_all, which you must define on the object
79         # (if it isn't already).
80 		def addToThisWidget(widget)
81    		    if !widget.class.ancestors.include?(Gtk::Window)
82     		    widget.gtkWidgetMainWindow = @gtkWidgetMainWindow
83     			gtkAddWidget(widget)
84     			if !isInTests?
85             		show_all
86                 end
87     	    else
88     	        widget.isAMainWindow
89     	        widget.set_transient_for(@gtkWidgetMainWindow)
90     	        if !isInTests?
91         		    widget.show_all
92         		end
93     	    end
94 		end
95 
96         # Remove the passed widget from this object.
97         # Calls gtkRemoveWidget, which you must define on the object.
98         # Normally this will simply call remove().
99         # Also calls show_all, which you must define on the object
100         # (if it isn't already).
101         def removeFromThisWidget(widget)
102             widget.gtkWidgetMainWindow = nil
103    		    if !widget.class.ancestors.include?(Gtk::Window)   
104                 gtkRemoveWidget(widget)
105                 if !isInTests?
106                     show_all
107                 end
108             end
109         end
110 
111         # Set a closure to be run when the widget has been
112         # added.  The block must accept the container widget
113         # as a parameter.
114         def afterWidgetIsAdded(&block)
115             @gtkWidgetAddedToCallback = block
116         end
117 
118         # Set a closure to be run when the widget has been
119         # removed.  The block must accept the container widget
120         # as a parameter.
121         def afterWidgetIsRemoved(&block)
122             @gtkWidgetRemovedFromCallback = block
123         end
124 
125 		# This method is called after the widget has been
126 		# successfully added to another widget
127 		def widgetWasAddedTo(widget)
128             if !@gtkWidgetAddedToCallback.nil?
129                 @gtkWidgetAddedToCallback.call(widget)
130             end
131 		end
132 		
133 		# This method is called after the widget has been
134 		# successfully removed from another widget
135 		def widgetWasRemovedFrom(widget)
136             if !@gtkWidgetRemovedFromCallback.nil?
137                 @gtkWidgetRemovedFromCallback.call(widget)
138             end
139 		end
140 
141         # Helper method for testing.  If this method is redefined to
142         # return true, then the items will not be shown on the screen.
143         def isInTests?
144             false
145         end
146 
147         # Default method for adding a widget.  Simply logs an warning.
148         # It does not add the widget.
149         def gtkAddWidget(widget)
150             Context::Log::warning("Context::Widget", 
151                                   "Attempted to add a widget " +
152                                   "to #{self.class} which doesn't define " +
153                                   "gtkAddWidget(). Ignoring addition.")
154         end
155 
156         def gtkRemoveWidget(widget)
157             Context::Log::warning("Context::Widget", 
158                                   "Attempted to remove a widget " +
159                                   "from #{self.class} which doesn't define " +
160                                   "gtkRemoveWidget(). Ignoring removal.")
161         end
162 	end
163 end

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