Class: Shoes::App

Inherits:
Object show all
Includes:
Mod2
Defined in:
lib/shoes/app.rb,
lib/shoes/text.rb,
lib/shoes/style.rb,
lib/plugins/httpd.rb,
lib/plugins/video.rb,
lib/plugins/thread.rb,
lib/plugins/thread.rb,
lib/plugins/systray.rb,
lib/shoes/projector.rb,
lib/plugins/code_box.rb,
lib/plugins/treeview.rb,
lib/shoes/helper_methods.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Mod2

#init_app_vars, #set_rotate_angle

Constructor Details

- (App) initialize(args = {})



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shoes/app.rb', line 5

def initialize args={}
  args.each do |k, v|
    instance_variable_set "@#{k}", v
  end

  win_title = @owner.instance_variable_get('@title')
  class << @owner; self end.
  class_eval do
    define_method :inspect do
      win_title or 'green shoes'
    end
  end if @owner

  App.class_eval do
    attr_accessor *(args.keys - [:width, :height, :title])
  end
  
  init_app_vars
  @canvas, @win, @swin, @top_slot = nil
  @cslot = (@app ||= self)
  @width_pre, @height_pre = @width, @height
  @link_style, @linkhover_style = LINK_DEFAULT, LINKHOVER_DEFAULT
  @context_angle = @pixbuf_rotate = 0
  (Shoes.APPS << self) unless @noapp
end

Instance Attribute Details

- (Object) animates (readonly)

Returns the value of attribute animates



34
35
36
# File 'lib/shoes/app.rb', line 34

def animates
  @animates
end

- (Object) app

Returns the value of attribute app



31
32
33
# File 'lib/shoes/app.rb', line 31

def app
  @app
end

- (Object) backs

Returns the value of attribute backs



31
32
33
# File 'lib/shoes/app.rb', line 31

def backs
  @backs
end

- (Object) canvas

Returns the value of attribute canvas



31
32
33
# File 'lib/shoes/app.rb', line 31

def canvas
  @canvas
end

- (Object) cmask

Returns the value of attribute cmask



31
32
33
# File 'lib/shoes/app.rb', line 31

def cmask
  @cmask
end

- (Object) contents

Returns the value of attribute contents



31
32
33
# File 'lib/shoes/app.rb', line 31

def contents
  @contents
end

- (Object) cslot

Returns the value of attribute cslot



31
32
33
# File 'lib/shoes/app.rb', line 31

def cslot
  @cslot
end

- (Object) dics

Returns the value of attribute dics



31
32
33
# File 'lib/shoes/app.rb', line 31

def dics
  @dics
end

- (Object) focus_ele

Returns the value of attribute focus_ele



31
32
33
# File 'lib/shoes/app.rb', line 31

def focus_ele
  @focus_ele
end

- (Object) focusables

Returns the value of attribute focusables



31
32
33
# File 'lib/shoes/app.rb', line 31

def focusables
  @focusables
end

- (Object) fronts

Returns the value of attribute fronts



31
32
33
# File 'lib/shoes/app.rb', line 31

def fronts
  @fronts
end

- (Object) height_pre

Returns the value of attribute height_pre



31
32
33
# File 'lib/shoes/app.rb', line 31

def height_pre
  @height_pre
end

Returns the value of attribute link_style



34
35
36
# File 'lib/shoes/app.rb', line 34

def link_style
  @link_style
end

- (Object) linkhover_style (readonly)

Returns the value of attribute linkhover_style



34
35
36
# File 'lib/shoes/app.rb', line 34

def linkhover_style
  @linkhover_style
end

- (Object) location (readonly)

Returns the value of attribute location



34
35
36
# File 'lib/shoes/app.rb', line 34

def location
  @location
end

- (Object) mccs

Returns the value of attribute mccs



31
32
33
# File 'lib/shoes/app.rb', line 31

def mccs
  @mccs
end

- (Object) mcs

Returns the value of attribute mcs



31
32
33
# File 'lib/shoes/app.rb', line 31

def mcs
  @mcs
end

- (Object) mhcs

Returns the value of attribute mhcs



31
32
33
# File 'lib/shoes/app.rb', line 31

def mhcs
  @mhcs
end

- (Object) mlcs

Returns the value of attribute mlcs



31
32
33
# File 'lib/shoes/app.rb', line 31

def mlcs
  @mlcs
end

- (Object) mmcs

Returns the value of attribute mmcs



31
32
33
# File 'lib/shoes/app.rb', line 31

def mmcs
  @mmcs
end

- (Object) mouse_button=(value) (writeonly)

Sets the attribute mouse_button



33
34
35
# File 'lib/shoes/app.rb', line 33

def mouse_button=(value)
  @mouse_button = value
end

- (Object) mouse_pos=(value) (writeonly)

Sets the attribute mouse_pos



33
34
35
# File 'lib/shoes/app.rb', line 33

def mouse_pos=(value)
  @mouse_pos = value
end

- (Object) mrcs

Returns the value of attribute mrcs



31
32
33
# File 'lib/shoes/app.rb', line 31

def mrcs
  @mrcs
end

- (Object) order

Returns the value of attribute order



31
32
33
# File 'lib/shoes/app.rb', line 31

def order
  @order
end

- (Object) owner (readonly)

Returns the value of attribute owner



34
35
36
# File 'lib/shoes/app.rb', line 34

def owner
  @owner
end

- (Object) shcs

Returns the value of attribute shcs



31
32
33
# File 'lib/shoes/app.rb', line 31

def shcs
  @shcs
end

- (Object) swin

Returns the value of attribute swin



31
32
33
# File 'lib/shoes/app.rb', line 31

def swin
  @swin
end

- (Object) textcursors (readonly)

Returns the value of attribute textcursors



34
35
36
# File 'lib/shoes/app.rb', line 34

def textcursors
  @textcursors
end

- (Object) textmarkers (readonly)

Returns the value of attribute textmarkers



34
35
36
# File 'lib/shoes/app.rb', line 34

def textmarkers
  @textmarkers
end

- (Object) top_slot

Returns the value of attribute top_slot



31
32
33
# File 'lib/shoes/app.rb', line 31

def top_slot
  @top_slot
end

- (Object) width_pre

Returns the value of attribute width_pre



31
32
33
# File 'lib/shoes/app.rb', line 31

def width_pre
  @width_pre
end

- (Object) win

Returns the value of attribute win



31
32
33
# File 'lib/shoes/app.rb', line 31

def win
  @win
end

Class Method Details

+ (Object) source_set(context)



10
11
12
# File 'lib/shoes/projector.rb', line 10

def (projector.controller.content.texture).source_set(context)
  context.set_source_pixbuf(self)
end

Instance Method Details

- (Object) animate(n = 10, repaint = true, &blk)



330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/shoes/app.rb', line 330

