class Etti::PageLayout
Constants
- ARROW_SIZE
- LABELS_H
- LABELS_V
- LABEL_PADDING
Attributes
entryChanged[R]
Public Class Methods
new(pageDatas)
click to toggle source
Calls superclass method
# File lib/etti/ui/page-layout.rb, line 12 def initialize pageDatas super(:vertical) @pageDatas = pageDatas @entryChanged = false self.border_width = 0 @pageSizes = ['a4'] @entries = {} @boxes = [] @lcNumeric = I18nToolbox::LcNumeric.new @dimensionData = {:borderTop => {:pos => [2, 3, 0, 1], :label => _('top border'), :tooltip => _('The distance from the label to the top leaf margin'), :range => 0.0..50.0}, :borderLeft => {:pos => [0, 1, 2, 3], :label => _('left border'), :tooltip => _('The distance from the label to the left leaf margin'), :range => 0.0..50.0}, :height => {:pos => [2, 3, 1, 2], :label => _('label height'), :tooltip => _('The height of a single label'), :range => 3.0..500.0}, :width => {:pos => [1, 2, 2, 3], :label => _('label width'), :tooltip => _('The width of a single label'), :range => 3.0..500.0}, :paddingH => {:pos => [2,3, 3, 4], :label => _('horizontal distance'), :tooltip => _('The horizontal distance between the labels'), :range => 0.0..20.0}, :paddingV => {:pos => [3, 4, 2, 3], :label => _('vertical distance'), :tooltip => _('The vertical distance between the labels'), :range => 0.0..20.0} } @descriptionData = {:manufacture => {:label => _('manufacturer'), :tooltip => _('Manufacturer of the label')}, :orderNr => {:label => _('order number'), :tooltip => _('The manufacturers order number')}, :description => {:label => _('description'), :tooltip => _('An aditional description for the label')}, :pageSize => {:label => _('page size'), :tooltip => _('The size of the sheet, i.e. "a4"')} } @sheetData = {:cols => {:pos => 0, :label => _('columns'), :tooltip => _('The number of labels horizontal'), :range => 1..100}, :rows => {:pos => 1, :label => _('rows'), :tooltip => _('The number of labels vertical'), :range => 1..100} } @sizeGroup = Gtk::SizeGroup.new :both widget = make_entry :name, _('Name'), _("The name of the label\nIt has to be unique") @saveButton = Gtk::Button.new :stock_id => Gtk::Stock::SAVE @saveButton.tooltip_text = _('Save the changes of the label sheet') @saveButton.signal_connect(:clicked) {on_save} widget.pack_end @saveButton, :expand => false, :fill => false, :padding => 32 self.pack_start widget, :expand => false, :fill => false, :padding => 12 # create the dimension entries @table = Gtk::Table.new 4, 4, true hbox = Gtk::Box.new :horizontal hbox.pack_start @table, :expand => false, :fill => false self.pack_start hbox, :expand => false, :fill => false @dimensionData.each_pair do |key, val| box = Gtk::Box.new :vertical @boxes << box @table.attach box, *val[:pos], 0, 0, LABEL_PADDING, LABEL_PADDING box.pack_start Gtk::Label.new(val[:label]), :expand => false, :fill => false entry = Rgw::RestrictedEntry.new if key == :width or key == :height entry.editable = false entry.sensitive = false end entry.restriction = :float entry.range = val[:range] @entries[key] = entry entry.name = key box.pack_start entry, :expand => false, :fill => false entry.set_max_length 7 entry.width_chars = 8 entry.tooltip_text = val[:tooltip] entry.signal_connect(:changed) {|entry| on_entry_changed entry} end # the box below the sheet preview bottomBox = Gtk::Box.new :horizontal self.pack_start bottomBox, :expand => false, :fill => false bottomLeft = Gtk::Box.new :vertical bottomBox.pack_start bottomLeft, :expand => false, :fill => false bottomRight = Gtk::Box.new :vertical bottomBox.pack_start bottomRight, :expand => false, :fill => false, :padding => 64 # create the page size combo box val = @descriptionData[:pageSize] cbox = Gtk::Box.new :horizontal bottomLeft.pack_start cbox, :expand => false, :fill => false label = Gtk::Label.new.set_markup("<b>%s</b>: " % val[:label]) label.xalign = 0.0 cbox.pack_start label, :expand => false, :fill => false, :padding => 6 @sizeGroup.add_widget label @pageSizeCombo = Gtk::ComboBoxText.new cbox.pack_start @pageSizeCombo, :expand => false, :fill => false, :padding => 4 @pageSizes.each do |pz| @pageSizeCombo.append_text pz end @pageSizeCombo.signal_connect(:changed) do @pageData[:pageSize] = @pageSizes[@pageSizeCombo.active] end # create the page description entries [:manufacture, :orderNr, :description].each do |key| val = @descriptionData[key] widget = make_entry key, val[:label], val[:tooltip] bottomLeft.pack_start widget, :expand => false, :fill => false, :padding => 4 end # create the column and row count display rcTable = Gtk::Table.new 3, 2, false bottomRight.pack_start rcTable, :expand => false, :fill => false @sheetData.each_pair do |key, val| label = Gtk::Label.new.set_markup("<b>%s: </b>" % val[:label]) label.xalign = 0.0 rcTable.attach_defaults label, 0, 1, val[:pos], val[:pos] + 1 entry = Rgw::RestrictedEntry.new entry.restriction = :integer entry.range = val[:range] @entries[key] = entry entry.name = key rcTable.attach_defaults entry, 1, 2, val[:pos], val[:pos] + 1 entry.set_max_length 3 entry.width_chars = 8 entry.tooltip_text = val[:tooltip] entry.signal_connect(:changed) {|entry| on_entry_changed entry} end signal_connect(:map) {on_map} signal_connect(:draw) do |widget| draw_bg false end signal_connect_after(:draw) {on_draw} end
Public Instance Methods
save()
click to toggle source
# File lib/etti/ui/page-layout.rb, line 223 def save on_save end
update_page_data(pageData)
click to toggle source
# File lib/etti/ui/page-layout.rb, line 191 def update_page_data pageData @pageData = pageData [:name, :manufacture, :orderNr, :description, :pageSize, :cols, :rows, :size, :borders, :padding].each do |key| case key when :name, :manufacture, :orderNr, :description @entries[key].text = @pageData[key] #.instance_variable_get '@' + key.to_s when :borders left, top = *@pageData[key] @entries[:borderTop].text = @lcNumeric.to_s top @entries[:borderLeft].text = @lcNumeric.to_s left when :padding h, v = *@pageData[key] @entries[:paddingH].text = @lcNumeric.to_s h @entries[:paddingV].text = @lcNumeric.to_s v when :size w, h = *@pageData[key] @entries[:width].text = @lcNumeric.to_s w @entries[:height].text = @lcNumeric.to_s h when :cols @entries[:cols].text = @lcNumeric.to_s @pageData[key] when :rows @entries[:rows].text = @lcNumeric.to_s @pageData[key] when :pageSize @pageSizeCombo.active = @pageSizes.index @pageData[:pageSize] end end @saveButton.sensitive = false @entryChanged = false end
Private Instance Methods
draw_arrow(dir, x, y, lg, out=false)
click to toggle source
# File lib/etti/ui/page-layout.rb, line 396 def draw_arrow dir, x, y, lg, out=false @cc.set_source_rgb 0.2, 0.2, 0.2 @cc.line_width = 1.0 unless out if dir == :h @cc.antialias = :none @cc.move_to x, y @cc.line_to x + lg, y @cc.stroke @cc.antialias = :subpixel @cc.move_to x, y @cc.line_to x + ARROW_SIZE, y - (ARROW_SIZE / 4.0) @cc.line_to x + ARROW_SIZE, y + (ARROW_SIZE / 4.0) @cc.fill.stroke @cc.move_to x + lg, y @cc.line_to x + lg - ARROW_SIZE, y - (ARROW_SIZE / 4.0) @cc.line_to x + lg - ARROW_SIZE, y + (ARROW_SIZE / 4.0) @cc.fill.stroke else @cc.antialias = :none @cc.move_to x, y @cc.line_to x, y + lg @cc.stroke @cc.antialias = :subpixel @cc.move_to x, y @cc.line_to x - (ARROW_SIZE / 4.0), y + ARROW_SIZE @cc.line_to x + (ARROW_SIZE / 4.0), y + ARROW_SIZE @cc.fill.stroke @cc.move_to x, y + lg @cc.line_to x - (ARROW_SIZE / 4.0), y + lg - ARROW_SIZE @cc.line_to x + (ARROW_SIZE / 4.0), y + lg - ARROW_SIZE @cc.fill.stroke end else if dir == :h @cc.antialias = :none @cc.move_to x - ARROW_SIZE * 2.0, y @cc.line_to x + lg + ARROW_SIZE * 8.0, y @cc.stroke @cc.antialias = :subpixel @cc.move_to x, y @cc.line_to x - ARROW_SIZE, y - (ARROW_SIZE / 4.0) @cc.line_to x - ARROW_SIZE, y + (ARROW_SIZE / 4.0) @cc.fill.stroke @cc.move_to x + lg, y @cc.line_to x + lg + ARROW_SIZE, y - (ARROW_SIZE / 4.0) @cc.line_to x + lg + ARROW_SIZE, y + (ARROW_SIZE / 4.0) @cc.fill.stroke else @cc.antialias = :none @cc.move_to x, y - ARROW_SIZE * 2.0 @cc.line_to x, y + lg + ARROW_SIZE * 8.0 @cc.stroke @cc.antialias = :subpixel @cc.move_to x, y @cc.line_to x - (ARROW_SIZE / 4.0), y - ARROW_SIZE @cc.line_to x + (ARROW_SIZE / 4.0), y - ARROW_SIZE @cc.fill.stroke @cc.move_to x, y + lg @cc.line_to x - (ARROW_SIZE / 4.0), y + lg + ARROW_SIZE @cc.line_to x + (ARROW_SIZE / 4.0), y + lg + ARROW_SIZE @cc.fill.stroke end end end
draw_bg()
click to toggle source
# File lib/etti/ui/page-layout.rb, line 312 def draw_bg box_allocation = @table.allocation bx = box_allocation.x by = box_allocation.y bw = box_allocation.width bh = box_allocation.height @cc = @table.window.create_cairo_context @cc.set_source_rgb *$colors.bg @cc.paint @cc.set_source_rgb 1.0, 1.0, 1.0 @cc.rectangle bx + 8, by + 8, bw - 12, bh - 12 @cc.fill.stroke end
make_entry(id, label, tooltip, head=nil)
click to toggle source
# File lib/etti/ui/page-layout.rb, line 228 def make_entry id, label, tooltip, head=nil hbox = Gtk::Box.new :horizontal label = Gtk::Label.new.set_markup("<b>#{label}</b>: ") hbox.pack_start label, :expand => false, :fill => false, :padding => 6 @sizeGroup.add_widget label label.xalign = 0.0 entry = Rgw::RestrictedEntry.new entry.range = id == :name ? 1..250 : 0..250 entry.name = id @entries[id] = entry hbox.pack_start entry, :expand => false, :fill => false entry.tooltip_text = tooltip entry.signal_connect(:changed) {|entry| on_entry_changed entry} hbox end
on_draw()
click to toggle source
# File lib/etti/ui/page-layout.rb, line 340 def on_draw box_allocation = @boxes.first.allocation bw = box_allocation.width bh = box_allocation.height bw = @boxW bh = @boxH @cc = @table.window.create_cairo_context # we don't have an own window @cc.translate(@table.allocation.x, @table.allocation.y) @cc.antialias = :none # border @cc.set_source_rgb 0.5, 0.5, 0.5 @cc.line_width = 2.0 @cc.move_to (bw + LABEL_PADDING * 2.0) * (LABELS_H + 1), 8 @cc.line_to 8, 8 @cc.line_to 8, (bh + LABEL_PADDING * 2.0) * (LABELS_V + 1) @cc.stroke @cc.set_source_rgb 0.4, 0.4, 0.9 @cc.line_width = 1.0 1.upto(LABELS_V) do |y| 1.upto(LABELS_H) do |x| @cc.rectangle (bw + LABEL_PADDING * 2.0) * x, (bh + LABEL_PADDING * 2.0) * y, bw + LABEL_PADDING * 1.5, bh + LABEL_PADDING * 1.5 @cc.stroke end end # border arrows draw_arrow :h, 8, (bh + LABEL_PADDING * 2.0) * 2.0 + 24, bw + LABEL_PADDING * 2.0 - 8 draw_arrow :v, (bw + LABEL_PADDING * 2.0) * 2.0 + 24, 8, bh + LABEL_PADDING * 2.0 - 8 # cell arrows draw_arrow :h, (bw + LABEL_PADDING * 2.0), (bh + LABEL_PADDING * 2.0) * 2.0 + 24.0, bw + LABEL_PADDING * 1.5 draw_arrow :v, (bw + LABEL_PADDING * 2.0) * 2.0 + 24, bh + LABEL_PADDING * 2.0, bh + LABEL_PADDING * 1.5 # padding arrows draw_arrow :h, (bw + LABEL_PADDING * 2.0) * 2.0 - LABEL_PADDING * 0.5, (bh + LABEL_PADDING * 2.0) * 3.0 + 24, LABEL_PADDING * 0.5, true draw_arrow :v, (bw + LABEL_PADDING * 2.0) * 3.0 + 24, (bh + LABEL_PADDING * 2.0) * 2.0 - LABEL_PADDING * 0.5, LABEL_PADDING * 0.5, true end
on_entry_changed(entry)
click to toggle source
# File lib/etti/ui/page-layout.rb, line 247 def on_entry_changed entry return if @pageData.nil? key = entry.name.to_sym return if key == :width or key == :height text = @entries[key].text return if text.nil? @entryChanged = true @saveButton.sensitive = true val = @lcNumeric.to_f text case key when :name, :manufacture, :orderNr, :description @pageData[key] = text when :paddingH @pageData[:padding][0] = val when :paddingV @pageData[:padding][1] = val when :borderLeft @pageData[:borders][0] = val when :borderTop @pageData[:borders][1] = val when :width @pageData[:size][0] = val when :height @pageData[:size][1] = val when :cols @pageData[:cols] = val when :rows @pageData[:rows] = val end recalculate_page_layout end
on_map()
click to toggle source
# File lib/etti/ui/page-layout.rb, line 329 def on_map @boxW = 0 @boxH = 0 @boxes.each do |box| allo = box.allocation @boxW = allo.width if allo.width > @boxW @boxH = allo.height if allo.height > @boxH end end
on_save()
click to toggle source
# File lib/etti/ui/page-layout.rb, line 291 def on_save @entries.each do |entry| if entry[1].text.nil? message = _('Some of the entries are invalid.') dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:close], :type => :info, :message => message, :title => _('Invalid Entries') dialog.run return nil end end return @pageDatas.save_page_data(@pageData, true) do |type, answers, message| if answers == :yes_no dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:yes, :no], :type => :info, :message => message dialog.run end end end
recalculate_page_layout()
click to toggle source
# File lib/etti/ui/page-layout.rb, line 281 def recalculate_page_layout pw, ph = *@pageDatas.get_page_dimensions(@pageData[:pageSize]) labelsWidth = (pw - @pageData[:borders][0] * 2 + @pageData[:padding][0] * 2) / @pageData[:cols] labelsHeight = (pw - @pageData[:borders][1] * 2 + @pageData[:padding][1] * 2) / @pageData[:rows] @entries[:width].text = @lcNumeric.to_s labelsWidth @entries[:height].text = @lcNumeric.to_s labelsHeight end