green_shoes 0.139.0 → 0.150.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.150.0
data/lib/green_shoes.rb CHANGED
@@ -18,6 +18,7 @@ module Shoes
18
18
  LINK_DEFAULT = "<span underline='single' underline_color='#06E' foreground='#06E' weight='normal'>"
19
19
  LINKHOVER_DEFAULT = "<span underline='single' underline_color='#039' foreground='#039' weight='normal'>"
20
20
  ROTATE = [Gdk::Pixbuf::ROTATE_NONE, Gdk::Pixbuf::ROTATE_CLOCKWISE, Gdk::Pixbuf::ROTATE_UPSIDEDOWN, Gdk::Pixbuf::ROTATE_COUNTERCLOCKWISE]
21
+ VERSION = IO.read(File.join(DIR, '../VERSION')).chomp
21
22
  end
22
23
 
23
24
  class Object
data/lib/shoes/app.rb CHANGED
@@ -26,8 +26,19 @@ class Shoes
26
26
  attr_reader :link_style, :linkhover_style, :animates
27
27
 
28
28
  def visit url
29
- $urls.each do |k, v|
30
- clear{init_app_vars; v.call self, $1} if k =~ url
29
+ if url =~ /^(http|https):\/\//
30
+ Thread.new do
31
+ case RUBY_PLATFORM
32
+ when /mingw/; system "start #{url}"
33
+ when /linux/; system("/etc/alternatives/x-www-browser #{url} &")
34
+ else
35
+ puts "Sorry, your platform [#{RUBY_PLATFORM}] is not supported..."
36
+ end
37
+ end
38
+ else
39
+ timer 0.001 do
40
+ $urls.each{|k, v| clear{init_app_vars; v.call self, $1} if k =~ url}
41
+ end
31
42
  end
32
43
  end
33
44
 
@@ -69,7 +80,6 @@ class Shoes
69
80
  def textblock klass, font_size, *msg
70
81
  args = msg.last.class == Hash ? msg.pop : {}
71
82
  args = basic_attributes args
72
- msg = msg.map{|s| s == self ? s.to_s.gsub('<', '[').gsub('>', ']') : s}
73
83
  args[:markup] = msg.map(&:to_s).join
74
84
  attr_list, dummy_text = Pango.parse_markup args[:markup].gsub('\u0026', '@')
75
85
  dummy_attr_list, text = Pango.parse_markup args[:markup]
@@ -89,6 +99,7 @@ class Shoes
89
99
  end
90
100
 
91
101
  if args[:create_real] or !layout_control
102
+ args[:width] = 1 if args[:width] <= 0
92
103
  surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, args[:width], args[:height]
93
104
  context = Cairo::Context.new surface
94
105
  layout = context.create_pango_layout
@@ -524,6 +535,7 @@ class Shoes
524
535
  args = basic_attributes args
525
536
 
526
537
  if args[:create_real] and !args[:height].zero?
538
+ args[:width] = 1 if args[:width] <= 0
527
539
  surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, args[:width], args[:height]
528
540
  context = Cairo::Context.new surface
529
541
  context.rounded_rectangle 0, 0, args[:width], args[:height], args[:curve]
@@ -588,7 +600,11 @@ class Shoes
588
600
  end
589
601
 
590
602
  def scroll_top
591
- @swin.vadjustment.value
603
+ @swin.vscrollbar.value
604
+ end
605
+
606
+ def scroll_top=(n)
607
+ @swin.vscrollbar.value = n
592
608
  end
593
609
  end
594
610
  end
data/lib/shoes/help.rb CHANGED
@@ -6,6 +6,8 @@ class Manual < Shoes
6
6
  font LANG == 'ja' ? 'MS UI Gothic' : 'Arial'
7
7
  style Link, underline: false, weight: 'bold'
8
8
  style LinkHover, stroke: '#06E'