def animate n=10, repaint=true, &blk
  n, i = 1000 / n, 0
  a = Anim.new
  @animates << a
  GLib::Timeout.add n do
    if a.continue? 
      blk[i = a.pause? ? i : i+1]
      Shoes.repaint_all_by_order self if repaint
    end
    a.continue?
  end
  a
end

- (Object) arc(l, t, w, h, a1, a2, args = {})



426
427
428
429
# File 'lib/shoes/app.rb', line 426

def arc l, t, w, h, a1, a2, args={}
  args.merge!({angle1: a1, angle2: a2})
  oval  l, t, w, h, args
end

- (Object) arrow(*attrs)



607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/shoes/app.rb', line 607

def arrow *attrs
  args = attrs.last.class == Hash ? attrs.pop : {}
  w = attrs[2]
  args.merge!({left: attrs[0], top: attrs[1], width: w, height: w})
  shape args do
    move_to 0, w*0.5*0.6
    line_to w*0.58, w*0.5*0.6
    line_to w*0.58, w*0.5*0.2
    line_to w, w*0.5
    line_to w*0.58, w*(1-0.5*0.2)
    line_to w*0.58, w*(1-0.5*0.6)
    line_to 0, w*(1-0.5*0.6)
    line_to 0, w*0.5*0.6
  end
end

- (Object) background(pat, args = {})



685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'lib/shoes/app.rb', line 685

def background pat, args={}
  args[:pattern] = pat
  args = basic_attributes args

  if args[:create_real] and !args[:height].zero?
    args[:width] = 1 if args[:width] <= 0
    surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, args[:width], args[:height]
    context = Cairo::Context.new surface
    context.rounded_rectangle 0, 0, args[:width], args[:height], args[:curve]
    gp = gradient pat, args[:width], args[:height], args[:angle]
    context.set_source gp
    context.fill
    img = create_tmp_png surface
    @canvas.put img, args[:left], args[:top]
    img.show_now
    args[:real] = img
  else
    args[:real] = false
  end

  args[:app] = self
  Background.new args
end


163
# File 'lib/shoes/app.rb', line 163

def banner *msg; textblock Banner, 48, *msg; end

- (Object) basic_attributes(args = {})



64
65
66
67
68
69
# File 'lib/shoes/helper_methods.rb', line 64

def basic_attributes args={}
  default = BASIC_ATTRIBUTES_DEFAULT
  default.merge!({nocontrol: true}) if @nolayout
  replace_string_to_float args
  default.merge args
end

- (Object) border(pat, args = {})



709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
# File 'lib/shoes/app.rb', line 709

def border pat, args={}
  args[:pattern] = pat
  args = basic_attributes args
  sw = args[:strokewidth] = ( args[:strokewidth] or strokewidth or 1 )

  if args[:create_real] and !args[:height].zero?
    surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, args[:width], args[:height]
    context = Cairo::Context.new surface
    gp = gradient pat, args[:width], args[:height], args[:angle]
    context.set_source gp
    context.set_line_width sw
    context.rounded_rectangle sw/2.0, sw/2.0, args[:width]-sw, args[:height]-sw, args[:curve]
    context.stroke
    
    img = create_tmp_png surface
    @canvas.put img, args[:left], args[:top]
    img.show_now
    args[:real] = img
  else
    args[:real] = false
  end

  args[:app] = self
  Border.new args
end

- (Object) button(name, args = {})



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/shoes/app.rb', line 210

def button name, args={}
  args = basic_attributes args
  (click_proc = args[:click]; args.delete :click) if args[:click]
  b = Gtk::Button.new name
  b.set_size_request args[:width], args[:height] if args[:width] > 0 and args[:height] > 0
  @canvas.put b, args[:left], args[:top]
  b.show_now
  args[:real], args[:text], args[:app] = b, name, self
  Button.new(args).tap do |s|
    s.click &click_proc if click_proc
    b.signal_connect "clicked" do
      yield s
    end if block_given?
  end
end

- (Object) cap(*line_cap)



802
803
804
805
806
807
808
809
# File 'lib/shoes/app.rb', line 802

def cap *line_cap
  @line_cap = case line_cap.first
    when :curve, :rect, :project
      LINECAP[line_cap.first]
    else
      @line_cap ||= LINECAP[:rect]
  end
end

- (Object) caption(*msg)



167
# File 'lib/shoes/app.rb', line 167

def caption *msg; textblock Caption, 14, *msg; end

- (Object) check(args = {})



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/shoes/app.rb', line 226

def check args={}
  args = basic_attributes args
  (click_proc = args[:click]; args.delete :click) if args[:click]
  cb = Gtk::CheckButton.new
  cb.active = true if args[:checked]
  @canvas.put cb, args[:left], args[:top]
  cb.show_now
  args[:real], args[:app] = cb, self
  Check.new(args).tap do |s|
    s.click &click_proc if click_proc
    cb.signal_connect "clicked" do
      yield s
    end if block_given?
  end
end

- (Object) clear(&blk)



108
109
110
111
# File 'lib/shoes/app.rb', line 108

def clear &blk
  mcs.each &:clear
  @top_slot.clear &blk
end

- (Object) clipboard



767
768
769
# File 'lib/shoes/app.rb', line 767

def clipboard
  Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD).wait_for_text
end

- (Object) clipboard=(str)



771
772
773
# File 'lib/shoes/app.rb', line 771

def clipboard=(str)
  Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD).text = str
end

- (Object) close



775
776
777
778
779
780
# File 'lib/shoes/app.rb', line 775

def close
  win.destroy
  Gtk.main_quit
  Shoes.APPS.delete app
  exit if Shoes.APPS.empty?
end

- (Object) close_dialog



86
87
88
89
# File 'lib/plugins/systray.rb', line 86

def close_dialog
	win.destroy
	Shoes.APPS.delete app
end

- (Object) code_box(args = {})



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/plugins/code_box.rb', line 3

def code_box args={}
  require 'gtksourceview2'
  args = basic_attributes args

  args[:width]  = 400 if args[:width].zero?
  args[:height] = 300 if args[:height].zero?

  (change_proc = args[:change]; args.delete :change) if args[:change]
  sv = Gtk::SourceView.new
  sv.show_line_numbers = true
  sv.insert_spaces_instead_of_tabs = true
  sv.smart_home_end = Gtk::SourceView::SMART_HOME_END_ALWAYS
  sv.tab_width = 2
  sv.buffer.text = args[:text].to_s
  sv.buffer.language = Gtk::SourceLanguageManager.new.get_language('ruby')
  sv.buffer.highlight_syntax = true
  sv.modify_font(Pango::FontDescription.new(args[:font])) if args[:font]

  cb = Gtk::ScrolledWindow.new
  cb.set_size_request args[:width], args[:height]
  cb.set_policy Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC
  cb.set_shadow_type Gtk::SHADOW_IN
  cb.add sv

  @canvas.put cb, args[:left], args[:top]

  cb.show_all
  args[:real], args[:app], args[:textview] = cb, self, sv
  CodeBox.new(args).tap do |s|
    s.change &change_proc
    sv.buffer.signal_connect "changed" do
      yield s
    end if block_given?
  end
