reterm 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +131 -0
  4. data/designer/main.rb +10 -0
  5. data/designer/src/ComponentParams.rb +120 -0
  6. data/designer/src/ComponentsList.rb +90 -0
  7. data/designer/src/CreatedList.rb +156 -0
  8. data/designer/src/Designer.rb +114 -0
  9. data/designer/src/ToggleArea.rb +67 -0
  10. data/designer/src/common.rb +1 -0
  11. data/designer/src/component_factory.rb +30 -0
  12. data/designer/src/component_map.rb +116 -0
  13. data/designer/src/glade/ComponentParams.glade +96 -0
  14. data/designer/src/glade/Designer.glade +184 -0
  15. data/designer/src/images/add.png +0 -0
  16. data/designer/src/images/asciitext.png +0 -0
  17. data/designer/src/images/blank.png +0 -0
  18. data/designer/src/images/blank_sm.png +0 -0
  19. data/designer/src/images/button.png +0 -0
  20. data/designer/src/images/dial.png +0 -0
  21. data/designer/src/images/entry.png +0 -0
  22. data/designer/src/images/hslider.png +0 -0
  23. data/designer/src/images/label.png +0 -0
  24. data/designer/src/images/matrix.png +0 -0
  25. data/designer/src/images/orig/Check.png +0 -0
  26. data/designer/src/images/orig/ascii_text.png +0 -0
  27. data/designer/src/images/orig/button.png +0 -0
  28. data/designer/src/images/orig/dial.png +0 -0
  29. data/designer/src/images/orig/entry.png +0 -0
  30. data/designer/src/images/orig/hslider.png +0 -0
  31. data/designer/src/images/orig/label.png +0 -0
  32. data/designer/src/images/orig/matrix.png +0 -0
  33. data/designer/src/images/orig/radio.png +0 -0
  34. data/designer/src/images/orig/rocker.png +0 -0
  35. data/designer/src/images/orig/slist.png +0 -0
  36. data/designer/src/images/orig/vslider.png +0 -0
  37. data/designer/src/images/radio.png +0 -0
  38. data/designer/src/images/remove.png +0 -0
  39. data/designer/src/images/rocker.png +0 -0
  40. data/designer/src/images/slist.png +0 -0
  41. data/designer/src/images/vslider.png +0 -0
  42. data/lib/reterm.rb +22 -0
  43. data/lib/reterm/color_pair.rb +66 -0
  44. data/lib/reterm/component.rb +40 -0
  45. data/lib/reterm/components.rb +32 -0
  46. data/lib/reterm/components/ascii_text.rb +46 -0
  47. data/lib/reterm/components/button.rb +31 -0
  48. data/lib/reterm/components/dial.rb +95 -0
  49. data/lib/reterm/components/dialog.rb +34 -0
  50. data/lib/reterm/components/entry.rb +38 -0
  51. data/lib/reterm/components/hslider.rb +32 -0
  52. data/lib/reterm/components/image.rb +55 -0
  53. data/lib/reterm/components/label.rb +20 -0
  54. data/lib/reterm/components/matrix.rb +43 -0
  55. data/lib/reterm/components/radio.rb +33 -0
  56. data/lib/reterm/components/rocker.rb +71 -0
  57. data/lib/reterm/components/slist.rb +32 -0
  58. data/lib/reterm/components/template.rb +23 -0
  59. data/lib/reterm/components/vslider.rb +61 -0
  60. data/lib/reterm/init.rb +95 -0
  61. data/lib/reterm/layout.rb +63 -0
  62. data/lib/reterm/layouts.rb +16 -0
  63. data/lib/reterm/layouts/horizontal.rb +19 -0
  64. data/lib/reterm/layouts/vertical.rb +19 -0
  65. data/lib/reterm/loader.rb +126 -0
  66. data/lib/reterm/menu.rb +81 -0
  67. data/lib/reterm/mixins/cdk_component.rb +45 -0
  68. data/lib/reterm/mixins/component_input.rb +37 -0
  69. data/lib/reterm/mixins/event_dispatcher.rb +20 -0
  70. data/lib/reterm/mixins/nav_input.rb +126 -0
  71. data/lib/reterm/panel.rb +37 -0
  72. data/lib/reterm/resize.rb +27 -0
  73. data/lib/reterm/terminal.rb +33 -0
  74. data/lib/reterm/version.rb +3 -0
  75. data/lib/reterm/window.rb +260 -0
  76. metadata +155 -0
