shul 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/shul.rb +253 -186
  5. metadata +1 -1
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63dddbdfa823fc54011d661b0ebdcc34fec9f997
4
- data.tar.gz: c7a3f7e25fb983f88e053fb29d0f4d09cf107964
3
+ metadata.gz: 250018912dfe1c289cdcc291096db3b888153a1b
4
+ data.tar.gz: e2be69b41bd343e9702c403ce36757c4de1957f8
5
5
  SHA512:
6
- metadata.gz: 2716793a176acd43b1b597ef1e681231b963f5b2ed5a372979980cbc2d1755e295dba7de24c3848508dd83f3bdd818b46f4faa96fac4d81ab535883cded99134
7
- data.tar.gz: 26d654568d116dbec3c607538187c649df9679fa4990f12988d99bc1cc768b01c7eb493837ac6b63d39ef9dc24ea9ab551443d75c777322809305fd118339875
6
+ metadata.gz: 5628cbfca17f5396003eec25ffef3691a25d87e84d100a8f3af618aa4b7f1f74aa40213feca23f8a73f09a88dbfb21679cdda06e504ccbca236973575abfabd6
7
+ data.tar.gz: c2dc301eb0a14c52bfc87fda3a5c3b79e4c1ab964f5ea660962594fc78683aa5a8f2b7ae5e6e35b181cec7f72c732a13b9aa9051df8ecc3d0d12b81b19fa4ea6
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -22,9 +22,12 @@ Shoes.app {Shul.new self, xml}
22
22
  =end
23
23
 
24
24
  # resources:
25
- # https://en.wikipedia.org/wiki/Shoes_%28GUI_toolkit%29
26
- # https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL
27
- # http://www.xul.fr/tutorial/
25
+ # xul:
26
+ # https://en.wikipedia.org/wiki/Shoes_%28GUI_toolkit%29
27
+ # https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL
28
+ # http://www.xul.fr/tutorial/
29
+ # shoes:
30
+ # http://shoesrb.com/manual/Element.html
28
31
  #------------------------------------------------------------------
29
32
 
30
33
  require 'rexle'
@@ -33,240 +36,304 @@ require 'rxfhelper'
33
36
 
34
37
  class Rexle::Element
35
38
 
36
- def obj()
37
- @obj
38
- end
39
-
40
- def obj=(obj)
41
- @obj = obj
42
- end
39
+ def obj() @obj end
40
+ def obj=(obj) @obj = obj end
43
41
 
44
42
  end
45
43
 
46
44
 
47
- class Shul
45
+ module Shul
48
46
 
49
- def initialize(shoes, source)
50
-
51
- @shoes = shoes
47
+ class Main
52
48
 
53
- @doc = if source.is_a? Rexle then source
54
- else
55
- xml, _ = RXFHelper.read(source)
56
- Rexle.new(xml)
57
- end
49
+ def initialize(shoes, xml)
58
50
 
59
- @doc.root.elements.each {|x| method(x.name.sub(':','_').to_sym).call(x) }
51
+ doc = Rexle.new xml
52
+
53
+ shoes.app(resizeable: false, width: 100, height: 100) do
60
54
 
61
- def @doc.element_by_id(id)
62
- self.root.element("//*[@id='#{id}']")
55
+ shul = Shul::App.new self, doc
56
+
57
+ end
58
+
63
59
  end
64
-
65
60
  end
66
61
 
67
- private
68
-
69
- def button(e)
62
+
63
+ class App
64
+
65
+ def initialize(shoes_app, source)
66
+
67
+ doc = if source.is_a? Rexle then source
68
+ else
69
+ xml, _ = RXFHelper.read(source)
70
+ Rexle.new(xml)
71
+ end
72
+
73
+ # To find out the window dimensions we must first render the app
74
+ shul = Window.new(shoes_app, doc)
70
75
 
