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

#initialize(args = {}) ⇒ App

Returns a new instance of App.



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

#animatesObject (readonly)

Returns the value of attribute animates.



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

def animates
  @animates
end

#appObject

Returns the value of attribute app.



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

def app
  @app
end

#backsObject

Returns the value of attribute backs.



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

def backs
  @backs
end

#canvasObject

Returns the value of attribute canvas.



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

def canvas
  @canvas
end

#cmaskObject

Returns the value of attribute cmask.



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

def cmask
  @cmask
end

#contentsObject

Returns the value of attribute contents.



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

def contents
  @contents
end

#cslotObject

Returns the value of attribute cslot.



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

def cslot
  @cslot
end

#dicsObject

Returns the value of attribute dics.



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

def dics
  @dics
end

#focus_eleObject

Returns the value of attribute focus_ele.



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

def focus_ele
  @focus_ele
end

#focusablesObject

Returns the value of attribute focusables.



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

def focusables
  @focusables
end

#frontsObject

Returns the value of attribute fronts.



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

def fronts
  @fronts
end

#height_preObject

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

#linkhover_styleObject (readonly)

Returns the value of attribute linkhover_style.



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

def linkhover_style
  @linkhover_style
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#mccsObject

Returns the value of attribute mccs.



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

def mccs
  @mccs
end

#mcsObject

Returns the value of attribute mcs.



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

def mcs
  @mcs
end

#mhcsObject

Returns the value of attribute mhcs.



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

def mhcs
  @mhcs
end

#mlcsObject

Returns the value of attribute mlcs.



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

def mlcs
  @mlcs
end

#mmcsObject

Returns the value of attribute mmcs.



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

def mmcs
  @mmcs
end

#mouse_button=(value) ⇒ Object (writeonly)

Sets the attribute mouse_button

Parameters:

  • value

    the value to set the attribute mouse_button to.



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

def mouse_button=(value)
  @mouse_button = value
end

#mouse_pos=(value) ⇒ Object (writeonly)

Sets the attribute mouse_pos

Parameters:

  • value

    the value to set the attribute mouse_pos to.



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

def mouse_pos=(value)
  @mouse_pos = value
end

#mrcsObject

Returns the value of attribute mrcs.



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

def mrcs
  @mrcs
end

#orderObject

Returns the value of attribute order.



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

def order
  @order
end

#ownerObject (readonly)

Returns the value of attribute owner.



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

def owner
  @owner
end

#pinning_elementsObject (readonly)

Returns the value of attribute pinning_elements.



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

def pinning_elements
  @pinning_elements
end

#shcsObject

Returns the value of attribute shcs.



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

def shcs
  @shcs
end

#swinObject

Returns the value of attribute swin.



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

def swin
  @swin
end

#textcursorsObject (readonly)

Returns the value of attribute textcursors.



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

def textcursors
  @textcursors
end

#textmarkersObject (readonly)

Returns the value of attribute textmarkers.



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

def textmarkers
  @textmarkers
end

#top_slotObject

Returns the value of attribute top_slot.



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

def top_slot
  @top_slot
end

#width_preObject

Returns the value of attribute width_pre.



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

def width_pre
  @width_pre
end

#winObject

Returns the value of attribute win.



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

def win
  @win
end

Class Method Details

.source_set(context) ⇒ Object



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

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



336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/shoes/app.rb', line 336

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

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



433
434
435
436
# File 'lib/shoes/app.rb', line 433

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

#arrow(*attrs) ⇒ Object



614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/shoes/app.rb', line 614

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

#background(pat, args = {}) ⇒ Object



692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# File 'lib/shoes/app.rb', line 692

def background pat, args={}
  pat = eval(pat) if pat.is_a?(String) and pat[0] != '#' and !((File.extname(pat).downcase) =~ /\.[png|jpg|gif|PNG|JPG|GIF]/)
  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

#basic_attributes(args = {}) ⇒ Object



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

#border(pat, args = {}) ⇒ Object



717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'lib/shoes/app.rb', line 717

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

#button(name, args = {}) ⇒ Object



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