@@ -0,0 +1,114 @@
1
+ require 'reterm'
2
+
3
+ # Main designer window
4
+ class Designer
5
+ include GladeGUI
6
+
7
+ attr_accessor :component_list
8
+ attr_accessor :created_list
9
+
10
+ attr_accessor :component
11
+ attr_accessor :ta
12
+
13
+ def initialize
14
+ @component_list = ComponentsList.new(self)
15
+ @created_list = CreatedList.new(self)
16
+ @component = ToggleArea.new(self)
17
+
18
+ set_components
19
+ end
20
+
21
+ def window
22
+ @builder["window1"]
23
+ end
24
+
25
+ def before_show
26
+ window.title = "RETerm Designer"
27
+ @builder["component_window"].add(@component_list, :expand => true)
28
+ @builder["created_window"].add(@created_list, :expand => true)
29
+ @builder["viewer"].add(@component.btn)
30
+ @component.show
31
+ end
32
+
33
+ def create_component(component, params)
34
+ c = build_component self, component, params
35
+ c, areas = *c if c.is_a?(Array)
36
+
37
+ parent = nil
38
+ if @component.is_a?(ToggleArea)
39
+ @builder["viewer"].remove(@component.btn)
40
+ @builder["viewer"].add(c)
41
+ c.show
42
+ areas.each { |a| a.show } if areas
43
+
44
+ @component = c
45
+
46
+ else
47
+ parent = component_with_toggle_area
48
+ index = parent.child_get_property(@ta.btn, :position)
49
+ parent.remove(@ta.btn)
50
+ parent.add(c, :expand => true)
51
+ parent.child_set_property(c, :position, index)
52
+ c.show
53
+ areas.each { |a| a.show } if areas
54
+ end
55
+
56
+ @created_list.register component, params, c, parent
57
+
58
+ self.toggle_area = nil
59
+ end
60
+
61
+ def remove_component(c)
62
+ if c == @component
63
+ @component = ToggleArea.new(self)
64
+ @builder["viewer"].remove(c)
65
+ @builder["viewer"].add(@component.btn)
66
+ @component.show
67
+
68
+ else
69
+ parent = component_with_widget(c)
70
+ index = parent.child_get_property(c, :position)
71
+ parent.remove(c)
72
+ ta = ToggleArea.new(self)
73
+ parent.add(ta.btn, :expand => true)
74
+ parent.child_set_property(ta.btn, :position, index)
75
+ ta.show
76
+ end
77
+ end
78
+
79
+ def toggle_area=(ta)
80
+ @ta.toggle_off if has_toggled_area?
81
+ @ta = ta
82
+ end
83
+
84
+ # XXX needed as we need to invoke from #toggle_off
85
+ def clear_toggle_area
86
+ @ta = nil
87
+ end
88
+
89
+ def has_toggled_area?
90
+ !!@ta
91
+ end
92
+
93
+ private
94
+
95
+ def component_with_toggle_area(c=component)
96
+ component_with_widget(@ta.btn, c)
97
+ end
98
+
99
+ def component_with_widget(widget, c=component)
100
+ return c if c.children.include?(widget)
101
+ c.children.each { |child|
102
+ ch = component_with_widget(widget, child) if child.kind_of?(Gtk::Box)
103
+ return ch unless ch.nil?
104
+ }
105
+ nil
106
+ end
107
+
108
+ def set_components
109
+ (RETerm::Layouts.all.sort +
110
+ RETerm::Components.all.sort).each { |c|
111
+ @component_list.add_component c if COMPONENTS.key?(c)
112
+ }
113
+ end
114
+ end
@@ -0,0 +1,67 @@
1
+ # Mechanism which user specifies area to add component
2
+ class ToggleArea
3
+ attr_accessor :toggled
4
+
5
+ def toggle_on
6
+ @toggled = true
7
+ btn.remove(add)
8
+ btn.add(rm)
9
+ @designer.toggle_area = self
10
+ end
11
+
12
+ def toggle_off
13
+ @toggled = false
14
+ btn.remove(rm)
15
+ btn.add(add)
16
+ show
17
+ @designer.clear_toggle_area
18
+ end
19
+
20
+ def add
21
+ @add ||= Gtk::Image.new :file => "#{IMG_DIR}/add.png"
22
+ end
23
+
24
+ def rm
25
+ @rm ||= Gtk::Image.new :file => "#{IMG_DIR}/remove.png"
26
+ end
27
+
28
+
29
+ def btn
30
+ @btn ||=
31
+ begin
32
+ b = Gtk::Button.new
33
+ b.add add
34
+
35
+ b.signal_connect("clicked") { |*args|
36
+ if @toggled
37
+ toggle_off
38
+ else
39
+ toggle_on
40
+ end
41
+
42
+ show
43
+ }
44
+
45
+ css_provider = Gtk::CssProvider.new
46
+ css_provider.load(data: "button:hover {background-image: image(#FFFF00);}")
47
+ b.style_context.add_provider(css_provider, Gtk::StyleProvider::PRIORITY_USER)
48
+
49
+ b
50
+ end
51
+ end
52
+
53
+ def show
54
+ btn.show
55
+
56
+ if @toggled
57
+ rm.show
58
+ else
59
+ add.show
60
+ end
61
+ end
62
+
63
+ def initialize(designer)
64
+ @designer = designer
65
+ @toggled = false
66
+ end
67
+ end
@@ -0,0 +1 @@
1
+ IMG_DIR = File.join(File.dirname(__FILE__), "images")
@@ -0,0 +1,30 @@
1
+ def build_component(designer, component, params)
2
+ if component == :Horizontal
3
+ areas = []
4
+ c = Gtk::HBox.new
5
+ cols = params.first
6
+ 0.upto(cols-1) {
7
+ area = ToggleArea.new(designer)
8
+ areas << area
9
+ c.add area.btn, :expand => true
10
+ }
11
+
12
+ return [c, areas]
13
+
14
+ elsif component == :Vertical
15
+ areas = []
16
+ c = Gtk::VBox.new
17
+ rows = params.first
18
+ 0.upto(rows-1) {
19
+ area = ToggleArea.new(designer)
20
+ areas << area
21
+ c.add area.btn, :expand => true
22
+ }
23
+
24
+ return [c, areas]
25
+
26
+ else
27
+ return designer.component_list.image_for(component)
28
+
29
+ end
30
+ end
@@ -0,0 +1,116 @@
1
+ COMPONENTS = {
2
+ # Layouts
3
+ :Horizontal => {
4
+ :desc => "Horizontal Layout",
5
+ :params => {
6
+ "Columns" => :int
7
+ }
8
+ },
9
+
10
+ :Vertical => {
11
+ :desc => "Vertical Layout",
12
+ :params => {
13
+ "Rows" => :int
14
+ }
15
+ },
16
+
17
+ :AsciiText => {
18
+ :desc => "Text Rendered Using Ascii Font",
19
+ :params => {
20
+ "Text" => :string
21
+ },
22
+
23
+ :init_keys => ["text"]
24
+ },
25
+
26
+ :Button => {
27
+ :desc => "Clickable Button",
28
+ :params => {
29
+ "Text" => :string
30
+ },
31
+
32
+ :init_keys => ["text"]
33
+ },
34
+
35
+ :Dial => {
36
+ :desc => "Rotatable Dial"
37
+ },
38
+
39
+ #:Dialog => {
40
+ # :desc => "Popup Dialog"
41
+ #},
42
+
43
+ :Entry => {
44
+ :desc => "Text Entry",
45
+ :params => {
46
+ "Title" => :string,
47
+ "Label" => :string
48
+ },
49
+
50
+ :init_keys => ["title", "label"]
51
+ },
52
+
53
+ :HSlider => {
54
+ :desc => "Horizontal Slider"
55
+ },
56
+
57
+ :Image => {
58
+ :desc => "Image rendered with ascii art",
59
+ :params => {
60
+ "Path" => :string
61
+ },
62
+
63
+ :init_keys => ["file"]
64
+ },
65
+
66
+ :Label => {
67
+ :desc => "Static String",
68
+ :params => {
69
+ "Text" => :string
70
+ },
71
+
72
+ :init_keys => ["text"]
73
+ },
74
+
75
+ :Matrix => {
76
+ :desc => "X/Y grid",
77
+ :params => {
78
+ "Rows" => :int,
79
+ "Columns" => :int
80
+ },
81
+
82
+ :init_keys => ["rows", "cols"]
83
+ },
84
+
85
+ :Radio => {
86
+ :desc => "Choice selection control",
87
+
88
+ :params => {
89
+ "Choices" => [:string]
90
+ }
91
+ },
92
+
93
+ :Rocker => {
94
+ :desc => "Toggleable input",
95
+
96
+ :params => {
97
+ "Choices" => [:string]
98
+ },
99
+
100
+ :init_keys => ["items"]
101
+ },
102
+
103
+ :SList => {
104
+ :desc => "Selectable List of Items",
105
+
106
+ :params => {
107
+ "Choices" => [:string]
108
+ },
109
+
110
+ :init_keys => ["items"]
111
+ },
112
+
113
+ :VSlider => {
114
+ :desc => "Vertical Slider"
115
+ }
116
+ }
@@ -0,0 +1,96 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Generated with glade 3.20.0 -->
3
+ <interface>
4
+ <requires lib="gtk+" version="3.20"/>
5
+ <object class="GtkWindow" id="window1">
6
+ <property name="can_focus">False</property>
7
+ <property name="resizable">False</property>
8
+ <property name="modal">True</property>
9
+ <child>
10
+ <object class="GtkBox">
11
+ <property name="visible">True</property>
12
+ <property name="can_focus">False</property>
13
+ <property name="margin_left">5</property>
14
+ <property name="margin_right">6</property>
15
+ <property name="margin_top">5</property>
16
+ <property name="margin_bottom">5</property>
17
+ <property name="orientation">vertical</property>
18
+ <child>
19
+ <object class="GtkLabel" id="component_edit_title">
20
+ <property name="visible">True</property>
21
+ <property name="can_focus">False</property>
22
+ <property name="margin_left">5</property>
23
+ <property name="margin_right">5</property>
24
+ <property name="margin_top">5</property>
25
+ <property name="margin_bottom">5</property>
26
+ </object>
27
+ <packing>
28
+ <property name="expand">False</property>
29
+ <property name="fill">True</property>
30
+ <property name="position">0</property>
31
+ </packing>
32
+ </child>
33
+ <child>
34
+ <object class="GtkBox" id="component_edit_layout">
35
+ <property name="visible">True</property>
36
+ <property name="can_focus">False</property>
37
+ <property name="orientation">vertical</property>
38
+ <child>
39
+ <placeholder/>
40
+ </child>
41
+ </object>
42
+ <packing>
43
+ <property name="expand">False</property>
44
+ <property name="fill">True</property>
45
+ <property name="position">1</property>
46
+ </packing>
47
+ </child>
48
+ <child>
49
+ <object class="GtkBox">
50
+ <property name="visible">True</property>
51
+ <property name="can_focus">False</property>
52
+ <child>
53
+ <object class="GtkButton" id="submit_button">
54
+ <property name="label" translatable="yes">Submit</property>
55
+ <property name="visible">True</property>
56
+ <property name="can_focus">True</property>
57
+ <property name="receives_default">True</property>
58
+ <property name="margin_left">5</property>
59
+ <property name="margin_right">5</property>
60
+ <property name="margin_top">5</property>
61
+ <property name="margin_bottom">5</property>
62
+ </object>
63
+ <packing>
64
+ <property name="expand">True</property>
65
+ <property name="fill">True</property>
66
+ <property name="position">0</property>
67
+ </packing>
68
+ </child>
69
+ <child>
70
+ <object class="GtkButton" id="cancel_button">
71
+ <property name="label" translatable="yes">Cancel</property>
72
+ <property name="visible">True</property>
73
+ <property name="can_focus">True</property>
74
+ <property name="receives_default">True</property>
75
+ <property name="margin_left">5</property>
76
+ <property name="margin_right">5</property>
77
+ <property name="margin_top">5</property>
78
+ <property name="margin_bottom">5</property>
79
+ </object>
80
+ <packing>
81
+ <property name="expand">True</property>
82
+ <property name="fill">True</property>
83
+ <property name="position">1</property>
84
+ </packing>
85
+ </child>
86
+ </object>
87
+ <packing>
88
+ <property name="expand">False</property>
89
+ <property name="fill">True</property>
90
+ <property name="position">2</property>
91
+ </packing>
92
+ </child>
93
+ </object>
94
+ </child>
95
+ </object>
96
+ </interface>
@@ -0,0 +1,184 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Generated with glade 3.20.0 -->
3
+ <interface>
4
+ <requires lib="gtk+" version="3.0"/>
5
+ <object class="GtkWindow" id="window1">
6
+ <property name="can_focus">False</property>
7
+ <property name="window_position">center</property>
8
+ <child>
9
+ <object class="GtkBox">
10
+ <property name="visible">True</property>
11
+ <property name="can_focus">False</property>
12
+ <property name="orientation">vertical</property>
13
+ <child>
14
+ <object class="GtkMenuBar" id="main_menu">
15
+ <property name="visible">True</property>
16
+ <property name="can_focus">False</property>
17
+ <child>
18
+ <object class="GtkMenuItem" id="file_menu">
19
+ <property name="visible">True</property>
20
+ <property name="can_focus">False</property>
21
+ <property name="label" translatable="yes">_File</property>
22
+ <property name="use_underline">True</property>
23
+ <child type="submenu">
24
+ <object class="GtkMenu">
25
+ <property name="visible">True</property>
26
+ <property name="can_focus">False</property>
27
+ <child>
28
+ <object class="GtkImageMenuItem" id="file_menu_new">
29
+ <property name="label">gtk-new</property>
30
+ <property name="visible">True</property>
31
+ <property name="can_focus">False</property>
32
+ <property name="use_underline">True</property>
33
+ <property name="use_stock">True</property>
34
+ </object>
35
+ </child>
36
+ <child>
37
+ <object class="GtkImageMenuItem" id="file_menu_open">
38
+ <property name="label">gtk-open</property>
39
+ <property name="visible">True</property>
40
+ <property name="can_focus">False</property>
41
+ <property name="use_underline">True</property>
42
+ <property name="use_stock">True</property>
43
+ </object>
44
+ </child>
45
+ <child>
46
+ <object class="GtkImageMenuItem" id="file_menu_save">
47
+ <property name="label">gtk-save</property>
48
+ <property name="visible">True</property>
49
+ <property name="can_focus">False</property>
50
+ <property name="use_underline">True</property>
51
+ <property name="use_stock">True</property>
52
+ </object>
53
+ </child>
54
+ <child>
55
+ <object class="GtkImageMenuItem" id="file_menu_save_as">
56
+ <property name="label">gtk-save-as</property>
57
+ <property name="visible">True</property>
58
+ <property name="can_focus">False</property>
59
+ <property name="use_underline">True</property>
60
+ <property name="use_stock">True</property>
61
+ </object>
62
+ </child>
63
+ <child>
64
+ <object class="GtkSeparatorMenuItem">
65
+ <property name="visible">True</property>
66
+ <property name="can_focus">False</property>
67
+ </object>
68
+ </child>
69
+ <child>
70
+ <object class="GtkImageMenuItem" id="file_menu_quit">
71
+ <property name="label">gtk-quit</property>
72
+ <property name="visible">True</property>
73
+ <property name="can_focus">False</property>
74
+ <property name="use_underline">True</property>
75
+ <property name="use_stock">True</property>
76
+ </object>
77
+ </child>
78
+ </object>
79
+ </child>
80
+ </object>
81
+ </child>
82
+ <child>
83
+ <object class="GtkMenuItem">
84
+ <property name="visible">True</property>
85
+ <property name="can_focus">False</property>
86
+ <property name="label" translatable="yes">_Help</property>
87
+ <property name="use_underline">True</property>
88
+ <child type="submenu">
89
+ <object class="GtkMenu">
90
+ <property name="visible">True</property>
91
+ <property name="can_focus">False</property>
92
+ <child>
93
+ <object class="GtkImageMenuItem">
94
+ <property name="label">gtk-about</property>
95
+ <property name="visible">True</property>
96
+ <property name="can_focus">False</property>
97
+ <property name="use_underline">True</property>
98
+ <property name="use_stock">True</property>
99
+ </object>
100
+ </child>
101
+ </object>
102
+ </child>
103
+ </object>
104
+ </child>
105
+ </object>
106
+ <packing>
107
+ <property name="expand">False</property>
108
+ <property name="fill">True</property>
109
+ <property name="position">0</property>
110
+ </packing>
111
+ </child>
112
+ <child>
113
+ <object class="GtkPaned">
114
+ <property name="visible">True</property>
115
+ <property name="can_focus">True</property>
116
+ <child>
117
+ <object class="GtkBox">
118
+ <property name="visible">True</property>
119
+ <property name="can_focus">False</property>
120
+ <property name="orientation">vertical</property>
121
+ <child>
122
+ <object class="GtkScrolledWindow" id="component_window">
123
+ <property name="width_request">300</property>
124
+ <property name="height_request">500</property>
125
+ <property name="visible">True</property>
126
+ <property name="can_focus">True</property>
127
+ <property name="shadow_type">in</property>
128
+ <child>
129
+ <placeholder/>
130
+ </child>
131
+ </object>
132
+ <packing>
133
+ <property name="expand">True</property>
134
+ <property name="fill">True</property>
135
+ <property name="position">0</property>
136
+ </packing>
137
+ </child>
138
+ <child>
139
+ <object class="GtkScrolledWindow" id="created_window">
140
+ <property name="can_focus">True</property>
141
+ <property name="shadow_type">in</property>
142
+ <child>
143
+ <placeholder/>
144
+ </child>
145
+ </object>
146
+ <packing>
147
+ <property name="expand">False</property>
148
+ <property name="fill">False</property>
149
+ <property name="position">1</property>
150
+ </packing>
151
+ </child>
152
+ </object>
153
+ <packing>
154
+ <property name="resize">False</property>
155
+ <property name="shrink">True</property>
156
+ </packing>
157
+ </child>
158
+ <child>
159
+ <object class="GtkEventBox" id="viewer">
160
+ <property name="width_request">500</property>
161
+ <property name="visible">True</property>
162
+ <property name="can_focus">False</property>
163
+ <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK | GDK_TOUCH_MASK | GDK_SMOOTH_SCROLL_MASK</property>
164
+ <property name="visible_window">False</property>
165
+ <child>
166
+ <placeholder/>
167
+ </child>
168
+ </object>
169
+ <packing>
170
+ <property name="resize">True</property>
171
+ <property name="shrink">True</property>
172
+ </packing>
173
+ </child>
174
+ </object>
175
+ <packing>
176
+ <property name="expand">True</property>
177
+ <property name="fill">True</property>
178
+ <property name="position">2</property>
179
+ </packing>
180
+ </child>
181
+ </object>
182
+ </child>
183
+ </object>
184
+ </interface>