Class: FormImage

Inherits:
Gtk::Button
  • Object
show all
Includes:
ManqodCommon
Defined in:
lib/FormHolder/Form/InputHolder/FormImage.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Constant Summary

Constants included from ManqodCommon

ManqodCommon::CRITICAL, ManqodCommon::DEBUG, ManqodCommon::ERROR, ManqodCommon::INFO, ManqodCommon::NORMAL, ManqodCommon::WARNING

Constants included from Eprint

Eprint::DOMAIN, Eprint::LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ManqodCommon

#add_where, #admin, #admin_cache, #admin_qrow, #admin_rows, #backtrace_to_debug, #cache, #changed_ids_of_base, #client, #client_fields, #client_image_of_id, #client_qrow, #client_query, #client_rows, #eeval, #escape_string, #getBinding, #guess_base, #guess_table, #image_of_id, #lzero, #manqod_db, #measure, #myexec, #nick, #nick_id, #number_format, #qrow, #query, #reconnect_manqod_db, #rows, #run_events, #send_message, #sendmail, #set_manqod_db_uri, #set_nick

Methods included from Eprint

#ecode, #edebug, #eerror, #einfo, #enormal, #eprint, #ewarn, #gtk_set_edebug, #set_edebug, #tell_exception

Constructor Details

#initialize(pc) ⇒ FormImage

Returns a new instance of FormImage.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 7

def initialize(pc)
	@pc=pc
	super()
	set_relief(Gtk::ReliefStyle::NONE)
	signal_connect("clicked"){|me,ev|
		if @pc.editable?
			fch=Gtk::FileChooserDialog.new
			fch.set_action(Gtk::FileChooser::Action::OPEN)
			fch.signal_connect("file-activated"){|me,ev|
				set_image(load_file(me.filename))
				me.close
			}
			fch.signal_connect("delete-event"){|me,ev|
				me.destroy
			}
			fch.run
		end
	}
end

Instance Attribute Details

#pcObject

Returns the value of attribute pc.



26
27
28
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 26

def pc
  @pc
end

Instance Method Details

#deserialize_pixdata(raw) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 38

def deserialize_pixdata(raw)
	begin
		pixdata=Gdk::Pixdata.deserialize(Marshal.load(raw))
		pb=pixdata.to_pixbuf(true)
		Gtk::Image.new(pb)
	rescue =>e
		ewarn("cannot load image: #{e}")
		Gtk::Image.new(Gtk::Stock::MISSING_IMAGE,Gtk::IconSize::MENU)
	end
end

#itemObject



34
35
36
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 34

def item
	@pc.item
end

#load_file(filename) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 49

def load_file(filename)
	im=Gtk::Image.new(filename)
	if im.storage_type==Gtk::Image::PIXBUF && pc.gtk_attribute('form-image-max-height') && pc.gtk_attribute('form-image-max-height').to_f < im.pixbuf.height
		nw,nh =im.pixbuf.width*pc.gtk_attribute('form-image-max-height').to_f / im.pixbuf.height, pc.gtk_attribute('form-image-max-height').to_f
		new_pb=im.pixbuf.scale(nw,nh)
		im.set_pixbuf(new_pb)
	end
	im
end

#modify_font(font) ⇒ Object



71
72
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 71

def modify_font(font)
end

#set_image(im) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 59

def set_image(im)
	super
	begin
		item['default']=Marshal.dump(Gdk::Pixdata.from_pixbuf(im.pixbuf,true).serialize) if im.pixbuf
	rescue =>err
		ewarn(err)
	end
end

#textObject



68
69
70
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 68

def text
	item["default"]
end

#update(im = item['default']) ⇒ Object



28
29
30
31
32
# File 'lib/FormHolder/Form/InputHolder/FormImage.rb', line 28

def update(im=item['default'])
	run_events(item['id'],'info_item-BeforeUpdate')
	set_image(deserialize_pixdata(im))
	run_events(item['id'],'info_item-AfterUpdate')
end