end

- (Object) create_tmp_png(surface)



85
86
87
88
# File 'lib/shoes/helper_methods.rb', line 85

def create_tmp_png surface
  surface.write_to_png TMP_PNG_FILE
  Gtk::Image.new TMP_PNG_FILE
end

- (Object) define_async_thread_invoker(period = 0.1)



17
18
19
20
21
22
23
24
25
# File 'lib/plugins/thread.rb', line 17

def define_async_thread_invoker(period=0.1)
   $__shoes_app__=self
   @queue=Queue.new if ! defined?(@queue)
   every(period) do
      while @queue.size>0
	    instance_eval  &@queue.pop
	  end
   end
end

- (Object) delete_mouse_events(ele)



155
156
157
158
159
# File 'lib/shoes/helper_methods.rb', line 155

def delete_mouse_events ele
  events = [mccs, mrcs, mmcs, mhcs]
  events.pop if ele.is_a? Basic
  events.each{|m| m.delete ele}
end

- (Object) download(name, args = {}, &blk)



746
747
748
# File 'lib/shoes/app.rb', line 746

def download name, args={}, &blk
  Download.new name, args, &blk
end

- (Object) edit_box(args = {})



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/shoes/app.rb', line 282

def edit_box args={}
  args = basic_attributes args
  args[:width] = 200 if args[:width].zero?
  args[:height] = 108 if args[:height].zero?
  (change_proc = args[:change]; args.delete :change) if args[:change]
  tv = Gtk::TextView.new
  tv.wrap_mode = Gtk::TextTag::WRAP_WORD
  tv.buffer.text = args[:text].to_s
  tv.modify_font(Pango::FontDescription.new(args[:font])) if args[:font]

  eb = Gtk::ScrolledWindow.new
  eb.set_size_request args[:width], args[:height]
  eb.set_policy Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC
  eb.set_shadow_type Gtk::SHADOW_IN
  eb.add tv

  @canvas.put eb, args[:left], args[:top]
  eb.show_all
  args[:real], args[:app], args[:textview] = eb, self, tv
  EditBox.new(args).tap do |s|
    s.change &change_proc
    tv.buffer.signal_connect "changed" do
      yield s
    end if block_given?
  end
end

- (Object) edit_line(args = {})



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/shoes/app.rb', line 262

def edit_line args={}
  args = basic_attributes args
  args[:width] = 200 if args[:width].zero?
  args[:height] = 28 if args[:height].zero?
  (change_proc = args[:change]; args.delete :change) if args[:change]
  el = Gtk::Entry.new
  el.visibility = false if args[:secret]
  el.text = args[:text].to_s
  el.set_size_request args[:width], args[:height]
  @canvas.put el, args[:left], args[:top]
  el.show_now
  args[:real], args[:app] = el, self
  EditLine.new(args).tap do |s|
    s.change &change_proc
    el.signal_connect "changed" do
      yield s
    end if block_given?
  end
end

- (Object) every(n = 1, &blk)



344
345
346
# File 'lib/shoes/app.rb', line 344

def every n=1, &blk
  animate 1.0/n, &blk
end

- (Object) flow(args = {}, &blk)



63
64
65
66
67
68
69
70
71
# File 'lib/shoes/app.rb', line 63

def flow args={}, &blk
  if args[:scroll]
    slot_with_scrollbar Flow, args, &blk
  else
    args[:app] = self
    (click_proc = args[:click]; args.delete :click) if args[:click]
    Flow.new(slot_attributes(args), &blk).tap{|s| s.click &click_proc if click_proc}
  end
end

- (Object) flush



787
788
789
# File 'lib/shoes/app.rb', line 787

def flush
  Shoes.call_back_procs self
end

- (Object) font(name)



22
23
24
# File 'lib/shoes/text.rb', line 22

def font name
  @font_family = name
end

- (Object) get_queue



13
14
15
16
# File 'lib/plugins/thread.rb', line 13

def get_queue()
   @queue=Queue.new if ! defined?(@queue)
   @queue
end

- (Object) gradient(*attrs)



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/shoes/app.rb', line 645

def gradient *attrs
  case attrs.length
    when 1, 2
      pat1, pat2 = attrs
      pat2 = pat1 unless pat2
      return tr_color(pat1)..tr_color(pat2)
    when 3, 4
      pat, w, h, angle = attrs
      angle = 0 unless angle
    else
    return black..black
  end

  pat = tr_color pat
  color = case pat
    when Range; [tr_color(pat.first), tr_color(pat.last)]
    when Array; [pat, pat]
    when String
      sp = Cairo::SurfacePattern.new Cairo::ImageSurface.from_png(pat)
      return sp.set_extend(Cairo::Extend::REPEAT)
    else
      [black, black]
  end
  dx, dy = w*angle/180.0, h*angle/180.0
  lp = Cairo::LinearPattern.new w*0.5-dx, dy, w*0.5+dx, h-dy
  lp.add_color_stop_rgba 0, *color[0]
  lp.add_color_stop_rgba 1, *color[1]
  lp
end

- (Object) gray(*attrs)



797
798
799
800
# File 'lib/shoes/app.rb', line 797

def gray *attrs
  g, a = attrs
  g ? rgb(g*255, g*255, g*255, a) : rgb(128, 128, 128)[0..2]
end

- (Object) hide_app



81
82
83
84
# File 'lib/plugins/systray.rb', line 81

def hide_app
	win.iconify
	win.hide
end

- (Object) image(name, args = {})



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/shoes/app.rb', line 171

def image name, args={}
  args = IMAGE_DEFAULT.merge args
  args = basic_attributes args
  args[:full_width] = args[:full_height] = 0
  (click_proc = args[:click]; args.delete :click) if args[:click]
  if name =~ /^(http|https):\/\//
    tmpname = File.join(Dir.tmpdir, "__green_shoes_#{Time.now.to_f}.png")
    d = download name, save: tmpname
    img = Gtk::Image.new File.join(DIR, '../static/downloading.png')
    downloading = true
  elsif name =~ /\.(png|jpg|gif)$/
    img = Gtk::Image.new name
    downloading = false
  else
    require 'rsvg2'
    img = Gtk::Image.new RSVG::Handle.new_from_data(name).pixbuf
    downloading = false
  end

  if (!args[:width].zero? or !args[:height].zero?) and !downloading 
    args[:full_width], args[:full_height] = imagesize(name)
    args[:width] = args[:full_width] if args[:width].zero?
    args[:height] = args[:full_height] if args[:height].zero?
    img = Gtk::Image.new img.pixbuf.scale(args[:width], args[:height])
  end
  @canvas.put img, args[:left], args[:top]
  img.show_now
  @canvas.remove img if args[:hidden]
  args[:real], args[:app], args[:path] = img, self, name
  Image.new(args).tap do |s|
    @dics.push([s, d, tmpname]) if downloading
    s.click &click_proc if click_proc
  end
