context 0.0.16 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/AUTHORS +1 -0
  2. data/COPYING +679 -0
  3. data/README +188 -0
  4. data/Rakefile.rb +64 -18
  5. data/lib/Context/Bridge.rb +7 -6
  6. data/lib/Context/Context.rb +14 -35
  7. data/lib/Context/Gtk/Widget.rb +139 -33
  8. data/lib/Context/Log.rb +10 -0
  9. data/lib/Context/Publisher.rb +108 -0
  10. data/lib/Context/Spec.rb +8 -0
  11. data/lib/Context/Version.rb +1 -1
  12. data/lib/Context/View.rb +16 -15
  13. data/lib/Context/Views/Gtk/PageView.rb +3 -23
  14. data/lib/Context/Views/Gtk/Widgets/MainWindow.rb +70 -0
  15. data/lib/Context/Views/Gtk/Widgets/VBox.rb +29 -0
  16. data/lib/Context/Widget.rb +18 -27
  17. data/spec/Context/Bridge_spec.rb +19 -20
  18. data/spec/Context/Context_spec.rb +77 -63
  19. data/spec/Context/Gtk/Widget_spec.rb +23 -23
  20. data/spec/Context/Publisher_spec.rb +53 -0
  21. data/spec/Context/View_spec.rb +10 -14
  22. data/spec/Context/Views/Gtk/PageView_spec.rb +25 -9
  23. data/spec/Context/require_all_spec.rb +14 -7
  24. data/test_results.html +84 -121
  25. metadata +74 -128
  26. data/coverage/-usr-local-lib-site_ruby-1_8-atk_rb.html +0 -612
  27. data/coverage/-usr-local-lib-site_ruby-1_8-gdk_pixbuf2_rb.html +0 -637
  28. data/coverage/-usr-local-lib-site_ruby-1_8-glib2_rb.html +0 -829
  29. data/coverage/-usr-local-lib-site_ruby-1_8-gtk2-base_rb.html +0 -709
  30. data/coverage/-usr-local-lib-site_ruby-1_8-gtk2_rb.html +0 -623
  31. data/coverage/-usr-local-lib-site_ruby-1_8-pango_rb.html +0 -665
  32. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-color_rb.html +0 -865
  33. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-colors_rb.html +0 -1266
  34. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-constants_rb.html +0 -632
  35. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-blur_rb.html +0 -655
  36. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-circle_rb.html +0 -619
  37. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-color_rb.html +0 -621
  38. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-path_rb.html +0 -726
  39. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-rectangle_rb.html +0 -643
  40. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-triangle_rb.html +0 -622
  41. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context_rb.html +0 -639
  42. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-paper_rb.html +0 -793
  43. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-papers_rb.html +0 -651
  44. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-path_rb.html +0 -625
  45. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-point_rb.html +0 -617
  46. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo_rb.html +0 -756
  47. data/coverage/index.html +0 -1170
  48. data/coverage/lib-Context-Bridge_rb.html +0 -673
  49. data/coverage/lib-Context-Context_rb.html +0 -756
  50. data/coverage/lib-Context-EnumeratedType_rb.html +0 -661
  51. data/coverage/lib-Context-ExecutionProxy_rb.html +0 -671
  52. data/coverage/lib-Context-Gtk-App_rb.html +0 -638
  53. data/coverage/lib-Context-Gtk-Key_rb.html +0 -664
  54. data/coverage/lib-Context-Gtk-Widget_rb.html +0 -667
  55. data/coverage/lib-Context-KeyAssignment_rb.html +0 -641
  56. data/coverage/lib-Context-KeyMap_rb.html +0 -653
  57. data/coverage/lib-Context-Key_rb.html +0 -667
  58. data/coverage/lib-Context-View_rb.html +0 -659
  59. data/coverage/lib-Context-Views-Gtk-PageView_rb.html +0 -660
  60. data/coverage/lib-Context-Views-PageView_rb.html +0 -627
  61. data/coverage/lib-Context-Widget_rb.html +0 -650
  62. data/coverage/lib-Context-require_all_rb.html +0 -623
  63. data/doc/classes/Context.html +0 -174
  64. data/doc/classes/Context/Bridge.html +0 -296
  65. data/doc/classes/Context/Context.html +0 -564
  66. data/doc/classes/Context/EnumeratedType.html +0 -283
  67. data/doc/classes/Context/ExecutionProxy.html +0 -228
  68. data/doc/classes/Context/Gtk.html +0 -126
  69. data/doc/classes/Context/Gtk/App.html +0 -217
  70. data/doc/classes/Context/Gtk/Key.html +0 -292
  71. data/doc/classes/Context/Gtk/PageView.html +0 -245
  72. data/doc/classes/Context/Gtk/PageView/MainWindow.html +0 -200
  73. data/doc/classes/Context/Gtk/Widget.html +0 -311
  74. data/doc/classes/Context/Key.html +0 -305
  75. data/doc/classes/Context/Key/Modifier.html +0 -117
  76. data/doc/classes/Context/KeyAssignment.html +0 -234
  77. data/doc/classes/Context/KeyMap.html +0 -273
  78. data/doc/classes/Context/PageView.html +0 -180
  79. data/doc/classes/Context/View.html +0 -334
  80. data/doc/classes/Context/Widget.html +0 -298
  81. data/doc/classes/Kernel.html +0 -148
  82. data/doc/classes/Object.html +0 -196
  83. data/doc/created.rid +0 -1
  84. data/doc/files/lib/Context/Bridge_rb.html +0 -108
  85. data/doc/files/lib/Context/Context_rb.html +0 -109
  86. data/doc/files/lib/Context/EnumeratedType_rb.html +0 -101
  87. data/doc/files/lib/Context/ExecutionProxy_rb.html +0 -101
  88. data/doc/files/lib/Context/Gtk/App_rb.html +0 -110
  89. data/doc/files/lib/Context/Gtk/Key_rb.html +0 -109
  90. data/doc/files/lib/Context/Gtk/Widget_rb.html +0 -109
  91. data/doc/files/lib/Context/KeyAssignment_rb.html +0 -108
  92. data/doc/files/lib/Context/KeyMap_rb.html +0 -109
  93. data/doc/files/lib/Context/Key_rb.html +0 -108
  94. data/doc/files/lib/Context/Version_rb.html +0 -101
  95. data/doc/files/lib/Context/View_rb.html +0 -101
  96. data/doc/files/lib/Context/Views/Gtk/PageView_rb.html +0 -111
  97. data/doc/files/lib/Context/Views/PageView_rb.html +0 -108
  98. data/doc/files/lib/Context/Widget_rb.html +0 -101
  99. data/doc/files/lib/Context/require_all_rb.html +0 -101
  100. data/doc/fr_class_index.html +0 -46
  101. data/doc/fr_file_index.html +0 -42
  102. data/doc/fr_method_index.html +0 -103
  103. data/doc/index.html +0 -24
  104. data/doc/rdoc-style.css +0 -208
  105. data/lib/Context/EnumeratedType.rb +0 -51
  106. data/lib/Context/ExecutionProxy.rb +0 -61
  107. data/lib/Context/Gtk/Key.rb +0 -54
  108. data/lib/Context/Key.rb +0 -57
  109. data/lib/Context/KeyAssignment.rb +0 -31
  110. data/lib/Context/KeyMap.rb +0 -43
  111. data/spec/Context/EnumeratedType_spec.rb +0 -51
  112. data/spec/Context/ExecutionProxy_spec.rb +0 -28
  113. data/spec/Context/Gtk/Key_spec.rb +0 -45
  114. data/spec/Context/KeyAssignment_spec.rb +0 -26
  115. data/spec/Context/KeyMap_spec.rb +0 -64
  116. data/spec/Context/Key_spec.rb +0 -22
  117. data/spec/Context/Widget_spec.rb +0 -15