9
+ self.scroll_top = 0
10
+ table_of_contents.each{|toc| TOC << toc} if TOC.empty?
9
11
  manual *get_title_and_desc(pnum.to_i)
10
12
  end
11
13
 
@@ -25,6 +27,7 @@ class Manual < Shoes
25
27
  chapter, section = e
26
28
  title = section ? DOCS[chapter][1][:sections][section][1][:title] : DOCS[chapter][0]
27
29
  title = title.sub('The', '').split(' ').first
30
+ TOC_LIST << [title, section]
28
31
  section ? [' ', link(title){visit "/manual/#{pnum}"}, "\n"] : [link(fg(title, darkgreen)){visit "/manual/#{pnum}"}, "\n"]
29
32
  end.flatten
30
33
  end
@@ -33,7 +36,7 @@ class Manual < Shoes
33
36
  flow do
34
37
  background tr_color("#ddd")..white, angle: 90
35
38
  background black..green, height: 90
36
- para fg("The Green Shoes Manual", gray), left: 120, top: 10
39
+ para fg("The Green Shoes Manual #{VERSION}", gray), left: 120, top: 10
37
40
  title fg(docs_title, white), left: 120, top: 30, font: 'Coolvetica'
38
41
  image File.join(DIR, '../static/gshoes-icon.png'), left: 5, top: -12, width: 110, height: 110, nocontrol: true
39
42
 
@@ -41,7 +44,7 @@ class Manual < Shoes
41
44
 
42
45
  stack{para NL * 4}
43
46
  flow width: 0.2, margin_left: 10 do
44
- para *table_of_contents
47
+ para *TOC
45
48
  end
46
49
 
47
50
  flow width: 0.8, margin: [10, 0, 20, 0] do
@@ -75,7 +78,7 @@ class Manual < Shoes
75
78
  n = lines[1] =~ /\#\!ruby/ ? 2 : 1
76
79
  code = lines[n...-1].join(NL+' ')
77
80
  flow do
78
- background lightsteelblue, curve: 5
81
+ background rgb(190, 190, 190), curve: 5
79
82
  inscription link(fg('Run this', green)){eval mk_executable(code), TOPLEVEL_BINDING}, margin_left: 480
80
83
  para ' ', fg(code, maroon), NL
81
84
  end
@@ -98,9 +101,9 @@ class Manual < Shoes
98
101
  def show_paragraph txt, intro, i, dot = nil
99
102
  txt = txt.gsub("\n", ' ').gsub(/`(.+?)`/m){fg code($1), rgb(255, 30, 0)}.
100
103
  gsub(/\^(.+?)\^/m, '\1').gsub(/'''(.+?)'''/m){strong($1)}.gsub(/''(.+?)''/m){em($1)}.
101
- gsub(/\[\[BR\]\]/i, "\n").gsub(/\[\[(\S+?)\]\]/m){link ins($1.split('.').last)}.
102
- gsub(/\[\[(\S+?) (.+?)\]\]/m){link ins($2)}
103
- case txt
104
+ gsub(/\[\[BR\]\]/i, "\n")
105
+ txts = txt.split(/(\[\[\S+?\]\])/m).map{|s| s.split(/(\[\[\S+? .+?\]\])/m)}.flatten
106
+ case txts[0]
104
107
  when /\A==== (.+) ====/; caption $1, size: 24
105
108
  when /\A=== (.+) ===/; tagline $1, size: 12, weight: 'bold'
106
109
  when /\A== (.+) ==/; subtitle $1
@@ -108,7 +111,7 @@ class Manual < Shoes
108
111
  when /\A\{COLORS\}/; flow{color_page}
109
112
  when /\A\{SAMPLES\}/; flow{sample_page}
110
113
  else
111
- para txt.gsub(IMAGE_RE, ''), NL, (intro and i.zero?) ? {size: 16} : ''
114
+ para *mk_links(txts), NL, (intro and i.zero?) ? {size: 16} : ''
112
115
  txt.gsub IMAGE_RE do