end

- (Object) imagesize(name)



206
207
208
# File 'lib/shoes/app.rb', line 206

def imagesize name
  Gtk::Image.new(name).size_request
end

- (Object) inscription(*msg)



169
# File 'lib/shoes/app.rb', line 169

def inscription *msg; textblock Para, 10, *msg; end

- (Object) keypress(&blk)



360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/shoes/app.rb', line 360

def keypress &blk
  win.set_events Gdk::Event::BUTTON_PRESS_MASK | Gdk::Event::BUTTON_RELEASE_MASK | Gdk::Event::POINTER_MOTION_MASK | Gdk::Event::KEY_PRESS_MASK
  win.signal_connect("key_press_event") do |w, e|
    k = Gdk::Keyval.to_name e.keyval
    k = case
      when Shoes::KEY_NAMES.include?(k); e.keyval.chr
      when k == 'Return'; "\n"
      when k == 'Tab'; "\t"
	  else k
    end
    blk[k]
  end
end

- (Object) line(*attrs)



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/shoes/app.rb', line 474

def line *attrs
  args = attrs.last.class == Hash ? attrs.pop : {}
  case attrs.length
    when 0, 1, 2
    when 3; args[:sx], args[:sy], args[:ex] = attrs; args[:ey] = args[:ex]
    else args[:sx], args[:sy], args[:ex], args[:ey] = attrs
  end
  sx, sy, ex, ey = args[:sx], args[:sy], args[:ex], args[:ey]
  sw = args[:strokewidth] = ( args[:strokewidth] or strokewidth or 1 )
  cw = hsw = sw*0.5
  args[:width], args[:height] = (sx - ex).abs, (sy - ey).abs
  args[:width] += cw
  args[:height] += cw
  
  args = basic_attributes args
  (click_proc = args[:click]; args.delete :click) if args[:click]
  surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, args[:width]+sw, args[:height]+sw
  context = Cairo::Context.new surface
  
  pat = (args[:stroke] or stroke)
  gp = gradient pat, args[:width], args[:height], args[:angle]
  context.set_source gp
  context.set_line_width args[:strokewidth]
  
  if ((sx - ex) < 0 and (sy - ey) < 0) or ((sx - ex) > 0 and (sy - ey) > 0)
    context.move_to cw+hsw, cw+hsw
    context.line_to args[:width]+hsw, args[:height]+hsw
    args[:left] = (sx - ex) < 0 ? sx - hsw : ex - hsw
    args[:top] = (sy - ey) < 0 ? sy - hsw : ey - hsw
  elsif ((sx - ex) < 0 and (sy - ey) > 0) or ((sx - ex) > 0 and (sy - ey) < 0)
    context.move_to cw+hsw, args[:height]+hsw
    context.line_to args[:width]+hsw, cw+hsw
    args[:left] = (sx - ex) < 0 ? sx - hsw : ex - hsw
    args[:top] = (sy - ey) < 0 ? sy - hsw : ey - hsw
  elsif !(sx - ex).zero? and (sy - ey).zero?
    context.move_to cw, cw+hsw
    context.line_to args[:width], cw+hsw
    args[:left] = (sx - ex) < 0 ? sx : ex
    args[:top] = (sy - ey) < 0 ? sy - hsw : ey - hsw
  elsif (sx - ex).zero? and !(sy - ey).zero?
    context.move_to cw+hsw, cw
    context.line_to cw+hsw, args[:height]
    args[:left] = (sx - ex) < 0 ? sx - hsw : ex - hsw
    args[:top] = (sy - ey) < 0 ? sy : ey
  else
    context.move_to 0, 0
    context.line_to 0, 0
    args[:left] = sw
    args[:top] = sy
  end
  
  context.set_line_cap(LINECAP[args[:cap]] || cap)
  context.stroke
  img = create_tmp_png surface
  @canvas.put img, (args[:left]-=cw), (args[:top]-=cw)
  img.show_now
  @canvas.remove img if args[:hidden]
  args[:real], args[:app] = img, self
  Line.new(args).tap{|s| s.click &click_proc if click_proc}
end


18
19
20
# File 'lib/shoes/text.rb', line 18

def link str, arg = {}, &blk
  Link.new "#{LINK_DEFAULT}#{str}</span>", arg, &blk
end

- (Object) list_box(args = {})



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/shoes/app.rb', line 309

def list_box args={}
  args = basic_attributes args
  args[:width] = 200 if args[:width].zero?
  args[:height] = 28 if args[:height].zero?
  (change_proc = args[:change]; args.delete :change) if args[:change]
  cb = Gtk::ComboBox.new
  args[:items] ||= []
  args[:items].each{|item| cb.append_text item.to_s}
  cb.set_size_request args[:width], args[:height]
  cb.active = args[:items].index(args[:choose]) if args[:choose]
  @canvas.put cb, args[:left], args[:top]
  cb.show_now
  args[:real], args[:app] = cb, self
  ListBox.new(args).tap do |s|
    s.change &change_proc
    cb.signal_connect("changed") do
      yield s
    end if block_given?
  end
end


90
91
92
93
94
95
96
97
98
# File 'lib/shoes/helper_methods.rb', line 90

def make_link_index msg
  start, links = 0, []
  msg.each do |e|
    len = e.to_s.gsub(/<\/.*?>/, '').gsub(/<.*?>/, '').bytesize
    (links << e; e.index = [start, start + len]) if e.is_a? Link
    start += len
  end
  links
end


100
101
102
103
104
105
106
# File 'lib/shoes/helper_methods.rb', line 100

def make_link_pos links, layout, line_height
  links.each do |e|
    e.pos = [layout.index_to_pos(e.index[0]).x / Pango::SCALE, layout.index_to_pos(e.index[0]).y / Pango::SCALE]
    e.pos << (layout.index_to_pos(e.index[1]).x / Pango::SCALE) << (layout.index_to_pos(e.index[1]).y / Pango::SCALE)
    e.pos << line_height
  end
end

- (Object) make_pango_attr(markup)



126
127
128
129
130
131
# File 'lib/shoes/helper_methods.rb', line 126

def make_pango_attr markup
  attr_list, dummy_text = Pango.parse_markup markup.gsub('\u0026', '@')
  dummy_attr_list, text = Pango.parse_markup markup
  text = text.gsub('\u0026', '&')
  return text, attr_list
end

- (Object) make_pango_layout(size, width, height, align, font, justify, leading, wrap, text, attr_list)



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/shoes/helper_methods.rb', line 133

