context 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. data/Rakefile.rb +107 -0
  2. data/coverage/-usr-local-lib-site_ruby-1_8-atk_rb.html +612 -0
  3. data/coverage/-usr-local-lib-site_ruby-1_8-gdk_pixbuf2_rb.html +637 -0
  4. data/coverage/-usr-local-lib-site_ruby-1_8-glib2_rb.html +829 -0
  5. data/coverage/-usr-local-lib-site_ruby-1_8-gtk2-base_rb.html +709 -0
  6. data/coverage/-usr-local-lib-site_ruby-1_8-gtk2_rb.html +623 -0
  7. data/coverage/-usr-local-lib-site_ruby-1_8-pango_rb.html +665 -0
  8. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-color_rb.html +865 -0
  9. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-colors_rb.html +1266 -0
  10. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-constants_rb.html +632 -0
  11. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-blur_rb.html +655 -0
  12. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-circle_rb.html +619 -0
  13. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-color_rb.html +621 -0
  14. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-path_rb.html +726 -0
  15. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-rectangle_rb.html +643 -0
  16. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context-triangle_rb.html +622 -0
  17. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-context_rb.html +639 -0
  18. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-paper_rb.html +793 -0
  19. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-papers_rb.html +651 -0
  20. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-path_rb.html +625 -0
  21. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo-point_rb.html +617 -0
  22. data/coverage/-var-lib-gems-1_8-gems-cairo-1_7_0-src-lib-cairo_rb.html +756 -0
  23. data/coverage/index.html +1170 -0
  24. data/coverage/lib-Context-Bridge_rb.html +673 -0
  25. data/coverage/lib-Context-Context_rb.html +756 -0
  26. data/coverage/lib-Context-EnumeratedType_rb.html +661 -0
  27. data/coverage/lib-Context-ExecutionProxy_rb.html +671 -0
  28. data/coverage/lib-Context-Gtk-App_rb.html +638 -0
  29. data/coverage/lib-Context-Gtk-Key_rb.html +664 -0
  30. data/coverage/lib-Context-Gtk-Widget_rb.html +667 -0
  31. data/coverage/lib-Context-KeyAssignment_rb.html +641 -0
  32. data/coverage/lib-Context-KeyMap_rb.html +653 -0
  33. data/coverage/lib-Context-Key_rb.html +667 -0
  34. data/coverage/lib-Context-View_rb.html +659 -0
  35. data/coverage/lib-Context-Views-Gtk-PageView_rb.html +660 -0
  36. data/coverage/lib-Context-Views-PageView_rb.html +627 -0
  37. data/coverage/lib-Context-Widget_rb.html +650 -0
  38. data/coverage/lib-Context-require_all_rb.html +623 -0
  39. data/doc/classes/Context.html +174 -0
  40. data/doc/classes/Context/Bridge.html +296 -0
  41. data/doc/classes/Context/Context.html +564 -0
  42. data/doc/classes/Context/EnumeratedType.html +283 -0
  43. data/doc/classes/Context/ExecutionProxy.html +228 -0
  44. data/doc/classes/Context/Gtk.html +126 -0
  45. data/doc/classes/Context/Gtk/App.html +217 -0
  46. data/doc/classes/Context/Gtk/Key.html +292 -0
  47. data/doc/classes/Context/Gtk/PageView.html +245 -0
  48. data/doc/classes/Context/Gtk/PageView/MainWindow.html +200 -0
  49. data/doc/classes/Context/Gtk/Widget.html +311 -0
  50. data/doc/classes/Context/Key.html +305 -0
  51. data/doc/classes/Context/Key/Modifier.html +117 -0
  52. data/doc/classes/Context/KeyAssignment.html +234 -0
  53. data/doc/classes/Context/KeyMap.html +273 -0
  54. data/doc/classes/Context/PageView.html +180 -0
  55. data/doc/classes/Context/View.html +334 -0
  56. data/doc/classes/Context/Widget.html +298 -0
  57. data/doc/classes/Kernel.html +148 -0
  58. data/doc/classes/Object.html +196 -0
  59. data/doc/created.rid +1 -0
  60. data/doc/files/lib/Context/Bridge_rb.html +108 -0
  61. data/doc/files/lib/Context/Context_rb.html +109 -0
  62. data/doc/files/lib/Context/EnumeratedType_rb.html +101 -0
  63. data/doc/files/lib/Context/ExecutionProxy_rb.html +101 -0
  64. data/doc/files/lib/Context/Gtk/App_rb.html +110 -0
  65. data/doc/files/lib/Context/Gtk/Key_rb.html +109 -0
  66. data/doc/files/lib/Context/Gtk/Widget_rb.html +109 -0
  67. data/doc/files/lib/Context/KeyAssignment_rb.html +108 -0
  68. data/doc/files/lib/Context/KeyMap_rb.html +109 -0
  69. data/doc/files/lib/Context/Key_rb.html +108 -0
  70. data/doc/files/lib/Context/Version_rb.html +101 -0
  71. data/doc/files/lib/Context/View_rb.html +101 -0
  72. data/doc/files/lib/Context/Views/Gtk/PageView_rb.html +111 -0
  73. data/doc/files/lib/Context/Views/PageView_rb.html +108 -0
  74. data/doc/files/lib/Context/Widget_rb.html +101 -0
  75. data/doc/files/lib/Context/require_all_rb.html +101 -0
  76. data/doc/fr_class_index.html +46 -0
  77. data/doc/fr_file_index.html +42 -0
  78. data/doc/fr_method_index.html +103 -0
  79. data/doc/index.html +24 -0
  80. data/doc/rdoc-style.css +208 -0
  81. data/lib/Context/Bridge.rb +63 -0
  82. data/lib/Context/Context.rb +146 -0
  83. data/lib/Context/EnumeratedType.rb +51 -0
  84. data/lib/Context/ExecutionProxy.rb +61 -0
  85. data/lib/Context/Gtk/App.rb +28 -0
  86. data/lib/Context/Gtk/Key.rb +54 -0
  87. data/lib/Context/Gtk/Widget.rb +57 -0
  88. data/lib/Context/Key.rb +57 -0
  89. data/lib/Context/KeyAssignment.rb +31 -0
  90. data/lib/Context/KeyMap.rb +43 -0
  91. data/lib/Context/Version.rb +5 -0
  92. data/lib/Context/View.rb +49 -0
  93. data/lib/Context/Views/Gtk/PageView.rb +50 -0
  94. data/lib/Context/Views/PageView.rb +17 -0
  95. data/lib/Context/Widget.rb +40 -0
  96. data/lib/Context/require_all.rb +13 -0
  97. data/spec/Context/Bridge_spec.rb +40 -0
  98. data/spec/Context/Context_spec.rb +102 -0
  99. data/spec/Context/EnumeratedType_spec.rb +51 -0
  100. data/spec/Context/ExecutionProxy_spec.rb +28 -0
  101. data/spec/Context/Gtk/App_spec.rb +24 -0
  102. data/spec/Context/Gtk/Key_spec.rb +45 -0
  103. data/spec/Context/Gtk/Widget_spec.rb +44 -0
  104. data/spec/Context/KeyAssignment_spec.rb +26 -0
  105. data/spec/Context/KeyMap_spec.rb +64 -0
  106. data/spec/Context/Key_spec.rb +22 -0
  107. data/spec/Context/View_spec.rb +62 -0
  108. data/spec/Context/Views/Gtk/PageView_spec.rb +44 -0
  109. data/spec/Context/Views/PageView_spec.rb +20 -0
  110. data/spec/Context/Widget_spec.rb +15 -0
  111. data/spec/Context/require_all_spec.rb +13 -0
  112. data/test_results.html +343 -0
  113. metadata +179 -0
