Class: Gtk::ImageComboList

Inherits:
ComboBox
  • Object
show all
Defined in:
lib/gui/widgets.rb

Instance Method Summary collapse

Constructor Details

#initialize(subd, filename, filetype = "png") ⇒ ImageComboList

Returns a new instance of ImageComboList.



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
162
163
164
165
# File 'lib/gui/widgets.rb', line 129

def initialize(subd, filename, filetype="png")
  @subdir = subd
  @filename = filename
  @filetype = filetype

  item_active = 0

  model = Gtk::ListStore.new(Gdk::Pixbuf, String)
  menu_icon_size = Gtk::IconSize.lookup(Gtk::IconSize::MENU)[0]
  pos = 0
  for typefile in Dir["#{PIXMAP_PATH}/#{subd}/*#{filetype}"].sort
	iter = model.append
	iter[0] =  Gdk::Pixbuf.new(typefile, menu_icon_size, menu_icon_size)
	iter[1] = typefile[PIXMAP_PATH.length+subd.length + 2 ,typefile.size - PIXMAP_PATH.length - subd.length - 2 - filetype.length - 1]
	if filename and iter[1] == filename
      item_active = pos
	end
	pos +=1
  end

  super(model)
  self.active = item_active

  # column 1
  renderer = Gtk::CellRendererPixbuf.new
  self.pack_start(renderer, false)
  self.set_attributes(renderer, :pixbuf => 0)

  # column 2
  renderer = Gtk::CellRendererText.new
  self.pack_start(renderer, true)
  self.set_attributes(renderer, :text => 1)

  #self.signal_connect("changed") do
  #  p self.filename
  #end
end

Instance Method Details

#filenameObject



113
114
115
# File 'lib/gui/widgets.rb', line 113

def filename
   return "#{@subdir}/#{self.active_iter[1]}.#{@filetype}"
end

#nameObject



117
118
119
# File 'lib/gui/widgets.rb', line 117

def name
   return "#{self.active_iter[1]}"
end

#selectedObject



121
122
123
124
125
126
127
# File 'lib/gui/widgets.rb', line 121

def selected
   if self
	  return self.active
   else
	 return nil
   end
end