71
- buttonx e
76
+ shoes_app.start do |app|
77
+
78
+ sleep 0.0001
79
+
80
+ box = doc.root.element('hbox | vbox').obj
81
+
82
+ h = {title: 'Shul', width: box.width, height: box.height}\
83
+ .merge doc.root.attributes
84
+
85
+ win = window(h) { Window.new self, doc }
86
+ win.start do |w|
87
+ sleep 0.0001
88
+
89
+ end
90
+ app.close # closes the initial shoes app
91
+ shul = nil
92
+
93
+ end
94
+ end
72
95
 
73
96
  end
74
-
75
- def buttonx(e, label = :label, oncommand = :oncommand)
76
97
 
77
- h = e.attributes
78
- label = h[label]
79
- command = h[oncommand]
80
-
81
- e.obj = @shoes.button label do
82
- eval command if command
83
- end
98
+ class Window
84
99
 
85
- def e.label=(v)
86
- self.obj.style[:text] = v
100
+ attr_reader :width, :height
101
+
102
+ def initialize(shoes, doc)
103
+
104
+ @shoes = shoes
105
+ @width, @height = 100, 100
106
+
107
+ @doc = doc
108
+
109
+ @doc.root.elements.each {|x| method(x.name.sub(':','_').to_sym).call(x) }
110
+
111
+ def @doc.element_by_id(id)
112
+ self.root.element("//*[@id='#{id}']")
113
+ end
114
+
115
+
87
116
  end
117
+
118
+ private
88
119
 
89
- end
90
-
91
- def checkbox(e)
92
-
93
- h = e.attributes
94
-
95
- @shoes.flow do
96
- c = @shoes.check
97
- c.checked = h[:checked] == 'true'
98
- @shoes.para h[:label]
120
+ def button(e)
121
+
122
+ buttonx e
123
+
99
124
  end
100
125
 
101
- end
126
+ def buttonx(e, label = :label, oncommand = :oncommand)
102
127
 
103
- def description(e)
104
- e.obj = @shoes.para e.attributes[:value]
105
- end
106
-
107
- def doc()
108
- @doc
109
- end
110
-
111
- def editbox(e, name = :edit_line)
112
-
113
- obj = @shoes.method(name).call
114
- obj.text = e.attributes[:value]
115
- obj.change {|x| e.value = x.text() if e.value != e.text}
116
- e.obj = obj
128
+ h = e.attributes
129
+ label = h[label]
130
+ command = h[oncommand]
131
+
132
+ e.obj = @shoes.button label do
133
+ eval command if command
134
+ end
135
+
136
+ def e.label=(v)
137
+ self.obj.style[:text] = v
138
+ end
139
+
140
+ end
117
141
 
118
- def e.value()
119
- self.attributes[:value]
120
- end
142
+ def checkbox(e)
121
143
 
122
- def e.value=(v)
123
- self.attributes[:value] = v
124
- self.obj.text = v
125
- end
144
+ h = e.attributes
145
+
146
+ @shoes.flow do
147
+ c = @shoes.check
148
+ c.checked = h[:checked] == 'true'
149
+ @shoes.para h[:label]
150
+ end
151
+
152
+ end
153
+
154
+ def description(e)
155
+ e.obj = @shoes.para e.attributes[:value]
156
+ end
126
157
 
127
- end
128
-
129
- # This method is under-development
130
- #
131
- def grid(e)
158
+ def doc()
159
+ @doc
160
+ end
132
161
 
133
- # get the grid width
134
- #grid_width = 100
162
+ def editbox(e, name = :edit_line)
163
+
164
+ obj = @shoes.method(name).call
165
+ obj.text = e.attributes[:value]
166
+ obj.change {|x| e.value = x.text() if e.value != e.text}
167
+ e.obj = obj
168
+
169
+ def e.value()
170
+ self.attributes[:value]
171
+ end
172
+
173
+ def e.value=(v)
174
+ self.attributes[:value] = v
175
+ self.obj.text = v
176
+ end
177
+
178
+ end
135
179
 