def make_pango_layout size, width, height, align, font, justify, leading, wrap, text, attr_list
  leading ||= 4
  wrap ||= 'word'
  wrap == 'trim' ? (wrap, ellipsize = nil, WRAP[wrap.to_sym]) : (wrap, ellipsize = WRAP[wrap.to_sym], nil)
  surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, width, height
  context = Cairo::Context.new surface
  layout = context.create_pango_layout
  layout.width = width * Pango::SCALE
  layout.wrap = wrap if wrap
  layout.ellipsize = ellipsize if ellipsize
  layout.spacing = leading  * Pango::SCALE
  layout.text = text
  layout.justify = justify
  layout.alignment = eval "Pango::ALIGN_#{align.upcase}"
  fd = Pango::FontDescription.new
  fd.family = font
  fd.size = size * Pango::SCALE
  layout.font_description = fd
  layout.attributes = attr_list
  return layout, context, surface
end

- (Object) make_textcursor_index(tb, x, y)



114
115
116
117
# File 'lib/shoes/helper_methods.rb', line 114

def make_textcursor_index tb, x, y
  layout = make_textcursor_layout tb
  layout.xy_to_index x * Pango::SCALE, y * Pango::SCALE
end

- (Object) make_textcursor_layout(tb)



119
120
121
122
123
124
# File 'lib/shoes/helper_methods.rb', line 119

def make_textcursor_layout tb
  markup, size, width, height, align, font, justify, leading, wrap = 
    %w[@markup @size @width @height @align @font @justify @leading @wrap].map{|v| tb.instance_variable_get v}
  text, attr_list = make_pango_attr markup
  make_pango_layout(size, width, height, align, font, justify, leading, wrap, text, attr_list)[0]
end

- (Object) make_textcursor_pos(tb, n)



108
109
110
111
112
# File 'lib/shoes/helper_methods.rb', line 108

def make_textcursor_pos tb, n
  layout = make_textcursor_layout tb
  n = tb.text.length if n == -1
  return layout.index_to_pos(n).x / Pango::SCALE, layout.index_to_pos(n).y / Pango::SCALE
end

- (Object) mask(&blk)



104
105
106
# File 'lib/shoes/app.rb', line 104

def mask &blk
  Mask.new(self, &blk).tap{|m| @mcs << m}
end

- (Object) mk_column(vals, parent = nil)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/plugins/treeview.rb', line 27

def mk_column vals, parent = nil
  vals.each_with_index do |v, i|
    if v.is_a? Array
      mk_column v, parent
    else
      if i.zero?
        parent = @tree_view_store.append parent
        @tree_view_methods.each_with_index{|e, i| parent[i] = eval("v.#{e}").to_s}
      else
        child = @tree_view_store.append parent
        @tree_view_methods.each_with_index{|e, i| child[i] = eval("v.#{e}").to_s}
      end
    end
  end
end

- (Object) mk_path(tree, path = [])



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/plugins/treeview.rb', line 53

def mk_path tree, path = []
  tree.each_with_index do |t, i|
    if t.is_a? Array
      path.push(path.empty? ? i : (i.zero? ? i : i-1))
      mk_path t, path
      path.pop
    else
      tmp = i.zero? ? path : [path, i-1]
      @tree_view_paths << tmp.flatten.join(':')
    end
  end
end

- (Object) mk_tree(tables)



43
44
45
46
47
48
49
50
51
# File 'lib/plugins/treeview.rb', line 43

def mk_tree tables
  tables.map do |table|
    if table.is_a? Array
      mk_tree table
    else
      return @tree_view_row.new( *tables )
    end
  end
end

- (Object) motion(&blk)



356
357
358
# File 'lib/shoes/app.rb', line 356

def motion &blk
  @mmcs << blk
end

- (Object) mouse



374
375
376
# File 'lib/shoes/app.rb', line 374

def mouse
  [@mouse_button, @mouse_pos[0], @mouse_pos[1]]
end

- (Object) nofill



641
642
643
# File 'lib/shoes/app.rb', line 641

def nofill
  @fill = false
end

- (Object) nolayout



750
751
752
# File 'lib/shoes/app.rb', line 750

def nolayout
  @nolayout = true
end

- (Object) nostroke



637
638
639
# File 'lib/shoes/app.rb', line 637

def nostroke
  strokewidth 0
end

- (Object) oval(*attrs)



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/shoes/app.rb', line 378

def oval *attrs
  args = attrs.last.class == Hash ? attrs.pop : {}
  case attrs.length
    when 0, 1
    when 2; args[:left], args[:top] = attrs
    when 3; args[:left], args[:top], args[:radius] = attrs
    else args[:left], args[:top], args[:width], args[:height] = attrs
  end
  args = basic_attributes args
  (click_proc = args[:click]; args.delete :click) if args[:click]
  args[:width].zero? ? (args[:width] = args[:radius] * 2) : (args[:radius] = args[:width]/2.0)
  args[:height] = args[:width] if args[:height].zero?
  args[:strokewidth] = ( args[:strokewidth] or strokewidth or 1 )
  args[:angle1] ||= 0
  args[:angle2] ||= 2*Math::PI

  w, h, mx, my = set_rotate_angle(args)
  my *= args[:width]/args[:height].to_f
  
  surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, w, h
  context = Cairo::Context.new surface
  context.rotate @context_angle
  context.scale(1,  args[:height]/args[:width].to_f)
  
  if pat = (args[:fill] or fill)
    gp = gradient pat, args[:width], args[:height], args[:angle]
    context.set_source gp
    context.arc args[:radius]+mx, args[:radius]-my, args[:radius], args[:angle1], args[:angle2]
    context.fill
  end
  
  pat = (args[:stroke] or stroke)
  gp = gradient pat, args[:width], args[:height], args[:angle]
  context.set_source gp
  context.set_line_width args[:strokewidth]
  context.arc args[:radius]+mx, args[:radius]-my, args[:radius]-args[:strokewidth]/2.0, args[:angle1], args[:angle2]
  context.set_line_cap(LINECAP[args[:cap]] || cap)
  context.stroke

  img = create_tmp_png surface
  img = Gtk::Image.new img.pixbuf.rotate(ROTATE[@pixbuf_rotate])
  @canvas.put img, args[:left], args[:top]
  img.show_now
  @canvas.remove img if args[:hidden]
  args[:real], args[:app] = img, self
  Oval.new(args).tap{|s| s.click &click_proc if click_proc}
end

- (Object) para(*msg)



168
# File 'lib/shoes/app.rb', line 168

def para *msg; textblock Para, 12, *msg; end

- (Object) progress(args = {})



735
736
737
738
739
740
741
742
743
744
# File 'lib/shoes/app.rb', line 735

