etti 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83cacfc33d97ca9758d06d8a3edfec4290788d67
4
- data.tar.gz: 73f4b727abe2a4a3fe4fd7a7a6eff42ec7b16a95
3
+ metadata.gz: 01d2ab51124b22c47e91b53f203896608f6864ba
4
+ data.tar.gz: 751753191c55665d7765dd7e16b84a701ce172d0
5
5
  SHA512:
6
- metadata.gz: d13a5be38ab88fbf6a872571e2b412f8677114b408e4c82fb7ae5e8a73ccb513666c6ad82e632331c5ac4e8d99687eb3d53430b2609bd4d39a8929297233429a
7
- data.tar.gz: 0147dd1c2a9c685656a7d6189343dbcd0e47a875ec6d9ae887456cb228925bb0f58a82e6c1ebd3d31d6d10ab9a0fb127161940c2130f4661f3c32aced0863508
6
+ metadata.gz: daf955706b9dac4c9ddd464c4732a848853b807bd56ed6016e835748c392827ca61b51f3cfc4e979d51aa378cbbd1e57fbb290f38bfc7984ccda574f0e11cace
7
+ data.tar.gz: 6ad7f544fd18741f19094ff9410bba699002f475697ebbcf7945abb321035dc90ec905ffed8f8bd19c3db60e663a48db1cf8cf308cf34e44c5da372f7a7ccc52
data/bin/etti CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  require 'etti'
5
5
 
6
+ $etti_developement_version = true
7
+
6
8
  window = Etti::Window.new
7
9
  window.show_all
8
10
  window.dataPage.update_data_preview 0
@@ -42,6 +42,20 @@ module Etti
42
42
  end
43
43
 
44
44
 
45
+ def to_h
46
+ hs = {}
47
+ if @showAs == SHOW_AS_TEXT
48
+ hs['showAs'] = 'text'
49
+ else
50
+ hs['showAs'] = 'qr'
51
+ ['qrWidth', 'qrHeight', 'qrVersion', 'qrErrorCorrection', 'qrEncoding'].each do |name|
52
+ hs[name] = get_by_name name
53
+ end
54
+ end
55
+ hs.merge super()
56
+ end
57
+
58
+
45
59
  def draw_selection view
46
60
  if @showAs == SHOW_AS_TEXT
47
61
  super
@@ -9,6 +9,7 @@ module Etti
9
9
  @size = size || 4.0
10
10
  end
11
11
 
12
+ # x, y, rotation, color have to be moved to the Etti::Element::Base class
12
13
  def set_by_name name, val
13
14
  if name == 'text' then @text = val; return; end
14
15
  if name == 'pos_x' then @x = val.to_f; return; end
@@ -29,6 +30,16 @@ module Etti
29
30
  end
30
31
 
31
32
 
33
+ def to_h
34
+ hs = {}
35
+ ['text', 'pos_x', 'pos_y', 'size', 'rotation', 'color'].each do |name|
36
+ hs[name] = get_by_name name
37
+ end
38
+ hs
39
+ # hs.merge super
40
+ end
41
+
42
+
32
43
  def redraw
33
44
 
34
45
  end
@@ -15,6 +15,8 @@ module Etti
15
15
  def initialize
16
16
  super()
17
17
 
18
+ @pageDimensions = {'a4' => [297.0, 210.0]}
19
+
18
20
  @pageDatas = {}
19
21
  @dataFiles = [DATA_PATH + 'page-data.json',
20
22
  File.expand_path('~') + '/.local/share/etti/page-data.json']
@@ -58,13 +60,18 @@ module Etti
58
60
  end
59
61
 
60
62
 
61
- def save_page_data page, &callback
63
+ def get_page_dimensions size
64
+ @pageDimensions[size]
65
+ end
66
+
67
+
68
+ def save_page_data page, savePage, &callback
62
69
  FileUtils.mkdir_p File.dirname(@dataFiles.last)
63
- if @pageDatas.key? page[:name]
70
+ if savePage and @pageDatas.key? page[:name]
64
71
  message = _("The page description\n\"%s\"\nalready exist.\n\nSould it be replaced?") % page[:name]
65
72
 
66
73
  ret = callback.call :warning, :yes_no, message
67
- return unless ret == 'yes'
74
+ return nil unless ret == 'yes'
68
75
  end
69
76
  # header
