Module: Ruiby_dsl
- Includes:
- Gtk, Ruiby_default_dialog
- Included in:
- Ruiby, Ruiby_dialog, Ruiby_gtk
- Defined in:
- lib/ruiby_gtk/systray.rb,
lib/ruiby_gtk/ruiby_dsl.rb,
lib/ruiby_gtk/ruiby_dsl3.rb
Instance Method Summary (collapse)
-
- (Object) _cbox(expand, box, add1)
private: generic packer.
- - (Object) _check_append(name, w, wref)
- - (Object) _create_log_window
- - (Object) _label(text, options = {})
- - (Object) _make_prop_line(prop_current, options, k, v)
-
- (Object) _nocodeeeeeeeeeee
Slot : H/V Box or Frame.
- - (Object) _pack(parent, box, expand)
- - (Object) _paned(horizontal, size, fragment)
- - (Object) _radio_buttons(sens, ltext = ["empty!"], value = -1))
- - (Object) _sub_image(name)
-
- (Object) accordion
create a accordion menu.
-
- (Object) aitem(txt, &blk)
a button menu in accordion.
-
- (Object) alabel(txt, &blk)
create e entry in button associate vue af a accordion menu.
-
- (Object) append_to(cont, &blk)
append the result of bloc parameter to a contener (stack or flow) thread protected Usage : .
-
- (Object) apply_options(w, options)
apply some styles property to an existing widget.
-
- (Object) attribs(w, options)
common widget property applied for (almost) all widget.
-
- (Object) autoslot(w = nil)
slot() precedently created widget if not sloted.
-
- (Object) box
box { } used for container which manage the widget (as stack(false) {} ) use it for cell in table : table { row { cell(box { });… };… }.
-
- (Object) button(text, option = {}, &blk)
create button, with text (or image if txt start with a '#') block argument is evaluate at button click.
-
- (Object) button_expand(text, initiale_state = false, options = {}, &b)
TODO: test!.
-
- (Object) buttoni(text, option = {}, &blk)
create button, with text (or image if txt start with a '#') block argument is evaluate at button click, slotied :.
-
- (Object) calendar(time = Time.now, options = {})
Month Calendar with callback on month/year move and day selection : calendar(Time.now-24*3600, :selection => proc {|day| } , :changed => proc {|widget| } calendar respond to * set_time(time) ; set a selected date from a Time object * get_time() ; return Time of selected day.
-
- (Object) calendar_set_time(cal, time = Time.now)
deprecated : change the current selection of a calendar, by Time object.
-
- (Object) canvas(width, height, option = {})
create a drawing area, for pixel draw option can define closure :mouse_down :mouse_up :mouse_move for interactive actions see tst.rb fo little example see samples/draw.rb for a little vector editor…
-
- (Object) cell(w)
a cell in a row/table.
-
- (Object) cell_bottom(w)
create a cell in a row/table, bottom aligned.
-
- (Object) cell_hspan(n, w)
a cell in a row/table.
-
- (Object) cell_hspan_left(n, w)
create a hspan_cell in a row/table, left justified.
-
- (Object) cell_hspan_right(n, w)
create a hspan_cell in a row/table, right justified.
-
- (Object) cell_hvspan(n, m, w)
a cell in a row/table.
-
- (Object) cell_left(w)
create a cell in a row/table, left justified.
-
- (Object) cell_pass(n = 1)
keep empty n cell consecutive on current row.
-
- (Object) cell_right(w)
create a cell in a row/table, right justified.
-
- (Object) cell_span(n = 2, w)
a cell in a row/table.
-
- (Object) cell_top(w)
create a cell in a row/table, top aligned.
-
- (Object) cell_vspan(n, w)
a cell in a row/table.
-
- (Object) cell_vspan_bottom(n, w)
a cell_vspan aligned on bottom.
-
- (Object) cell_vspan_top(n, w)
a cell_vspan aligned on top.
-
- (Object) center
center { } container which center his content (auto-sloted).
-
- (Object) check_button(text = "", value = false, option = {})
create a checked button no callback state can be read by cb.active?.
-
- (Object) clear(cont)
clear a containet (stack or flow) thread protected.
-
- (Object) clear_append_to(cont, &blk)
clear a container (stack or flow) and append the result of bloc parameter to this container thread protected.
-
- (Object) clickable(method_name, &b)
specific to gtk : some widget like label can't support click event, so they must be contained in a clickable parent (EventBox).
- - (Object) close_dialog
-
- (Object) color_choice(text = nil, options = {}, &cb)
create a button wich will show a dialog for color choice if bloc is given, it with be call on each change, with new color value as parameter.
- - (Object) color_conversion(color)
-
- (Object) combo(choices, default = -1,, option = {})
combo box, decribe with a Hash choice-text => value-of-choice.
-
- (Object) def_style(string_style = nil)
define style !! Warning: specific to gtk see ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ARC %GTK_BASEPATH%/share/themes/Metal/gtk-2.0/gtkrc.
-
- (Object) def_style3(string_style = nil)
not ready!!!.
-
- (Object) delete(w)
delete a widget or a timer thread protected.
-
- (Object) dialog(title = "")
dialog_sync(“title”) {
flow { button("dd") ... }} Dialog contents is build with bloc parameter.
-
- (Object) dialog_async(title, config = {}, &b)
dialog_async(“title”,:response=> bloc {|dia,e| }) {
flow { button("dd") ... }} Dialog content is build with bloc parameter.
-
- (Object) entry(value, size = 10, option = {}, &blk)
create a text entry for keyboard input if block defined, it while be trigger on eech of (character) change of the entry.
-
- (Object) fentry(value, option = {}, &blk)
create a integer text entry for keyboed input option must define :min :max :by for spin button.
- - (Object) field(tlabel, width, value, option = {}, &blk)
- - (Object) fields(alabel, option = {}, &blk)
-
- (Object) flow(add1 = true, &b)
container : horizontal box, take all space available, sloted in parent by default.
-
- (Object) flow_paned(size, fragment, &blk)
split current frame in 2 panes create a container which can containe 2 widgets, separated by movable bar block invoked must return a array of 2 box wich will put in the 2 panes horizonaly disposed.
-
- (Object) flowi(add1 = true, &b)
container : horizontal box, take only necessary space , sloted in parent.
-
- (Object) force_update(canvas)
update a canvas.
-
- (Object) frame(t = "", add1 = true, &b)
a box with border and texte title, take all space.
-
- (Object) framei(t = "", add1 = true, &b)
a box with border and texte title, take only necessary space.
-
- (Object) get_config(w)
get a Hash aff all properties of a gtk widget.
- - (Object) get_current_container
-
- (Object) get_icon(name)
raster images access #############################.
-
- (Object) get_image_from(name)
get a Image widget from a file or from a Gtk::Stock image can be a filename or a predefined icon in GTK::Stock for file image, whe can specify a sub image (sqared) :.
- - (Object) get_pixbuf(name)
-
- (Object) get_stockicon_pixbuf(name)
Image#initialize(:label => nil, :mnemonic => nil, :stock => nil, :size => nil)'.
-
- (Object) grid(names, w = 0, h = 0)
create a grid of data (as list, but multicolumn) use set_data() to put a 2 dimensions array of text same methods as list widget all columnes are String type.
-
- (Object) haccordion
create a hoizontral accordion menu.
- - (Object) hide_app
-
- (Object) hradio_buttons(ltext = ["empty!"], value = -1))
as vradio_buttons , but horizontaly disposed.
-
- (Object) htoolbar(items, options = {})
horizontal toolbar of icon button and/or separator if icon name contain a '/', second last is tooltip text Usage: .
-
- (Object) ientry(value, option = {}, &blk)
create a integer text entry for keyboed input option must define :min :max :by for spin button.
-
- (Object) image(file, options = {})
create a icon with a raster file option can specify a new size : :width and :height, or :size (square image).
-
- (Object) islider(value, option = {}, &b)
create a slider option must define :min :max :by for spin button current value can be read by w.value if bloc is given, it with be call on each change, with new value as parameter.
-
- (Object) label(text, options = {})
create label, with text (or image if txt start with a '#').
- - (Object) labeli(text, options = {})
-
- (Object) list(title, w = 0, h = 0)
create a verticale liste of data, with scrollbar if necessary define methods:
-
list() : get (gtk)list widget embeded
-
model() : get (gtk) model of the list widget
-
clear() clear content of the list
-
set_data(array) : clear and put new data in the list
-
selected() : get the selected item (or nil)
-
index() : get the index of selected item (or nil).
-
-
- (Object) log(*txt)
put a line of message text in log dialog (create and show the log dialog if not exist).
-
- (Object) menu(text)
a vertial drop-down menu, only for menu_bar container.
-
- (Object) menu_bar
create a application menu.
-
- (Object) menu_button(text = "?", &blk)
create an text entry in a menu.
-
- (Object) menu_checkbutton(text = "?", state = false, &blk)
create an checkbox entry in a menu.
- - (Object) menu_separator
-
- (Object) notebook
create a notebook widget.
-
- (Object) page(title, icon = nil)
a page widget.
-
- (Object) pclickable(aproc, &b)
clickable with callback by closure : pclicakble(proc { alert(“e”) }) { alabel(“click me!”) }.
-
- (Object) popup(w = nil)
Popup create a dynamic popup.
-
- (Object) pp_item(text, &blk)
a button in a popup.
-
- (Object) pp_separator
a bar separator in a popup.
-
- (Object) properties(title, hash, options = {:edit=>false, :scroll=>[0,0]})
create a property shower/editor : vertical liste of label/entry representing the ruby Hash content Edition: Option: use :edit => true for show value in text entry, and a validate button, on button action, yield of bloc parameter is done with modified Hash as argument widget define set_data()methods for changing current value.
-
- (Object) propertys(title, hash, options = {:edit=>false, :scroll=>[0,0]}, &b)
deprecated: see properties.
-
- (Object) razslot
forget precedent wdget oconstructed.
-
- (Object) row
create a row.
-
- (Object) scrolled(width, height, &b)
create a Scrolled widget with a autobuild stack in it stack can be populated respond to : scrooo_to_top; scroll_to_bottom,.
-
- (Object) separator(width = 1.0)
create a bar (vertical or horizontal according to stack/flow current container).
- - (Object) show_all_children(c)
- - (Object) show_app
-
- (Object) show_methods(obj = nil, filter = nil)
show methods of a object/class in log window.
-
- (Object) slot(w)
pack widget in parameter, share space with prother widget this is the default: all widget will be sloted if they are not slotied this is done by attribs(w) which is call after construction of almost all widget.
-
- (Object) slot_append_after(w, wref)
append the widget w after anotherone wref) thread protected.
-
- (Object) slot_append_before(w, wref)
append the widget w before another one wref thread protected.
-
- (Object) sloti(w)
pack widget in parameter, take only necessary space.
-
- (Object) source_editor(args = {})
a source_editor widget : text as showed in fixed font, colorized (default: ruby syntaxe) from: green shoes plugin options= :width :height :on_change :lang :font @edit=source_editor().editor @edit.buffer.text=File.read(@filename).
-
- (Object) space(n = 1)
create a one-character size space, (or n character x n line space).
-
- (Object) stack(add1 = true, &b)
container : vertical box, take all space available, sloted in parent by default.
-
- (Object) stack_paned(size, fragment, &blk)
Panned : split current frame in 2 panes create a container which can containe 2 widgets, separated by movable bar block invoked must return a array of 2 box wich will put in the 2 panes vertivaly disposed.
-
- (Object) stacki(add1 = true, &b)
container : vertical box, take only necessary space , sloted in parent.
- - (Object) syst_add_button(label, &prc)
- - (Object) syst_add_check(label, &prc)
- - (Object) syst_add_sepratator
- - (Object) syst_icon(file)
- - (Object) syst_quit_button(yes)
- - (Object) systray(x = nil, y = nil)
- - (Object) systray_setup(config)
-
- (Object) table(nb_col, nb_row, config = {})
table create a container for table-disposed widgets.
-
- (Object) text_area(w = 200, h = 100, args = {})
multiline entry w=text_area(min_width,min_height,options) .
-
- (Object) toggle_button(text1, text2 = nil, value = false, option = {}, &blk)
to state button, with text for each state and a initiale value value can be read by w.active? callback on state change with new value as argument.
-
- (Object) tree_grid(names, w = 0, h = 0, options = {})
create a tree view of data (as grid, but first column is a tree) use set_data() to put a Hash of data same methods as grid widget a columns Class are distinges by column name :.
-
- (Object) var_box(sens, add1 = true, &b)
container : vertical or horizontal box (stack/flow, choice by first argument), sloted in parent by default.
-
- (Object) var_boxi(sens, add1 = true, &b)
container : vertical or horizontal box (stacki/flowi, choice by first argument), sloted in parent by default.
- - (Object) vbox_scrolled(width, height, &b)
-
- (Object) video(uri, w = 300, h = 200)
Video from: green shoes plugin ** not tested! **.
-
- (Object) vradio_buttons(ltext = ["empty!"], value = -1))
create a liste of radio button, vertically disposed value is the indice of active item (0..(n-1)) at creation time define 2 methods:
-
get_selected # get indice of active radio-button
-
set_selected(indice) # set indice of active radio-button.
-
- - (Object) widget_properties(title = nil, w = nil)
Methods included from Ruiby_default_dialog
#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, #trace
Instance Method Details
- (Object) _cbox(expand, box, add1)
private: generic packer
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 70 def _cbox(,box,add1) autoslot() if add1 ? @lcur.last.add(box) : @lcur.last.pack_start(box,false,false,3) end @lcur << box yield autoslot() @lcur.pop end |
- (Object) _check_append(name, w, wref)
194 195 196 197 198 199 200 201 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 194 def _check_append(name,w,wref) raise("#{name}(w,r) : Widget ref not created!") unless wref raise("#{name}(w,r) : new Widget not created!") unless w parent=wref.parent raise("#{name}(w,r): r=#{parent.inspect} is not a XBox or Frame !") unless !parent || parent.kind_of?(Container) raise("#{name}(w,r): r=#{parent.inspect} is not a XBox or Frame !") unless parent.respond_to?(:reorder_child) parent end |
- (Object) _create_log_window
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1334 def _create_log_window() return(@loglabel) if defined?(@loglabel) && @loglabel && ! @loglabel.destroyed? wdlog = Dialog.new("Logs : #{$0}", nil, 0, [ Stock::OK, Dialog::RESPONSE_NONE ]) Ruiby.set_last_log_window(wdlog) logBuffer = TextBuffer.new @loglabel=TextView.new(logBuffer) sw=ScrolledWindow.new() sw.set_width_request(800) sw.set_height_request(200) sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS) sw.(@loglabel) wdlog.vbox.add(sw) wdlog.signal_connect('response') { wdlog.destroy } wdlog.show_all @loglabel end |
- (Object) _label(text, options = {})
306 307 308 309 310 311 312 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 306 def _label(text,={}) l=if text && text[0,1]=="#" get_image_from(text[1..-1]); else Label.new(text); end end |
- (Object) _make_prop_line(prop_current, options, k, v)
657 658 659 660 661 662 663 664 665 666 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 657 def _make_prop_line(prop_current,,k,v) if k.to_s =~/^sep\d+$/ cell_span(2,HSeparator.new) else cell_right(label(" "+k.to_s+" : ")) cell_left([:edit] ? (prop_current[k]=entry(v.to_s)) : label(v.to_s)) end end |
- (Object) _nocodeeeeeeeeeee
Slot : H/V Box or Frame
27 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 27 def _nocodeeeeeeeeeee() end |
- (Object) _pack(parent, box, expand)
86 87 88 89 90 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 86 def _pack(parent,box,) parent.respond_to?(:pack_start) ? parent.pack_start(box, :expand => , :fill => true): parent.add(box) end |
- (Object) _paned(horizontal, size, fragment)
890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 890 def _paned(vertical,size,fragment) paned = vertical ? HPaned.new : VPaned.new slot(paned) @lcur << paned frame1,frame2=*yield() @lcur.pop (frame1.shadow_type = Gtk::SHADOW_IN) rescue nil (frame2.shadow_type = Gtk::SHADOW_IN) rescue nil paned.position=size*fragment vertical ? paned.set_size_request(size, -1) : paned.set_size_request(-1,size) paned.pack1(frame1, true, false) paned.pack2(frame2, false, false) show_all_children(paned) end |
- (Object) _radio_buttons(sens, ltext = ["empty!"], value = -1))
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 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 478 def (sens,ltext=["empty!"],value=-1) b0=nil s=var_box(sens,false) { ltext.each_with_index {|t,i| b=if i==0 b0=slot(RadioButton.new(t)) else slot(RadioButton.new(b0,t)) end if i==value b.toggled b.set_active(true) end } } # TODO: test! class << s ; def get_selected() b0.group.each_with_index.map { |w,index| return(index) if w.active? } end ; def set_selected(indice) b0.group.each_with_index.map { |w,index| w.active=true if indice==index } end end s end |
- (Object) _sub_image(name)
245 246 247 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 245 def _sub_image(name) Image.new(get_pixbuf(name)) end |
- (Object) accordion
create a accordion menu. must contain aitem() which must containe alabel() : accordion { aitem(txt) { alabel(lib) { code }; …} … }
841 842 843 844 845 846 847 848 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 841 def accordion() @slot_accordion_active=nil #only one accordion active by window! w=stack { stacki { yield }} separator w end |
- (Object) aitem(txt, &blk)
a button menu in accordion
859 860 861 862 863 864 865 866 867 868 869 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 859 def aitem(txt,&blk) b2=nil b=(txt) { clear_append_to(@slot_accordion_active) {} if @slot_accordion_active @slot_accordion_active=b2 clear_append_to(b2) { blk.call() } } b2=stacki { } end |
- (Object) alabel(txt, &blk)
create e entry in button associate vue af a accordion menu
872 873 874 875 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 872 def alabel(txt,&blk) l=nil pclickable(proc { blk.call(l) if blk} ) { l=label(txt) } end |
- (Object) append_to(cont, &blk)
append the result of bloc parameter to a contener (stack or flow) thread protected Usage :
@stack= stack {}
. . . .
append_to(@stack) { button("Hello") }
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 104 def append_to(cont,&blk) if $__mainthread__ != Thread.current gui_invoke { append_to(cont,&blk) } return end @lcur << cont yield autoslot() @lcur.pop show_all_children(cont) end |
- (Object) apply_options(w, options)
apply some styles property to an existing widget. options are :size, :width; :height, :bg, :fg, :font apply_options(w,:size=> [10,10], :width=>100;:heigh=>200,:bg=>'#FF00AA“,:fg=> Gdk::Color:RED,:font=> ”Tahoma bold 32“)
292 293 294 295 296 297 298 299 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 292 def (w,) w.set_size_request(*[:size]) if [:size] w.width_request=([:width].to_i) if [:width] w.height_request=([:height].to_i) if [:height] w.override_background_color(:normal,color_conversion([:bg])) if [:bg] w.override_color(:normal,color_conversion([:fg])) if [:fg] w.override_font(Pango::FontDescription.new([:font])) if [:font] end |
- (Object) attribs(w, options)
common widget property applied for (almost) all widget. options are last argument of every dsl command, see apply_options
271 272 273 274 275 276 277 278 279 280 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 271 def attribs(w,) w.set_size_request(*[:size]) if [:size] w.width_request=([:width]) if [:width] w.height_request=([:height]) if [:height] w.modify_bg(Gtk::STATE_NORMAL,color_conversion([:bg])) if [:bg] # not work on window w.modify_fg(Gtk::STATE_NORMAL,color_conversion([:fg])) if [:fg] # not work on window w.modify_font(Pango::FontDescription.new([:font])) if [:font] autoslot(w) # slot() precedent widget if existe and not already sloted, and declare this one as the precedent w end |
- (Object) autoslot(w = nil)
slot() precedently created widget if not sloted. this is done by attribs(w) which is call after construction of almost all widget
91 92 93 94 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 91 def autoslot(w=nil) (slot(@current_widget)) if @current_widget!=nil @current_widget=w end |
- (Object) box
box { } used for container which manage the widget (as stack(false) {} ) use it for cell in table : table { row { cell(box { });… };… }
40 41 42 43 44 45 46 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 40 def box() box=VBox.new(false, 2) @lcur << box yield autoslot() @lcur.pop end |
- (Object) button(text, option = {}, &blk)
create button, with text (or image if txt start with a '#') block argument is evaluate at button click
333 334 335 336 337 338 339 340 341 342 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 333 def (text,option={},&blk) if text && text[0,1]=="#" b=Button.new() b.set_image(get_image_from(text[1..-1])) else b=Button.new(text); end b.signal_connect("clicked") { |e| blk.call(e) rescue error($!) } if blk attribs(b,option) end |
- (Object) button_expand(text, initiale_state = false, options = {}, &b)
TODO: test!
1260 1261 1262 1263 1264 1265 1266 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1260 def (text,initiale_state=false,={},&b) = Gtk::Expander.new(text) . = initiale_state frame=box(&b) .add(frame) attribs(,) end |
- (Object) buttoni(text, option = {}, &blk)
create button, with text (or image if txt start with a '#') block argument is evaluate at button click, slotied :
packed without expand for share free place
347 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 347 def (text,option={},&blk) sloti((text,option,&blk)) end |
- (Object) calendar(time = Time.now, options = {})
Month Calendar with callback on month/year move and day selection : calendar(Time.now-24*3600, :selection => proc {|day| } , :changed => proc {|widget| } calendar respond to * set_time(time) ; set a selected date from a Time object * get_time() ; return Time of selected day
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 978 def calendar(time=Time.now,={}) c = Calendar.new #c.display_options(Calendar::SHOW_HEADING | Calendar::SHOW_DAY_NAMES | # Calendar::SHOW_WEEK_NUMBERS ) after(1) { c.signal_connect("day-selected") { |w,e| [:selection].call(w.day) rescue error($!) } } if [:selection] after(1) { c.signal_connect("month-changed") { |w,e| [:changed].call(w) rescue error($!) } }if [:changed] calendar_set_time(c,time) class << c def set_time(time) select_month(time.month,time.year) select_day(time.day) end def get_time() year, month, day= *date() Time.local(year, month, day) end end attribs(c,) end |
- (Object) calendar_set_time(cal, time = Time.now)
deprecated : change the current selection of a calendar, by Time object
1000 1001 1002 1003 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1000 def calendar_set_time(cal,time=Time.now) cal.select_month(time.month,time.year) cal.select_day(time.day) end |
- (Object) canvas(width, height, option = {})
create a drawing area, for pixel draw option can define closure :mouse_down :mouse_up :mouse_move for interactive actions see tst.rb fo little example see samples/draw.rb for a little vector editor…
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 563 def canvas(width,height,option={}) autoslot() w=DrawingArea.new() w.set_size_request(width,height) w.events |= ( ::Gdk::Event::BUTTON_PRESS_MASK | ::Gdk::Event::POINTER_MOTION_MASK | ::Gdk::Event::BUTTON_RELEASE_MASK) w.signal_connect( 'expose-event' ) { |w1,e| cr = w1.window.create_cairo_context cr.save { cr.set_line_join(Cairo::LINE_JOIN_ROUND) cr.set_line_cap(Cairo::LINE_CAP_ROUND) cr.set_line_width(2) cr.set_source_rgba(1,1,1,1) cr.paint if option[:expose] begin option[:expose].call(w1,cr) rescue Exception => e bloc=option[:expose] option.delete(:expose) after(1) { error(e) } after(3000) { puts "reset expose bloc" ;option[:expose] = bloc } end end } } @do=nil w.signal_connect('button_press_event') { |wi,e| @do = option[:mouse_down].call(wi,e) rescue error($!) ; force_update(wi) } if option[:mouse_down] w.signal_connect('button_release_event') { |wi,e| (option[:mouse_up].call(wi,e,@do) rescue error($!)) if @do ; @do=nil ; force_update(wi) if @do } if option[:mouse_up] w.signal_connect('motion_notify_event') { |wi,e| (@do = option[:mouse_move].call(wi,e,@do) rescue error($!)) if @do ; force_update(wi) if @do } if option[:mouse_move] w.signal_connect('key_press_event') { |wi,e| (option[:key_press].call(wi,e) rescue error($!)) ; force_update(wi) } if option[:key_press] attribs(w,option) def w.redraw() self.queue_draw_area(0,0,1000,1000) end w end |
- (Object) cell(w)
a cell in a row/table. take all space, centered
625 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 625 def cell(w) cell_hspan(1,w) end |
- (Object) cell_bottom(w)
create a cell in a row/table, bottom aligned
648 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 648 def cell_bottom(w) razslot();w.set_alignment(0.5, 1.0)rescue nil ; cell(w) end |
- (Object) cell_hspan(n, w)
a cell in a row/table. take space of n cells, horizontaly
627 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 627 def cell_hspan(n,w) razslot();@lcur.last.attach(w,@ltable.last[:col],@ltable.last[:col]+n,@ltable.last[:row],@ltable.last[:row]+1) ; @ltable.last[:col]+=n end |
- (Object) cell_hspan_left(n, w)
create a hspan_cell in a row/table, left justified
641 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 641 def cell_hspan_left(n,w) razslot();w.set_alignment(0.0, 0.5)rescue nil ; cell_hspan(n,w) end |
- (Object) cell_hspan_right(n, w)
create a hspan_cell in a row/table, right justified
643 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 643 def cell_hspan_right(n,w) razslot();w.set_alignment(1.0, 0.5)rescue nil ; cell_hspan(n,w) end |
- (Object) cell_hvspan(n, m, w)
a cell in a row/table. take space of n x m cells, horizontaly x verticaly
671 672 673 674 675 676 677 678 679 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 671 def cell_hvspan(n,m,w) razslot(); @lcur.last.attach(w, @ltable.last[:col],@ltable.last[:col]+n, @ltable.last[:row],@ltable.last[:row]+m+1 ) @ltable.last[:col]+=n @ltable.last[:row]+=m end |
- (Object) cell_left(w)
create a cell in a row/table, left justified
636 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 636 def cell_left(w) razslot();w.set_alignment(0.0, 0.5) rescue nil; cell(w) end |
- (Object) cell_pass(n = 1)
keep empty n cell consecutive on current row
631 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 631 def cell_pass(n=1) @ltable.last[:col]+=n end |
- (Object) cell_right(w)
create a cell in a row/table, right justified
638 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 638 def cell_right(w) razslot();w.set_alignment(1.0, 0.5)rescue nil ; cell(w) end |
- (Object) cell_span(n = 2, w)
a cell in a row/table. take space of n cells, horizontaly
633 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 633 def cell_span(n=2,w) cell_hspan(n,w) end |
- (Object) cell_top(w)
create a cell in a row/table, top aligned
646 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 646 def cell_top(w) razslot();w.set_alignment(0.5, 0.0)rescue nil ; cell(w) end |
- (Object) cell_vspan(n, w)
a cell in a row/table. take space of n cells, verticaly
629 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 629 def cell_vspan(n,w) razslot();@lcur.last.attach(w,@ltable.last[:col],@ltable.last[:col]+1,@ltable.last[:row],@ltable.last[:row]+n) ; @ltable.last[:col]+=1 end |
- (Object) cell_vspan_bottom(n, w)
a cell_vspan aligned on bottom
702 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 702 def cell_vspan_bottom(n,w) razslot();w.set_alignment(0.5, 1.0)rescue nil ; cell_vspan(n,w) end |
- (Object) cell_vspan_top(n, w)
a cell_vspan aligned on top
700 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 700 def cell_vspan_top(n,w) razslot();w.set_alignment(0.5, 0.0)rescue nil ; cell_vspan(n,w) end |
- (Object) center
center { } container which center his content (auto-sloted)
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 48 def center() autoslot() valign = Gtk::Alignment.new(0,0,0,0) @lcur.last.pack_start(valign,false,false,0) vbox=VBox.new(true, 0) valign.add(vbox) @lcur << vbox yield autoslot() @lcur.pop end |
- (Object) check_button(text = "", value = false, option = {})
create a checked button no callback state can be read by cb.active?
430 431 432 433 434 435 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 430 def (text="",value=false,option={}) b=CheckButton.new(text) .set_active(value) attribs(b,option) b end |
- (Object) clear(cont)
clear a containet (stack or flow) thread protected
118 119 120 121 122 123 124 125 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 118 def clear(cont) if $__mainthread__ != Thread.current p "not in main thread" gui_invoke { clear(cont) } return end cont.children.each { |w| cont.remove(w) } end |
- (Object) clear_append_to(cont, &blk)
clear a container (stack or flow) and append the result of bloc parameter to this container thread protected
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 130 def clear_append_to(cont,&blk) if $__mainthread__ != Thread.current p "not in main thread" gui_invoke { clear_append_to(cont,&blk) } return end cont.children.each { |w| cont.remove(w) } @lcur << cont yield autoslot() @lcur.pop show_all_children(cont) end |
- (Object) clickable(method_name, &b)
specific to gtk : some widget like label can't support click event, so they must be contained in a clickable parent (EventBox)
Exemple: clickable(:callback_click_name) { label(“ click me! ”) }
click callback is definied by a method name. see pclickable for callback by closure.
1056 1057 1058 1059 1060 1061 1062 1063 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1056 def clickable(methode_name,&b) eventbox = Gtk::EventBox.new eventbox.events = Gdk::Event::BUTTON_PRESS_MASK ret=_cbox(true,eventbox,true,&b) eventbox.realize eventbox.signal_connect('button_press_event') { |w, e| self.send(methode_name,ret) rescue error($!) } ret end |
- (Object) close_dialog
96 97 98 |
# File 'lib/ruiby_gtk/systray.rb', line 96 def close_dialog destroy end |
- (Object) color_choice(text = nil, options = {}, &cb)
create a button wich will show a dialog for color choice if bloc is given, it with be call on each change, with new color value as parameter
544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 544 def color_choice(text=nil,={},&cb) b,d=nil,nil hb=flow(false) { b = slot((text.to_s||"Color?...")) ; d=slot(DrawingArea.new) } b.signal_connect("clicked") { c=ask_color if c d.modify_bg(Gtk::STATE_NORMAL,c) b.modify_bg(Gtk::STATE_NORMAL,c) cb.call(c) if block_given? end } attribs(hb,) hb end |
- (Object) color_conversion(color)
281 282 283 284 285 286 287 288 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 281 def color_conversion(color) case color when String then ::Gdk::Color.parse(color) when ::Gdk::Color then color else raise "unknown color : #{color}" end end |
- (Object) combo(choices, default = -1,, option = {})
combo box, decribe with a Hash choice-text => value-of-choice
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 392 def combo(choices,default=-1,option={}) if Ruiby.gtk_version(2) w=ComboBox.new() choices.each do |text,indice| w.append_text(text) end w.set_active(default) if default>=0 attribs(w,option) w else w=ComboBoxText.new() choices.each do |text,indice| w.append_text(text) end w.set_active(default) if default>=0 attribs(w,option) w end end |
- (Object) def_style(string_style = nil)
define style !! Warning: specific to gtk see ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ARC %GTK_BASEPATH%/share/themes/Metal/gtk-2.0/gtkrc
style “mstyle” { GtkWidget::interior_focus = 1 GtkButton::default_spacing = { 1, 1, 1, 1 } GtkButton::default_outside_spacing = { 0, 0, 0, 0 } font_name = “lucida”
bg_pixmap[NORMAL] = 'pixmap.png'
bg = { 0.80, 0.80, 0.80 } bg = { 0.80, 0.80, 1.00 } bg = { 0.80, 0.80, 0.80 } bg = { 0.60, 0.60, 0.80 } text = { 0.00, 0.00, 0.00 } text = { 0.00, 0.00, 0.00 } } class “GtkLabel” style “mstyle”
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1376 def def_style(string_style=nil) unless string_style fn=caller[0].gsub(/.rb$/,".rc") raise "Style: no ressource (#{fn} not-exist)" if !File.exists?(fn) string_style=File.read(fn) end begin Gtk::RC.parse_string(string_style) @style_loaded=true rescue Exception => e error "Error loading style : #{e}\n#{string_style}" end end |
- (Object) def_style3(string_style = nil)
not ready!!!
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 1456 def def_style3(string_style=nil) unless string_style fn=caller[0].gsub(/.rb$/,".rc") raise "Style: no ressource (#{fn} not-exist)" if !File.exists?(fn) string_style=File.read(fn) end begin provider=Gtk::CssProvider.new show_methods(provider) show_methods(Gtk::StyleContext.new) provider.load(string_style) #.add_provider(new Gtk.CssProvider.load_from_data(string_style, -1)) @style_loaded=true rescue Exception => e error "Error loading style : #{e}\n#{string_style}" end end |
- (Object) delete(w)
delete a widget or a timer thread protected
181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 181 def delete(w) if $__mainthread__ != Thread.current gui_invoke { delete(w) } return end if Numeric === w && @hTimer[w] @hTimer[w]=false elsif GLib::Timeout === w w.destroy else w.parent.remove(w) rescue error($!) end end |
- (Object) dialog(title = "")
dialog_sync(“title”) {
flow { button("dd") ... }
} Dialog contents is build with bloc parameter. call is bloced until action on Ok/Nok/delete button return true if dialog quit is done by action on OK button
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1302 def dialog(title="") dialog = Dialog.new(title, self, Dialog::DESTROY_WITH_PARENT, [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT], [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT]) @lcur << dialog.vbox hbox=stack { yield } @lcur.pop dialog.set_window_position(Window::POS_CENTER) dialog.show_all rep=dialog.run dialog.destroy rep end |
- (Object) dialog_async(title, config = {}, &b)
dialog_async(“title”,:response=> bloc {|dia,e| }) {
flow { button("dd") ... }
} Dialog content is build with bloc parameter. Action on Ok/Nok/delete button make a call to :response bloc. dialog is destoy if return value of :response is true
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1276 def dialog_async(title,config,&b) dialog = Dialog.new("Message", self, Dialog::DESTROY_WITH_PARENT, [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT], [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT]) dialog.set_window_position(Window::POS_CENTER) @lcur << dialog.vbox hbox=stack { yield } @lcur.pop dialog.signal_connect('response') do |w,e| rep=config[:response].call(dialog,e) if dialog.destroy if rep end dialog.show_all end |
- (Object) entry(value, size = 10, option = {}, &blk)
create a text entry for keyboard input if block defined, it while be trigger on eech of (character) change of the entry
473 474 475 476 477 478 479 480 481 482 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 473 def entry(value,size=10,option={},&blk) w=Entry.new().tap {|e| e.set_text(value ? value.to_s : "") } after(1) do w.signal_connect("key-press-event") do |en,e| after(1) { blk.call(w.text) rescue error($!) } false end end if block_given? attribs(w,option) end |
- (Object) fentry(value, option = {}, &blk)
create a integer text entry for keyboed input option must define :min :max :by for spin button
500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 500 def fentry(value,option={},&blk) w=SpinButton.new(option[:min].to_f,option[:max].to_f,option[:by].to_f) w.set_numeric(true) w.set_value(value ? value.to_f : 0.0) w.signal_connect("value-changed") do |en| after(1) { blk.call(w.value) rescue error($!) } false end if block_given? attribs(w,option) w end |
- (Object) field(tlabel, width, value, option = {}, &blk)
511 512 513 514 515 516 517 518 519 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 511 def field(tlabel,width,value,option={},&blk) e=nil flow { l=label(tlabel+ " : ") l.width_chars=width+3 e=entry(value,option,&blk) } e end |
- (Object) fields(alabel, option = {}, &blk)
520 521 522 523 524 525 526 527 528 529 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 520 def fields(alabel,option={},&blk) size=alabel.map {|t| t[0].size}.max stack { le=alabel.map { |(label,value)| field(label,size,value) } if block_given? ("Validation") { blk.call(*le.map {|t| t.text}) } ("Annulation") { blk.call(*le.map {|t| nil}) } end } end |
- (Object) flow(add1 = true, &b)
container : horizontal box, take all space available, sloted in parent by default
32 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 32 def flow(add1=true,&b) _cbox(true,HBox.new(false, 2),add1,&b) end |
- (Object) flow_paned(size, fragment, &blk)
split current frame in 2 panes create a container which can containe 2 widgets, separated by movable bar block invoked must return a array of 2 box wich will put in the 2 panes horizonaly disposed
888 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 888 def flow_paned(size,fragment,&blk) _paned(true,size,fragment,&blk) end |
- (Object) flowi(add1 = true, &b)
container : horizontal box, take only necessary space , sloted in parent
36 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 36 def flowi(add1=true,&b) _cbox(false,HBox.new(false, 2),add1,&b) end |
- (Object) force_update(canvas)
update a canvas
600 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 600 def force_update(canvas) canvas.queue_draw unless canvas.destroyed? end |
- (Object) frame(t = "", add1 = true, &b)
a box with border and texte title, take all space
61 62 63 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 61 def frame(t="",add1=true,&b) _cbox(true,Frame.new(t),add1) { stack { b.call } } end |
- (Object) framei(t = "", add1 = true, &b)
a box with border and texte title, take only necessary space
65 66 67 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 65 def framei(t="",add1=true,&b) _cbox(false,Frame.new(t),add1) { stack { b.call } } end |
- (Object) get_config(w)
get a Hash aff all properties of a gtk widget
207 208 209 210 211 212 213 214 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 207 def get_config(w) return({"nil"=>""}) unless w && w.class.respond_to?("properties") w.class.properties().inject({"class"=>w.class.to_s}) { |h,meth| data=(w.send(meth) rescue nil) h[meth]=data.inspect.gsub(/^#/,'')[0..32] if data h } end |
- (Object) get_current_container
204 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 204 def get_current_container() @lcur.last end |
- (Object) get_icon(name)
raster images access #############################
218 219 220 221 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 218 def get_icon(name) return name if name.index('.') && File.exists?(name) iname=eval("Gtk::Stock::"+name.upcase) rescue nil end |
- (Object) get_image_from(name)
get a Image widget from a file or from a Gtk::Stock image can be a filename or a predefined icon in GTK::Stock for file image, whe can specify a sub image (sqared) :
filename.png[NoCol , NoRow]xSize
filename.png[3,2]x32 : extract a icon of 32x32 pixel size from third column/second line
see samples/draw.rb
232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 232 def get_image_from(name) if name.index('.') return Image.new(name) if File.exists?(name) return _sub_image(name) if name.index("[") alert("unknown icone #{name}") end iname=get_icon(name) if iname Image.new(iname,IconSize::BUTTON) else nil end end |
- (Object) get_pixbuf(name)
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 248 def get_pixbuf(name) @cach_pix={} unless defined?(@cach_pix) filename,px,py,bidon,dim=name.split(/\[|,|(\]x)/) if filename && px && py && bidon && dim && File.exist?(filename) dim=dim.to_i @cach_pix[filename]=Gdk::Pixbuf.new(filename) unless @cach_pix[filename] x0= dim*px.to_i y0= dim*py.to_i #p [x0,y0,"/",@cach_pix[filename].width,@cach_pix[filename].height] Gdk::Pixbuf.new(@cach_pix[filename],x0,y0,dim,dim) elsif File.exists?(name) @cach_pix[name]=Gdk::Pixbuf.new(name) unless @cach_pix[name] @cach_pix[name] elsif ! name.index(".") get_stockicon_pixbuf(name) else raise("file #{name} not exist"); end end |
- (Object) get_stockicon_pixbuf(name)
Image#initialize(:label => nil, :mnemonic => nil, :stock => nil, :size => nil)'
233 234 235 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 233 def get_stockicon_pixbuf(name) Image.new(eval("Gtk::Stock::"+name.upcase),IconSize::BUTTON).pixbuf end |
- (Object) grid(names, w = 0, h = 0)
create a grid of data (as list, but multicolumn) use set_data() to put a 2 dimensions array of text same methods as list widget all columnes are String type
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1125 def grid(names,w=0,h=0) scrolled_win = Gtk::ScrolledWindow.new scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC) scrolled_win.set_width_request(w) if w>0 scrolled_win.set_height_request(h) if h>0 model = Gtk::ListStore.new(*([String]*names.size)) treeview = Gtk::TreeView.new(model) treeview.selection.set_mode(Gtk::SELECTION_SINGLE) names.each_with_index do |name,i| treeview.append_column( Gtk::TreeViewColumn.new( name,Gtk::CellRendererText.new,{:text => i} ) ) end if block_given? treeview.signal_connect("row-activated") do |view, path, column| iter = view.model.get_iter(path) yield(names.size.times.map { |i| iter[i] }) end end def scrolled_win.grid() children[0].children[0] end def scrolled_win.model() grid().model end def scrolled_win.add_row(words) l=grid().model.append() words.each_with_index { |w,i| l[i] = w.to_s } end $ici=self def scrolled_win.get_data() raise("grid.get_data() out of main thread!")if $__mainthread__ != Thread.current @ruiby_data end def scrolled_win.set_data(data) @ruiby_data=data raise("grid.set_data() out of main thread!")if $__mainthread__ != Thread.current grid().model.clear() ; data.each { |words| add_row(words) } end def scrolled_win.selection() a=grid().selection.selected ; a ? a[0] : nil ; end def scrolled_win.index() grid().selection.selected end scrolled_win.(treeview) autoslot(nil) slot(scrolled_win) end |
- (Object) haccordion
create a hoizontral accordion menu.
850 851 852 853 854 855 856 857 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 850 def haccordion() @slot_accordion_active=nil #only one accordion active by window! w=flow { flowi { yield }} separator w end |
- (Object) hide_app
91 92 93 94 |
# File 'lib/ruiby_gtk/systray.rb', line 91 def hide_app iconify hide end |
- (Object) hradio_buttons(ltext = ["empty!"], value = -1))
as vradio_buttons , but horizontaly disposed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 437 def (ltext=["empty!"],value=-1) flow(false) { b0=nil ltext.each_with_index {|t,i| b=if i==0 b0=slot(RadioButton.new(t)) else slot(RadioButton.new(b0,t)) end if i==value b.toggled b.set_active(true) end } } end |
- (Object) htoolbar(items, options = {})
horizontal toolbar of icon button and/or separator if icon name contain a '/', second last is tooltip text Usage:
htoolbar(["text/tooltip", proc { },"separator" => "", ....]
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 353 def (items,={}) b=Toolbar.new b.(Toolbar::Style::ICONS) i=0 items.each {|name_tooltip,v| name,tooltip=name_tooltip,nil if ((ar=name_tooltip.split('/')).size>1) name,tooltip=*ar tooltip=" #{tooltip.capitalize} " end iname=get_icon(name) w=if iname Gtk::ToolButton.new(iname).tap { |but| but.signal_connect("clicked") { v.call rescue error($!) } if v but.set_tooltip_text(tooltip) if tooltip } elsif name=~/^sep/i Gtk::SeparatorToolItem.new elsif name=~/^right-(.*)/i Gtk::ToolButton.new(get_icon($1)).tap { |but| but.signal_connect("clicked") { v.call rescue error($!) } if v but.set_tooltip_text(tooltip) if tooltip } else puts "=======================\nUnknown icone : #{name}\n=====================" puts "Icones dispo: #{Stock.constants.map { |ii| ii.downcase }.join(", ")}" Gtk::ToolButton.new(Stock::MISSING_IMAGE) end if w Ruiby.gtk_version(2) ? b.insert(i,w) : b.insert(w,i) end i+=1 } attribs(b,) end |
- (Object) ientry(value, option = {}, &blk)
create a integer text entry for keyboed input option must define :min :max :by for spin button
485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 485 def ientry(value,option={},&blk) w=SpinButton.new(option[:min].to_i,option[:max].to_i,option[:by]) w.set_numeric(true) w.set_value(value ? value.to_i : 0) w.signal_connect("value-changed") do |en| after(1) { blk.call(w.value) } false end if block_given? attribs(w,option) w end |
- (Object) image(file, options = {})
create a icon with a raster file option can specify a new size : :width and :height, or :size (square image)
316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 316 def image(file,={}) im=if File.exists?(file) pix=Gdk::Pixbuf.new(file) pix=pix.scale([:width],[:height],Gdk::Pixbuf::INTERP_BILINEAR) if [:width] && [:height] pix=pix.scale([:size],[:size],Gdk::Pixbuf::INTERP_BILINEAR) if [:size] Image.new(pix) else label("? "+file) end .delete(:size) attribs(im,) end |
- (Object) islider(value, option = {}, &b)
create a slider option must define :min :max :by for spin button current value can be read by w.value if bloc is given, it with be call on each change, with new value as parameter
534 535 536 537 538 539 540 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 534 def (value,option={},&b) w=HScale.new(option[:min].to_i,option[:max].to_i,option[:by]) .set_value(value ? value.to_i : 0) attribs(w,option) w.signal_connect(:value_changed) { || b.call(w.value) rescue error($!) } if block_given? w end |
- (Object) label(text, options = {})
create label, with text (or image if txt start with a '#')
301 302 303 304 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 301 def label(text,={}) l=_label(text,) attribs(l,) end |
- (Object) labeli(text, options = {})
305 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 305 def labeli(text,={}) sloti(label(text,)) end |
- (Object) list(title, w = 0, h = 0)
create a verticale liste of data, with scrollbar if necessary define methods:
-
list() : get (gtk)list widget embeded
-
model() : get (gtk) model of the list widget
-
clear() clear content of the list
-
set_data(array) : clear and put new data in the list
-
selected() : get the selected item (or nil)
-
index() : get the index of selected item (or nil)
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1086 def list(title,w=0,h=0) scrolled_win = Gtk::ScrolledWindow.new scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC) scrolled_win.set_width_request(w) if w>0 scrolled_win.set_height_request(h) if h>0 model = Gtk::ListStore.new(String) column = Gtk::TreeViewColumn.new(title.to_s,Gtk::CellRendererText.new, {:text => 0}) treeview = Gtk::TreeView.new(model) if block_given? treeview.signal_connect("row-activated") do |view, path, column| iter = view.model.get_iter(path) yield iter[0] end end treeview.append_column(column) treeview.selection.set_mode(Gtk::SELECTION_SINGLE) scrolled_win.(treeview) def scrolled_win.list() children[0].children[0] end def scrolled_win.model() list().model end def scrolled_win.clear() list().model.clear end def scrolled_win.add_item(word) raise("list.add_item() out of main thread!") if $__mainthread__ != Thread.current list().model.append[0]=word end def scrolled_win.set_data(words) raise("list.set_data() out of main thread!") if $__mainthread__ != Thread.current list().model.clear words.each { |w| list().model.append[0]=w } end def scrolled_win.selection() a=list().selection.selected ; a ? a[0] : nil ; end def scrolled_win.index() list().selection.selected end autoslot(scrolled_win) scrolled_win end |
- (Object) log(*txt)
put a line of message text in log dialog (create and show the log dialog if not exist)
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1323 def log(*txt) if $__mainthread__ && $__mainthread__ != Thread.current gui_invoke { log(*txt) } return end loglabel=_create_log_window() loglabel.buffer.text += Time.now.to_s+" | " + (txt.join(" ").encode("UTF-8"))+"\n" if ( loglabel.buffer.text.size>1000*1000) loglabel.buffer.text=loglabel.buffer.text[-7000..-1].gsub(/^.*\n/m,"......\n\n") end end |
- (Object) menu(text)
a vertial drop-down menu, only for menu_bar container
804 805 806 807 808 809 810 811 812 813 814 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 804 def (text) raise("menu(#{text}) without menu_bar {}") unless @menuBar @filem = MenuItem.new(text.to_s) @menuBar.append(@filem) @mmenu = Menu.new() yield @filem.=@mmenu show_all_children(@mmenu) @filem=nil @mmenu=nil end |
- (Object) menu_bar
create a application menu. must contain menu() {} : menu_bar {menu(“F”) {menu_button(“a”) { } ; menu_separator; menu_checkbutton(“b”) { |w|} …}}
794 795 796 797 798 799 800 801 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 794 def () @menuBar= MenuBar.new ret=@menuBar yield sloti(@menuBar) @menuBar=nil ret end |
- (Object) menu_button(text = "?", &blk)
create an text entry in a menu
817 818 819 820 821 822 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 817 def (text="?",&blk) raise("menu_button(#{text}) without menu('ee') {}") unless @mmenu item = MenuItem.new(text.to_s) @mmenu.append(item) item.signal_connect("activate") { blk.call(text) rescue error($!) } end |
- (Object) menu_checkbutton(text = "?", state = false, &blk)
create an checkbox entry in a menu
825 826 827 828 829 830 831 832 833 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 825 def (text="?",state=false,&blk) raise("menu_button(#{text}) without menu('ee') {}") unless @mmenu item = CheckMenuItem.new(text,false) item.active=state @mmenu.append(item) item.signal_connect("activate") { blk.call(item,text) rescue error($!.to_s) } end |
- (Object) menu_separator
834 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 834 def () @mmenu.append( SeparatorMenuItem.new ) end |
- (Object) notebook
create a notebook widget. it must contain page() wigget notebook { page(“first”) { … } ; … }
748 749 750 751 752 753 754 755 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 748 def notebook() nb = Notebook.new() slot(nb) @lcur << nb yield @lcur.pop nb end |
- (Object) page(title, icon = nil)
a page widget. only for notebook container. button can be text or icone (if startin by '#', as label)
758 759 760 761 762 763 764 765 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 758 def page(title,icon=nil) if icon && icon[0,1]=="#" l = Image.new(get_icon(icon[1..-1]),IconSize::BUTTON); #flow(false) { label(icon) ; label(title) } else l=Label.new(title) end @lcur.last.append_page( stack(false) { yield }, l ) end |
- (Object) pclickable(aproc, &b)
clickable with callback by closure : pclicakble(proc { alert(“e”) }) { alabel(“click me!”) }
1067 1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1067 def pclickable(aproc,&b) eventbox = Gtk::EventBox.new eventbox.events = Gdk::Event::BUTTON_PRESS_MASK ret=_cbox(true,eventbox,true,&b) eventbox.realize eventbox.signal_connect('button_press_event') { |w, e| aproc.call(w,e) rescue error($!) } ret end |
- (Object) popup(w = nil)
Popup create a dynamic popup. (shoud by calling in a closure) opup block can be composed by pp_item and pp_separator Exemple : popup { pp_item(“text”) { } ; pp_seperator ; pp_item('Exit“) { exit!(0)} ; .…}
769 770 771 772 773 774 775 776 777 778 779 780 781 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 769 def popup(w=nil) w ||= @lcur.last() = Gtk::Menu.new @lcur << yield @lcur.pop .show_all w.add_events(Gdk::Event::BUTTON_PRESS_MASK) w.signal_connect("button_press_event") do |, event| .popup(nil, nil, event., event.time) if (event. == 3) end end |
- (Object) pp_item(text, &blk)
a button in a popup
836 837 838 839 840 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 836 def pp_item(text,&blk) item = Gtk::MenuItem.new(text) item.signal_connect('activate') { |w| blk.call() } @lcur.last.append(item) end |
- (Object) pp_separator
a bar separator in a popup
842 843 844 845 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 842 def pp_separator() item = Gtk::SeparatorMenuItem.new() @lcur.last.append(item) end |
- (Object) properties(title, hash, options = {:edit=>false, :scroll=>[0,0]})
create a property shower/editor : vertical liste of label/entry representing the ruby Hash content Edition: Option: use :edit => true for show value in text entry, and a validate button, on button action, yield of bloc parameter is done with modified Hash as argument widget define set_data()methods for changing current value
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 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 734 735 736 737 738 739 740 741 742 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 680 def properties(title,hash,={:edit=>false, :scroll=>[0,0]}) if ! defined?(@prop_index) @prop_index=0 @prop_hash={} else @prop_index+=1 end prop_current=(@prop_hash[@prop_index]={}) value={} =stacki { framei(title.to_s) { stack { if [:scroll] && [:scroll][1]>0 vbox_scrolled([:scroll][0],[:scroll][1]) { table(2,hash.size) { hash.each { |k,v| row { _make_prop_line(prop_current,,k,v) }} } } else table(2,hash.size) { hash.each { |k,v| row { _make_prop_line(prop_current,,k,v) }} } end if [:edit] sloti(("Validation") { nhash=.get_data() if block_given? yield(nhash) else hash.clear nhash.each { |k,v| hash[k]=v } end }) end } } } .instance_variable_set(:@prop_current,prop_current) .instance_variable_set(:@hash_initial,hash) def .set_data(newh) newh.each { |k,v| @prop_current[k].text=v.to_s } end def .get_data() @prop_current.inject({}) {|nhash,(k,w)| v_old=@hash_initial[k] v_new=w.text vbin=case v_old when String then v_new when Fixnum then v_new.to_i when Float then v_new.to_f when /^(\[.*\])|(\{.*\})$/ then eval( v_new ) rescue error($!) else v_new.to_s end nhash[k]=vbin nhash } end end |
- (Object) propertys(title, hash, options = {:edit=>false, :scroll=>[0,0]}, &b)
deprecated: see properties
654 655 656 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 654 def propertys(title,hash,={:edit=>false, :scroll=>[0,0]},&b) properties(title,hash,,&b) end |
- (Object) razslot
forget precedent wdget oconstructed
96 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 96 def razslot() @current_widget=nil; end |
- (Object) row
create a row. must be defined in a table closure Closure argment should only contain cell(s) call. many cell type are disponibles : cell cell_bottom cell_hspan cell_hspan_left cell_hspan_right cell_left cell_pass cell_right cell_span cell_top cell_vspan cell_vspan_bottom cell_vspan_top row do
cell( label("ee")) ; cell_hspan(3, button("rr") ) }
end
618 619 620 621 622 623 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 618 def row() autoslot() @ltable.last[:col]=0 # will be increment by cell..() yield @ltable.last[:row]+=1 end |
- (Object) scrolled(width, height, &b)
create a Scrolled widget with a autobuild stack in it stack can be populated respond to : scrooo_to_top; scroll_to_bottom,
1034 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1034 def scrolled(width,height,&b) vbox_scrolled(width,height,&b) end |
- (Object) separator(width = 1.0)
create a bar (vertical or horizontal according to stack/flow current container)
295 296 297 298 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 295 def separator(width=1.0) autoslot() sloti(HBox === @lcur.last ? VSeparator.new : HSeparator.new) end |
- (Object) show_all_children(c)
143 144 145 146 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 143 def show_all_children(c) return unless c c.each { |f| show_all_children(f) if f.respond_to?(:children) ; f.show() } ; c.show end |
- (Object) show_app
87 88 89 90 |
# File 'lib/ruiby_gtk/systray.rb', line 87 def show_app() deiconify show end |
- (Object) show_methods(obj = nil, filter = nil)
show methods of a object/class in log window
668 669 670 671 672 673 674 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 668 def show_methods(obj=nil,filter=nil) obj=self unless obj title="\n============ #{Class===obj.class ? obj : obj.class} ===========\n" data=(obj.methods-Object.methods).grep(filter || /.*/).sort.each_slice(3).map { |a,b,c| "%-30s| %-30s| %-30s" % [a,b,c]}.join("\n") ="\n==================================================\n" log( title+data+) end |
- (Object) slot(w)
pack widget in parameter, share space with prother widget this is the default: all widget will be sloted if they are not slotied this is done by attribs(w) which is call after construction of almost all widget
84 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 84 def slot(w) @current_widget=nil; @lcur.last.add(w) ; w end |
- (Object) slot_append_after(w, wref)
append the widget w after anotherone wref) thread protected
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 165 def slot_append_after(w,wref) if $__mainthread__ != Thread.current gui_invoke { slot_append_after(w,wref) } return end parent=_check_append("slot_append_after",w,wref) parent.add(w) parent.children.each_with_index { |child,i| next if child!=wref parent.reorder_child(w,i+1) break } w end |
- (Object) slot_append_before(w, wref)
append the widget w before another one wref thread protected
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 149 def slot_append_before(w,wref) if $__mainthread__ != Thread.current gui_invoke { slot_append_before(w,wref) } return end parent=_check_append("slot_append_before",w,wref) parent.add(w) parent.children.each_with_index { |child,i| next if child!=wref parent.reorder_child(w,i) break } w end |
- (Object) sloti(w)
pack widget in parameter, take only necessary space
87 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 87 def sloti(w) @current_widget=nil; @lcur.last.pack_start(w,false,false,3) ; w end |
- (Object) source_editor(args = {})
a source_editor widget : text as showed in fixed font, colorized (default: ruby syntaxe) from: green shoes plugin options= :width :height :on_change :lang :font @edit=source_editor().editor @edit.buffer.text=File.read(@filename)
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 912 def source_editor(args={}) # from green_shoes plugin return begin require 'gtksourceview2' rescue Exception => e log('gtksourceview2 not installed!, please use text_area') return end args[:width] = 400 unless args[:width] args[:height] = 300 unless args[:height] change_proc = proc { } (change_proc = args[:on_change]; args.delete :on_change) if args[:on_change] sv = ::Gtk::SourceView.new sv.show_line_numbers = true sv.insert_spaces_instead_of_tabs = false sv.smart_home_end = Gtk::SourceView::SMART_HOME_END_ALWAYS sv.tab_width = 4 sv.buffer.text = (args[:text]||"").to_s sv.buffer.language = Gtk::SourceLanguageManager.new.get_language(args[:lang]||'ruby') sv.buffer.highlight_syntax = true sv.modify_font( Pango::FontDescription.new(args[:font] || "Courier new 10")) cb = ScrolledWindow.new cb.define_singleton_method(:editor) { sv } cb.define_singleton_method(:text=) { |t| sv.buffer.text=t } cb.define_singleton_method(:text) { sv.buffer.text } cb.set_size_request(args[:width], args[:height]) cb.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) cb.set_shadow_type(SHADOW_IN) cb.add(sv) cb.show_all attribs(cb,{}) end |
- (Object) space(n = 1)
create a one-character size space, (or n character x n line space)
329 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 329 def space(n=1) label(([" "*n]*n).join("\n")) end |
- (Object) stack(add1 = true, &b)
container : vertical box, take all space available, sloted in parent by default
30 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 30 def stack(add1=true,&b) _cbox(true,VBox.new(false, 2),add1,&b) end |
- (Object) stack_paned(size, fragment, &blk)
Panned : split current frame in 2 panes create a container which can containe 2 widgets, separated by movable bar block invoked must return a array of 2 box wich will put in the 2 panes vertivaly disposed
882 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 882 def stack_paned(size,fragment,&blk) _paned(false,size,fragment,&blk) end |
- (Object) stacki(add1 = true, &b)
container : vertical box, take only necessary space , sloted in parent
34 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 34 def stacki(add1=true,&b) _cbox(false,VBox.new(false, 2),add1,&b) end |
- (Object) syst_add_button(label, &prc)
80 |
# File 'lib/ruiby_gtk/systray.rb', line 80 def (label,&prc) @systray_config[label]=prc ; end |
- (Object) syst_add_check(label, &prc)
82 |
# File 'lib/ruiby_gtk/systray.rb', line 82 def syst_add_check(label,&prc) @systray_config["+"+label]=prc ; end |
- (Object) syst_add_sepratator
81 |
# File 'lib/ruiby_gtk/systray.rb', line 81 def syst_add_sepratator() @systray_config["--#{@systray_config.size}"]= proc {} ; end |
- (Object) syst_icon(file)
79 |
# File 'lib/ruiby_gtk/systray.rb', line 79 def syst_icon(file) @systray_config[:icon]=file ; end |
- (Object) syst_quit_button(yes)
83 |
# File 'lib/ruiby_gtk/systray.rb', line 83 def (yes) @systray_config[:quit]=yes ; end |
- (Object) systray(x = nil, y = nil)
73 74 75 76 77 78 |
# File 'lib/ruiby_gtk/systray.rb', line 73 def systray(x=nil,y=nil) @title=File.basename($0).gsub(/\.rb/,'') unless defined?(@title) @systray_config={} yield @systray=::Gtk::SysTray.new(self,@title,@systray_config,x,y) end |
- (Object) systray_setup(config)
84 85 86 |
# File 'lib/ruiby_gtk/systray.rb', line 84 def systray_setup(config) @systray=::Gtk::SysTray.new(self,@title,config) end |
- (Object) table(nb_col, nb_row, config = {})
table create a container for table-disposed widgets. this is not a grid! table(r,c) { row { cell(w) ; .. } ; … }
605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 605 def table(nb_col,nb_row,config={}) table = Gtk::Table.new(nb_row,nb_col,false) table.set_column_spacings(config[:set_column_spacings]) if config[:set_column_spacings] #sloti(table) @lcur << table @ltable << { :row => 0, :col => 0} yield @ltable.pop @lcur.pop attribs(table,config) end |
- (Object) text_area(w = 200, h = 100, args = {})
multiline entry w=text_area(min_width,min_height,options)
Some binding are defined :
-
w.text_area ; get text area widdget (w is a ScrolledWindow)
-
w.text=“” ; set content
-
puts w.text() ; get content
-
w.append(“data n”) ; append conent to the end of current content
-
w.text_area.wrap_mode = :none/:word
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 950 def text_area(w=200,h=100,args={}) # from green_shoes app tv = Gtk::TextView.new tv.wrap_mode = TextTag::WRAP_WORD tv.buffer.text = args[:text].to_s if args[:text] tv.modify_font(Pango::FontDescription.new(args[:font])) if args[:font] tv.accepts_tab = true eb = Gtk::ScrolledWindow.new eb.set_size_request(w,h) eb.add(tv) eb.define_singleton_method(:text_area) { tv } class << eb def text=(a) self.children[0].buffer.text=a.to_s end def text() self.children[0].buffer.text end def append(a) self.children[0].buffer.text+=a.to_s.encode("UTF-8") end end eb.children[0].buffer.text=(args[:text]||"") eb.show_all eb end |
- (Object) toggle_button(text1, text2 = nil, value = false, option = {}, &blk)
to state button, with text for each state and a initiale value value can be read by w.active? callback on state change with new value as argument
415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 415 def (text1,text2=nil,value=false,option={},&blk) text2 = "- "+text1 unless text2 b=ToggleButton.new(text1); b.signal_connect("toggled") do |w,e| w.label= w.active?() ? text2.to_s : text1.to_s ( blk.call(w.active?()) rescue error($!) ) if blk end b.set_active(value) b.label= value ? text2.to_s : text1.to_s attribs(b,option) b end |
- (Object) tree_grid(names, w = 0, h = 0, options = {})
create a tree view of data (as grid, but first column is a tree) use set_data() to put a Hash of data same methods as grid widget a columns Class are distinges by column name : <li> raster image if name start with a '#' <li> checkbutton if name start with a '?' <li> Integer if name start with a '0' <li> String else
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1178 def tree_grid(names,w=0,h=0,={}) scrolled_win = Gtk::ScrolledWindow.new scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC) scrolled_win.set_width_request(w) if w>0 scrolled_win.set_height_request(h) if h>0 scrolled_win.shadow_type = Gtk::SHADOW_ETCHED_IN types=names.map do |name| case name[0,1] when "#" then Gdk::Pixbuf when "?" then TrueClass when "0".."9" then Integer else String end end model = Gtk::TreeStore.new(*types) treeview = Gtk::TreeView.new(model) treeview.selection.set_mode(Gtk::SELECTION_SINGLE) names.each_with_index do |name,i| renderer,symb= *( if types[i]==TrueClass then [Gtk::CellRendererToggle.new().tap { |r| r.signal_connect('toggled') { } },:win] elsif types[i]==Gdk::Pixbuf then [Gtk::CellRendererPixbuf.new,:active] elsif types[i]==Numeric then [Gtk::CellRendererText.new,:text] else [Gtk::CellRendererText.new,:text] end ) treeview.append_column( Gtk::TreeViewColumn.new( name.gsub(/^[#?0-9]/,""),renderer,{symb => i} ) ) end #------------- Build singleton def scrolled_win.init(types) @types=types end scrolled_win.init(types) def scrolled_win.tree() children[0].children[0] end def scrolled_win.model() tree().model end $ici=self def scrolled_win.get_data() raise("tree.get_data() out of main thread!")if $__mainthread__ != Thread.current @ruiby_data end def scrolled_win.set_data(hdata,parent=nil,first=true) raise("tree.set_data() out of main thread!")if $__mainthread__ != Thread.current if parent==nil && first @ruiby_data=hdata model.clear() end hdata.each do |k,v| case v when Array set_row([k.to_s]+v,parent) when Hash p=model.append(parent) p[0] =k.to_s set_data(v,p,false) end end end def scrolled_win.set_row(data,parent=nil) puts "treeview: raw data size nok : #{data.size}/#{data.inspect}" if data.size!=@types.size i=0 c=self.model.append(parent) data.zip(@types) do |item,clazz| c[i]=if clazz==TrueClass then (item ? true : false) elsif clazz==Gdk::Pixbuf then $ici.get_pixbuf(item.to_s).tap {|a| p [item,clazz,a]} elsif clazz==Integer then item.to_i else item.to_s end i+=1 end end def scrolled_win.selection() a=tree().selection.selected ; a ? a[0] : nil ; end def scrolled_win.index() tree().selection.selected end scrolled_win.(treeview) autoslot(nil) slot(scrolled_win) end |
- (Object) var_box(sens, add1 = true, &b)
container : vertical or horizontal box (stack/flow, choice by first argument), sloted in parent by default
34 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 34 def var_box(sens,add1=true,&b) _cbox(true,Box.new(sens, 2),add1,&b) end |
- (Object) var_boxi(sens, add1 = true, &b)
container : vertical or horizontal box (stacki/flowi, choice by first argument), sloted in parent by default
41 |
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 41 def var_boxi(sens,add1=true,&b) _cbox(false,Box.new(sens, 2),add1,&b) end |
- (Object) vbox_scrolled(width, height, &b)
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1035 def vbox_scrolled(width,height,&b) sw=slot(ScrolledWindow.new()) sw.set_width_request(width) if width>0 sw.set_height_request(height) if height>0 sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS) ret= stack(false,&b) if block_given? sw.(ret) class << sw def scroll_to_top() vadjustment.set_value( 0 ) ; vadjustment.value_changed ; end def scroll_to_bottom() vadjustment.set_value( vadjustment.upper - 100); vadjustment.value_changed ; end #def scroll_to_left() hadjustment.set_value( 0 ) end #def scroll_to_right() hadjustment.set_value( hadjustment.upper-1 ) end end attribs(sw,{}) end |
- (Object) video(uri, w = 300, h = 200)
Video from: green shoes plugin ** not tested! **
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 1008 def video(uri,w=300,h=200) wid=DrawingArea.new() wid.set_size_request(w,h) uri = File.join('file://', uri.gsub("\\", '/').sub(':', '')) unless uri =~ /^(\w\w+):\/\// require('gst') require('win32api') rescue nil v = Gst::ElementFactory.make('playbin2') v.video_sink = Gst::ElementFactory.make('dshowvideosink') v.uri = uri args[:real], args[:app] = v, self handle = wid.window.class.method_defined?(:xid) ? @app.win.window.xid : Win32API.new('user32', 'GetForegroundWindow', [], 'N').call v.video_sink.xwindow_id = handle wid.events |= ( ::Gdk::Event::BUTTON_PRESS_MASK | ::Gdk::Event::POINTER_MOTION_MASK | ::Gdk::Event::BUTTON_RELEASE_MASK) wid.signal_connect('expose_event') do |w1,e| end def wid.video() v end wid.video.play end |
- (Object) vradio_buttons(ltext = ["empty!"], value = -1))
create a liste of radio button, vertically disposed value is the indice of active item (0..(n-1)) at creation time define 2 methods:
-
get_selected # get indice of active radio-button
-
set_selected(indice) # set indice of active radio-button
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 455 def (ltext=["empty!"],value=-1) stack(false) { b0=nil ltext.each_with_index {|t,i| b=if i==0 b0=slot(RadioButton.new(t)) else slot(RadioButton.new(b0,t)) end if i==value b.toggled b.set_active(true) end } } end |
- (Object) widget_properties(title = nil, w = nil)
289 290 291 292 |
# File 'lib/ruiby_gtk/ruiby_dsl.rb', line 289 def (title=nil,w=nil) widg=w||@current_widget||@lcur.last properties(title||widg.to_s,{},get_config(widg)) end |