@@ -0,0 +1,31 @@
1
+ require 'Context/Key'
2
+
3
+ module Context
4
+
5
+ # Represents the assignment of an action to a key press
6
+ class KeyAssignment
7
+ attr_reader :action
8
+
9
+ # Creates an assignment where action will be called when key is pressed
10
+ def initialize(key, &action)
11
+ @key = key
12
+ @action = action
13
+ end
14
+
15
+ # Returns true if this KeyAssignment has an action assigned for key
16
+ def handles?(key)
17
+ @key.eql?(key)
18
+ end
19
+
20
+ # Run the action assigned to key if there is one. Returns true if
21
+ # an action was run, false otherwise
22
+ def try(key)
23
+ if handles?(key)
24
+ @action.call
25
+ true
26
+ else
27
+ false
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ require 'Context/Key'
2
+ require 'Context/KeyAssignment'
3
+
4
+ module Context
5
+
6
+ # Represents a map of key strokes to actions
7
+ class KeyMap
8
+
9
+ def initialize
10
+ @list = []
11
+ end
12
+
13
+ # Add a KeyAssignment to the map
14
+ def add(assignment)
15
+ @list.push(assignment)
16
+ end
17
+
18
+ # Returns the assignment that handles this key or nil if it doesn't
19
+ # exist
20
+ def findKey(key)
21
+ @list.find do |a|
22
+ a.handles?(key)
23
+ end
24
+ end
25
+
26
+ # Returns true if this map can handle the key. Otherwise false.
27
+ def handles?(key)
28
+ !findKey(key).nil?
29
+ end
30
+
31
+ # Press the key and run the associated action, if it exits.
32
+ # Returns true if an action was run, false otherwise.
33
+ def press(key)
34
+ assignment = findKey(key)
35
+ if !assignment.nil?
36
+ assignment.try(key)
37
+ else
38
+ false
39
+ end
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,5 @@
1
+ module Context
2
+
3
+ VERSION = "0.0.16"
4
+
5
+ end
@@ -0,0 +1,49 @@
1
+ module Context
2
+
3
+ # This is the abstract view class
4
+ class View
5
+ attr_reader :context
6
+ def initialize(context)
7
+ @context = context
8
+ end
9
+
10
+ def addView(view)
11
+ myWidget = getWidget()
12
+ if(myWidget != nil)
13
+ newWidget = view.getWidget()
14
+ if !newWidget.nil?
15
+ myWidget.add(newWidget)
16
+ newWidget.addedTo(myWidget)
17
+ end
18
+ end
19
+ end
20
+
21
+ def removeView(view)
22
+ myWidget = getWidget()
23
+ if(myWidget != nil)
24
+ oldWidget = view.getWidget()
25
+ if !oldWidget.nil?
26
+ myWidget.remove(oldWidget)
27
+ oldWidget.removedFrom(myWidget)
28
+ end
29
+ end
30
+ 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
+
40
+ # Concrete classes should override this method
41
+ def getWidget
42
+ return nil
43
+ end
44
+
45
+ def notifyKey(widget, key)
46
+ @context.notifyKey(self, key)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,50 @@
1
+ require 'Context/Views/PageView'
2
+ require 'Context/Gtk/Key'
3
+ require 'Context/Gtk/Widget'
4
+ require 'gtk2'
5
+
6
+ module Context::Gtk
7
+
8
+ class PageView < Context::PageView
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
+ attr_reader :mainWindow
29
+
30
+ def initialize(context, title="No Title")
31
+ super(context)
32
+ @mainWindow = MainWindow.new(title, self)
33
+ @mainWindow.set_default_size(600, 400)
34
+ @widget = Context::Gtk::Widget.new(@mainWindow)
35
+ end
36
+
37
+ def open
38
+ @mainWindow.show_all
39
+ @mainWindow.grab_focus
40
+ end
41
+
42
+ def getWidget
43
+ @widget
44
+ end
45
+
46
+ def emitDestroyEvent
47
+ @mainWindow.signal_emit("destroy")
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ require 'Context/View'
2
+
3
+ module Context
4
+ class PageView < View
5
+ def initialize(context)
6
+ super(context)
7
+ end
8
+
9
+ # The page view is meant to be the main view for a context
10
+ # (in Gtk it's a window). So if the view closes, it should
11
+ # close the context. Actually, I'm not sure if I like this
12
+ # idea. It might change.
13
+ def close
14
+ @context.close
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ module Context
2
+
3
+ class Widget
4
+
5
+ attr_reader :delegate
6
+
7
+ def initialize(delegate)
8
+ @delegate = delegate
9
+ end
10
+
11
+ # This method is called after the widget has been
12
+ # successfully added to another widget
13
+ def addedTo(widget)
14
+ # This is an abstract method, the child classes should
15
+ # implement this
16
+ end
17
+
18
+ # This method is called after the widget has been
19
+ # 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)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ module Kernel
2
+
3
+ # Requires all the files that match the glob in the
4
+ # current load-path
5
+ def require_all(glob)
6
+ $:.each do |path|
7
+ Dir.glob(path + "/" + glob) do |file|
8
+ name = file.to_s.sub(path + "/", "")
9
+ require name
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ require 'Context/Bridge'
2
+
3
+ module Other
4
+ module Special
5
+ class Fun
6
+ end
7
+
8
+ class In
9
+ end
10
+ end
11
+ end
12
+
13
+ module Context::Special
14
+ class Fun
15
+ end
16
+ end
17
+
18
+ module Context
19
+ class Fun
20
+ end
21
+ end
22
+
23
+ module Excluded
24
+ class Sun
25
+ end
26
+ end
27
+
28
+ module Context
29
+
30
+ describe Bridge do
31
+
32
+ it "should reference classes in the namespace provided" do
33
+ bridge = Bridge.new([Special, Other::Special])
34
+
35
+ bridge.Fun.should be(Special::Fun)
36
+ bridge.In.should be(Other::Special::In)
37
+ bridge.Sun.should_not be(Excluded::Sun)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,102 @@
1
+ require 'Context/Context'
2
+ require 'Context/Bridge'
3
+ require 'Context/View'
4
+
5
+ module Context
6
+
7
+ class TestContext < Context
8
+ def initialize(bridge)
9
+ super(bridge)
10
+ end
11
+
12
+ def createViews
13
+ @mainView = View.new(self)
14
+ end
15
+ end
16
+
17
+ describe Context do
18
+
19
+ before(:each) do
20
+ @bridge = Bridge.new(TestContext)
21
+ @parent = TestContext.new(@bridge)
22
+ @context = TestContext.new(@bridge)
23
+ end
24
+
25
+ it "should not have a parent set on creation" do
26
+ @context.parent.should be_nil
27
+ end
28
+
29
+ it "should set the parent on entry" do
30
+ @parent.createViews
31
+ @parent.should_receive(:addView)
32
+ @context.enter(@parent)
33
+ @context.parent.should equal(@parent)
34
+ end
35
+
36
+ it "should add new views to the main view" do
37
+ newContext = TestContext.new(@bridge)
38
+ newContext.createViews
39
+ @context.createViews
40
+ @context.mainView.should_receive(:addView).with(newContext.mainView)
41
+
42
+ @context.addView(newContext.mainView)
43
+ end
44
+
45
+ it "should remove views on exit" do
46
+ @parent.createViews
47
+ @parent.mainView.should_receive(:removeView).with(@context.peekAtView)
48
+ @parent.should_receive(:addView)
49
+ @context.enter(@parent)
50
+ @context.exit
51
+ end
52
+
53
+ it "should be able to set key bindings" do
54
+ key = Key.new(Key::Modifier.Control, 'k')
55
+ exit = Proc.new do
56
+ @context.exit
57
+ end
58
+ @context.getKeyBinding(key).should be_nil
59
+ @context.setKeyBinding(key, &exit)
60
+ @context.getKeyBinding(key).should be(exit)
61
+ @context.should_receive(:exit)
62
+ @context.notifyKey(mock("View"), key)
63
+ end
64
+
65
+ it "should create the views on entry" do
66
+ @context.should_receive(:setupViews) do
67
+ @context.createViews
68
+ end
69
+ @parent.should_receive(:addView)
70
+ @parent.createViews
71
+ @context.enter(@parent)
72
+ end
73
+
74
+ it "should destroy the views on exit" do
75
+ @parent.createViews
76
+ @context.should_receive(:setupViews).exactly(2).times do
77
+ @context.createViews
78
+ end
79
+ @parent.should_receive(:addView)
80
+ @context.enter(@parent)
81
+ @parent.mainView.should_receive(:removeView).with(@context.peekAtView)
82
+ @context.should_receive(:destroyViews)
83
+ @context.exit
84
+ end
85
+
86
+ it "should keep track if the context has been entered or not" do
87
+ @parent.createViews
88
+ @context.should_receive(:setupViews).exactly(2).times do
89
+ @context.createViews
90
+ end
91
+ @parent.should_receive(:addView)
92
+ @context.isEntered?.should be(false)
93
+ @context.enter(@parent)
94
+ @context.isEntered?.should be(true)
95
+ @parent.mainView.should_receive(:removeView).with(@context.peekAtView)
96
+ @context.should_receive(:destroyViews)
97
+ @context.exit
98
+ @context.isEntered?.should be(false)
99
+ end
100
+
101
+ end
102
+ end
@@ -0,0 +1,51 @@
1
+ require 'Context/EnumeratedType'
2
+
3
+ module Context
4
+
5
+ class A < EnumeratedType
6
+ symbols [:Zero]
7
+ end
8
+
9
+ class B < EnumeratedType
10
+ symbols [:Zero, :One, :Two]
11
+ end
12
+
13
+ class C < EnumeratedType
14
+ start_at 5
15
+ symbols [:Five, :Six, :Seven]
16
+ end
17
+
18
+ describe EnumeratedType do
19
+
20
+ it "should start at 0 by default" do
21
+ A.Zero.should eql(0)
22
+ end
23
+
24
+ it "should increment by one for each value" do
25
+ B.Zero.should eql(0)
26
+ B.One.should eql(1)
27
+ B.Two.should eql(2)
28
+ end
29
+
30
+ it "should start at the number specified" do
31
+ C.Five.should eql(5)
32
+ C.Six.should eql(6)
33
+ C.Seven.should eql(7)
34
+ end
35
+
36
+ it "should only respond to the names of the defined symbols" do
37
+ A.responds_to?(:Zero).should be(true)
38
+ B.responds_to?(:Zero).should be(true)
39
+ B.responds_to?(:One).should be(true)
40
+ B.responds_to?(:Two).should be(true)
41
+ C.responds_to?(:Five).should be(true)
42
+ C.responds_to?(:Six).should be(true)
43
+ C.responds_to?(:Seven).should be(true)
44
+ # This is strange that it returns nil, but there isn't any
45
+ # documentation of responds_to?, so I guess that's what's supposed to
46
+ # happen.
47
+ A.responds_to?(:One).should be(nil)
48
+ C.responds_to?(:Zero).should be(nil)
49
+ end
50
+ end
51
+ end