#cap(*line_cap) ⇒ Object



830
831
832
833
834
835
836
837
# File 'lib/shoes/app.rb', line 830

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

#caption(*msg) ⇒ Object



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

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

#check(args = {}) ⇒ Object



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

#clear(&blk) ⇒ Object



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

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

#clipboardObject



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

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

#clipboard=(str) ⇒ Object



801
802
803
# File 'lib/shoes/app.rb', line 801

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

#closeObject



805
806
807
808
# File 'lib/shoes/app.rb', line 805

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

#close_dialogObject



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

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

#code_box(args = {}) ⇒ Object



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

#create_tmp_png(surface) ⇒ Object



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

#define_async_thread_invoker(period = 0.1) ⇒ Object



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

#delete_mouse_events(ele) ⇒ Object



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

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



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

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

#edit_box(*attrs) ⇒ Object



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

def edit_box *attrs
  args = attrs.last.class == Hash ? attrs.pop : {}
  txt = attrs.first unless attrs.empty?
  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 = txt || args[:text].to_s
  tv.modify_font(Pango::FontDescription.new(args[:font])) if args[:font]
  tv.accepts_tab = args[:accepts_tab]
  args.delete :accepts_tab

  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

#edit_line(*attrs) ⇒ Object



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

def edit_line *attrs
  args = attrs.last.class == Hash ? attrs.pop : {}
  txt = attrs.first unless attrs.empty?
  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 = txt || 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

#every(n = 1, &blk) ⇒ Object



350
351
352
# File 'lib/shoes/app.rb', line 350

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

#flow(args = {}, &blk) ⇒ Object



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

#flushObject



815
816
817
# File 'lib/shoes/app.rb', line 815

def flush
  Shoes.call_back_procs self
end

#font(name) ⇒ Object



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

def font name
  @font_family = name
end

#get_queueObject



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

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

#gradient(*attrs) ⇒ Object



652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'lib/shoes/app.rb', line 652

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

#gray(*attrs) ⇒ Object



825
826
827
828
# File 'lib/shoes/app.rb', line 825

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

#gutterObject



793
794
795
# File 'lib/shoes/app.rb', line 793

def gutter
  @swin.vscrollbar.size_request.first
end

#hide_appObject



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

def hide_app
	win.iconify
	win.hide
end

#image(name, args = {}) ⇒ Object



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|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

#imagesize(name) ⇒ Object



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

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

#inscription(*msg) ⇒ Object



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

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

#keypress(&blk) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/shoes/app.rb', line 366

def keypress &blk
  win.signal_handler_disconnect @key_press_handler if @key_press_handler
  win.set_events Gdk::Event::BUTTON_PRESS_MASK | Gdk::Event::BUTTON_RELEASE_MASK | Gdk::Event::POINTER_MOTION_MASK | Gdk::Event::KEY_PRESS_MASK
  @key_press_handler = 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

#line(*attrs) ⇒ Object



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
534
535
536
537
538
539
540
# File 'lib/shoes/app.rb', line 481

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_style}#{str}</span>", arg, &blk
end

#list_box(args = {}) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/shoes/app.rb', line 315

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

#make_pango_attr(markup) ⇒ Object



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

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



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

#make_textcursor_index(tb, x, y) ⇒ Object



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

#make_textcursor_layout(tb) ⇒ Object



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

#make_textcursor_pos(tb, n) ⇒ Object



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

#mask(&blk) ⇒ Object



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

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

#mk_column(vals, parent = nil) ⇒ Object



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

#mk_path(tree, path = []) ⇒ Object



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

#mk_tree(tables) ⇒ Object



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

#motion(&blk) ⇒ Object



362
363
364
# File 'lib/shoes/app.rb', line 362

def motion &blk
  @mmcs << blk
end

#mouseObject



381
382
383
# File 'lib/shoes/app.rb', line 381

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

#nofillObject



648
649
650
# File 'lib/shoes/app.rb', line 648

def nofill
  @fill = false
end

#nolayoutObject



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

def nolayout
  @nolayout = true
