Class: MyColumn

Inherits:
Gtk::TreeViewColumn
  • Object
show all
Includes:
Conf, GtkAttributes, ManqodCommon
Defined in:
lib/ListHolder/EditableList/Column.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 Conf

#get_conf, #load_conf, #save_conf, #set_conf

Methods included from GtkAttributes

#default_attribute, #gtk_attribute, #gtk_attribute_of_object, #gtkobjectid, #gtkobjecttype, #set_gtk_attribute

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(list, header) ⇒ MyColumn

Returns a new instance of MyColumn.



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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ListHolder/EditableList/Column.rb', line 9

def initialize(list,header)
	@list=list
	@header=header

	#replace our type if list has set 'ordering' attribute to us
	@header['type']='gtk_ordering' if list.gtk_attribute("ordering") == data
	@header['editable']=@header['editable']=='true' && (@header['wgrp_id'].to_i<1 || Nick.instance.ingroup_id?(@header['wgrp_id'].to_i))

	attributes=Hash.new

	case header['type']
		when 'gtk_combo' then @renderer=MyCellRendererCombo.new(self)
		when 'gtk_const_combo' then @renderer=MyCellRendererConstCombo.new(self)
		when 'gtk_text','String' then
			@renderer=MyCellRendererText.new(self)
			attributes={"text" => header['model_col']}
		when 'gtk_int','gtk_float','gtk_duration','gtk_timestamp','Integer','Bignum','gtk_ordering' then @renderer=MyCellRendererText.new(self)
		when 'gtk_pixbuf' then @renderer=MyCellRendererPixbuf.new(self)
			#attributes={:pixbuf => DrbImages.instance.image_of_id(header['model_col'].to_i)}
		when 'gtk_toggle' then
			@renderer=MyCellRendererToggle.new(self)
			attributes={"active" => header['model_col']}
		when 'gtk_const_text' then @renderer=MyCellRendererConstText.new(self)
		when 'gtk_combo_text' then @renderer=MyCellRendererComboText.new(self)
		when 'gtk_progress' then @renderer=MyCellRendererProgress.new(self)
	end

	super(header['header'],@renderer,attributes)
	set_widget(@header_widget=Gtk::Label.new(header['header']).set_visible(true))
	header_widget.set_angle(gtk_attribute("header_angle").to_f) if gtk_attribute("header_angle")
	@list.tip.set_tip(header_widget,header['header'],'extra hint')
	@list.tip.enable
	#set color
