Class: Ruiby_gtk

Inherits:
Gtk::Window
  • Object
show all
Includes:
Ruiby_dsl, Ruiby_threader
Defined in:
lib/ruiby_gtk/windows.rb

Overview

Creative Commons BY-SA : Regis d'Aubarede <[email protected]> LGPL

windows.rb : main ruiby windows

Direct Known Subclasses

Editor, PopupForm, PopupTable

Constant Summary

Constants included from Ruiby_dsl

Ruiby_dsl::GTK2ICONNAME

Instance Method Summary collapse

Methods included from Ruiby_threader

#after, #anim, #init_threader, #on_idle, #threader

Methods included from Ruiby_dsl

#_, #_accept?, #_cbox, #_check_append, #_create_log_window, #_dyn_check_button, #_dyn_entry, #_dyn_fslider, #_dyn_ientry, #_dyn_islider, #_dyn_label, #_dyn_progress, #_dyn_toggle_button, #_exe_posix, #_exe_windows, #_label, #_make_prop_line, #_nocodeeeeeeeeeee, #_pack, #_paned, #_radio_buttons, #_set_accepter, #_sub_image, #aaa_generalities, #accordion, #aitem, #alabel, #append_to, #apply_options, #attribs, #autoslot, #background, #backgroundi, #bourrage, #box, #button, #button_expand, #button_icon_text, #button_left_icon_text, #buttoni, #calendar, #canvas, #canvasOld, #cell, #cell_bottom, #cell_hspan, #cell_hspan_left, #cell_hspan_right, #cell_hvspan, #cell_left, #cell_pass, #cell_right, #cell_span, #cell_top, #cell_vspan, #cell_vspan_bottom, #cell_vspan_top, #center, #check_button, #clear, #clear_append_to, #clickable, #close_dialog, #color_choice, #color_conversion, #combo, #css_name, #current_layout, cv_color_html, #def_style, #delete, #dialog, #dialog_async, #entry, #exe, #fentry, #field, #fields, #flow, #flow_paned, #flowi, #force_update, #frame, #framei, #fslider, #get_config, #get_current_container, #get_icon, #get_image, #get_image_from, #get_pixbuf, #get_pixmap, #get_stockicon_pixbuf, #grid, #haccordion, #hide_app, #hradio_buttons, #html_color, html_color, #htoolbar, #htoolbar_with_icon_text, #ientry, #image, #install_composant, #islider, #label, #label_clickable, #labeli, #left, #levelbar, #list, #log, #log_as_widget, #menu, #menu_bar, #menu_button, #menu_checkbutton, #menu_separator, #next_row, #notebook, #on_canvas_button_motion, #on_canvas_button_press, #on_canvas_button_release, #on_canvas_draw, #on_canvas_key_press, #on_canvas_resize, #on_delete, #page, #panel, #panel_async, #panel_progress, #pclickable, #pclickablie, #plot, #popup, #popup_clear_append, #pp_item, #pp_separator, #progress, #progress_bar, #properties, #propertys, #razslot, #regular, #right, #row, #script, #scrolled, #sentence, #sentenci, #separator, #show_all_children, #show_app, #show_methods, #show_source, #slider, #slot, #slot_append_after, #slot_append_before, #sloti, #snapshot, #source_editor, #space, #spacei, #spacing, #stack, #stack_paned, #stacki, #syst_add_button, #syst_add_check, #syst_add_sepratator, #syst_icon, #syst_quit_button, #systray, #systray_setup, #table, #text_area, #text_area_dyn, #toggle_button, #toolbar_button, #toolbar_separator, #tooltip, #trace, #tree_grid, #update, #var_box, #var_boxi, #vbox_scrolled, #video, #vradio_buttons, #widget_properties, #window

Methods included from Ruiby_default_dialog

#_gooooooooooo, #_process_terminal_key, #alert, #ask, #ask_color, #ask_dir_to_read, #ask_dir_to_write, #ask_file_to_read, #ask_file_to_write, #dialog_chooser, #edit, #error, #message, #prompt, #promptSync, #terminal, #trace