70
77
  json = {'Etti' => 'page data file',
@@ -76,30 +83,35 @@ module Etti
76
83
  json['Data'][key] = val if val[:source] == 1
77
84
  end
78
85
 
79
- hs = nil
86
+ pageHash = nil
80
87
  newPage = !@pageDatas.key?(page[:name])
81
88
 
82
89
  # fill the current or new page with the page data from the UI
83
90
  if newPage
84
- hs = {}
91
+ pageHash = {}
85
92
  else
86
- hs = @pageDatas[page[:name]]
93
+ pageHash = @pageDatas[page[:name]]
87
94
  end
88
95
  FIELDS.each do |key|
89
- hs[key.to_s] = page[key]
96
+ pageHash[key.to_s] = page[key]
90
97
  end
91
98
 
92
- json['Data'][page[:name]] = hs
99
+ json['Data'][page[:name]] = pageHash
93
100
 
94
- if newPage
95
- hs['source'] = 1
96
- @pageDatas[page[:name]] = hs
97
- signal_emit :new_page, [page[:name], hs]
101
+ if savePage and newPage
102
+ pageHash['source'] = 1
103
+ @pageDatas[page[:name]] = pageHash
104
+ signal_emit :new_page, [page[:name], pageHash]
98
105
  end
99
106
 
107
+ return pageHash unless savePage
100
108
  fd = File.new @dataFiles.last, File::CREAT|File::TRUNC|File::RDWR, 0644
101
- fd.write JSON.pretty_generate json
109
+ fileData = $etti_developement_version ? JSON.pretty_generate(json) : JSON.fast_generate(json)
110
+ fd.write fileData
102
111
  fd.flush
112
+
113
+ # we need pageHash also in saving the complete document
114
+ pageHash
103
115
  end
104
116
 
105
117
  private
@@ -34,6 +34,28 @@ module Etti
34
34
  end
35
35
 
36
36
 
37
+ def get_user_settings
38
+ settings = {}
39
+ section = @radioRevealer.active
40
+ if section == 0
41
+ settings['section'] = 'enumeration'
42
+ settings['prefix'] = @dataEntries[0].text
43
+ settings['string'] = @dataEntries[1].text
44
+ settings['postfix'] = @dataEntries[2].text
45
+ elsif section == 1
46
+
47
+
48
+ end
49
+ settings
50
+ end
51
+
52
+
53
+ def set_user_settings
54
+
55
+
56
+ end
57
+
58
+
37
59
  def update_data_preview idx
38
60
  # data from enumeration
39
61
  if idx == 0
@@ -65,6 +65,7 @@ module Etti
65
65
  cc.font_size = 16.0
66
66
  cc.show_text text
67
67
  cc.stroke
68
+ # remove this, if we switch to a newer ruby-gtk version dependency, and keep the from_surface call
68
69
  pixbuf = nil
69
70
  if ([2, 2, 2] <=> Gtk::BINDING_VERSION) < 1
70
71
  pixbuf = Gdk::Pixbuf.from_surface surface, 0, 0, ext.width, ext.height * 1.5
@@ -6,24 +6,23 @@ module Etti
6
6
  GetText.bindtextdomain 'etti', :path => Etti::LOCALE_PATH
7
7
 
8
8
  def initialize
9
- super :vertical
10
- @printPageSetup = nil
9
+ super :vertical #:orientation => :vertical
11
10
 
12
- create_toolbar
13
- self.pack_start @toolbar, :expand => false, :fill => false, :padding => 6
14
-
15
11
  hbox = Gtk::Box.new :horizontal
16
12
  self.pack_start hbox, :expand => true, :fill => true
17
-
13
+
18
14
  create_property_view
19
- hbox.pack_start @propertyView, :expand => false, :fill => false
20
-
15
+ hbox.pack_start @propertyView, :expand => false, :fill => false, :padding => 6
16
+
21
17
  paned = Gtk::Paned.new :horizontal
22
18
  hbox.pack_start paned, :expand => true, :fill => true
23
19
 
24
20
  @layoutPreview = Etti::LabelLayout.new @propertyViews
25
21
  paned.pack1 @layoutPreview, :resize => true, :shrink => true
26
-
22
+ # @layoutPreview.signal_connect(:element_count_changed) do |widget, count|
23
+ # @saveButton.sensitive = (count > 0 and @saveButtonActivated)
24
+ # @saveAsButton.sensitive = count > 0
25
+ # end
27
26
 
28
27
  ebox = Gtk::Box.new :horizontal
29
28
 
@@ -36,8 +35,30 @@ module Etti
36
35
  @labelElements = Etti::LabelElements.new
37
36
  ebox.pack_start @labelElements, :expand => true, :fill => true
38
37
  end
38
+ attr_reader :layoutPreview
39
+
40
+ def get_user_settings
41
+ settings = {}
42
+ settings['scale'] = @layoutPreview.scale
43
+ settings['centerX'] = @layoutPreview.centerX
44
+ settings['centerY'] = @layoutPreview.centerY
45
+ elementData = []
46
+ @layoutPreview.elements.each {|element| elementData << element.to_h}
47
+ settings['elements'] = elementData
48
+ end
49
+
50
+ def set_user_settings
51
+
52
+ end
39
53
 
40
54
 
55
+ =begin
56
+ def activate_save state
57
+ @saveButtonActivate = state
58
+ @saveButton.sensitive = (state and @layoutPreview.elements.length() > 0)
59
+ end
60
+ =end
61
+
41
62
  def update_page_data pageData
42
63
  @pageData = pageData
43
64
  @layoutPreview.update_page_data pageData
@@ -83,46 +104,62 @@ module Etti
83
104
  end
84
105
  end
85
106
 
86
-
87
- def create_toolbar
88
- @toolbar = Gtk::Box.new :horizontal
89
107
  =begin
90
- @fontButton = Gtk::FontButton.new
91
- @toolbar.pack_start @fontButton, :expand => false, :fill => false
92
- @fontButton.use_font = true
93
-
94
- texts = ['a'..'z', 'A'..'Z']
95
- text = ''
96
- texts.each {|txt| text += txt.to_a.join}
97
- @fontButton.preview_text = text
98
- =end
108
+ def create_toolbar
109
+ toolbar = Gtk::Box.new :horizontal
110
+ toolbarData = [{:stock => Gtk::Stock::OPEN,
111
+ :method => proc{on_open},
112
+ :tooltip => _('open a new document')},
113
+ {:stock => Gtk::Stock::SAVE,
114
+ :method => proc{on_save true},
115
+ :tooltip => _('save the document')},
116
+ {:stock => Gtk::Stock::SAVE_AS,
117
+ :method => proc{on_save false},
118
+ :tooltip => _('save the document under a new name')},
119
+ {:stock => Gtk::Stock::PRINT,
120
+ :method => proc{on_print},
121
+ :tooltip => _('print the labels')},
122
+ :separator,
123
+ {:stock => Gtk::Stock::ZOOM_IN,
124
+ :method => proc{@layoutPreview.zoom_in},
125
+ :tooltip => _('zoom in')},
126
+ {:stock => Gtk::Stock::ZOOM_OUT,
127
+ :method => proc{@layoutPreview.zoom_out},
128
+ :tooltip => _('zoom out')},
129
+ {:stock => Gtk::Stock::ZOOM_FIT,
130
+ :method => proc{@layoutPreview.zoom_fit},
131
+ :tooltip => _('zoom that all is displayed')}]
132
+ toolbarData.each_with_index do |buttonData, idx|
133
+ if buttonData.is_a? Hash
134
+ button = Gtk::Button.new
135
+ if idx == 1
136
+ @saveButton = button
137
+ button.sensitive = false
138
+ elsif idx == 2
139
+ @saveAsButton = button
140
+ button.sensitive = false
141
+ end
142
+ button.tooltip_text = buttonData[:tooltip]
143
+ button.signal_connect(:clicked) {buttonData[:method].call}
144
+ img = Gtk::Image.new :stock => buttonData[:stock], :size => :large_toolbar
145
+ button << img
146
+ toolbar.pack_start button, :expand => false, :fill => false, :padding => 0
147
+ elsif buttonData.is_a? Symbol
148
+ sep = Gtk::Separator.new :vertical
149
+ toolbar.pack_start sep, :expand => false, :fill => false, :padding => 8
150
+ end
151
+ end
152
+ toolbar
153
+ end
99
154
 
100
- button = Gtk::Button.new
101
- button.signal_connect(:clicked) {@layoutPreview.zoom_in}
102
- img = Gtk::Image.new :stock => Gtk::Stock::ZOOM_IN, :size => :small_toolbar
103
- button << img
104
- @toolbar.pack_start button, :expand => false, :fill => false, :padding => 0
105
-
106
- button = Gtk::Button.new
107
- button.signal_connect(:clicked) {@layoutPreview.zoom_out}
108
- img = Gtk::Image.new :stock => Gtk::Stock::ZOOM_OUT, :size => :small_toolbar
109
- button << img
110
- @toolbar.pack_start button, :expand => false, :fill => false, :padding => 0
111
-
112
- button = Gtk::Button.new
113
- button.signal_connect(:clicked) {@layoutPreview.zoom_fit}
114
- img = Gtk::Image.new :stock => Gtk::Stock::ZOOM_FIT, :size => :small_toolbar
115
- button << img
116
- @toolbar.pack_start button, :expand => false, :fill => false, :padding => 0
117
-
118
- sep = Gtk::Separator.new :vertical
119
- @toolbar.pack_start sep, :expand => false, :fill => false, :padding => 8
120
-
121
- button = Gtk::Button.new
122
- button.signal_connect(:clicked) {on_print}
123
- img = Gtk::Image.new :stock => Gtk::Stock::PRINT, :size => :small_toolbar
124
- button << img
125
- @toolbar.pack_start button, :expand => false, :fill => false, :padding => 0
155
+
156
+ def on_open
157
+ p 'open file'
158
+ end
159
+
160
+
161
+ def on_save same
162
+ signal_emit :save_document, same
126
163
  end
127
164
 
128
165
 
@@ -148,7 +185,7 @@ module Etti
148
185
 
149
186
  ret = printOperation.run :print_dialog, self.toplevel
150
187
 
151
- =begin
188
+ #=begin
152
189
  # only for debugging purpose
153
190
  printOperation.signal_connect('end-print') {print "-=== printing ended\n"}
154
191
 
@@ -187,7 +224,8 @@ module Etti
187
224
  else
188
225
  print "unknown result: ",printr.inspect,"\n"
189
226
  end
190
- =end
227
+ #=end
191
228
  end
229
+ =end
192
230
  end
193
231
  end
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Etti
4
4
  class LabelLayout < Gtk::EventBox
5
+ self.type_register
6
+ self.signal_new :element_count_changed, GLib::Signal::RUN_FIRST, nil, GLib::Type['void'], Integer
7
+ def signal_do_element_count_changed bla; end
8
+
5
9
  include GetText
6
10
  GetText.bindtextdomain 'etti', :path => Etti::LOCALE_PATH
7
11
 
@@ -68,6 +72,7 @@ module Etti
68
72
  @elements << Etti::Element::Text.new(data, cx, cy)
69
73
  end
70
74
  queue_draw
75
+ signal_emit :element_count_changed, @elements.length
71
76
  end
72
77
 
73
78
 
@@ -27,7 +27,7 @@ module Etti
27
27
  self.position = 300
28
28
  end
29
29
 
30
- attr_reader :labelList, :pageData
30
+ attr_reader :labelList, :pageData, :pageDatas
31
31
 
32
32
  def create_label_list
33
33
  @labelListStore = Gtk::ListStore.new String
@@ -51,26 +51,24 @@ module Etti
51
51
 
52
52
 
53
53
  def on_label_list_cursor_changed
54
- name = @labelListStore.get_iter(@labelList.cursor[0]).get_value 0
55
- if @previewArea.entryChanged and @pageData[:name] != name
56
- message = _("The page was changed. Should it be saved?")
57
- dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:yes, :no, :cancel],
58
- :type => :info, :message => message, :title => _('Page was changed')
59
- ret = dialog.run
60
- case ret
61
- when 'cancel'
62
- idx = @pageDatas.get_page_names.index @pageData[:name]
63
- @labelList.selection.select_path Gtk::TreePath.new(idx.to_s)
64
- return
65
- when 'yes'
66
- @previewArea.save
67
- end
54
+ name = @labelListStore.get_iter(@labelList.cursor[0]).get_value 0
55
+ if @previewArea.entryChanged and @pageData[:name] != name
56
+ message = _("The page was changed. Should it be saved?")
57
+ dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:yes, :no, :cancel],
58
+ :type => :info, :message => message, :title => _('Page was changed')
59
+ ret = dialog.run
60
+ case ret
61
+ when 'cancel'
62
+ idx = @pageDatas.get_page_names.index @pageData[:name]
63
+ @labelList.selection.select_path Gtk::TreePath.new(idx.to_s)
64
+ return
65
+ when 'yes'
66
+ @previewArea.save
68
67
  end