#		header_widget.modify_fg(Gtk::STATE_NORMAL,Gdk::Color.new(0,35000, 0))
#		header_widget.modify_fg(Gtk::STATE_PRELIGHT,Gdk::Color.new(0,35000, 0))

	header_widget.modify_font(Pango::FontDescription.new(gtk_attribute("header-font")||list.gtk_attribute("list-header-font")))
	
	
	@decimals_attribute=(gtk_attribute("decimals") || if header['type']=="gtk_float" then "2" else "0" end).to_i
	@duration_format=gtk_attribute("column-duration-format") || "%d %H:%M:%S"
	@timestamp_format=gtk_attribute("column-timestamp-format") || "%Y-%b-%d %H:%M:%S"
	case header['type']
		when 'gtk_ordering' then set_cell_data_func(renderer) { |column, cell, model, iter| cell.text=path_format(iter)}
		when 'gtk_float' then set_cell_data_func(renderer) { |column, cell, model, iter| cell.text=number_format(iter[column.colnum],decimals_attribute)}
		when 'gtk_int' then set_cell_data_func(renderer) { |column, cell, model, iter| cell.text=number_format(iter[column.colnum],0)}
		when 'gtk_duration' then set_cell_data_func(renderer) { |column, cell, model, iter| cell.text=iter[column.colnum].strftime(@duration_format)}
		when 'gtk_timestamp' then set_cell_data_func(renderer) { |column, cell, model, iter| cell.text=iter[column.colnum]==0 ? "" : Time.at(iter[column.colnum]).strftime(@timestamp_format)}
		when 'gtk_const_text','gtk_combo_text' then set_cell_data_func(renderer) { |column, cell, model, iter| cell.text = cell.get_display(iter[column.colnum])}
		when 'gtk_combo','gtk_const_combo' then set_cell_data_func(renderer){ |column, cell, model, iter| cell.text = cell.get_text_from_value(iter[column.colnum])}
		when 'gtk_pixbuf' then 
			if client.nil?
				set_cell_data_func(renderer){|column, cell, model, iter| 
					cell.pixbuf=image_of_id(iter[column.colnum],get_conf(0,0,"list-image-size"))
				}
			else
				set_cell_data_func(renderer){|column, cell, model, iter| 
					cell.pixbuf=client_image_of_id(iter[column.colnum],get_conf(0,0,"list-image-size"))
				}
			end
		when 'gtk_progress' then set_cell_data_func(renderer){|column, cell, model, iter| cell.set_value(iter[column.colnum])}
	end

	#query gtkattribute
	if header["querySQL"].length == 0 && sqlid=gtk_attribute("query")
		if sql=admin.qrow("select `sql` from `queries` where `id` = '#{sqlid}'")["sql"]
			header["querySQL"]=sql
		end
	end
	unless header["querySQL"].length == 0
		#key gtkattribute
		if col_key=gtk_attribute("key")
			header["key"]=col_key
			else
			header["key"]="#{guess_base(header["querySQL"])}.cdata"
		end
		#display gtkattribute
		if col_disp=gtk_attribute("display")
			header["display"]=col_disp
			else
			header["display"]="#{guess_base(header["querySQL"])}.cdisplay"
		end
	end

	@renderer.set_column(self)
	#set_attributes(@renderer,attributes)
	@renderer.set_xalign(header['align'].to_f)
	set_resizable((gtk_attribute("resizable") || list.gtk_attribute("columns_resizable") || "true") == "true")
	set_expand(!resizable?)
	set_reorderable((gtk_attribute("reorderable") || list.gtk_attribute("columns_reorderable") || "false") =="true")
	set_spacing((list.gtk_attribute("column_spacing") || "1").to_i)
	set_min_width((list.default_attribute("column_min_width") || "1").to_i)
	#override the sorting attributes set by user if 'ordering' is set
	if list.gtk_attribute("ordering")
		#set sorting to us, and noone else
		if list.gtk_attribute("ordering") == data
			set_sort_column_id(header["model_col"]) 
			@list.list_model.sorter.set_sort_column_id(header["model_col"])
		end
		set_clickable(false)
	else
		set_sort_column_id(header["model_col"]) if (gtk_attribute("sortable") || list.gtk_attribute("columns_sortable") || "true") == "true"
		set_clickable(true)
	end
	set_alignment(header['align'].to_f)
	set_renderers_background
	set_renderers_foreground
	set_renderers_sensitive
	@renderer.set_font(get_conf(0,0,"list-cell-font"))
	load_config
=begin
	signal_connect("destroy"){|me|
#			save_config
		@renderer.destroy if [email protected]?
	}
=end
end

Instance Attribute Details

#decimals_attributeObject (readonly)

Returns the value of attribute decimals_attribute.



129
130
131
# File 'lib/ListHolder/EditableList/Column.rb', line 129

def decimals_attribute
  @decimals_attribute
end

#duration_formatObject (readonly)

Returns the value of attribute duration_format.



129
130
131
# File 'lib/ListHolder/EditableList/Column.rb', line 129

def duration_format
  @duration_format
end

#headerObject

Returns the value of attribute header.



127
128
129
# File 'lib/ListHolder/EditableList/Column.rb', line 127

def header
  @header
end

#header_widgetObject

Returns the value of attribute header_widget.



127
128
129
# File 'lib/ListHolder/EditableList/Column.rb', line 127

def header_widget
  @header_widget
end

#listObject