136
- # get the columns
137
- columns = e.element 'columns'
138
- cols = columns.xpath 'column'
139
- cols_flex = cols.map {|x| x.attributes[:flex].to_s.to_i}
180
+ def find_max_dimensions(e)
181
+
182
+ a = e.elements.map(&:obj)
183
+ maxwidth = a.max_by{|x| x.width}.width
184
+ maxheight = a.inject(0) {|r,x2| r += x2.height }
185
+
186
+ [maxwidth.to_i, maxheight]
187
+
188
+ end
140
189
 
141
- # get the rows
142
- rows = e.element 'rows'
143
- rows.each do |row|
144
- a = row.xpath 'row'
145
- # resize the width of each item
146
- a.each do |x|
147
- #x.width = 400
148
- #puts "x: %s width: %s" + [x.inspect, x.width]
190
+ # This method is under-development
191
+ #
192
+ def grid(e)
193
+
194
+ # get the grid width
195
+ #grid_width = 100
196
+
197
+ # get the columns
198
+ columns = e.element 'columns'
199
+ cols = columns.xpath 'column'
200
+ cols_flex = cols.map {|x| x.attributes[:flex].to_s.to_i}
201
+
202
+ # get the rows
203
+ rows = e.element 'rows'
204
+ rows.each do |row|
205
+ a = row.xpath 'row'
206
+ # resize the width of each item
207
+ a.each do |x|
208
+ #x.width = 400
209
+ #puts "x: %s width: %s" + [x.inspect, x.width]
210
+ end
149
211
  end
150
212
  end
151
- end
152
-
153
- def hbox(e)
213
+
214
+ def hbox(e)
154
215
 
155
- @shoes.flow do
156
- e.elements.each {|x| method(x.name.sub(':','_').to_sym).call(x) }
157
- end
216
+ flow = @shoes.flow do
217
+ e.elements.each {|x| method(x.name.sub(':','_').to_sym).call(x) }
218
+ end
219
+ e.obj = flow
158
220
 
159
- end
160
-
161
- alias flow hbox
221
+ end
222
+
223
+ alias flow hbox
162
224
 
163
- def html_a(e)
225
+ def html_a(e)
164
226
 
165
- command = e.attributes[:oncommand]
227
+ command = e.attributes[:oncommand]
166
228
 
167
- @shoes.para(
168
- e.obj = @shoes.link(e.text).click do
169
- eval command if command
170
- end
171
- )
229
+ @shoes.para(
230
+ e.obj = @shoes.link(e.text).click do
231
+ eval command if command
232
+ end
233
+ )
172
234
 
173
- end
174
-
175
- def html_em(e)
176
- e.obj = obj = @shoes.em(e.text)
177
- @shoes.para()
178
- end
179
-
180
- alias html_i html_em
235
+ end
236
+
237
+ def html_em(e)
238
+ e.obj = obj = @shoes.em(e.text)
239
+ @shoes.para()
240
+ end
241
+
242
+ alias html_i html_em
181
243
 
182
- def html_input(e)
244
+ def html_input(e)
245
+
246
+ case e.attributes[:type]
247
+ when 'text'
248
+ editbox e
249
+ when 'button'
250
+ buttonx e, :value, :onclick
251
+ end
252
+ end
183
253
 
184
- case e.attributes[:type]
185
- when 'text'
186
- editbox e
187
- when 'button'
188
- buttonx e, :value, :onclick
254
+ def html_p(e)
255
+ e.obj = @shoes.para e.text
256
+ e.elements.each {|x| method(x.name.sub(':','_').to_sym).call(x) }
189
257
  end