113
116
  image File.join(DIR, "../static/#{$3}"), eval("{#{$2 or "margin_left: 50"}}")
114
117
  para
@@ -116,6 +119,12 @@ class Manual < Shoes
116
119
  end
117
120
  end
118
121
 
122
+ def mk_links txts
123
+ txts.map{|txt| txt.gsub(IMAGE_RE, '')}.
124
+ map{|txt| txt =~ /\[\[(\S+?)\]\]/m ? (t = $1.split('.'); link(ins t.last){visit "/manual/#{find_pnum t.first}"}) : txt}.
125
+ map{|txt| txt =~ /\[\[(\S+?) (.+?)\]\]/m ? (url = $1; link(ins $2){visit url}) : txt}
126
+ end
127
+
119
128
  def mk_paras str
120
129
  str.split("\n\n") - ['']
121
130
  end
@@ -159,6 +168,13 @@ class Manual < Shoes
159
168
  end
160
169
  end
161
170
  end
171
+
172
+ def find_pnum page
173
+ TOC_LIST.each_with_index do |e, i|
174
+ title, section = e
175
+ return i if title == page
176
+ end
177
+ end
162
178
 
163
179
  def self.load_docs path
164
180
  str = IO.read(path).force_encoding("UTF-8")
@@ -194,6 +210,7 @@ class Manual < Shoes
194
210
  DOCS = load_docs File.join(DIR, "../static/manual-#{LANG}.txt")
195
211
  PNUMS = mk_page_numbers DOCS
196
212
  PEND = PNUMS.length
213
+ TOC, TOC_LIST = [], []
197
214
  COLORS = Shoes::App::COLORS
198
215
  end
199
216
 
data/lib/shoes/main.rb CHANGED
@@ -63,7 +63,8 @@ class Shoes
63
63
 
64
64
  app.canvas = projector ? Gtk::DrawingArea.new : Gtk::Layout.new
65
65
  swin = Gtk::ScrolledWindow.new
66
- swin.set_policy Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC
66
+ swin.set_policy Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC
67
+ swin.vadjustment.step_increment = 10
67
68
  swin.add app.canvas
68
69
  win.add swin
69
70
  app.canvas.style = style
data/lib/shoes/ruby.rb CHANGED
@@ -37,6 +37,10 @@ class Object
37
37
  Gtk.main_quit
38
38
  File.delete Shoes::TMP_PNG_FILE if File.exist? Shoes::TMP_PNG_FILE
39
39
  end
40
+
41
+ def to_s
42
+ super.gsub('<', '[').gsub('>', ']')
43
+ end
40
44
  end
41
45
 
42
46
  class String
data/lib/shoes/slot.rb CHANGED
@@ -8,7 +8,7 @@ class Shoes
8
8
  end
9
9
 
10
10
  Slot.class_eval do
11
- attr_accessor *args.keys
11
+ attr_accessor *(args.keys - [:app])
12
12
  end
13
13
 
14
14
  set_margin
@@ -28,6 +28,11 @@ class Shoes
28
28
 
29
29
  attr_accessor :contents, :masked
30
30
  attr_reader :parent, :initials
31
+ attr_writer :app
32
+
33
+ def app &blk
34
+ blk ? @app.instance_eval(&blk) : @app
35
+ end
31
36
 
32
37
  def move3 x, y
33
38
  @left, @top = x, y
@@ -35,6 +40,7 @@ class Shoes
35
40
 
36
41
  def positioning x, y, max
37
42
  @width = (parent.width * @initials[:width]).to_i if @initials[:width].is_a? Float
43
+ @width = (parent.width + @initials[:width]) if @initials[:width] < 0
38
44
  @width -= (margin_left + margin_right)
39
45
  if parent.is_a?(Flow) and x + @width <= parent.left + parent.width
40
46
  move3 x + parent.margin_left, max.top + parent.margin_top