Constructor Details

#initialize(title, w, h) ⇒ Ruiby_gtk

Returns a new instance of Ruiby_gtk.


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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ruiby_gtk/windows.rb', line 10

def initialize(title,w,h)
  super()
  $app=self unless defined?($app)
  init_threader()
  #threader(10) # must be call by user window, if necessary
  set_title(title)
  
  # set default size/position
  set_window_position Gtk::WindowPosition::CENTER  # default, can be modified by window_position(x,y)
  set_default_size(w,h)
  
  # set quit handler    
  signal_connect "destroy" do 
      if @is_main_window
        (EM.stop rescue nil) if defined?(EM) 
        @is_main_window=false
        Gtk.main_quit rescue nil
      end
  end
  # set default icon for application
  iconfn=Ruiby::DIR+"/../media/ruiby.png"
  #set_icon(name:  iconfn) if File.exists?(iconfn)
  
  # set Ctrl-Shift-h handler
  agroup = Gtk::AccelGroup.new
  agroup.connect(Gdk::Keyval::KEY_H, 
    Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::SHIFT_MASK, 
    :visible) do |w| 
    terminal("Debug terminal for #{$0}")
  end
  add_accel_group(agroup)
  
  @lcur=[self]
  @ltable=[]
  @current_widget=nil
  @cur=nil

  begin
    component  
  rescue
    error("COMPONENT() : "+$!.to_s + " :\n     " +  $!.backtrace[0..10].join("\n     "))
    exit(1)
  end
 Ruiby.apply_provider(self)
  begin
    show_all 
  rescue
    puts "Error in show_all : illegal state of some widget? "+ $!.to_s
  end
  if ARGV.any? {|v| v=="take-a-snapshot" }
    after(100) { 
      snapshot("#{Dir.exists?("media") ? "media/" : ""}snapshot_#{File.basename($0)}.png")
      after(100) { exit(0)  } 
    }
  end
end

Instance Method Details

#chrome(on = false) ⇒ Object

show or supress the window system decoration


109
110
111
# File 'lib/ruiby_gtk/windows.rb', line 109

def chrome(on=false)
  set_decorated(on)
end

#componentObject


87
88
89
# File 'lib/ruiby_gtk/windows.rb', line 87

def component
  raise("Abstract: 'def component()' must be overiden in a Ruiby class")
end

#on_destroy(&blk) ⇒ Object

define action when window is closed


72
73
74
# File 'lib/ruiby_gtk/windows.rb', line 72

def on_destroy(&blk) 
      signal_connect("destroy") { blk.call }
end

#on_resize(&blk) ⇒ Object

define a action when window is resized


67
68
69
70
# File 'lib/ruiby_gtk/windows.rb', line 67

def on_resize(&blk)
  self.resizable=true
  signal_connect("configure_event") { blk.call } if blk
end

#rposition(x, y) ⇒ Object

change position of window in the desktop. relative position works only in *nix system.


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ruiby_gtk/windows.rb', line 93

def rposition(x,y)
  if x==0 && y==0
    set_window_position Gtk::WindowPosition::CENTER
    return
  elsif     x>=0 && y>=0
    gravity= Gdk::Gravity::NORTH_WEST
  elsif   x<0 && y>=0
    gravity= Gdk::Gravity::NORTH_EAST
  elsif   x>=0 && y<0
    gravity= Gdk::Gravity::SOUTH_WEST
  elsif   x<0 && y<0
    gravity= Gdk::Gravity::SOUTH_EAST
  end
  move(x.abs,y.abs)
end

#ruiby_exitObject


84
85
86
# File 'lib/ruiby_gtk/windows.rb', line 84

def ruiby_exit()
  Gtk.main_quit 
end

#set_window_icon(filename) ⇒ Object

set taskbar icon for current window filename must have absolute path


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

def set_window_icon(filename)
  if File.exists?(filename)
    self.set_icon_from_file(filename)
  else
    error("set_xindow_icon() : file #{filename} do not exists !!!")
  end
end