def progress args={}
  args = basic_attributes args
  args[:width] = 150 if args[:width] < 150
  pb = Gtk::ProgressBar.new
  pb.text = ' ' * (args[:width] / 4 - 2)
  @canvas.put pb, args[:left], args[:top]
  pb.show_now
  args[:real], args[:app], args[:noorder], args[:nocontrol] = pb, self, true, true
  Progress.new args
end

- (Object) projector(file)



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shoes/projector.rb', line 3

def projector file
  projector = Projector.new
  projector.controller = SwingController.new
  projector.controller.content = TextureMappingData.new
  projector.controller.content.face_list = AkatsukiFace::create
  projector.controller.content.texture = Gdk::Pixbuf.new(file)
  
  def (projector.controller.content.texture).source_set(context)
    context.set_source_pixbuf(self)
  end
  
  @canvas.tap do |drawing_area|
    drawing_area.signal_connect('expose-event') do |widget, event|
      projector.controller.region(widget.allocation)
      projector.update
      projector.draw
      true
    end
    drawing_area.add_events(Gdk::Event::BUTTON_PRESS_MASK)
    drawing_area.signal_connect('button_press_event') do |widget, event|
      projector.controller.press(event)
      true
    end
    drawing_area.add_events(Gdk::Event::POINTER_MOTION_MASK)
    drawing_area.signal_connect('motion_notify_event') do |widget, event|
      projector.controller.motion(event)
      true
    end
    drawing_area.add_events(Gdk::Event::BUTTON_RELEASE_MASK)
    drawing_area.signal_connect('button_release_event') do |widget, event|
      projector.controller.release(event)
      true
    end
  end

  projector.widget = @canvas
  animate{projector.draw}
end

- (Object) radio(*attrs)



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/shoes/app.rb', line 242

def radio *attrs
  args = attrs.last.class == Hash ? attrs.pop : {}
  group = attrs.first unless attrs.empty?
  group = args[:group] if args[:group]
  group = group ? (@radio_groups[group] ||= Gtk::RadioButton.new) : cslot.radio_group
  args = basic_attributes args
  (click_proc = args[:click]; args.delete :click) if args[:click]
  rb = Gtk::RadioButton.new group
  rb.active = true if args[:checked]
  @canvas.put rb, args[:left], args[:top]
  rb.show_now
  args[:real], args[:app] = rb, self
  Radio.new(args).tap do |s|
    s.click &click_proc if click_proc
    rb.signal_connect "clicked" do
      yield s
    end if block_given?
  end
end

- (Object) rect(*attrs)



431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/shoes/app.rb', line 431

def rect *attrs
  args = attrs.last.class == Hash ? attrs.pop : {}
  case attrs.length
    when 0, 1
    when 2; args[:left], args[:top] = attrs
    when 3; args[:left], args[:top], args[:width] = attrs
    else args[:left], args[:top], args[:width], args[:height] = attrs
  end
  args[:height] = args[:width] unless args[:height]
  sw = args[:strokewidth] = ( args[:strokewidth] or strokewidth or 1 )

  w, h, mx, my = set_rotate_angle(args)

  args = basic_attributes args
  (click_proc = args[:click]; args.delete :click) if args[:click]
  surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, w, h
  context = Cairo::Context.new surface

  context.rotate @context_angle
  
  if pat = (args[:fill] or fill)
    gp = gradient pat, args[:width], args[:height], args[:angle]
    context.set_source gp
    context.rounded_rectangle mx, -my, args[:width], args[:height], args[:curve]
    context.fill
  end
  
  pat = (args[:stroke] or stroke)
  gp = gradient pat, args[:width], args[:height], args[:angle]
  context.set_source gp
  context.set_line_width sw
  context.rounded_rectangle sw/2.0+mx, sw/2.0-my, args[:width]-sw, args[:height]-sw, args[:curve]
  context.stroke
  
  img = create_tmp_png surface
  img = Gtk::Image.new img.pixbuf.rotate(ROTATE[@pixbuf_rotate])
  @canvas.put img, args[:left], args[:top]
  img.show_now
  @canvas.remove img if args[:hidden]
  args[:real], args[:app] = img, self
  Rect.new(args).tap{|s| s.click &click_proc if click_proc}
end

- (Object) replace_string_to_float(args = {})



77
78
79
80
81
82
83
# File 'lib/shoes/helper_methods.rb', line 77

def replace_string_to_float args={}
  [:width, :height, :left, :top].each do |k|
    if args[k].is_a? String
      args[k] = args[k].include?('%') ? args[k].to_f / 100 : args[k].to_i
    end
  end
end

- (Object) resize(new_width, new_height)

Resize the app window.



755
756
757
# File 'lib/shoes/app.rb', line 755

def resize new_width, new_height
  win.resize new_width, new_height
end

- (Object) rgb(r, g, b, l = 1.0)



629
630
631
# File 'lib/shoes/app.rb', line 629

def rgb r, g, b, l=1.0
  (r < 1 and g < 1 and b < 1) ? [r, g, b, l] : [r/255.0, g/255.0, b/255.0, l]
end

- (Object) rotate(angle)



623
624
625
626
627
# File 'lib/shoes/app.rb', line 623

def rotate angle
  @pixbuf_rotate, angle = angle.divmod(90)
  @pixbuf_rotate %= 4
  @context_angle = Math::PI * angle / 180
end

- (Object) scroll_top



759
760
761
# File 'lib/shoes/app.rb', line 759

def scroll_top
  @swin.vscrollbar.value
end

- (Object) scroll_top=(n)



763
764
765
# File 'lib/shoes/app.rb', line 763

def scroll_top=(n)
  @swin.vscrollbar.value = n
end

- (Object) shape(args = {}, &blk)



576
577
578
579
580
581
# File 'lib/shoes/app.rb', line 576

def shape args={}, &blk
  args[:left] ||= 0
  args[:top] ||= 0
  args[:block] = blk
  shapebase Shape, args
end

- (Object) shapebase(klass, args)



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/shoes/app.rb', line 535

def shapebase klass, args
  blk = args[:block]
  args[:width] ||= 300
  args[:height] ||= 300

  w, h, mx, my = set_rotate_angle(args)

  args = basic_attributes args
  (click_proc = args[:click]; args.delete :click) if args[:click]
  surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, w, h
  context = Cairo::Context.new surface
  args[:strokewidth] = ( args[:strokewidth] or strokewidth or 1 )
  context.set_line_width args[:strokewidth]
  context.set_line_cap(LINECAP[args[:cap]] || cap)

  context.rotate @context_angle
  
  mk_path = proc do |pat|
    gp = gradient pat, args[:width], args[:height], args[:angle]
    context.set_source gp
    context.move_to 0, 0
    klass == Shoes::Star ? context.instance_eval{blk[self, mx, -my]} : context.instance_eval(&blk)
  end

  if pat = (args[:fill] or fill)
    mk_path.call pat
    context.fill
  end
  
  mk_path.call (args[:stroke] or stroke)
  context.stroke
  
  img = create_tmp_png surface
  img = Gtk::Image.new img.pixbuf.rotate(ROTATE[@pixbuf_rotate])
  @canvas.put img, args[:left], args[:top]
  img.show_now
  @canvas.remove img if args[:hidden]
  args[:real], args[:app] = img, self
  klass.new(args).tap{|s| s.click &click_proc if click_proc}