69
-
70
-
71
- @pageData = @pageDatas.get_page_data name
72
- signal_emit :page_changed, @pageData
73
- @previewArea.update_page_data @pageData
68
+ end
69
+ @pageData = @pageDatas.get_page_data name
70
+ signal_emit :page_changed, @pageData
71
+ @previewArea.update_page_data @pageData
74
72
  end
75
73
 
76
74
 
@@ -65,6 +65,19 @@ module Etti
65
65
  :tooltip => _('The size of the sheet, i.e. "a4"')}
66
66
  }
67
67
 
68
+ @sheetData = {:cols =>
69
+ {:pos => 0,
70
+ :label => _('columns'),
71
+ :tooltip => _('The number of labels horizontal'),
72
+ :range => 1..100},
73
+ :rows =>
74
+ {:pos => 1,
75
+ :label => _('rows'),
76
+ :tooltip => _('The number of labels vertical'),
77
+ :range => 1..100}
78
+ }
79
+
80
+
68
81
 
69
82
  @sizeGroup = Gtk::SizeGroup.new :both
70
83
  widget = make_entry :name, _('Name'), _("The name of the label\nIt has to be unique")
@@ -91,6 +104,11 @@ module Etti
91
104
  box.pack_start Gtk::Label.new(val[:label]), :expand => false, :fill => false