@@ -0,0 +1,10 @@
1
+ module Context
2
+
3
+ # Implements some rudimentary logging for context.
4
+ # This is basically just to output warnings.
5
+ class Log
6
+ def Log::warning(system, message)
7
+ $stderr.print("WARNING #{system}: #{message}\n")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,108 @@
1
+ module Context
2
+
3
+ # Publisher implements an observer pattern.
4
+ # An object creates a Publisher, using itself as the source.
5
+ # It can then publish to several different streams. Observers can
6
+ # subscribe to a stream. When the stream for an observer
7
+ # is updated, a method on each observer, named <stream>Updated(),
8
+ # is called. The source is passed to this method.
9
+ # In Context, Publishers are usually used to notify Contexts
10
+ # when model objects have been updated (and hence the view
11
+ # needs to change).
12
+ class Publisher
13
+ attr_reader :source
14
+
15
+ # Create a Publisher with the source as the source object.
16
+ def initialize(source)
17
+ @source = source
18
+ @streamSubscribers = {}
19
+ @blocked = false
20
+ end
21
+
22
+ # Subscribe an observer to a stream. The stream must be
23
+ # a string. It is allowable to observe to streams that
24
+ # don't exist. The observer *must* implement
25
+ # <stream>Updated(source). For example if in a method
26
+ # of class A I write:
27
+ # publisher.subscribe(self, "hello")
28
+ # then A *must* implement the method helloUpdated(source)
29
+ # otherwise the program will crash when the stream
30
+ # is publish.
31
+ def subscribe(observer, stream)
32
+ if @streamSubscribers.has_key?(stream)
33
+ observers = @streamSubscribers[stream]
34
+ if !observers.find do |x|
35
+ x == observer
36
+ end
37
+ observers.push(observer)
38
+ end
39
+ else
40
+ @streamSubscribers[stream] = [observer]
41
+ end
42
+ end
43
+
44
+ # Unsubscribe an observer from the stream.
45
+ # Remove the observer from the list of objects
46
+ # that are subscribed to the stream.
47
+ # Very Important Note: If you don't unsubscribe
48
+ # from a publisher at the end of the lifetime
49
+ # of your object, the publisher will retain
50
+ # a reference to the object. This means it will
51
+ # continue to exist until the publisher is destroyed.
52
+ # This could potentially cause problems in your code.
53
+ # *Always* unsubscribe from a Publisher when you are
54
+ # finished with the object.
55
+ def unsubscribe(observer, stream)
56
+ if @streamSubscribers.has_key?(stream)
57
+ observers = @streamSubscribers[stream]
58
+ observers.delete(observer)
59
+ end
60
+ end
61
+
62
+ # Publish to the observers that the stream has been updated.
63
+ # This is usually called by the source object, but it
64
+ # doesn't have to be. The source object can also be changed
65
+ # (it defaults to the source in the Publisher). This is
66
+ # useful if a source is publishing on behalf of another object
67
+ # (essentially acting as a mediator).
68
+ def update(stream, source=@source)
69
+ if blocked?
70
+ return
71
+ end
72
+ if @streamSubscribers.has_key?(stream)
73
+ @streamSubscribers[stream].each do |subscriber|
74
+ eval("subscriber." + stream + "Updated(source)")
75
+ end
76
+ end
77
+ end
78
+
79
+ # Returns true if the publisher is blocked.
80
+ # A blocked publisher will not publish, even if
81
+ # update() is called.
82
+ def blocked?
83
+ @blocked
84
+ end
85
+
86
+ # Block a publisher from publishing. A blocked publisher
87
+ # will not publish to observers, even if update() is
88
+ # called. This is useful for when you know that the
89
+ # source is being updated a lot and you only want to
90
+ # signal it at the end (for instance when you are loading
91
+ # a file).
92
+ # Important Note: block() and unblock() are not counted.
93
+ # No matter how many times you call block(), the first
94
+ # unblock() will unblock it.
95
+ def block
96
+ @blocked = true
97
+ end
98
+
99
+ # Unblock a publisher so that it may continue to publish.
100
+ # Important Note: block() and unblock() are not counted.
101
+ # No matter how many times you call block(), the first
102
+ # unblock() will unblock it.
103
+ def unblock
104
+ @blocked = false
105
+ end
106
+ end
107
+
108
+ end
@@ -0,0 +1,8 @@
1
+ # This is simply a handy way to predefine Context::Spec so that
2
+ # I don't have to indent things like crazy elsewhere.
3
+ # Suppose I can potentially put useful things here someday.
4
+
5
+ module Context
6
+ module Spec
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  module Context
2
2
 