end

#nostrokeObject



644
645
646
# File 'lib/shoes/app.rb', line 644

def nostroke
  strokewidth 0
end

#oval(*attrs) ⇒ Object



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
425
426
427
428
429
430
431
# File 'lib/shoes/app.rb', line 385

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

#para(*msg) ⇒ Object



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

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

#pinning(*eles) ⇒ Object



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

def pinning *eles
  eles.each do |ele|
    ele.is_a?(Basic) ? (@pinning_elements << ele) : ele.contents.each{|e| (@pinning_elements << e) if e.is_a? Basic}
  end
  @pinning_elements.uniq!
end

#progress(args = {}) ⇒ Object



743
744
745
746
747
748
749
750
751
752
# File 'lib/shoes/app.rb', line 743

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

#projector(file) ⇒ Object



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

#radio(*attrs) ⇒ Object



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

#rect(*attrs) ⇒ Object



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
473
474
475
476
477
478
479
# File 'lib/shoes/app.rb', line 438

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 sw/2.0+mx, sw/2.0-my, args[:width]-sw, args[:height]-sw, 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

#replace_string_to_float(args = {}) ⇒ Object



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

#resize(new_width, new_height) ⇒ Object

Resize the app window.



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

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

#rgb(r, g, b, l = 1.0) ⇒ Object



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

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

#rotate(angle) ⇒ Object



630
631
632
633
634
# File 'lib/shoes/app.rb', line 630

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

#scroll_topObject



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

def scroll_top
  @swin.vscrollbar.value
end

#scroll_top=(n) ⇒ Object



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

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

#scrolled=(n) ⇒ Object



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

def scrolled=(n)
  @_scroll_top = n
end

#scrolled?Boolean

Returns:

  • (Boolean)


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

def scrolled?
  @_scroll_top ||= 0
  d = scroll_top - @_scroll_top
  @_scroll_top = scroll_top
  d.zero? ? false : d
end

#shape(args = {}, &blk) ⇒ Object



583
584
585
586
587
588
# File 'lib/shoes/app.rb', line 583

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

#shapebase(klass, args) ⇒ Object



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
575
576
577
578
579
580
581
# File 'lib/shoes/app.rb', line 542

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

#show_appObject



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

def show_app()
	win.deiconify	
	win.show 
end

#slot_attributes(args = {}) ⇒ Object



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

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



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], swin: swin)

  app.instance_eval &blk

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

#span(str, args = {}) ⇒ Object



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

#stack(args = {}, &blk) ⇒ Object



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

#star(*attrs) ⇒ Object



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/shoes/app.rb', line 590

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

#style(klass, args = {}) ⇒ Object



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.dup
    @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.dup
    @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

#subtitle(*msg) ⇒ Object



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

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

#syst_add_button(label, &prc) ⇒ Object



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

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

#syst_add_check(label, &prc) ⇒ Object



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

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

#syst_add_sepratatorObject



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

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

#syst_icon(file) ⇒ Object



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

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

#syst_quit_button(yes) ⇒ Object



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

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

#systrayObject



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

#systray_setup(config) ⇒ Object



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

#tagline(*msg) ⇒ Object



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

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

#textblock(klass, font_size, *msg) ⇒ Object



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

#timer(n = 1, &blk) ⇒ Object



354
355
356
357
358
359
360
# File 'lib/shoes/app.rb', line 354

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

#title(*msg) ⇒ Object



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

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

#tr_color(pat) ⇒ Object



682
683
684
685
686
687
688
689
690
# File 'lib/shoes/app.rb', line 682

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

#tree_view(titles, tables) ⇒ Object



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

#video(uri) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# 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.video_sink = Gst::ElementFactory.make('directdrawsink') unless v.video_sink
  v.uri = uri
  args[:real], args[:app] = v, self
  Video.new args
end

#visit(url) ⇒ Object



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

#web_server(port = 9908, config = {}) ⇒ Object



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

#window(args = {}, &blk) ⇒ Object



810
811
812
813
# File 'lib/shoes/app.rb', line 810

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