Module: Ruiby
- Includes:
- Ruiby_default_dialog, Ruiby_dsl, Ruiby_threader
- Defined in:
- lib/Ruiby.rb,
lib/ruiby_gtk/windows.rb
Overview
can be included by a gtk windows, for use ruiby. do an include, and then call ruiby_component() with bloc for use ruiby dsl
Constant Summary collapse
- DIR =
Pathname.new(__FILE__).realpath.dirname.to_s
- MEDIA =
Pathname.new(__FILE__).realpath.dirname.dirname.to_s+"/media"
- VERSION =
IO.read(File.join(DIR, '../VERSION')).chomp
- GUI =
'gtk'
Constants included from Ruiby_dsl
Class Method Summary collapse
-
.app(config = {}, &blk) ⇒ Object
Direct acces to Ruiby DSL config can contain :title, :width, :height Warning ! bolc is invoked vy instance_eval on window def action() puts “Hello…” end Ruib.app { stack do button(“test”) { action() } end }.
- .apply_provider(widget) ⇒ Object
- .destroy_log ⇒ Object
- .gtk_version(major) ⇒ Object
- .make_doc_api ⇒ Object
- .set_last_log_window(win) ⇒ Object
- .set_style_provider(provider) ⇒ Object
-
.start(&bloc) ⇒ Object
start ruiby.
-
.start_secure(&bloc) ⇒ Object
Start ruiby with a main loop which trap all error : A Exception in a callback will not kill the process.
-
.stock_get(name, default = "") ⇒ Object
read a value associated to a name from persistant storage.
-
.stock_put(name, value) ⇒ Object
persistent stock a value associated to a name dictionary is serialised (Marshalling) to a default file file is /tmp/$0.storage.
-
.stock_reset ⇒ Object
clear persistant strorage.
-
.update ⇒ Object
Update gui while event is pending to be use if current algorithme is long and user want see gui update log long list of message to screen…
Instance Method Summary collapse
-
#ruiby_component ⇒ Object
ruiby_component() must be call one shot for a window, it initialise ruiby.
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
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
Class Method Details
.app(config = {}, &blk) ⇒ Object
Direct acces to Ruiby DSL config can contain :title, :width, :height Warning ! bolc is invoked vy instance_eval on window def action() puts “Hello…” end Ruib.app {
stack do ("test") { action() } end
}
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/Ruiby.rb', line 162 def self.app(config={},&blk) $blk=blk klass = Class.new Ruiby_gtk do def initialize(title,w,h) super threader(10) end end klass.send(:define_method,:component,&blk) klass.send(:chrome,config[:chrome]) if config.has_key?(:chrome) start_secure { w=klass.new(config[:title] || "",config[:width] ||600,config[:height] ||600) w.send(:chrome,config[:chrome]) if config[:chrome] $app=w } end |
.apply_provider(widget) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/Ruiby.rb', line 82 def apply_provider() return unless defined?(@@provider) .style_context.add_provider(@@provider, GLib::MAXUINT) if .is_a?(Gtk::Container) .each_all { |child| Ruiby.apply_provider(child) } elsif .respond_to?(:child) Ruiby.apply_provider(.child) end end |
.destroy_log ⇒ Object
181 182 183 184 185 |
# File 'lib/Ruiby.rb', line 181 def self.destroy_log() return unless @last_log && ! @last_log.destroyed? @last_log.destroy() rescue nil @last_log=nil end |
.gtk_version(major) ⇒ Object
64 65 66 67 68 |
# File 'lib/Ruiby.rb', line 64 def self.gtk_version(major) p "executing Gtk::Version.or_later? ..." Gtk::Version.or_later?(major, 0, 0) p ".or_later done." end |
.make_doc_api ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/Ruiby.rb', line 69 def self.make_doc_api() lfile=Dir.glob(DIR+"/**/*dsl*.rb") ret=lfile.map do |src| File.read(src).split(/\r?\n/).grep(/^\s*def[\s\t]+[^_]/).map {|a| a.strip.gsub(/def\s+/,"").split(')')[0]+")" unless a.index(".") } end ret.flatten.compact.sort end |
.set_last_log_window(win) ⇒ Object
178 179 180 |
# File 'lib/Ruiby.rb', line 178 def self.set_last_log_window(win) @last_log=win end |
.set_style_provider(provider) ⇒ Object
79 80 81 |
# File 'lib/Ruiby.rb', line 79 def set_style_provider(provider) @@provider=provider end |
.start(&bloc) ⇒ Object
start ruiby. Usage: Ruiby.start { Win.new() } One shot :reloading of source can be done, block wjile not be evaluated
Thread.abort_on_exception, BasicSocket.do_not_reverse_lookup, trap(‘INT’) are settings
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/Ruiby.rb', line 128 def self.start(&bloc) return if defined?($__MARKER_IS_RUIBY_INITIALIZED) $__MARKER_IS_RUIBY_INITIALIZED = true $stdout.sync=true $stderr.sync=true Thread.abort_on_exception = true BasicSocket.do_not_reverse_lookup = true if defined?(BasicSocket) trap("INT") { exit(0) } yield secure_main() end |
.start_secure(&bloc) ⇒ Object
Start ruiby with a main loop which trap all error : A Exception in a callback will not kill the process. Gtk Exception are trapped, so process should not exited by ruiby fault!
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/Ruiby.rb', line 143 def self.start_secure(&bloc) return if defined?($__MARKER_IS_RUIBY_INITIALIZED) $__MARKER_IS_RUIBY_INITIALIZED = true $stdout.sync=true $stderr.sync=true Thread.abort_on_exception = true BasicSocket.do_not_reverse_lookup = true if defined?(BasicSocket) trap("INT") { exit(0) } yield secure_main() end |
.stock_get(name, default = "") ⇒ Object
read a value associated to a name from persistant storage
107 108 109 110 111 112 |
# File 'lib/Ruiby.rb', line 107 def self.stock_get(name,default="") db="#{Dir.tmpdir}/#{File.basename($0)}.storage" data={} (File.open(db,"r") { |f| data=Marshal.load(f) } if File.exists?(db) )rescue nil data[name] || default end |
.stock_put(name, value) ⇒ Object
persistent stock a value associated to a name dictionary is serialised (Marshalling) to a default file file is /tmp/$0.storage
99 100 101 102 103 104 105 |
# File 'lib/Ruiby.rb', line 99 def self.stock_put(name,value) db="#{Dir.tmpdir}/#{File.basename($0)}.storage" data={} (File.open(db,"r") { |f| data=Marshal.load(f) } if File.exists?(db)) rescue nil data[name]=value File.open(db,"w") { |f| Marshal.dump(data,f) } end |
.stock_reset ⇒ Object
clear persistant strorage
114 115 116 117 |
# File 'lib/Ruiby.rb', line 114 def self.stock_reset() db="#{Dir.tmpdir}/#{File.basename($0)}.storage" File.delete(db) if File.exists?(db) end |
Instance Method Details
#ruiby_component ⇒ Object
ruiby_component() must be call one shot for a window, it initialise ruiby. then append_to(),append_before()… can be use fore dsl usage
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/ruiby_gtk/windows.rb', line 124 def ruiby_component() init_threader() @lcur=[self] @ltable=[] @current_widget=nil @cur=nil begin yield rescue error("ruiby_component block : "+$!.to_s + " :\n " + $!.backtrace[0..10].join("\n ")) exit! end Ruiby.apply_provider(self) show_all end |