92
105
 
93
106
  entry = Rgw::RestrictedEntry.new
107
+ if key == :width or key == :height
108
+ entry.editable = false
109
+ entry.sensitive = false
110
+ end
111
+
94
112
  entry.restriction = :float
95
113
  entry.range = val[:range]
96
114
  @entries[key] = entry
@@ -101,17 +119,23 @@ module Etti
101
119
  entry.width_chars = 8
102
120
 
103
121
  entry.tooltip_text = val[:tooltip]
104
- entry.editable = true
105
122
 
106
123
  entry.signal_connect(:changed) {|entry| on_entry_changed entry}
107
124
  end
108
125
 
126
+ # the box below the sheet preview
127
+ bottomBox = Gtk::Box.new :horizontal
128
+ self.pack_start bottomBox, :expand => false, :fill => false
129
+ bottomLeft = Gtk::Box.new :vertical
130
+ bottomBox.pack_start bottomLeft, :expand => false, :fill => false
131
+ bottomRight = Gtk::Box.new :vertical
132
+ bottomBox.pack_start bottomRight, :expand => false, :fill => false, :padding => 64
109
133
 
110
134
  # create the page size combo box
111
135
  val = @descriptionData[:pageSize]
112
136
  cbox = Gtk::Box.new :horizontal