data/samples/sample36.rb CHANGED
@@ -19,10 +19,11 @@ class Book < Shoes
19
19
  link(title){visit "/incidents/#{i}"},
20
20
  " / "
21
21
  end
22
- toc[0...-1] << "\n"*3
22
+ toc[0...-1] << "\n"*5
23
23
  end
24
24
 
25
25
  def incident num
26
+ self.scroll_top = 0
26
27
  num = num.to_i
27
28
  stack margin_left: 190 do
28
29
  banner "Incident"
@@ -34,7 +35,7 @@ class Book < Shoes
34
35
  para *table_of_contents, size: 8
35
36
  end
36
37
 
37
- stack width: 460, margin_left: 10 do
38
+ stack width: -180, margin_left: 10 do
38
39
  INCIDENTS[num][1].split(/\n\n+/).each do |p|
39
40
  para p
40
41
  end
data/static/manual-en.txt CHANGED
@@ -79,14 +79,14 @@ At first, install Ruby. On '''Windows''',
79
79
  visit the site of [[http://rubyinstaller.org/ RubyInstaller for Windows]] to
80
80
  download '''RubyInstaller 1.9.2-p136'''.
81
81
 
82
- Then just do the following.
82
+ Then just do the following one line.
83
83
 
84
- * gem install gtk2 --no-ri --no-rdoc
85
84
  * gem install green_shoes
86
85
 
87
86
  That's all. Too easy?
88
87
 
89
- ''Note: green_shoes gem is now under development.''
88
+ '''Note:''' green_shoes gem is on [[http://rubygems.org/gems/green_shoes RubyGems.org]].
89
+ If you get some errors of rdoc, try to add `--no-ri --no-rdoc` option.
90
90
 
91
91
  ==== Step 2: Start a New Text File ====
92
92
 
@@ -263,17 +263,20 @@ Like let's say you pass around a stack object. And you have a class that edits
263
263
  that object.
264
264
 
265
265
  {{{
266
- # Not yet available
267
266
  class Messenger
268
- def initialize(stack)
269
- @stack = stack
267
+ def initialize slot
268
+ @slot = slot
270
269
  end
271
- def add(msg)
272
- @stack.append do
273
- para msg
274
- end
270
+ def add msg
271
+ para msg rescue puts $!
275
272
  end
276
273
  end
274
+
275
+ Shoes.app do
276
+ slot = stack
277
+ m = Messenger.new slot
278
+ m.add 'hello'
279
+ end
277
280
  }}}
278
281
 
279
282
  So, let's assume you pass the stack object into your Messenger class when the
@@ -284,22 +287,25 @@ Nope, it won't work. The `para` method won't be found. The App object isn't
284
287
  around any more. And it's the one with the `para` method.
285
288
 
286
289
  Fortunately, each Shoes object has an `app` method that will let you reopen the
287
- App object so you can do somefurther editing.
290
+ App object so you can do some further editing.
288
291
 
289
292
  {{{
290
- # Not yet available
291
293
  class Messenger
292
- def initialize(stack)
293
- @stack = stack
294
+ def initialize slot
295
+ @slot = slot
294
296
  end
295
- def add(msg)
296
- @stack.app do
297
- @stack.append do
298
- para msg
299
- end
297
+ def add msg
298
+ @slot.app do
299
+ para msg rescue puts $!
300
300
  end
301
301
  end
302
302
  end
303
+
304
+ Shoes.app do
305
+ slot = stack
306
+ m = Messenger.new slot
307
+ m.add 'hello'
308
+ end
303
309
  }}}
304
310
 
305
311
  As you can imagine, the `app` object changes `self` to the App object.
@@ -318,14 +324,15 @@ stack.'''
318
324
  Fixed widths on slots are great so you can split the window into columns.
319
325
 
320
326
  {{{
321
- # Not yet available
322
327
  Shoes.app do
323
328
  flow do
324
329
  stack :width => 200 do
330
+ background lavender
325
331
  caption "Column one"
326
332
  para "is 200 pixels wide"
327
333
  end
328
334
  stack :width => -200 do
335
+ background bisque
329
336
  caption "Column two"
330
337
  para "is 100% minus 200 pixels wide"
331
338
  end
@@ -346,7 +353,6 @@ On difference between normal slots and nested window slots is that the latter
346
353
  can have scrollbars.
347
354
 
348
355
  {{{
349
- # Not yet available
350
356
  Shoes.app do
351
357
  stack :width => 200, :height => 200, :scroll => true do
352
358
  background "#DFA"
@@ -361,6 +367,20 @@ These nested windows require more memory. They tax the application a bit more.
361
367
  So if you're experiencing some slowness with hundreds of fixed-height slots,
362
368
  try a different approach.
363
369
 
370
+ '''Note''': Fixed height magic (the slot becomes a nested window) is not implemented
371
+ in Green Shoes so far. Scrollbar will appear automatically but at main window only.
372
+
373
+ {{{
374
+ Shoes.app do
375
+ stack :width => 200 do
376
+ background "#DFA"
377
+ 100.times do |i|
378
+ para "Paragraph No. #{i}"
379
+ end
380
+ end
381
+ end
382
+ }}}
383
+
364
384
  ==== Image and Shape Blocks ====
365
385
 
366
386
  Most beginners start littering the window with shapes. It's just easier to
@@ -423,6 +443,9 @@ The point is: it's easy to group shapes together into image or shape blocks, so
423
443
  give it a try if you're looking to gain some speed. Shape blocks particularly
424
444
  will save you some memory and speed.
425
445
 
446
+ '''NOTE''': Green Shoes doesn't support this magic (grouping shapes together
447
+ into image or shape blocks) so far.
448
+
426
449
  ==== UTF-8 Everywhere ====
427
450
 
428
451
  Ruby itself isn't Unicode aware. And UTF-8 is a type of Unicode. (See
@@ -430,11 +453,11 @@ Ruby itself isn't Unicode aware. And UTF-8 is a type of Unicode. (See
430
453
  UTF-8.)
431
454
 
432
455
  However, UTF-8 is common on the web. And lots of different platforms support
433
- it. So to cut down on the amount of conversion that Shoes has to do, Shoes
434
- expects all strings to be in UTF-8 format.
456
+ it. So to cut down on the amount of conversion that Green Shoes has to do,
457
+ Green Shoes expects all strings to be in UTF-8 format.
435
458
 
436
459
  This is great because you can show a myriad of languages (Russian, Japanese,
437
- Spanish, English) using UTF-8 in Shoes. Just be sure that your text editor
460
+ Spanish, English) using UTF-8 in Green Shoes. Just be sure that your text editor
438
461
  uses UTF-8!
439
462
 
440
463
  To illustrate:
@@ -451,8 +474,8 @@ To illustrate:
451
474
  }}}
452
475
 
453
476
  This app will copy anything you paste into the edit box and display it in a
454
- Shoes paragraph. You can try copying some foreign text (such as Greek or
455
- Japanese) into this box to see how it displays.
477
+ Green Shoes paragraph. You can try copying some foreign text (such as
478
+ Greek or Japanese) into this box to see how it displays.
456
479
 
457
480
  This is a good test because it proves that the edit box gives back UTF-8
458
481
  characters. And the paragraph can be set to any UTF-8 characters.
@@ -473,15 +496,15 @@ UI Gothic'''.
473
496
  end
474
497
  }}}
475
498
 
476
- Again, anything which takes a string in Shoes will need a UTF-8 string. Edit
477
- boxes, edit lines, list boxes, window titles and text blocks all take UTF-8. If
478
- you give a string with bad characters in it, an error will show up in the
499
+ Again, anything which takes a string in Green Shoes will need a UTF-8 string.
500
+ Edit boxes, edit lines, list boxes, window titles and text blocks all take UTF-8.
501
+ If you give a string with bad characters in it, an error will show up in the
479
502
  console.
480
503
 
481
504
  ==== The Main App and Its Requires ====
482
505
 
483
- '''NOTE:''' This rule is for Raisins. Policeman uses TOPLEVEL_BINDING. So, you
484
- can get `main`, Ruby top-level object, with the first snippet. Although you
506
+ '''NOTE:''' This rule is for Raisins. Policeman and Green Shoes use TOPLEVEL_BINDING.
507
+ So, you can get `main`, Ruby top-level object, with the first snippet. Although you
485
508
  need to use `Shoes::Para` instead of `Para` outside `Shoes.app` block.
486
509
 
487
510
  Each Shoes app is given a little room where it can create itself. You can
@@ -510,7 +533,7 @@ The second part is especially important to remember.
510
533
 
511
534
  {{{
512
535
  class Storage; end
513
-
536
+
514
537
  Shoes.app do
515
538
  para Storage.new
516
539
  end
@@ -538,7 +561,7 @@ thorough and clear about everything.
538
561
 
539
562
  So, if you've hit this far in the manual and you're still hazy about getting
540
563
  started, you should probably either go back to the [[Hello! beginning]] of the
541
- manual. Or you could try [[https://github.com/downloads/shoes/shoes/nks.pdf Nobody Knows
564
+ manual. Or you could try [[https://cloud.github.com/downloads/shoes/shoes/nks.pdf Nobody Knows
542
565
  Shoes]], the beginner's leaflet PDF.
543
566
 
544
567
  ==== Finding Your Way ====
@@ -598,19 +621,24 @@ slots. See the section on [[Slots]] for more.
598
621
 
599
622
  ==== Built-in Constants ====
600
623
 
601
- Shoes also has a handful of built-in constants which may prove useful if you
602
- are trying to sniff out what release of Shoes is running.
624
+ Green Shoes also has a handful of built-in constants which may prove useful if you
625
+ are trying to sniff out what release of Green Shoes is running.
603
626
 
604
- '''Shoes::RELEASE_NAME''' contains a string with the name of the Shoes release.
605
- All Shoes releases are named, starting with Curious.
627
+ '''DIR''' is a full path of `green_shoes/lib`.
606
628
 
607
- '''Shoes::RELEASE_ID''' contains a number representing the Shoes release. So,
608
- for example, Curious is number 1, as it was the first official release.
629
+ '''COLORS''' is a complete list of colors available to the app.
609
630
 
610
- '''Shoes::REVISION''' is the Subversion revision number for this build.
631
+ '''FONTS''' is a complete list of fonts available to the app.
611
632
 
612
- '''Shoes::FONTS''' is a complete list of fonts available to the app. This list
613
- includes any fonts loaded by the [[Built-in.font]] method.
633
+ {{{
634
+ Shoes.app do
635
+ para VERSION
636
+ para fg(DIR, red)
637
+ image File.join(DIR, '../static/gshoes-icon.png')
638
+ para fg(FONTS.join(', '), green)
639
+ para COLORS.map{|k, v| [k, v]}
640
+ end
641
+ }}}
614
642
 
615
643
  === alert(message: a string) » nil ===
616
644
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 139
7
+ - 150
8
8
  - 0
9
- version: 0.139.0
9
+ version: 0.150.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - ashbb
@@ -14,10 +14,22 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-06 00:00:00 +09:00
17
+ date: 2011-02-10 00:00:00 +09:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: gtk2
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
21
33
  description: Green Shoes is one of colorful Shoes, written in pure Ruby with Ruby/GTK2.
22
34
  email: ashbbb@gmail.com
23
35
  executables: []
@@ -28,6 +40,7 @@ extra_rdoc_files:
28
40
  - LICENSE
29
41
  - README.md
30
42
  files:
43
+ - VERSION
31
44
  - lib/ext/bloops.rb
32
45
  - lib/ext/bloops/bloops.so
33
46
  - lib/ext/bloops/libportaudio-2.dll