Class: TECSCDE::AttrTreeView
Overview
AttrTreeView: show cell list
formerly this class is sub-class of Gtk::TreeView currently this class has Gtk::TreeView
Constant Summary collapse
- COL_NAME =
@choice_list::name=>ListStore @cell::TmCell @ct_attr_list::{ String(attr_name) => String(initializer) } @view::TECSCDE::View::MainView @tree_view::Gtk::TreeView
0
- COL_TYPE =
1
- COL_VALUE =
2
Instance Attribute Summary collapse
-
#tree_view ⇒ Object
readonly
Gtk::TreeView.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(tree_view) ⇒ AttrTreeView
constructor
initialize.
-
#set_cell(cell) ⇒ Object
AttrTreeView#set_cell cell::TmCell.
-
#set_view(view) ⇒ Object
AttrTreeView#set_view view::TECSCDE::View::MainView.
Constructor Details
#initialize(tree_view) ⇒ AttrTreeView
initialize
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 126 127 128 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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/tecscde/attr_tree_view.rb', line 68 def initialize(tree_view) @tree_view = tree_view combo_list = Gtk::ListStore.new(String) iter = combo_list.append iter[0] = "a0" combo_list = Gtk::ListStore.new(String, String, String) # iter = combo_list.append # iter[0] = "a0" # iter[1] = "b0" # iter[2] = "c0" # iter = combo_list.append # iter[0] = "a1" # iter[1] = "b1" # iter[2] = "c1" # combo_list2 = Gtk::ListStore.new(String, String, String) # iter = combo_list2.append # iter[0] = "A0" # iter[1] = "B0" # iter[2] = "C0" # iter = combo_list2.append # iter[0] = "A1" # iter[1] = "B1" # iter[2] = "C1" # create data model liststore = Gtk::ListStore.new(String, String, String) # set data model to tree view(self) @tree_view.set_model(liststore) # create renderer for text renderer = Gtk::CellRendererText.new #----- set column information -----# # ATTRIBUTE column col = Gtk::TreeViewColumn.new("attribute", renderer, text: COL_NAME) col.set_cell_data_func(renderer) do |_col, renderer, _model, iter| if iter[COL_VALUE].nil? || iter[COL_VALUE] == "" renderer.foreground = "red" elsif @cell.editable? renderer.foreground = "black" else renderer.foreground = "blue" end end @tree_view.append_column(col) # TYPE column col = Gtk::TreeViewColumn.new("type", renderer, text: COL_TYPE) col.set_cell_data_func(renderer) do |_col, renderer, _model, _iter| if @cell.editable? renderer.foreground = "black" else renderer.foreground = "blue" end end @tree_view.append_column(col) # VALUE column renderer = Gtk::CellRendererCombo.new renderer.text_column = 0 renderer.model = combo_list col = Gtk::TreeViewColumn.new("value", renderer, text: COL_VALUE) col.set_cell_data_func(renderer) do |_col, renderer, _model, iter| # p "iter[0]=#{iter[0]}" if @cell.get_attr_list[iter[COL_NAME].to_sym].nil? renderer.foreground = "orange" elsif @cell.editable? renderer.foreground = "black" else renderer.foreground = "blue" end if @cell.editable? renderer.editable = true else renderer.editable = false end if @choice_list[iter[0]] renderer.model = @choice_list[iter[0]] renderer.has_entry = false renderer.text_column = 0 else renderer.model = nil renderer.text_column = 0 renderer.has_entry = true end # if iter[2] && iter[2] != "" # if iter[1] == "ID" # renderer.model = combo_list # renderer.has_entry = false # renderer.text_column = 0 # elsif iter[1] == "SIZE" # renderer.model = combo_list2 # renderer.has_entry = false # renderer.text_column = 1 # elsif iter[1] == "PRI" # renderer.model = combo_list # renderer.has_entry = false # renderer.text_column = 2 # else # renderer.model = nil # renderer.text_column = 0 # renderer.has_entry = true # end end renderer.signal_connect("edited") do |_w, path, new_text| # new_text can be wrong if 'text_column' is changed in each row # after selection is changed, before sending signal, many rows are redrawn # p "new_text='#{new_text}'" if (iter = @tree_view.model.get_iter(path)) if new_text.nil? || new_text == "" if @ct_attr_list[iter[COL_NAME]] iter[COL_VALUE] = @ct_attr_list[iter[COL_NAME]] else iter[COL_VALUE] = new_text end if new_text == "" new_text = nil end else iter[COL_VALUE] = new_text end @cell.set_attr(iter[COL_NAME].to_sym, new_text) @cell.model.set_undo_point @view.paint_canvas end end @tree_view.append_column(col) end |
Instance Attribute Details
#tree_view ⇒ Object (readonly)
Gtk::TreeView
65 66 67 |
# File 'lib/tecscde/attr_tree_view.rb', line 65 def tree_view @tree_view end |
Instance Method Details
#clear ⇒ Object
243 244 245 |
# File 'lib/tecscde/attr_tree_view.rb', line 243 def clear @tree_view.model.clear end |
#set_cell(cell) ⇒ Object
AttrTreeView#set_cell
cell::TmCell
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/tecscde/attr_tree_view.rb', line 207 def set_cell(cell) clear @cell = cell @choice_list = {} @ct_attr_list = {} cell_attr_list = cell.get_attr_list ct = @cell.get_celltype return unless ct #----- register attributes and initializer to tree view model -----# ct.get_attribute_list.each do |attr| iter = @tree_view.model.append name = attr.get_name.to_s if attr.get_initializer @ct_attr_list[name] = attr.get_initializer.to_CDL_str end iter[COL_NAME] = name iter[COL_TYPE] = "#{attr.get_type.get_type_str}#{attr.get_type.get_type_str_post}" if cell_attr_list[name.to_sym] iter[COL_VALUE] = cell_attr_list[name.to_sym] elsif attr.get_initializer iter[COL_VALUE] = attr.get_initializer.to_CDL_str end #----- choice list model -----# if attr.get_choice_list @choice_list[name] = Gtk::ListStore.new(String) attr.get_choice_list.each do |choice| iter = @choice_list[name].append iter[0] = CDLString.remove_dquote(choice.val) end end end end |
#set_view(view) ⇒ Object
AttrTreeView#set_view
view::TECSCDE::View::MainView
249 250 251 |
# File 'lib/tecscde/attr_tree_view.rb', line 249 def set_view(view) @view = view end |