113
- self.pack_start cbox, :expand => false, :fill => false
114
- label = Gtk::Label.new.set_markup(_("<b>%s</b>: " % val[:label]))
137
+ bottomLeft.pack_start cbox, :expand => false, :fill => false
138
+ label = Gtk::Label.new.set_markup("<b>%s</b>: " % val[:label])
115
139
  label.xalign = 0.0
116
140
  cbox.pack_start label, :expand => false, :fill => false, :padding => 6
117
141
  @sizeGroup.add_widget label
@@ -128,8 +152,32 @@ module Etti
128
152
  [:manufacture, :orderNr, :description].each do |key|
129
153
  val = @descriptionData[key]
130
154
  widget = make_entry key, val[:label], val[:tooltip]
131
- self.pack_start widget, :expand => false, :fill => false, :padding => 4
155
+ bottomLeft.pack_start widget, :expand => false, :fill => false, :padding => 4
132
156
  end
157
+
158
+ # create the column and row count display
159
+ rcTable = Gtk::Table.new 3, 2, false
160
+ bottomRight.pack_start rcTable, :expand => false, :fill => false
161
+ @sheetData.each_pair do |key, val|
162
+ label = Gtk::Label.new.set_markup("<b>%s: </b>" % val[:label])
163
+ label.xalign = 0.0
164
+ rcTable.attach_defaults label, 0, 1, val[:pos], val[:pos] + 1
165
+
166
+ entry = Rgw::RestrictedEntry.new
167
+ entry.restriction = :integer
168
+ entry.range = val[:range]
169
+ @entries[key] = entry
170
+ entry.name = key
171
+ rcTable.attach_defaults entry, 1, 2, val[:pos], val[:pos] + 1
172
+
173
+ entry.set_max_length 3
174
+ entry.width_chars = 8
175
+
176
+ entry.tooltip_text = val[:tooltip]
177
+
178
+ entry.signal_connect(:changed) {|entry| on_entry_changed entry}
179
+ end
180
+
133
181
  signal_connect(:map) {on_map}
134
182
  signal_connect(:draw) do |widget|
135
183
  draw_bg
@@ -159,6 +207,10 @@ module Etti
159
207
  w, h = *@pageData[key]
160
208
  @entries[:width].text = @lcNumeric.to_s w
161
209
  @entries[:height].text = @lcNumeric.to_s h
210
+ when :cols
211
+ @entries[:cols].text = @lcNumeric.to_s @pageData[key]
212
+ when :rows
213
+ @entries[:rows].text = @lcNumeric.to_s @pageData[key]
162
214
  when :pageSize
163
215
  @pageSizeCombo.active = @pageSizes.index @pageData[:pageSize]
164
216
  end
@@ -195,6 +247,7 @@ private
195
247
  def on_entry_changed entry
196
248
  return if @pageData.nil?
