class Etti::DataPage
Constants
- PREVIEW_LABEL_COUNT
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/etti/ui/data-page.rb, line 14 def initialize super(:orientation => :vertical) @dataPageUser = Gtk::Box.new :vertical pack_start @dataPageUser, :expand => false, :fill => false @dataFromFile = nil @dataFromFileNumCols = 1 @previewList = Rgw::BigList.new 1 @radioRevealer = Rgw::RadioRevealer.new @dataPageUser.pack_start @radioRevealer, :expand => false, :fill => false, :padding => 6 @radioRevealer.create_entry _('Enumeration'), create_enumeration_section @radioRevealer.create_entry _('From File'), create_file_section @radioRevealer.signal_connect(:revealed) {|widget, idx| update_data_preview idx} label = Gtk::Label.new label.markup = _("<b>data preview</b>") pack_start label, :expand => false, :fill => false pack_start @previewList, :expand => true, :fill => true end
Public Instance Methods
get_user_settings()
click to toggle source
# File lib/etti/ui/data-page.rb, line 37 def get_user_settings settings = {} section = @radioRevealer.active if section == 0 settings['section'] = 'enumeration' settings['prefix'] = @dataEntries[0].text settings['string'] = @dataEntries[1].text settings['postfix'] = @dataEntries[2].text elsif section == 1 settings['section'] = 'file' settings['fileName'] = @fileButton.filename settings['separator'] = @previewList.separator settings['hasHead'] = @hasHeadCheckButton.active? ? 1 : 0 end settings end
set_user_settings(settings)
click to toggle source
# File lib/etti/ui/data-page.rb, line 75 def set_user_settings settings if settings['section'] == 'enumeration' @radioRevealer.active = 0 @dataEntries[0].text = settings['prefix'] @dataEntries[1].text = settings['string'] @dataEntries[2].text = settings['postfix'] else @radioRevealer.active = 0 @fileButton.filename = settings['fileName'] @fileSeparatorCombo.active = @separatorStrings.index settings['separator'] @hasHeadCheckButton.active = settings['hasHead'] == 1 end end
signal_do_data_changed(foo, bla;)
click to toggle source
# File lib/etti/ui/data-page.rb, line 7 def signal_do_data_changed foo, bla; end
update_data_preview(idx)
click to toggle source
# File lib/etti/ui/data-page.rb, line 90 def update_data_preview idx # data from enumeration if idx == 0 @previewList.num_cols = 1 @previewList.heads = [_('Enumeration')] prefix = @dataEntries[0].text string = @dataEntries[1].text postfix = @dataEntries[2].text @dataRanges = [] toc = string.split ',' tocClean = [] toc.each do |text| textClean = text.strip tocClean << textClean if textClean.length() > 0 end # no enumeration entered if tocClean.length == 0 if prefix.length() > 0 or postfix.length() > 0 @previewList.data = [[prefix + (tocClean[0].nil? ? '' : tocClean[0]) + postfix]] else @previewList.data = [] end else labelTexts = [] fullLength = 0 tocClean.each do |text| # its a range like "1 - 99" or "aa-zz" if text.match /^\w+\s*\-\s*\w+$/ rgFrom, rgTo = *text.split('-') rg = Range.new rgFrom.strip, rgTo.strip if rg.count() > 1 @dataRanges << rg fullLength += rg.count else @dataRanges << text fullLength += 1 end else @dataRanges << text fullLength += 1 end end @dataRanges.each do |data| if data.is_a? Range labelTexts += data.to_a else labelTexts << data end end text = [] labelTexts.each {|txt| text << [prefix + txt + postfix]} @previewList.data = text end # data from file elsif idx == 1 unless @dataFromFile.nil? @previewList.num_cols = @dataFromFileNumCols if @hasHeadCheckButton.active? if @dataFromFile.length() > 0 heads = @dataFromFile[0] heads[@previewList.numCols - 1] = nil if heads.length() < @previewList.numCols i = 0 heads.map! do |a| val = a.nil? ? "col" + i.to_s : a i += 1 val end @previewList.heads = heads if @dataFromFile.length() > 1 @previewList.data = @dataFromFile[1..-1] end else @previewList.heads = Array.new @previewList.numCols, "" end else heads = [] 1.upto(@previewList.numCols) {|i| heads << 'col' + i.to_s} @previewList.heads = heads @previewList.data = @dataFromFile end else @previewList.heads = nil @previewList.data = [] end end signal_emit :data_changed, @previewList.heads, @previewList.data end
validate_user_settings(settings)
click to toggle source
# File lib/etti/ui/data-page.rb, line 55 def validate_user_settings settings if settings['section'] == 'enumeration' return _('DataPage prefix is not a String.') unless settings['prefix'].is_a? String return _('DataPage data string is not a String.') unless settings['string'].is_a? String return _('DataPage postfix is not a String.') unless settings['postfix'].is_a? String elsif settings['selection'] == 'file' fn = settings['file'] return _('DataPage filename is not a String.') unless fn.is_a? String return _("DataPage file doesn'exist, or is not readable.") unless File.exist? fn and File.readable? fn sep = settings['separator'] return _('DataPage separator is not a String') unless sep.is_a? String and @separatorStrings.include? sep hs = settings['hasHead'] return _('DataPage has head setting is invalid (not 0 or 1)') unless hs.is_a? Integer and (hs == 0 or hs == 1) else return _('DataPage section is invalid') end nil end
Private Instance Methods
add_data_entry(label, sizeGroup)
click to toggle source
# File lib/etti/ui/data-page.rb, line 266 def add_data_entry label, sizeGroup hbox = Gtk::Box.new :horizontal @dataBox.pack_start hbox, :expand => false, :fill => false label = Gtk::Label.new.set_markup("<b>#{label}</b>: ") hbox.pack_start label, :expand => false, :fill => false sizeGroup.add_widget label label.xalign = 0.0 entry = Gtk::Entry.new @dataEntries << entry hbox.pack_start entry, :expand => false, :fill => false, :padding => 6 entry.signal_connect(:changed) {update_data_preview 0} end
create_enumeration_section()
click to toggle source
# File lib/etti/ui/data-page.rb, line 182 def create_enumeration_section hbox = Gtk::Box.new :horizontal @dataBox = Gtk::Box.new :vertical hbox.pack_start @dataBox, :expand => false, :fill => false sizeGroup = Gtk::SizeGroup.new :both @dataEntries = [] [_('Prefix'), _('Data Row'), _('Postfix')].each {|label| add_data_entry label, sizeGroup} hbox end
create_file_section()
click to toggle source
# File lib/etti/ui/data-page.rb, line 195 def create_file_section vbox = Gtk::Box.new :vertical hbox = Gtk::Box.new :horizontal vbox.pack_start hbox, :expand => false, :fill => false, :padding => 4 sizeGroup = Gtk::SizeGroup.new :both label = Gtk::Label.new.set_markup _('<b>File: </b>') sizeGroup.add_widget label label.xalign = 0.0 hbox.pack_start label, :expand => false, :fill => false @fileButton = Gtk::FileChooserButton.new _('Choose file'), :open hbox.pack_start @fileButton, :expand => false, :fill => false @fileButton.signal_connect(:file_set) do data, cols = *Etti::FileReader.data_read(@fileButton.filename, @previewList.separator, 20) do |type, message, types=nil| answer = nil btn = [:yes, :no] tp = type == Etti::FileReader::WARNING ? :warning : :error dialog = Etti::MessageDialog.new self.toplevel, :buttons => btn, :type => tp, :message => message, :title => _('Question from file reader') case dialog.run when 'yes' Etti::FileReader::YES when 'no' Etti::FileReader::NO end end unless data.nil? @dataFromFile = data @dataFromFileNumCols = cols update_data_preview 1 end end hbox = Gtk::Box.new :horizontal vbox.pack_start hbox, :expand => false, :fill => false, :padding => 4 label = Gtk::Label.new.set_markup _('<b>Column separator: </b>') sizeGroup.add_widget label label.xalign = 0.0 hbox.pack_start label, :expand => false, :fill => false @fileSeparatorCombo = Gtk::ComboBoxText.new hbox.pack_start @fileSeparatorCombo, :expand => false, :fill => false @separatorNames = [_('tab'), _('space'), ',', '.'] @separatorStrings = ["\t", ' ', ',', '.'] @separatorNames.each {|sep| @fileSeparatorCombo.append_text sep} @fileSeparatorCombo.signal_connect(:changed) do @previewList.separator = @separatorStrings[@fileSeparatorCombo.active] end @fileSeparatorCombo.active = 0 hbox = Gtk::Box.new :horizontal @hasHeadCheckButton = Gtk::CheckButton.new label = Gtk::Label.new.set_markup _('<b>Columns have headlines</b>') @hasHeadCheckButton.add label hbox.pack_start @hasHeadCheckButton, :expand => false, :fill => false vbox.pack_start hbox, :expand => false, :fill => false, :padding => 4 @hasHeadCheckButton.signal_connect(:toggled) do update_data_preview 1 end vbox end
create_group_label(text)
click to toggle source
# File lib/etti/ui/data-page.rb, line 282 def create_group_label text label = Gtk::Label.new.set_xalign(0.04) label.markup = '<span size="large" weight="bold">' + text + '</span>' label end