190
- end
191
-
192
- def html_p(e)
193
- e.obj = @shoes.para e.text
194
- e.elements.each {|x| method(x.name.sub(':','_').to_sym).call(x) }
195
- end
196
-
197
- def html_span(e)
198
- e.obj = @shoes.span e.text
199
- end
200
-
201
- def html_strong(e)
202
- e.obj = @shoes.strong e.text
203
- end
204
-
205
- alias html_b html_strong
206
-
207
- def image(e)
208
- h = e.attributes
209
- e.obj = @shoes.image h[:src], top: h[:top], left: h[:left]
210
- end
211
-
212
- def label(e)
213
- e.obj = @shoes.para e.attributes[:value]
214
- end
215
-
216
- def listbox(e)
217
- a = e.xpath 'listem/attribute::label'
218
- e.obj = @shoes.list_box items: a
219
- end
220
-
221
- def progressmeter(e)
222
- e.obj = @shoes.progress
223
- end
224
-
225
- def radiogroup(e)
258
+
259
+ def html_span(e)
260
+ e.obj = @shoes.span e.text
261
+ end
262
+
263
+ def html_strong(e)
264
+ e.obj = @shoes.strong e.text
265
+ end
266
+
267
+ alias html_b html_strong
226
268
 
269
+ def image(e)
270
+ h = e.attributes
271
+ e.obj = @shoes.image h[:src], top: h[:top], left: h[:left]
272
+ end
273
+
274
+ def label(e)
275
+ e.obj = @shoes.para e.attributes[:value]
276
+ end
277
+
278
+ def listbox(e)
279
+ a = e.xpath 'listem/attribute::label'
280
+ e.obj = @shoes.list_box items: a
281
+ end
282
+
283
+ def progressmeter(e)
284
+ e.obj = @shoes.progress
285
+ end
227
286
 
228
- e.xpath('radio').each do |x|
287
+ def radiogroup(e)
288
+
229
289
 
230
- def x.value() self.attributes[:value] end
231
- def x.value=(v) self.attributes[:value] = v end
290
+ e.xpath('radio').each do |x|
232
291
 
233
- x.value = x.attributes[:value]
234
- h = x.attributes
235
- @shoes.flow do
236
- r = @shoes.radio :radiogroup01
292
+ def x.value() self.attributes[:value] end
293
+ def x.value=(v) self.attributes[:value] = v end
237
294
 
238
- r.checked = h[:checked] == 'true'
239
- @shoes.para h[:label]
295
+ x.value = x.attributes[:value]
296
+ h = x.attributes
297
+ @shoes.flow do
298
+ r = @shoes.radio :radiogroup01
299
+
300
+ r.checked = h[:checked] == 'true'
301
+ @shoes.para h[:label]
302
+ end
303
+
240
304
  end
241
305
 
242
306
  end
243
307
 
244
- end
245
-
246
- def script(e)
247
- eval e.text.unescape
248
- end
308
+ def script(e)
309
+ eval e.text.unescape
310
+ end
249
311
 
250
- def textbox(e)
251
-
252
- name = if e.attributes[:multiline] and e.attributes[:multiline] == 'true' then
253
- :edit_box
254
- else
255
- :edit_line
312
+ def textbox(e)
313
+
314
+ name = if e.attributes[:multiline] \
315
+ and e.attributes[:multiline] == 'true' then
316
+ :edit_box
317
+ else
318
+ :edit_line
319
+ end
320
+
321
+ editbox e, name
322
+
256
323
  end
257
324
 
258
- editbox e, name
259
-
260
- end
261
-
262
- def vbox(e)
325
+ def vbox(e)
263
326
 
264
- @shoes.stack do
265
- e.elements.each {|x| method(x.name.sub(':','_').to_sym).call(x) }
266
- end
327
+ stack = @shoes.stack do
328
+ e.elements.each {|x| method(x.name.sub(':','_').to_sym).call(x) }
329
+ end
330
+
331
+ e.obj = stack
332
+
267
333
 
334
+ end
335
+
336
+ alias stack vbox
337
+
268
338
  end
269
-
270
- alias stack vbox
271
-
272
339
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file