3
- VERSION = "0.0.16"
3
+ VERSION = "0.0.22"
4
4
 
5
5
  end
@@ -12,38 +12,39 @@ module Context
12
12
  if(myWidget != nil)
13
13
  newWidget = view.getWidget()
14
14
  if !newWidget.nil?
15
- myWidget.add(newWidget)
16
- newWidget.addedTo(myWidget)
15
+ myWidget.addToThisWidget(newWidget)
16
+ newWidget.widgetWasAddedTo(myWidget)
17
17
  end
18
18
  end
19
+ view.viewAddedTo(self)
19
20
  end
21
+
22
+ # Override this method to do something when your view has been
23
+ # added to another view. Most useful for adding subviews
24
+ def viewAddedTo(parent)
25
+ end
20
26
 
21
27
  def removeView(view)
28
+ view.removingViewFrom(self)
22
29
  myWidget = getWidget()
23
30
  if(myWidget != nil)
24
31
  oldWidget = view.getWidget()
25
32
  if !oldWidget.nil?
26
- myWidget.remove(oldWidget)
27
- oldWidget.removedFrom(myWidget)
33
+ myWidget.removeFromThisWidget(oldWidget)
34
+ oldWidget.widgetWasRemovedFrom(myWidget)
28
35
  end
29
36
  end