197
249
  key = entry.name.to_sym
250
+ return if key == :width or key == :height
198
251
  text = @entries[key].text
199
252
  return if text.nil?
200
253
  @entryChanged = true
@@ -216,10 +269,25 @@ private
216
269
  @pageData[:size][0] = val
217
270
  when :height
218
271
  @pageData[:size][1] = val
272
+ when :cols
273
+ @pageData[:cols] = val
274
+ when :rows
275
+ @pageData[:rows] = val
219
276
  end
277
+ recalculate_page_layout
220
278
  end
221
279
 
222
280
 
281
+ def recalculate_page_layout
282
+ pw, ph = *@pageDatas.get_page_dimensions(@pageData[:pageSize])
283
+ labelsWidth = (pw - @pageData[:borders][0] * 2 + @pageData[:padding][0] * 2) / @pageData[:cols]
284
+ labelsHeight = (pw - @pageData[:borders][1] * 2 + @pageData[:padding][1] * 2) / @pageData[:rows]
285
+ @entries[:width].text = @lcNumeric.to_s labelsWidth
286
+ @entries[:height].text = @lcNumeric.to_s labelsHeight
287
+ end
288
+
289
+
290
+
223
291
  def on_save
224
292
  @entries.each do |entry|
225
293
  if entry[1].text.nil?
@@ -228,10 +296,10 @@ private
228
296
  :type => :info, :message => message,
229
297
  :title => _('Invalid Entries')
230
298
  dialog.run
231
- return
299
+ return nil
232
300
  end
233
301
  end
234
- @pageDatas.save_page_data(@pageData) do |type, answers, message|
302
+ return @pageDatas.save_page_data(@pageData, true) do |type, answers, message|
235
303
  if answers == :yes_no
236
304
  dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:yes, :no],
237
305
  :type => :info, :message => message
@@ -1,6 +1,7 @@
1
1
  #encoding: UTF-8
2
2
 
3
3
  module Etti
4
+ DOCUMENT_SUFFIX = 'ettidoc'
4
5
  class Window < Gtk::Window
5
6
  include GetText
6
7
  GetText.bindtextdomain 'etti', :path => Etti::LOCALE_PATH
@@ -9,14 +10,20 @@ module Etti
9
10
  super()
10
11
  signal_connect(:delete_event) {on_quit false}
11
12
  signal_connect(:destroy) {on_quit true}
12
- signal_connect_after(:draw) {paint_logo}
13
13
  self.border_width = 3
14
14
  self.title = 'Etti'
15
15
  set_default_size 1200, 900
16
16
  self.icon = Etti::PIXMAP_PATH + 'win-logo.png'
17
-
18
17
  @logoPixbuf = Gdk::Pixbuf.new Etti::PIXMAP_PATH + 'logo.png'
19
18
 
19
+ # the current document, if is read from a file or already saved
20
+ @document = nil
21
+ @documentFileFilter = Gtk::FileFilter.new
22
+ @documentFileFilter.add_pattern '*\.' + DOCUMENT_SUFFIX
23
+
24
+ @printPageSetup = nil
25
+ @saveButtonActivated = false
26
+
20
27
  @accelGroup = Gtk::AccelGroup.new
21
28
  add_accel_group @accelGroup
22
29
 
@@ -28,15 +35,24 @@ module Etti
28
35
  @labelSelectionPage.signal_connect(:page_changed) do |widget, pageData|
29
36
  @labelLayoutPage.update_page_data pageData
30
37
  end
38
+
39
+ @labelLayoutPage.layoutPreview.signal_connect(:element_count_changed) do |widget, count|
40
+ @saveButton.sensitive = (count > 0 and @saveButtonActivated)
41
+ @saveAsButton.sensitive = count > 0
42
+ end
43
+
31
44
  @labelLayoutPage.update_page_data @labelSelectionPage.pageData
32
45
 
46
+ pile = Rgw::Pile.new
47
+ self.add pile
33
48
  @notebook = Gtk::Notebook.new
34
- add @notebook
49
+ pile.set_child @notebook
50
+ pile.set_pile_child create_toolbar, -24, 6
51
+
35
52
  notebook_append_page @dataPage, _("<b> Data \n Input </b>")
36
53
  notebook_append_page @labelSelectionPage, _("<b> Label \n Selection </b>")
37
54
  notebook_append_page @labelLayoutPage, _("<b> Label \n Formatting </b>")
38
55
  notebook_append_page @aboutPage, _("<b> About Etti </b>")
39
-
40
56
  end
41
57
  attr_reader :dataPage, :labelLayoutPage, :labelSelectionPage
42
58
 
