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
@@ -1,61 +0,0 @@
1
- module Context
2
-
3
- # A Proxy for carrying on conditional execution.
4
- class ExecutionProxy
5
- # Set the true object on which to execute and the condition to execute.
6
- # NOTE: The condition is a bool. In other words it has *already*
7
- # been evaluated before we get to this point.
8
- def initialize(object, cond)
9
- @object = object
10
- @cond = cond
11
- end
12
-
13
- # Conditionally execute the block. If the condition is true,
14
- # execute the block. Otherwise return the true object.
15
- # NOTE: Crazy name is so that you don't have something with
16
- # the same name and accidently call it with method_missing.
17
- def execute_if_you_can(&block)
18
- if @cond
19
- @object.instance_eval(&block)
20
- else
21
- @object
22
- end
23
- end
24
-
25
- # Conditionally evaluate the symbol. If the condition is true,
26
- # evaluate the symbol. Otherwise return the true object.
27
- def method_missing(symbol)
28
- if @cond
29
- @object.instance_eval(symbol.to_s)
30
- else
31
- @object
32
- end
33
- end
34
- end
35
- end
36
-
37
- class Object
38
-
39
- # Execute the block if the condition is *true*. Or if there is no
40
- # block, then return the proxy object. Usually this is so you
41
- # can say something like:
42
- # * object.execute_if(condition).property
43
- # If the condition is *false*, execution of the block, or evaluation
44
- # of the property will return the original object.
45
- def execute_if(cond, &block)
46
- proxy = Context::ExecutionProxy.new(self, cond)
47
- # Note: Wouldn't it be nice if the following could be replaced by
48
- # proxy.execute_if(!block.nil) do execute_if_you_can(&block) end
49
- proxy_if_block_exists = Context::ExecutionProxy.new(proxy, !block.nil?)
50
- proxy_if_block_exists.execute_if_you_can() do
51
- execute_if_you_can(&block)
52
- end
53
- end
54
-
55
- # If the object is not nil, execute the block (or evaluate
56
- # the property). Otherwise return nil.
57
- def unless_nil(&block)
58
- execute_if(!nil?, &block)
59
- end
60
- end
61
-
@@ -1,54 +0,0 @@
1
- require 'Context/Key'
2
- require 'gtk2'
3
-
4
- module Context::Gtk
5
-
6
- class Key < Context::Key
7
-
8
- def Key::getModifierFromEvent(event)
9
- case event.state
10
- when 0
11
- Context::Key::Modifier::NONE
12
- when Gdk::Window::CONTROL_MASK
13
- Context::Key::Modifier::CONTROL
14
- else
15
- Context::Key::Modifier::ERROR
16
- end
17
- end
18
-
19
- def getGtkState
20
- case @modifier
21
- when Context::Key::Modifier::CONTROL
22
- Gdk::Window::CONTROL_MASK
23
- else
24
- 0
25
- end
26
- end
27
-
28
- def Key::getCharacterFromEvent(event)
29
- Gdk::Keyval::to_name(event.keyval)
30
- end
31
-
32
- def getGtkKeyval
33
- Gdk::Keyval::from_name(@character)
34
- end
35
-
36
- def Key::createFromGtkEvent(event)
37
- modifier = getModifierFromEvent(event)
38
- character = getCharacterFromEvent(event)
39
- if((modifier != Context::Key::Modifier::ERROR) &&
40
- (!character.nil?))
41
- Key.new(modifier, character)
42
- else
43
- Key.null
44
- end
45
- end
46
-
47
- def createGtkEvent
48
- event = Gdk::EventKey.new(Gdk::Event::KEY_PRESS)
49
- event.set_state(getGtkState)
50
- event.set_keyval(getGtkKeyval)
51
- event
52
- end
53
- end
54
- end
@@ -1,57 +0,0 @@
1
- require 'Context/EnumeratedType'
2
-
3
- module Context
4
-
5
- # Represents a keypress. Each key is represented
6
- # by a character and a modifier (e.g., the control
7
- # key)
8
- #
9
- # One could argue that this doesn't deserve to be
10
- # here at all. It is possible that some UI types
11
- # won't have a keyboard at all. However given that
12
- # most will operate the same way indicates that
13
- # it should have some level of abstraction. I have
14
- # a feeling that this is YAGNI, though. And as such
15
- # it might disappear at any point.
16
- class Key
17
- # Types of key modifiers. Currently only
18
- # control or none is supported.
19
- class Modifier < EnumeratedType
20
- start_at 0
21
- symbols [:ERROR, :NONE, :CONTROL]
22
- end
23
-
24
- attr_reader :modifier, :character
25
-
26
- def initialize(modifier, character)
27
- @modifier = modifier
28
- @character = character
29
- end
30
-
31
- # A non key that can be used as an error condition.
32
- # Note: Perhaps this should be a constant??? Currently
33
- # key.eql?(Key.null) will work, but key == Key.null
34
- # won't. FIXME
35
- def Key.null
36
- Key.new(Modifier.NONE, '\0')
37
- end
38
-
39
- # Returns true if the two keys have the same character and modifier.
40
- def eql?(key)
41
- (@modifier == key.modifier) && (@character == key.character)
42
- end
43
-
44
- # Creates a hash for the key. This is needed for the KeyMap
45
- # which is implemented as a hash.
46
- def hash
47
- hashValue = @modifier.to_s
48
- hashValue += @character
49
- hashValue.hash
50
- end
51
-
52
- # Returns true if the key is equal to Key.null.
53
- def null?
54
- eql?(Key.null)
55
- end
56
- end
57
- end
@@ -1,31 +0,0 @@
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
@@ -1,43 +0,0 @@
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
@@ -1,51 +0,0 @@
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
@@ -1,28 +0,0 @@
1
- require 'Context/ExecutionProxy'
2
-
3
- module Context
4
-
5
- describe ExecutionProxy do
6
-
7
- it "should execute methods" do
8
- a = nil
9
- a.unless_nil.fake.should be(nil)
10
-
11
- a = 5
12
- a.unless_nil.self.should be(5)
13
- end
14
-
15
- it "should execute code blocks" do
16
- a = nil
17
- a.unless_nil do
18
- fake
19
- end.should be(nil)
20
-
21
- a = 5
22
- a.unless_nil do
23
- self
24
- end.should be(5)
25
- end
26
- end
27
- end
28
-
@@ -1,45 +0,0 @@
1
- require 'Context/Gtk/Key'
2
-
3
- module Context::Gtk
4
-
5
- describe Key do
6
-
7
- it "should have a factory method to convert from a GTK KeyPressEvent and back" do
8
- event = Gdk::EventKey.new(Gdk::Event::KEY_PRESS)
9
- event.set_state(Gdk::Window::CONTROL_MASK)
10
- event.set_keyval(Gdk::Keyval::GDK_o)
11
-
12
- key = Key.createFromGtkEvent(event)
13
- key.should_not be_nil
14
- key.should eql(Key.new(Context::Key::Modifier::CONTROL, 'o'))
15
- key.getGtkState.should be_eql(Gdk::Window::CONTROL_MASK)
16
- key.getGtkKeyval.should be_eql(Gdk::Keyval::GDK_o)
17
- e = key.createGtkEvent
18
- e.state.should be_eql(Gdk::Window::CONTROL_MASK)
19
- e.keyval.should be_eql(Gdk::Keyval::GDK_o)
20
- end
21
-
22
- it "should convert characters with no modifier and back" do
23
- event = Gdk::EventKey.new(Gdk::Event::KEY_PRESS)
24
- event.set_state(0)
25
- event.set_keyval(Gdk::Keyval::GDK_Tab)
26
-
27
- key = Key.createFromGtkEvent(event)
28
- key.should_not be_nil
29
- key.should eql(Key.new(Context::Key::Modifier::NONE, 'Tab'))
30
- e = key.createGtkEvent
31
- e.state.should be_eql(0)
32
- e.keyval.should be_eql(Gdk::Keyval::GDK_Tab)
33
- end
34
-
35
- it "should create a null character if it doesn't know how to make it" do
36
- event = Gdk::EventKey.new(Gdk::Event::KEY_PRESS)
37
- event.set_state(Gdk::Window::META_MASK)
38
- event.set_keyval(Gdk::Keyval::GDK_q)
39
-
40
- key = Key.createFromGtkEvent(event)
41
- key.should_not be_nil
42
- key.should be_null
43
- end
44
- end
45
- end
@@ -1,26 +0,0 @@
1
- require 'Context/Key'
2
- require 'Context/KeyAssignment'
3
-
4
- module Context
5
-
6
- describe KeyAssignment do
7
-
8
- it "should have a key and a proc" do
9
- run = false
10
- ctlD = Key.new(Key::Modifier.CONTROL, 'd')
11
- d = Key.new(Key::Modifier.NONE, 'd')
12
- ka = KeyAssignment.new(ctlD) do
13
- run = true
14
- end
15
- newCtlD = Key.new(Key::Modifier.CONTROL, 'd')
16
- newD = Key.new(Key::Modifier.NONE, 'd')
17
- ka.handles?(newD).should be(false)
18
- ka.handles?(newCtlD).should be(true)
19
- ka.try(newD).should be(false)
20
- run.should be(false)
21
- ka.try(newCtlD).should be(true)
22
- run.should be(true)
23
- end
24
-
25
- end
26
- end
@@ -1,64 +0,0 @@
1
- require 'Context/Key'
2
- require 'Context/KeyAssignment'
3
- require 'Context/KeyMap'
4
-
5
- module Context
6
-
7
- describe KeyMap do
8
-
9
- before(:each) do
10
- @map = KeyMap.new
11
- @ctlD = Key.new(Key::Modifier.CONTROL, 'd')
12
- @ctlDPressed = false
13
- @ctlDAssignment = KeyAssignment.new(@ctlD) do
14
- @ctlDPressed = true
15
- end
16
- @d = Key.new(Key::Modifier.NONE, 'd')
17
- @dPressed = false
18
- @dAssignment = KeyAssignment.new(@ctlD) do
19
- @dPressed = true
20
- end
21
- @newCtlD = Key.new(Key::Modifier.CONTROL, 'd')
22
- @newD = Key.new(Key::Modifier.NONE, 'd')
23
- end
24
-
25
- it "should be able to contain a KeyAssignment" do
26
- @map.handles?(@newCtlD).should be(false)
27
- @map.handles?(@newD).should be(false)
28
- @map.add(@ctlDAssignment)
29
- @map.handles?(@newCtlD).should be(true)
30
- @map.handles?(@newD).should be(false)
31
- end
32
-
33
- it "should be able to contain many KeyAssignments" do
34
- @map.handles?(@newCtlD).should be(false)
35
- @map.handles?(@newD).should be(false)
36
- @map.add(@ctlDAssignment)
37
- @map.handles?(@newCtlD).should be(true)
38
- @map.handles?(@newD).should be(false)
39
- @map.add(@dAssignment)
40
- @map.handles?(@newD).should be(false)
41
- end
42
-
43
- it "should be able to press a key" do
44
- @map.add(@ctlDAssignment)
45
- @map.add(@dAssignment)
46
- @ctlDPressed.should be(false)
47
- @dPressed.should be(false)
48
- @map.press(@newCtlD).should be(true)
49
- @ctlDPressed.should be(true)
50
- @dPressed.should be(false)
51
- end
52
-
53
- it "should return false if a non-handled key is pressed" do
54
- @map.add(@ctlDAssignment)
55
- @ctlDPressed.should be(false)
56
- @dPressed.should be(false)
57
- @map.handles?(@d).should be(false)
58
- @map.press(@d).should be(false)
59
- @dPressed.should be(false)
60
- @ctlDPressed.should be(false)
61
- end
62
-
63
- end
64
- end