30
37
  end
31
-
32
- # Concrete classes should override this method
33
- def open
34
- end
35
-
36
- # Concrete classes should override this method
37
- def close
38
- end
39
38
 
39
+ # Override this method to do something when your view being
40
+ # removed from another view. Most useful for removing subviews
41
+ def removingViewFrom(parent)
42
+ end
43
+
40
44
  # Concrete classes should override this method
41
45
  def getWidget
42
46
  return nil
43
47
  end
44
48
 
45
- def notifyKey(widget, key)
46
- @context.notifyKey(self, key)
47
- end
48
49
  end
49
50
  end
@@ -1,46 +1,26 @@
1
1
  require 'Context/Views/PageView'
2
- require 'Context/Gtk/Key'
3
2
  require 'Context/Gtk/Widget'
3
+ require 'Context/Views/Gtk/Widgets/MainWindow'
4
4
  require 'gtk2'
5
5
 
6
6
  module Context::Gtk
7
7
 
8
8
  class PageView < Context::PageView
9
9
 
10
- class MainWindow < Gtk::Window
11
- def initialize(title, view)
12
- super(title)
13
- @view = view
14
- connectSignals unless @view.nil?
15
- end
16
-
17
- def connectSignals
18
- signal_connect('destroy') do
19
- closeView
20
- end
21
- end
22
-
23
- def closeView
24
- @view.close
25
- end
26
- end
27
-
28
10
  attr_reader :mainWindow
29
11
 
30
12
  def initialize(context, title="No Title")
31
13
  super(context)
32
14
  @mainWindow = MainWindow.new(title, self)
33
15
  @mainWindow.set_default_size(600, 400)
34
- @widget = Context::Gtk::Widget.new(@mainWindow)
35
16
  end
36
17
 
37
18
  def open
38
- @mainWindow.show_all
39
- @mainWindow.grab_focus
19
+ @mainWindow.open
40
20
  end
41
21
 
42
22
  def getWidget
43
- @widget
23
+ @mainWindow
44
24
  end
45
25
 
46
26
  def emitDestroyEvent
@@ -0,0 +1,70 @@
1
+ require 'gtk2'
2
+
3
+ module Context::Gtk
4
+
5
+ # A Gtk widget representing a main window.
6
+ # It is simply a Gtk::Window into which you can add new widgets.
7
+ # You must implement the following methods on the view that
8
+ # you pass to initialize:
9
+ #
10
+ # close() -- closes the view.
11
+ class MainWindow < Gtk::Window
12
+ include Context::Gtk::Widget
13
+ # Create a main window with a given title corresponding to
14
+ # a Context::View.
15
+ def initialize(title, view)
16
+ super(title)
17
+ @view = view
18
+ setupWidget
19
+ isAMainWindow
20
+ @closed = false
21
+ connectSignals unless @view.nil?
22
+ end
23
+
24
+ # Connect the Gtk signals we care about.
25
+ def connectSignals
26
+ signal_connect('destroy') do
27
+ if !@closed
28
+ closeView
29
+ end
30
+ end
31
+ signal_connect('delete-event') do
32
+ if !@closed
33
+ closeView
34
+ end
35
+ true
36
+ end
37
+ end
38
+
39
+ # Explicitly destroy the window through the code rather
40
+ # than having the window destroyed by pressing the close
41
+ # button.
42
+ def explicitDestroy
43
+ @closed = true
44
+ self.destroy
45
+ end
46
+
47
+ # Close the view. This is called when the destroy
48
+ # signal has been emitted.
49
+ # Note: the View *must* implement close()
50
+ def closeView
51
+ @view.close
52
+ end
53
+
54
+ # Context::Gtk::Widget requirements
55
+
56
+ # Add a widget to this window.
57
+ # Note that Gtk::Windows can only add a single item.
58
+ # If you want to add more items, you will have to make
59
+ # another widget (like a table or a vbox) and add it to
60
+ # this one.
61
+ def gtkAddWidget(widget)
62
+ add(widget)
63
+ end
64
+
65
+ # Remove the contained widget from this window
66
+ def gtkRemoveWidget(widget)
67
+ remove(widget)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,29 @@
1
+ require 'Context/Gtk/Widget'
2
+ require 'gtk2'
3
+
4
+ module Context::Gtk
5
+
6
+ # Container class for making vertical lists of widgets.
7
+ # The primary purpose of this class is to create a container
8
+ # that respects the packing hints in the Widget mixin.
9
+ # Something tells me that needing this class means
10
+ # something is screwed up somewhere...
11
+ class VBox < Gtk::VBox
12
+ include Context::Gtk::Widget
13
+
14
+ def initialize
15
+ super
16
+ setupWidget
17
+ end
18
+
19
+ def gtkAddWidget(widget)
20
+ pack_start(widget,
21
+ widget.expandWidgetHeight?,
22
+ widget.expandWidgetWidth?)
23
+ end
24
+
25
+ def gtkRemoveWidget(widget)
26
+ remove(widget)
27
+ end
28
+ end
29
+ end
@@ -1,40 +1,31 @@
1
1
  module Context