@@ -99,19 +115,184 @@ module Etti
99
115
  end
100
116
 
101
117
 
102
- def on_quit destroy
103
- # @project.save_project
104
- Gtk.main_quit
118
+ def create_toolbar
119
+ vbox = Gtk::Box.new :vertical
120
+ toolbar = Gtk::Box.new :horizontal
121
+
122
+ logo = Gtk::Image.new :pixbuf => @logoPixbuf # Etti::PIXMAP_PATH + 'logo.png'
123
+ toolbar.pack_end logo, :expand => false, :fill => false, :padding => 32
124
+
125
+
126
+ vbox.pack_start toolbar, :expand => false, :fill => false, :padding => 6
127
+ toolbarData = [{:stock => Gtk::Stock::OPEN,
128
+ :method => proc{on_open},
129
+ :tooltip => _('open a new document')},
130
+ {:stock => Gtk::Stock::SAVE,
131
+ :method => proc{on_save true},
132
+ :tooltip => _('save the document')},
133
+ {:stock => Gtk::Stock::SAVE_AS,
134
+ :method => proc{on_save false},
135
+ :tooltip => _('save the document under a new name')},
136
+ {:stock => Gtk::Stock::PRINT,
137
+ :method => proc{on_print},
138
+ :tooltip => _('print the labels')},
139
+ :separator,
140
+ {:stock => Gtk::Stock::ZOOM_IN,
141
+ :method => proc{@labelLayoutPage.layoutPreview.zoom_in},
142
+ :tooltip => _('zoom in')},
143
+ {:stock => Gtk::Stock::ZOOM_OUT,
144
+ :method => proc{@labelLayoutPage.layoutPreview.zoom_out},
145
+ :tooltip => _('zoom out')},
146
+ {:stock => Gtk::Stock::ZOOM_FIT,
147
+ :method => proc{@labelLayoutPage.layoutPreview.zoom_fit},
148
+ :tooltip => _('zoom that all is displayed')}]
149
+ toolbarData.each_with_index do |buttonData, idx|
150
+ if buttonData.is_a? Hash
151
+ button = Gtk::Button.new
152
+ if idx == 1
153
+ @saveButton = button
154
+ button.sensitive = false
155
+ elsif idx == 2
156
+ @saveAsButton = button
157
+ button.sensitive = false
158
+ end
159
+ button.tooltip_text = buttonData[:tooltip]
160
+ button.signal_connect(:clicked) {buttonData[:method].call}
161
+ img = Gtk::Image.new :stock => buttonData[:stock], :size => :large_toolbar
162
+ button << img
163
+ toolbar.pack_start button, :expand => false, :fill => false, :padding => 0
164
+ elsif buttonData.is_a? Symbol
165
+ sep = Gtk::Separator.new :vertical
166
+ toolbar.pack_start sep, :expand => false, :fill => false, :padding => 8
167
+ end
168
+ end
169
+ vbox
105
170
  end
106
171
 
107
172
 
108
- def paint_logo
109
- return if self.window.nil?
110
- cc = window.create_cairo_context
111
- cc.set_source_pixbuf @logoPixbuf, allocation.width - 70, 12
112
- cc.paint
113
- false
173
+ def on_open
174
+
175
+ end
176
+
177
+
178
+ def on_save same
179
+ path = @document
180
+ unless same
181
+ fileChooser = Gtk::FileChooserDialog.new :title => _('Select File'),
182
+ :parent => self.toplevel,
183
+ :action => :save,
184
+ :buttons => [[:cancel, :cancel],
185
+ [:ok, :ok]]
186
+
187
+ fileChooser.filter = @documentFileFilter
188
+ ret = fileChooser.run
189
+ path = fileChooser.filename.clone
190
+ fileChooser.destroy
191
+
192
+ return if ret == Gtk::ResponseType::CANCEL
193
+ return if path.nil?
194
+
195
+ path += '.' + DOCUMENT_SUFFIX unless path.end_with? '.' + DOCUMENT_SUFFIX
196
+
197
+ if File.exist? path
198
+ message = _("Shall the document\n\"%s\"\nbe replaced?") % File.basename(path)
199
+ dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:yes, :cancel],
200
+ :type => :info, :message => message
201
+ ret = dialog.run
202
+ return unless ret == 'yes'
203
+ end
204
+ end
205
+
206
+ @document = path
207
+ activate_save true
208
+
209
+ json = {'Etti' => 'document file', 'Version' => [1, 0]}
210
+ json['UserData'] = @dataPage.get_user_settings
211
+ json['PageData'] = @labelSelectionPage.pageDatas.save_page_data(@labelSelectionPage.pageData, false){}
212
+ json['LabelLayout'] = @labelLayoutPage.get_user_settings
114
213
 