end

- (Object) show_app



77
78
79
80
# File 'lib/plugins/systray.rb', line 77

def show_app()
	win.deiconify	
	win.show 
end

- (Object) slot_attributes(args = {})



71
72
73
74
75
# File 'lib/shoes/helper_methods.rb', line 71

def slot_attributes args={}
  default = SLOT_ATTRIBUTES_DEFAULT
  replace_string_to_float args
  default.merge args
end

- (Object) slot_with_scrollbar(slot, args = {}, &blk)



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/shoes/app.rb', line 73

def slot_with_scrollbar slot, args={}, &blk
  args[:left] ||= 0
  args[:top] ||= 0
  args[:width] ||= 200
  args[:height] ||= 200

  app = App.new noapp: true
  app.instance_variable_set :@_w, args[:width]
  app.instance_variable_set :@_h, args[:height]
  def app.width; @_w end
  def app.height; @_h end
  app.win = win

  swin = Gtk::ScrolledWindow.new
  swin.set_size_request args[:width], args[:height]
  swin.set_policy Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC
  swin.vadjustment.step_increment = 10

  layout = Gtk::Layout.new
  swin.add layout
  layout.style = @canvas.style

  app.canvas = layout
  app.top_slot = slot.new app.slot_attributes(app: app, left: args[:left], top: args[:top], width: args[:width], height: args[:height])

  app.instance_eval &blk

  @canvas.put swin, args[:left], args[:top]
  app.top_slot
end

- (Object) span(str, args = {})



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shoes/text.rb', line 26

def span str, args={}
  tmp = args.map do |k, v|
    v *= 1000 if v.is_a?(Integer) && k != :weight
    (v = v == 'single' ? 'yes' : 'no') if k == :strikethrough
    k = SPAN_FORM[k] if SPAN_FORM[k]
    if k.to_s.index('_color') and v.is_a?(Array)
      v = v.map{|x| (x * 255).to_i} if v[0].is_a?(Float)
      v = ("#%2s%2s%2s" % v.map{|x| x.to_s 16}).gsub(' ', '0')
    end
    [k, v]
  end
  form = tmp.map{|k, v| "#{k}='#{v}'"}.join(' ')
  "<span #{form}>#{str}</span>"
end

- (Object) stack(args = {}, &blk)



53
54
55
56
57
58
59
60
61
# File 'lib/shoes/app.rb', line 53

def stack args={}, &blk
  if args[:scroll]
    slot_with_scrollbar Stack, args, &blk
  else
    args[:app] = self
    (click_proc = args[:click]; args.delete :click) if args[:click]
    Stack.new(slot_attributes(args), &blk).tap{|s| s.click &click_proc if click_proc}
  end
end

- (Object) star(*attrs)



583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File 'lib/shoes/app.rb', line 583

def star *attrs
  args = attrs.last.class == Hash ? attrs.pop : {}
  case attrs.length
    when 2; args[:left], args[:top] = attrs
    when 5; args[:left], args[:top], args[:points], args[:outer], args[:inner] = attrs
    else
  end
  args[:points] ||= 10; args[:outer] ||= 100.0; args[:inner] ||= 50.0
  args[:width] = args[:height] = args[:outer]*2.0
  x = y = outer = args[:outer]
  points, inner = args[:points], args[:inner]

  args[:block] = proc do |s, mx, my|
    x += mx; y += my
    s.move_to x, y + outer
    (1..points*2).each do |i|
      angle =  i * Math::PI / points
      r = (i % 2 == 0) ? outer : inner
      s.line_to x + r * Math.sin(angle), y + r * Math.cos(angle)
    end
  end
  shapebase Star, args
end

- (Object) style(klass, args = {})



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/shoes/style.rb', line 3

def style klass, args={}
  if klass == Shoes::Link
    @link_style = LINK_DEFAULT
    @link_style.sub!('single', 'none') if args[:underline] == false
    @link_style.sub!("foreground='#06E'", "foreground='#{args[:stroke]}'") if args[:stroke]
    @link_style.sub!('>', " background='#{args[:fill]}'>") if args[:fill]
    @link_style.sub!('normal', "#{args[:weight]}") if args[:weight]
  elsif klass == Shoes::LinkHover
    @linkhover_style = LINKHOVER_DEFAULT
    @linkhover_style.sub!('single', 'none') if args[:underline] == false
    @linkhover_style.sub!("foreground='#039'", "foreground='#{args[:stroke]}'") if args[:stroke]
    @linkhover_style.sub!('>', " background='#{args[:fill]}'>") if args[:fill]
    @linkhover_style.sub!('normal', "#{args[:weight]}") if args[:weight]
  elsif klass.superclass == Shoes::TextBlock or klass == Shoes::Image
    eval("#{klass.to_s[7..-1].upcase}_DEFAULT").clear.merge! args
  end
end

- (Object) subtitle(*msg)



165
# File 'lib/shoes/app.rb', line 165

def subtitle *msg; textblock Subtitle, 26, *msg; end

- (Object) syst_add_button(label, &prc)



70
# File 'lib/plugins/systray.rb', line 70

def syst_add_button(label,&prc)  @systray_config[label]=prc     ; end

- (Object) syst_add_check(label, &prc)



72
# File 'lib/plugins/systray.rb', line 72

def syst_add_check(label,&prc)   @systray_config["+"+label]=prc ; end

- (Object) syst_add_sepratator



71
# File 'lib/plugins/systray.rb', line 71

def syst_add_sepratator()        @systray_config["--#{@systray_config.size}"]= proc {} ; end

- (Object) syst_icon(file)



69
# File 'lib/plugins/systray.rb', line 69

def syst_icon(file)		         @systray_config[:icon]=file     ; end

- (Object) syst_quit_button(yes)



73
# File 'lib/plugins/systray.rb', line 73

def syst_quit_button(yes)       @systray_config[:quit]=yes       ; end

- (Object) systray



64
65
66
67
68
# File 'lib/plugins/systray.rb', line 64

def systray 
    @systray_config={}
	yield
	@systray=::Gtk::SysTray.new(self.win,@owner.instance_variable_get('@title'),@systray_config)
end

- (Object) systray_setup(config)



74
75
76
# File 'lib/plugins/systray.rb', line 74

def systray_setup(config)
	@systray=::Gtk::SysTray.new(self.win,@owner.instance_variable_get('@title'),config)
end

