Class: LegendsButton

Inherits:
Gtk::ToggleButton
  • Object
show all
Includes:
Conf
Defined in:
lib/ListHolder/ListButtonHolder/LegendsButton.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Conf

#get_conf, #load_conf, #save_conf, #set_conf

Constructor Details

#initialize(list_holder) ⇒ LegendsButton

Returns a new instance of LegendsButton.



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
41
42
43
44
# File 'lib/ListHolder/ListButtonHolder/LegendsButton.rb', line 8

def initialize(list_holder)
  @list_holder=list_holder
  @auto_update=false
  super()
  set_relief(Gtk::ReliefStyle::NONE)
  set_image(Gtk::Image.new(Gtk::Stock::SELECT_COLOR,Gtk::IconSize.from_name(get_conf(0,0,"button-size"))))
  signal_connect('toggled'){|me|
if me.active?
  lmodel=Gtk::ListStore.new(String,String,String) #legend,foreground,background
  column=Gtk::TreeViewColumn.new("Legend",Gtk::CellRendererText.new, {:text => 0, :foreground => 1, :background => 2})
  @legend_window=Gtk::Window.new(Gtk::Window::POPUP).add(legend=Gtk::TreeView.new(lmodel))#.set_modal(true)
  legend.selection.set_mode(Gtk::SelectionMode::NONE)
  legend.append_column(column)
  @list_holder.list.list_model.foreground_legend.each_pair{|color,legend|
    iter=lmodel.append
    iter[0]=legend
    iter[1]=color
  }
  @list_holder.list.list_model.background_legend.each_pair{|color,legend|
    iter=lmodel.append
    iter[0]=legend
    iter[2]=color
  }
  @legend_window.
    realize.
    set_transient_for(get_ancestor(Gtk::Window)).
    move(get_ancestor(Gtk::Window).position[0] + allocation.x + allocation.width,
      get_ancestor(Gtk::Window).position[1] + allocation.y + allocation.height - @legend_window.allocation.height).
    show_all.
    move(get_ancestor(Gtk::Window).position[0] + allocation.x + allocation.width,
      get_ancestor(Gtk::Window).position[1] + allocation.y + allocation.height - @legend_window.allocation.height)
    
else
  @legend_window.destroy unless @legend_window.nil? || @legend_window.destroyed?
end
  }
end

Instance Attribute Details

#list_holderObject

Returns the value of attribute list_holder.



45
46
47
# File 'lib/ListHolder/ListButtonHolder/LegendsButton.rb', line 45

def list_holder
  @list_holder
end

Instance Method Details

#to_sObject



51
52
53
# File 'lib/ListHolder/ListButtonHolder/LegendsButton.rb', line 51

def to_s
  "LegendsButton of #{@list_holder}"
end

#updateObject



47
48
49
50
# File 'lib/ListHolder/ListButtonHolder/LegendsButton.rb', line 47

def update
  set_no_show_all(!(!@list_holder.list.list_model.foreground_legend.empty? || !@list_holder.list.list_model.background_legend.empty?))
  set_visible(!@list_holder.list.list_model.foreground_legend.empty? || !@list_holder.list.list_model.background_legend.empty?)
end