2
+ # This is the Widget mixin for Context. If you wish to be able
3
+ # to add to, add, or remove a widget inside a View using context,
4
+ # this mixin must be included. This is an abstract mixin. The
5
+ # methods do nothing. They should be overriden in the concrete
6
+ # mixins. Please see Context::Gtk::Widget for an example.
7
+ module Widget
2
8
 
3
- class Widget
9
+ # This method creates any instance variables that you might have.
10
+ def setupWidget
11
+ end
4
12
 
5
- attr_reader :delegate
6
-
7
- def initialize(delegate)
8
- @delegate = delegate
13
+ # Use this widget as a container for the passed widget
14
+ def addToThisWidget(widget)
9
15
  end
10
-
16
+
17
+ # Remove the passed widget from this object.
18
+ def removeFromThisWidget(widget)
19
+ end
20
+
11
21
  # This method is called after the widget has been
12
22
  # successfully added to another widget
13
- def addedTo(widget)
14
- # This is an abstract method, the child classes should
15
- # implement this
23
+ def widgetWasAddedTo(widget)
16
24
  end
17
25
 
18
26
  # This method is called after the widget has been
19
27
  # successfully removed from another widget
20
- def removedFrom(widget)
21
- # This is an abstract method, the child classes should
22
- # implement this
23
- end
24
-
25
- # Use this widget as a container for the passed widget
26
- def add(widget)
27
- # This is an abstract method, the child classes should
28
- # implement this
29
- end
30
-
31
- def remove(widget)
32
- # This is an abstract method, the child classes should
33
- # implement this
34
- end
35
-
36
- def eql?(widget)
37
- @delegate.eql?(widget.delegate)
28
+ def widgetWasRemovedFrom(widget)
38
29
  end
39
30
  end
40
31
  end
@@ -1,36 +1,35 @@
1
+ require 'Context/Spec'
1
2
  require 'Context/Bridge'
2
3
 
3
- module Other
4
- module Special
5
- class Fun
6
- end
4
+ module Context::Spec::BridgeStory
7
5
 
8
- class In
6
+ module Other
7
+ module Special
8
+ class Fun
9
+ end
10
+
11
+ class In
12
+ end
9
13
  end
10
14
  end
11
- end
12
15
 
13
- module Context::Special
14
- class Fun
16
+ module Special
17
+ class Fun
18
+ end
15
19
  end
16
- end
17
20
 
18
- module Context
19
21
  class Fun
20
22
  end
21
- end
22
-
23
- module Excluded
24
- class Sun
25
- end
26
- end
27
-
28
- module Context
23
+
24
+ module Excluded
25
+ class Sun
26
+ end
27
+ end
29
28
 
30
- describe Bridge do
29
+ describe Context::Bridge do
31
30
 
32
31
  it "should reference classes in the namespace provided" do
33
- bridge = Bridge.new([Special, Other::Special])
32
+ bridge = Context::Bridge.new([Special, Other::Special])
34
33
 
35
34
  bridge.Fun.should be(Special::Fun)
36
35
  bridge.In.should be(Other::Special::In)