- (Object) tagline(*msg)



166
# File 'lib/shoes/app.rb', line 166

def tagline *msg; textblock Tagline, 18, *msg; end

- (Object) textblock(klass, font_size, *msg)



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/shoes/app.rb', line 113

def textblock klass, font_size, *msg
  args = msg.last.class == Hash ? msg.pop : {}
  args = eval("#{klass.to_s[7..-1].upcase}_DEFAULT").merge args
  args = basic_attributes args
  args[:markup] = msg.map(&:to_s).join
  args[:markup] = fg(args[:markup], tr_color(args[:stroke])) if args[:stroke]
  args[:markup] = bg(args[:markup], tr_color(args[:fill])) if args[:fill]
  form = {}
  args.each{|k, v| form.merge!({k => v}) if SPAN_FORM[k]}
  args[:markup] = span(args[:markup], form) unless form.empty?
  SPAN_FORM.keys.+([:stroke, :fill]).each{|k| args.delete k}
  text, attr_list = make_pango_attr args[:markup]
  args[:size] ||= font_size
  (args[:size] = font_size * FONT_SIZE[args[:size]]) if FONT_SIZE[args[:size]]
  args[:font] ||= (@font_family or 'sans')
  args[:align] ||= 'left'
  line_height =  args[:size] * 2
  
  args[:links] = make_link_index(msg) unless args[:links]

  if !(args[:left].zero? and args[:top].zero?) and (args[:width].zero? or args[:height].zero?)
    args[:nocontrol], args[:add_mlcs], args[:width], args[:height] = true, true, self.width, self.height
    layout_control = false
  else
    layout_control = true
  end
  
  if args[:create_real] or !layout_control
    args[:width] = 1 if args[:width] <= 0
    layout, context, surface = 
      make_pango_layout args[:size], args[:width], args[:height], args[:align], args[:font], args[:justify], args[:leading], args[:wrap], text, attr_list
    context.show_pango_layout layout
    context.show_page
    
    make_link_pos args[:links], layout, line_height
    
    args[:height] = layout.line_count * line_height
    img = create_tmp_png surface
    @canvas.put img, args[:left], args[:top]
    img.show_now
    @canvas.remove img if args[:hidden]
    args[:real], args[:noorder] = img, layout_control
  else
    args[:real] = false
  end
  
  args[:app] = self
  klass.new args
end

- (Object) timer(n = 1, &blk)



348
349
350
351
352
353
354
# File 'lib/shoes/app.rb', line 348

def timer n=1, &blk
  GLib::Timeout.add 1000*n do
    blk.call
    Shoes.repaint_all_by_order self
    false
  end
end

- (Object) title(*msg)



164
# File 'lib/shoes/app.rb', line 164

def title *msg; textblock Title, 34, *msg; end

- (Object) tr_color(pat)



675
676
677
678
679
680
681
682
683
# File 'lib/shoes/app.rb', line 675

def tr_color pat
  if pat.is_a?(String) and pat[0] == '#'
    color = pat[1..-1]
    color = color.gsub(/(.)/){$1 + '0'} if color.length == 3
    rgb *color.gsub(/(..)/).map{$1.hex}
  else
    pat
  end
end

- (Object) tree_view(titles, tables)



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/plugins/treeview.rb', line 3

def tree_view titles, tables
  @tree_view_methods = titles.map{|s| s.downcase.gsub(' ', '_').to_sym}
  @tree_view_row = Struct.new *@tree_view_methods
  tree = mk_tree tables
  @tree_view_paths, @tree_view_rows = [], {}
  mk_path tree
  tmp = tree.flatten
  @tree_view_paths.each_with_index do |path, i|
    @tree_view_rows[path] = tmp[i]
  end
  
  titles.each_with_index do |name, i|
    canvas.append_column Gtk::TreeViewColumn.new(name, Gtk::CellRendererText.new, "text" => i)
  end
  @tree_view_store = Gtk::TreeStore.new *Array.new(@tree_view_methods.length){String}
  
  mk_column tree
  canvas.model = @tree_view_store
  
  canvas.signal_connect("cursor-changed") do |s|
    yield @tree_view_rows[s.cursor[0].to_str]
  end if block_given?
end

- (Object) video(uri)



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/plugins/video.rb', line 101

def video uri
  args = {}
  uri = File.join('file://', uri.gsub("\\", '/').sub(':', '')) unless uri =~ /^(http|https|file):\/\//
  require 'gst'
  require 'win32api'
  v = Gst::ElementFactory.make 'playbin2'
  v.video_sink = Gst::ElementFactory.make('dshowvideosink')
  v.uri = uri
  args[:real], args[:app] = v, self
  Video.new args
end

- (Object) visit(url)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shoes/app.rb', line 36

def visit url
  if url =~ /^(http|https):\/\//
    Thread.new do
      case RUBY_PLATFORM
      when /mingw/; system "start #{url}"
      when /linux/; system("/etc/alternatives/x-www-browser #{url} &")
      else
        puts "Sorry, your platform [#{RUBY_PLATFORM}] is not supported..."
      end
    end
  else
    timer 0.001 do
      $urls.each{|k, v| clear{init_app_vars; @location = url; v.call self, $1} if k =~ url}
    end
  end
end

- (Object) web_server(port = 9908, config = {})



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/plugins/httpd.rb', line 203

def web_server(port=9908,config={}) 
	@ws=WebserverRoot.new(port,"/","green-shoes",10,300, {})
	@html_menu="<div>"+config.map {|label,proc| "<a href='%s'>%s</a>" % [label,label.size>1 ? label[1..-1].capitalize : "Home"] }.join(" ")+"</div>"
	lm=[]
	config.each { |key,proc| 
		case key
			when String
			lm << [key,key.gsub(/\//,"")]
			@ws.serve(key) {
			   [200,".html",@template_proc.call(proc.call(self))]
			}
			when :template
			   @template_proc=proc
			when :menu
			   @html_menu="<div>"+proc.map {|label,href| "[<a href='%s'>%s</a>]" % [href,label] }.join(" ")+"</div>"
			else
			  raise("option web serveur unknown : <#{key}>")
		end
	}
	if ! config[:menu]
		@html_menu="<hr><div>"+lm.map {|href,label| "<a href='%s'>%s</a>" % [href,label.size>1 ? label[1..-1].capitalize : "Home"] }.join(" ")+"</div>"
	end
	if ! config[:template]
		@template_proc= proc {|body| "<html><body><center><h2> #{Time.now}</h2></center>"+@html_menu+"<hr>"+body+"<hr></body></html>"}
	end
	puts "  WebServer ready on http://host:#{port}/"
	@ws
end

- (Object) window(args = {}, &blk)



782
783
784
785
# File 'lib/shoes/app.rb', line 782

def window args={}, &blk
  args.merge! owner: self
  Shoes.app args, &blk
end