signal_connect(“destroy”){|me| # save_config @renderer.destroy if [email protected]? }



126
127
128
# File 'lib/ListHolder/EditableList/Column.rb', line 126

def list
  @list
end

#rendererObject

Returns the value of attribute renderer.



128
129
130
# File 'lib/ListHolder/EditableList/Column.rb', line 128

def renderer
  @renderer
end

#timestamp_formatObject (readonly)

Returns the value of attribute timestamp_format.



129
130
131
# File 'lib/ListHolder/EditableList/Column.rb', line 129

def timestamp_format
  @timestamp_format
end

Instance Method Details

#colnumObject



151
152
153
# File 'lib/ListHolder/EditableList/Column.rb', line 151

def colnum
	header["model_col"]
end

#dataObject



167
168
169
# File 'lib/ListHolder/EditableList/Column.rb', line 167

def data
	header["data"]
end

#data_typeObject



159
160
161
# File 'lib/ListHolder/EditableList/Column.rb', line 159

def data_type
	list.headertypes[colnum]
end

#inspectObject



163
164
165
# File 'lib/ListHolder/EditableList/Column.rb', line 163

def inspect
	"ListColumn #{text}(#{@header['type']}:#{colnum})"
end

#load_configObject



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ListHolder/EditableList/Column.rb', line 135

def load_config
	if gtk_attribute("width")
		stored_width=gtk_attribute("width") 
		else
		stored_width=get_conf(list.get_id,header['id'],"width") if resizable?
	end
	if stored_width
		set_sizing(Gtk::TreeViewColumn::FIXED)
		set_fixed_width(stored_width.to_i)
	end
end

#pango_ellipsizeObject



198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/ListHolder/EditableList/Column.rb', line 198

def pango_ellipsize
	if gtk_attribute("ellipsize")
		case gtk_attribute("ellipsize")
			when 'NONE' then Pango::ELLIPSIZE_NONE
			when 'START' then Pango::ELLIPSIZE_START
			when 'END' then Pango::ELLIPSIZE_END
			when 'MIDDLE' then Pango::ELLIPSIZE_MIDDLE
			else Pango::ELLIPSIZE_NONE
		end
		else
		Pango::ELLIPSIZE_NONE
	end
end

#pango_layout_alignmentObject



186
187
188
189
190
191
192
193
194
195
196
# File 'lib/ListHolder/EditableList/Column.rb', line 186

def pango_layout_alignment
	if alignment < 0.25
		Pango::Layout::Alignment::LEFT
		else 
		if alignment > 0.25 and alignment < 0.75
			Pango::Layout::Alignment::CENTER
			else
			Pango::Layout::Alignment::RIGHT
		end
	end
end

#path_format(iter) ⇒ Object



237
238
239
# File 'lib/ListHolder/EditableList/Column.rb', line 237

def path_format(iter)
	iter.path.indices.collect{|i| i+=1}.join(".")
end

#printableObject



174
175
176
# File 'lib/ListHolder/EditableList/Column.rb', line 174

def printable
	header['printable']
end

#printable?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/ListHolder/EditableList/Column.rb', line 178

def printable?
	printable == "true"
end

#save_configObject



131
132
133
# File 'lib/ListHolder/EditableList/Column.rb', line 131

def save_config
	set_conf(list.get_id.to_s,header['id'].to_s,"width",width.to_s) if resizable? and width >0
end

#set_colnum(colnum) ⇒ Object



147
148
149
150
# File 'lib/ListHolder/EditableList/Column.rb', line 147

def set_colnum(colnum)
	header["model_col"]=colnum
	self
end

#set_renderers_backgroundObject



212
213
214
215
216
217
# File 'lib/ListHolder/EditableList/Column.rb', line 212

def set_renderers_background
	unless @list.list_model.column_of_background.nil?
		add_attribute(@renderer,"cell-background",@list.list_model.column_of_background)
		edebug("#{@renderer} attribute added: background_color => #{@list.list_model.column_of_background}","list","debug")
	end
end

#set_renderers_foregroundObject



218
219
220
221
222
223
224
225
# File 'lib/ListHolder/EditableList/Column.rb', line 218

def set_renderers_foreground
	unless @list.list_model.column_of_foreground.nil?
		unless ["MyCellRendererToggle", "MyCellRendererPixbuf", "MyCellRendererProgress"].include?(@renderer.class.name)
			add_attribute(@renderer,"foreground",@list.list_model.column_of_foreground)
			edebug("#{@renderer} attribute added: foreground_color => #{@list.list_model.column_of_foreground}","list","debug")
		end
	end
end

#set_renderers_sensitiveObject



226
227
228
229
230
231
# File 'lib/ListHolder/EditableList/Column.rb', line 226

def set_renderers_sensitive
	unless @list.list_model.column_of_sensitive.nil?
		add_attribute(@renderer,"sensitive",@list.list_model.column_of_sensitive)
		edebug("#{@renderer} attribute added: sensitive => #{@list.list_model.column_of_sensitive}","list","debug")
	end
end

#summable?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/ListHolder/EditableList/Column.rb', line 182

def summable?
	["gtk_duration","gtk_float","gtk_int"].include?(header['type'])
end

#textObject



170
171
172
# File 'lib/ListHolder/EditableList/Column.rb', line 170

def text
	header["header"]
end

#to_sObject



155
156
157
# File 'lib/ListHolder/EditableList/Column.rb', line 155

def to_s
	inspect
end

#wipeObject



232
233
234
235
236
# File 'lib/ListHolder/EditableList/Column.rb', line 232

def wipe
	save_config
	@renderer.destroy unless @renderer.destroyed?
	destroy unless destroyed?
end