214
+ fd = File.new path, File::CREAT|File::TRUNC|File::RDWR, 0644
215
+ fd.write JSON.pretty_generate(json)
216
+ fd.flush
217
+ end
218
+
219
+
220
+ def activate_save state
221
+ @saveButtonActivate = state
222
+ @saveButton.sensitive = (state and @labelLayoutPage.layoutPreview.elements.length() > 0)
223
+ end
224
+
225
+
226
+ def on_print
227
+ # set the borders from the selected label sheet
228
+ pd = @labelSelectionPage.pageData
229
+ lp = @labelLayoutPage.layoutPreview
230
+ pageSetup = Gtk::PageSetup.new
231
+ pageSetup.set_left_margin pd[:borders][0], :mm
232
+ pageSetup.set_top_margin pd[:borders][1], :mm
233
+ pageSetup.set_right_margin pd[:borders][0], :mm
234
+ pageSetup.set_bottom_margin pd[:borders][1], :mm
235
+
236
+
237
+ printOperation = Gtk::PrintOperation.new
238
+ printOperation.show_progress = true
239
+ printOperation.default_page_setup = pageSetup
240
+ printOperation.n_pages = (lp.elementDataData.length().to_f /
241
+ (pd[:cols] * pd[:rows]).to_f).ceil
242
+
243
+ printOperation.signal_connect('draw-page') do |widget, printContext, pageNumber|
244
+ cc = printContext.cairo_context
245
+ lp.print_labels cc, pageNumber
246
+ end
247
+
248
+ ret = printOperation.run :print_dialog, self.toplevel
249
+
250
+ =begin
251
+ # only for debugging purpose
252
+ printOperation.signal_connect('end-print') {print "-=== printing ended\n"}
253
+
254
+ printOperation.signal_connect('status-changed') do
255
+ case printOperation.status
256
+ when Gtk::PrintOperation::Status::INITIAL
257
+ p 'initial'
258
+ when Gtk::PrintOperation::Status::PREPARING
259
+ p 'preparing'
260
+ when Gtk::PrintOperation::Status::GENERATING_DATA
261
+ p 'GENERATING_DATA'
262
+ when Gtk::PrintOperation::Status::SENDING_DATA
263
+ p 'SENDING_DATA'
264
+ when Gtk::PrintOperation::Status::PENDING
265
+ p 'PENDING'
266
+ when Gtk::PrintOperation::Status::PRINTING
267
+ p 'PRINTING'
268
+ when Gtk::PrintOperation::Status::FINISHED
269
+ p 'FINISHED'
270
+ when Gtk::PrintOperation::Status::FINISHED_ABORTED
271
+ p 'FINISHED_ABORTED'
272
+ else
273
+ 'p unknown'
274
+ end
275
+ end
276
+
277
+ case ret
278
+ when Gtk::PrintOperation::Result::ERROR
279
+ print "error\n"
280
+ when Gtk::PrintOperation::Result::CANCEL
281
+ print "cancelled\n"
282
+ when Gtk::PrintOperation::Result::APPLY
283
+ print "applied\n"
284
+ when Gtk::PrintOperation::Result::IN_PROGRESS
285
+ print "in progress\n"
286
+ else
287
+ print "unknown result: ",printr.inspect,"\n"
288
+ end
289
+ =end
290
+ end
291
+
292
+
293
+ def on_quit destroy
294
+ # @project.save_project
295
+ Gtk.main_quit
115
296
  end
116
297
  end
117
298
  end
data/lib/etti/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Etti
2
- VERSION = [0, 3, 1]
2
+ VERSION = [0, 5, 0]
3
3
  end
data/lib/etti.rb CHANGED
@@ -14,6 +14,7 @@ require 'qrencoder'
14
14
  require 'filemagic'
15
15
 
16
16
  require 'rgw/big-list'
17
+ require 'rgw/pile'
17
18
  require 'rgw/property-editor'
18
19
  require 'rgw/radio-revealer'
19
20
  require 'rgw/restricted-entry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Detlef Reichl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-31 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n-toolbox
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.5'
33
+ version: '0.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.5'
40
+ version: '0.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gettext
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +127,7 @@ files:
127
127
  - COPYING
128
128
  - README.md
129
129
  - bin/etti
130
+ - lib/data/locale/de/LC_MESSAGES/etti.mo
130
131
  - lib/data/page-data.json
131
132
  - lib/data/pixmaps/logo.png
132
133
  - lib/data/pixmaps/logo.svg