etti 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/etti/elements/data.rb +48 -6
- data/lib/etti/elements/text.rb +39 -4
- data/lib/etti/page-datas.rb +25 -1
- data/lib/etti/ui/data-page.rb +36 -5
- data/lib/etti/ui/label-layout-page.rb +43 -138
- data/lib/etti/ui/label-layout.rb +12 -9
- data/lib/etti/ui/label-selection-page.rb +53 -1
- data/lib/etti/ui/message-dialog.rb +8 -1
- data/lib/etti/ui/property-editor-data.rb +4 -1
- data/lib/etti/ui/window.rb +68 -4
- data/lib/etti/version.rb +1 -1
- data/lib/etti.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89d498ee2a421b67fe7a12feb07ddd52235b6c84
|
4
|
+
data.tar.gz: 3c9bfb33e739f40f16d06b4d8361a9cab4f9fb98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85f9d0437799b067274fbde95db136cde8f585184163ea812e996484696f7750cea97e26fa23d214cf5fcf6836db856253719424f49c8d759d6cd584d4c5f043
|
7
|
+
data.tar.gz: 9794973cc6429b7265120b67a7b2e750e94fab7a62d19411cd1b6e7f2046eddc827ebda7acf204e06b6b2affcd8c277c9245d997ab25c2c3a48645c17bad8528
|
data/lib/etti/elements/data.rb
CHANGED
@@ -3,10 +3,14 @@
|
|
3
3
|
module Etti
|
4
4
|
module Element
|
5
5
|
class Data < Etti::Element::Text
|
6
|
+
include GetText
|
7
|
+
GetText.bindtextdomain 'etti', :path => Etti::LOCALE_PATH
|
8
|
+
|
6
9
|
SHOW_AS_TEXT = 0
|
7
10
|
SHOW_AS_QR = 1
|
8
11
|
QR_ERROR_LEVELS = [:low, :medium, :quarter, :high]
|
9
12
|
QR_ENCODING = [:numeric, :alphanumeric, :ascii, :kanji]
|
13
|
+
QR_KEYS = ['dataGroup', 'qrWidth', 'qrHeight', 'qrVersion', 'qrErrorCorrection', 'qrEncoding']
|
10
14
|
def initialize dataGroup, text, x=nil, y=nil, size=nil
|
11
15
|
super text, x, y, size
|
12
16
|
@dataGroup = dataGroup
|
@@ -26,7 +30,11 @@ module Etti
|
|
26
30
|
elsif name == 'qrVersion' then @qrVersion = val.to_i; return;
|
27
31
|
elsif name == 'qrErrorCorrection' then @qrErrorCorrection = QR_ERROR_LEVELS[val.to_i]; return;
|
28
32
|
elsif name == 'qrEncoding' then @qrEncoding = QR_ENCODING[val.to_i]; return;
|
29
|
-
elsif name == '
|
33
|
+
elsif name == 'dataGroup' then @dataGroup = val; return;
|
34
|
+
elsif name == 'showAs'
|
35
|
+
@showAs = (val == SHOW_AS_TEXT or val == 'text') ? SHOW_AS_TEXT : SHOW_AS_QR
|
36
|
+
return;
|
37
|
+
end
|
30
38
|
super name, val
|
31
39
|
end
|
32
40
|
|
@@ -37,22 +45,56 @@ module Etti
|
|
37
45
|
elsif name == 'qrVersion' then return @qrVersion;
|
38
46
|
elsif name == 'qrErrorCorrection' then return QR_ERROR_LEVELS.index @qrErrorCorrection;
|
39
47
|
elsif name == 'qrEncoding' then return QR_ENCODING.index @qrEncoding;
|
40
|
-
elsif name == 'showAs' then return @showAs;
|
48
|
+
elsif name == 'showAs' then return @showAs;
|
49
|
+
elsif name == 'dataGroup' then return @dataGroup; end
|
41
50
|
super name
|
42
51
|
end
|
43
52
|
|
44
53
|
|
45
54
|
def to_h
|
46
|
-
hs =
|
55
|
+
hs = super()
|
56
|
+
hs['elementType'] = 'data'
|
47
57
|
if @showAs == SHOW_AS_TEXT
|
48
58
|
hs['showAs'] = 'text'
|
49
59
|
else
|
50
60
|
hs['showAs'] = 'qr'
|
51
|
-
|
52
|
-
|
61
|
+
QR_KEYS.each {|name| hs[name] = get_by_name name}
|
62
|
+
end
|
63
|
+
hs
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def validate_from_h hs
|
68
|
+
sections = Etti::PropertyEditorData::DATA_PROPS.select{|a| a.key? :revealSections}.first[:revealSections]
|
69
|
+
|
70
|
+
if hs['showAs'] == 'text'
|
71
|
+
return super(hs)
|
72
|
+
elsif hs['showAs'] == 'qr'
|
73
|
+
data = sections.select{|a| a[:section] == 'QR-Code'}.first[:data]
|
74
|
+
# sort out all keys which are no in qrKeys and give them to the parent class
|
75
|
+
keys = hs.keys - QR_KEYS
|
76
|
+
diff = hs.select {|k, v| keys.include? k}
|
77
|
+
ret = super diff
|
78
|
+
return ret if ret
|
79
|
+
|
80
|
+
# check the value of the remaining keys
|
81
|
+
QR_KEYS.each do |name|
|
82
|
+
next if hs[name].nil?
|
83
|
+
if name == 'dataGroup'
|
84
|
+
return _('ElementData invalid type or size for dataGroup') unless hs[name].is_a? String and hs[name].length() > 0
|
85
|
+
next
|
86
|
+
end
|
87
|
+
entry = data.select {|dat| dat[:id0] == name or dat[:id1] == name}
|
88
|
+
if entry[0][:range]
|
89
|
+
return _("ElementData %s is out of range") % name unless entry[0][:range].cover? hs[name]
|
90
|
+
elsif entry[0][:entries]
|
91
|
+
return _("ElementData %s is out of range") % name if hs[name] < 0 or hs[name] >= entry[0][:entries].length
|
92
|
+
end
|
53
93
|
end
|
94
|
+
else
|
95
|
+
return _('ElementData invalid data type')
|
54
96
|
end
|
55
|
-
|
97
|
+
nil
|
56
98
|
end
|
57
99
|
|
58
100
|
|
data/lib/etti/elements/text.rb
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
module Etti
|
4
4
|
module Element
|
5
5
|
class Text < Etti::Element::Base
|
6
|
+
include GetText
|
7
|
+
GetText.bindtextdomain 'etti', :path => Etti::LOCALE_PATH
|
8
|
+
|
9
|
+
TEXT_KEYS = ['text', 'pos_x', 'pos_y', 'size', 'rotation', 'color']
|
10
|
+
GROUP_KEYS = ['elementType', 'dataGroup', 'showAs']
|
6
11
|
def initialize text, x=nil, y=nil, size=nil
|
7
12
|
super x, y
|
8
13
|
@text = text || ''
|
@@ -27,16 +32,46 @@ module Etti
|
|
27
32
|
elsif name == 'size' then return @size;
|
28
33
|
elsif name == 'rotation' then return @rotation;
|
29
34
|
elsif name == 'color' then return @color; end
|
35
|
+
nil
|
30
36
|
end
|
31
37
|
|
32
38
|
|
33
39
|
def to_h
|
40
|
+
# hs = super() # use this if we take data from Element::Base
|
34
41
|
hs = {}
|
35
|
-
['
|
36
|
-
|
37
|
-
end
|
42
|
+
hs['elementType'] = 'text'
|
43
|
+
TEXT_KEYS.each {|name| hs[name] = get_by_name name}
|
38
44
|
hs
|
39
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def validate_from_h hs
|
49
|
+
data = Etti::PropertyEditorData::TEXTS_PROPS
|
50
|
+
# stop if hs has a key that is not in TEXT_KEYS
|
51
|
+
return _('ElementText invalid property keys') if (hs.keys - GROUP_KEYS - TEXT_KEYS).length() > 0
|
52
|
+
# check the value of the keys
|
53
|
+
TEXT_KEYS.each do |name|
|
54
|
+
next if hs[name].nil?
|
55
|
+
entry = data.select {|dat| dat[:id0] == name or dat[:id1] == name}
|
56
|
+
if entry[0][:range]
|
57
|
+
return _("ElementText %s is out of range") % name unless entry[0][:range].cover? hs[name]
|
58
|
+
elsif name == 'text'
|
59
|
+
# we limit the text length to 10_000 chars; for a label thats more than enough
|
60
|
+
return _("ElementText %s length is out of range") % name if hs[name].length() < 1 or hs[name].length > 10_000
|
61
|
+
elsif name == 'color'
|
62
|
+
col = hs[name]
|
63
|
+
return _('ElementText color is invalid') if !col.is_a? Array or col.length() != 4
|
64
|
+
col.each do |val|
|
65
|
+
return _('ElementText invalid value in color') if val < 0.0 or val > 1.0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def from_h hs
|
74
|
+
hs.each_pair {|k, v| set_by_name k, v}
|
40
75
|
end
|
41
76
|
|
42
77
|
|
data/lib/etti/page-datas.rb
CHANGED
@@ -36,7 +36,7 @@ module Etti
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
attr_reader :pageDatas, :pageDimensions
|
40
40
|
|
41
41
|
|
42
42
|
def get_page_names
|
@@ -60,6 +60,26 @@ module Etti
|
|
60
60
|
end
|
61
61
|
|
62
62
|
|
63
|
+
def set_page_data type, data
|
64
|
+
newPage = !@pageDatas.key?(type)
|
65
|
+
if newPage
|
66
|
+
pageHash = {}
|
67
|
+
else
|
68
|
+
pageHash = @pageDatas[type]
|
69
|
+
end
|
70
|
+
FIELDS.each do |key|
|
71
|
+
d = data[key]
|
72
|
+
if d.is_a? Array or d.is_a? String
|
73
|
+
pageHash[key.to_sym] = d.clone
|
74
|
+
else
|
75
|
+
pageHash[key.to_sym] = data[key]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
pageHash[:name] = type
|
79
|
+
signal_emit(:new_page, [type, pageHash]) if newPage
|
80
|
+
end
|
81
|
+
|
82
|
+
|
63
83
|
def get_page_dimensions size
|
64
84
|
@pageDimensions[size]
|
65
85
|
end
|
@@ -104,6 +124,10 @@ module Etti
|
|
104
124
|
signal_emit :new_page, [page[:name], pageHash]
|
105
125
|
end
|
106
126
|
|
127
|
+
unless savePage
|
128
|
+
pageHash['name'] = page[:name]
|
129
|
+
end
|
130
|
+
|
107
131
|
return pageHash unless savePage
|
108
132
|
fd = File.new @dataFiles.last, File::CREAT|File::TRUNC|File::RDWR, 0644
|
109
133
|
fileData = $etti_developement_version ? JSON.pretty_generate(json) : JSON.fast_generate(json)
|
data/lib/etti/ui/data-page.rb
CHANGED
@@ -43,16 +43,47 @@ module Etti
|
|
43
43
|
settings['string'] = @dataEntries[1].text
|
44
44
|
settings['postfix'] = @dataEntries[2].text
|
45
45
|
elsif section == 1
|
46
|
-
|
47
|
-
|
46
|
+
settings['section'] = 'file'
|
47
|
+
settings['fileName'] = @fileButton.filename
|
48
|
+
settings['separator'] = @previewList.separator
|
49
|
+
settings['hasHead'] = @hasHeadCheckButton.active? ? 1 : 0
|
48
50
|
end
|
49
51
|
settings
|
50
52
|
end
|
51
53
|
|
52
54
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
55
|
+
def validate_user_settings settings
|
56
|
+
if settings['section'] == 'enumeration'
|
57
|
+
return _('DataPage prefix is not a String.') unless settings['prefix'].is_a? String
|
58
|
+
return _('DataPage data string is not a String.') unless settings['string'].is_a? String
|
59
|
+
return _('DataPage postfix is not a String.') unless settings['postfix'].is_a? String
|
60
|
+
elsif settings['selection'] == 'file'
|
61
|
+
fn = settings['file']
|
62
|
+
return _('DataPage filename is not a String.') unless fn.is_a? String
|
63
|
+
return _("DataPage file doesn'exist, or is not readable.") unless File.exist? fn and File.readable? fn
|
64
|
+
sep = settings['separator']
|
65
|
+
return _('DataPage separator is not a String') unless sep.is_a? String and @separatorStrings.include? sep
|
66
|
+
hs = settings['hasHead']
|
67
|
+
return _('DataPage has head setting is invalid (not 0 or 1)') unless hs.is_a? Integer and (hs == 0 or hs == 1)
|
68
|
+
else
|
69
|
+
return _('DataPage section is invalid')
|
70
|
+
end
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def set_user_settings settings
|
76
|
+
if settings['section'] == 'enumeration'
|
77
|
+
@radioRevealer.active = 0
|
78
|
+
@dataEntries[0].text = settings['prefix']
|
79
|
+
@dataEntries[1].text = settings['string']
|
80
|
+
@dataEntries[2].text = settings['postfix']
|
81
|
+
else
|
82
|
+
@radioRevealer.active = 0
|
83
|
+
@fileButton.filename = settings['fileName']
|
84
|
+
@fileSeparatorCombo.active = @separatorStrings.index settings['separator']
|
85
|
+
@hasHeadCheckButton.active = settings['hasHead'] == 1
|
86
|
+
end
|
56
87
|
end
|
57
88
|
|
58
89
|
|
@@ -19,13 +19,8 @@ module Etti
|
|
19
19
|
|
20
20
|
@layoutPreview = Etti::LabelLayout.new @propertyViews
|
21
21
|
paned.pack1 @layoutPreview, :resize => true, :shrink => true
|
22
|
-
# @layoutPreview.signal_connect(:element_count_changed) do |widget, count|
|
23
|
-
# @saveButton.sensitive = (count > 0 and @saveButtonActivated)
|
24
|
-
# @saveAsButton.sensitive = count > 0
|
25
|
-
# end
|
26
22
|
|
27
23
|
ebox = Gtk::Box.new :horizontal
|
28
|
-
|
29
24
|
paned.pack2 ebox, :resize => false, :shrink => false
|
30
25
|
|
31
26
|
label = Gtk::Label.new _(' Drag the elements over ')
|
@@ -37,6 +32,7 @@ module Etti
|
|
37
32
|
end
|
38
33
|
attr_reader :layoutPreview
|
39
34
|
|
35
|
+
|
40
36
|
def get_user_settings
|
41
37
|
settings = {}
|
42
38
|
settings['scale'] = @layoutPreview.scale
|
@@ -45,19 +41,52 @@ module Etti
|
|
45
41
|
elementData = []
|
46
42
|
@layoutPreview.elements.each {|element| elementData << element.to_h}
|
47
43
|
settings['elements'] = elementData
|
48
|
-
|
49
|
-
|
50
|
-
def set_user_settings
|
51
|
-
|
44
|
+
settings
|
52
45
|
end
|
53
46
|
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
def validate_user_settings settings
|
49
|
+
return _('LabelLayout scale is not a Numeric') unless settings['scale'].is_a? Numeric
|
50
|
+
return _('LabelLayout scale is out of range') if settings['scale'] < Etti::LabelLayout::SCALE_MIN or
|
51
|
+
settings['scale'] > Etti::LabelLayout::SCALE_MAX
|
52
|
+
return _('LabelLayout centerX is not a Numeric') unless settings['centerX'].is_a? Numeric
|
53
|
+
return _('LabelLayout centerY is not a Numeric') unless settings['centerY'].is_a? Numeric
|
54
|
+
return _('LabelLayout elements is not an Array') unless settings['elements'].is_a? Array
|
55
|
+
settings['elements'].each do |element|
|
56
|
+
el = nil
|
57
|
+
if element['elementType'] == 'text'
|
58
|
+
el = Etti::Element::Text.new 'vali'
|
59
|
+
elsif element['elementType'] == 'data'
|
60
|
+
el = Etti::Element::Data.new :dg, 'vali'
|
61
|
+
else
|
62
|
+
return _("LabelLayout element type %s is unknown") % element['elementType'].to_s
|
63
|
+
end
|
64
|
+
ret = el.validate_from_h element
|
65
|
+
return ret if ret
|
66
|
+
end
|
67
|
+
nil
|
59
68
|
end
|
60
|
-
|
69
|
+
|
70
|
+
|
71
|
+
def set_user_settings settings
|
72
|
+
@layoutPreview.scale = settings['scale']
|
73
|
+
@layoutPreview.centerX = settings['centerX']
|
74
|
+
@layoutPreview.centerY = settings['centerY']
|
75
|
+
|
76
|
+
@layoutPreview.elements.clear
|
77
|
+
|
78
|
+
settings['elements'].each do |element|
|
79
|
+
el = nil
|
80
|
+
if element['elementType'] == 'text'
|
81
|
+
el = Etti::Element::Text.new element['text']
|
82
|
+
elsif element['elementType'] == 'data'
|
83
|
+
el = Etti::Element::Data.new element['dataGroup'], element['text']
|
84
|
+
end
|
85
|
+
el.from_h element
|
86
|
+
@layoutPreview.elements << el
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
61
90
|
|
62
91
|
def update_page_data pageData
|
63
92
|
@pageData = pageData
|
@@ -103,129 +132,5 @@ module Etti
|
|
103
132
|
end
|
104
133
|
end
|
105
134
|
end
|
106
|
-
|
107
|
-
=begin
|
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
|
154
|
-
|
155
|
-
|
156
|
-
def on_open
|
157
|
-
p 'open file'
|
158
|
-
end
|
159
|
-
|
160
|
-
|
161
|
-
def on_save same
|
162
|
-
signal_emit :save_document, same
|
163
|
-
end
|
164
|
-
|
165
|
-
|
166
|
-
def on_print
|
167
|
-
# set the borders from the selected label sheet
|
168
|
-
pageSetup = Gtk::PageSetup.new
|
169
|
-
pageSetup.set_left_margin @pageData[:borders][0], :mm
|
170
|
-
pageSetup.set_top_margin @pageData[:borders][1], :mm
|
171
|
-
pageSetup.set_right_margin @pageData[:borders][0], :mm
|
172
|
-
pageSetup.set_bottom_margin @pageData[:borders][1], :mm
|
173
|
-
|
174
|
-
|
175
|
-
printOperation = Gtk::PrintOperation.new
|
176
|
-
printOperation.show_progress = true
|
177
|
-
printOperation.default_page_setup = pageSetup
|
178
|
-
printOperation.n_pages = (@layoutPreview.elementDataData.length().to_f /
|
179
|
-
(@pageData[:cols] * @pageData[:rows]).to_f).ceil
|
180
|
-
|
181
|
-
printOperation.signal_connect('draw-page') do |widget, printContext, pageNumber|
|
182
|
-
cc = printContext.cairo_context
|
183
|
-
@layoutPreview.print_labels cc, pageNumber
|
184
|
-
end
|
185
|
-
|
186
|
-
ret = printOperation.run :print_dialog, self.toplevel
|
187
|
-
|
188
|
-
#=begin
|
189
|
-
# only for debugging purpose
|
190
|
-
printOperation.signal_connect('end-print') {print "-=== printing ended\n"}
|
191
|
-
|
192
|
-
printOperation.signal_connect('status-changed') do
|
193
|
-
case printOperation.status
|
194
|
-
when Gtk::PrintOperation::Status::INITIAL
|
195
|
-
p 'initial'
|
196
|
-
when Gtk::PrintOperation::Status::PREPARING
|
197
|
-
p 'preparing'
|
198
|
-
when Gtk::PrintOperation::Status::GENERATING_DATA
|
199
|
-
p 'GENERATING_DATA'
|
200
|
-
when Gtk::PrintOperation::Status::SENDING_DATA
|
201
|
-
p 'SENDING_DATA'
|
202
|
-
when Gtk::PrintOperation::Status::PENDING
|
203
|
-
p 'PENDING'
|
204
|
-
when Gtk::PrintOperation::Status::PRINTING
|
205
|
-
p 'PRINTING'
|
206
|
-
when Gtk::PrintOperation::Status::FINISHED
|
207
|
-
p 'FINISHED'
|
208
|
-
when Gtk::PrintOperation::Status::FINISHED_ABORTED
|
209
|
-
p 'FINISHED_ABORTED'
|
210
|
-
else
|
211
|
-
'p unknown'
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
case ret
|
216
|
-
when Gtk::PrintOperation::Result::ERROR
|
217
|
-
print "error\n"
|
218
|
-
when Gtk::PrintOperation::Result::CANCEL
|
219
|
-
print "cancelled\n"
|
220
|
-
when Gtk::PrintOperation::Result::APPLY
|
221
|
-
print "applied\n"
|
222
|
-
when Gtk::PrintOperation::Result::IN_PROGRESS
|
223
|
-
print "in progress\n"
|
224
|
-
else
|
225
|
-
print "unknown result: ",printr.inspect,"\n"
|
226
|
-
end
|
227
|
-
#=end
|
228
|
-
end
|
229
|
-
=end
|
230
135
|
end
|
231
136
|
end
|
data/lib/etti/ui/label-layout.rb
CHANGED
@@ -57,7 +57,8 @@ module Etti
|
|
57
57
|
@width = nil
|
58
58
|
@height = nil
|
59
59
|
end
|
60
|
-
attr_reader :backBuffer, :
|
60
|
+
attr_reader :backBuffer, :elementDataData
|
61
|
+
attr_accessor :scale, :centerX, :centerY, :elements
|
61
62
|
|
62
63
|
|
63
64
|
def on_drag_drop context, x, y
|
@@ -194,7 +195,7 @@ module Etti
|
|
194
195
|
h = @pageData[:size][1] * 2.8346457
|
195
196
|
|
196
197
|
sl = (@pageData[:cols] * @pageData[:rows]) * page
|
197
|
-
el = elementDataData.length
|
198
|
+
el = @elementDataData.length
|
198
199
|
labels = el - sl
|
199
200
|
|
200
201
|
idc = []
|
@@ -277,13 +278,15 @@ module Etti
|
|
277
278
|
minY = 2**31
|
278
279
|
maxY = - 2**31
|
279
280
|
|
280
|
-
@
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
281
|
+
if @backBuffer
|
282
|
+
@elements.each do |element|
|
283
|
+
ext = element.get_extent self
|
284
|
+
# TODO use min max methodes
|
285
|
+
minX = ext.x if ext.x < minX
|
286
|
+
minY = ext.y if ext.y < minY
|
287
|
+
maxX = ext.x + ext.width if ext.x + ext.width > maxX
|
288
|
+
maxY = ext.y + ext.height if ext.y + ext.height > maxY
|
289
|
+
end
|
287
290
|
end
|
288
291
|
|
289
292
|
# get the label in
|
@@ -29,6 +29,58 @@ module Etti
|
|
29
29
|
|
30
30
|
attr_reader :labelList, :pageData, :pageDatas
|
31
31
|
|
32
|
+
|
33
|
+
def get_user_settings
|
34
|
+
@pageDatas.save_page_data(@pageData, false){}
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def validate_user_settings settings
|
39
|
+
settings.keys.each do |key|
|
40
|
+
unless Etti::PageDatas::FIELDS.include? key.to_sym
|
41
|
+
next if key == 'source' or key == 'name'
|
42
|
+
return _("PageData has invalid property key %s") % key.to_s
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
[:manufacture, :orderNr, :description, :name].each do |label|
|
47
|
+
val = settings[label.to_s]
|
48
|
+
next if val.nil?
|
49
|
+
return _("PageData %s is invalid") % label unless val.is_a? String
|
50
|
+
return _('PageData name is invalid') if label == :name and val.length() < 1
|
51
|
+
end
|
52
|
+
[:cols, :rows].each do |label|
|
53
|
+
val = settings[label.to_s]
|
54
|
+
next if val.nil?
|
55
|
+
return _("PageData %s is invalid") % label unless val.is_a? Numeric and val > 0.0
|
56
|
+
end
|
57
|
+
[:size, :borders, :padding].each do |label|
|
58
|
+
val = settings[label.to_s]
|
59
|
+
next if val.nil?
|
60
|
+
return _("PageData %s is invalid") % label unless val.is_a? Array and val.length() == 2
|
61
|
+
return _("PageData %s is invalid") % label unless val[0].is_a? Numeric and val[1].is_a? Numeric and val[0] >= 0 and val[1] >= 0
|
62
|
+
end
|
63
|
+
return _('PageData pageSize is invalid') unless @pageDatas.pageDimensions.include? settings['pageSize']
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def set_user_settings settings
|
69
|
+
name = settings['name']
|
70
|
+
@pageDatas.set_page_data name, settings
|
71
|
+
pt = nil
|
72
|
+
@labelListStore.each do |model, path, iter|
|
73
|
+
if iter[0] == name
|
74
|
+
@labelList.selection.select_path path
|
75
|
+
# We have to call the update manualy, because sometimes the :cursor_changed signal
|
76
|
+
# not emited.
|
77
|
+
on_label_list_cursor_changed
|
78
|
+
return
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
32
84
|
def create_label_list
|
33
85
|
@labelListStore = Gtk::ListStore.new String
|
34
86
|
@labelList = Gtk::TreeView.new @labelListStore
|
@@ -51,7 +103,7 @@ module Etti
|
|
51
103
|
|
52
104
|
|
53
105
|
def on_label_list_cursor_changed
|
54
|
-
name = @labelListStore.
|
106
|
+
name = @labelListStore.get_value @labelList.selection.selected, 0
|
55
107
|
if @previewArea.entryChanged and @pageData[:name] != name
|
56
108
|
message = _("The page was changed. Should it be saved?")
|
57
109
|
dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:yes, :no, :cancel],
|
@@ -26,7 +26,7 @@ module Etti
|
|
26
26
|
if flags[:buttons]
|
27
27
|
@buttonBox = Gtk::Box.new :horizontal
|
28
28
|
@buttonBox.homogeneous = true
|
29
|
-
@vbox.
|
29
|
+
@vbox.pack_end @buttonBox, :expand => false, :fill => false
|
30
30
|
|
31
31
|
flags[:buttons].each do |btn|
|
32
32
|
stock = case btn
|
@@ -77,6 +77,13 @@ module Etti
|
|
77
77
|
@hbox.pack_start label, :expand => true, :fill => true, :padding => 12
|
78
78
|
end
|
79
79
|
|
80
|
+
|
81
|
+
if flags[:additional]
|
82
|
+
label = Gtk::Label.new flags[:additional]
|
83
|
+
@vbox.pack_start label, :expand => true, :fill => true, :padding => 12
|
84
|
+
end
|
85
|
+
|
86
|
+
|
80
87
|
if flags[:remind]
|
81
88
|
|
82
89
|
end
|
@@ -29,7 +29,10 @@ module Etti
|
|
29
29
|
|
30
30
|
{label: _('rotation'), type: :spin, useDefault: true,
|
31
31
|
id0: 'rotation', range: 0.0..360.0, step: 1.0,
|
32
|
-
default0: DEFAULT_TEXTS_ROTATION}
|
32
|
+
default0: DEFAULT_TEXTS_ROTATION},
|
33
|
+
|
34
|
+
{label: _('color'), type: :color, useDefault: true,
|
35
|
+
id0: 'color', default0: DEFAUTL_TEXTS_COLOR},
|
33
36
|
]
|
34
37
|
|
35
38
|
|
data/lib/etti/ui/window.rb
CHANGED
@@ -171,14 +171,78 @@ module Etti
|
|
171
171
|
|
172
172
|
|
173
173
|
def on_open
|
174
|
-
|
174
|
+
fileChooser = Gtk::FileChooserDialog.new :title => _('Open File'),
|
175
|
+
:parent => self.toplevel,
|
176
|
+
:action => :open,
|
177
|
+
:buttons => [[:cancel, :cancel],
|
178
|
+
[:ok, :ok]]
|
179
|
+
|
180
|
+
fileChooser.filter = @documentFileFilter
|
181
|
+
ret = fileChooser.run
|
182
|
+
path = fileChooser.filename.clone
|
183
|
+
fileChooser.destroy
|
184
|
+
|
185
|
+
return if ret == Gtk::ResponseType::CANCEL
|
186
|
+
return if path.nil?
|
187
|
+
|
188
|
+
@document = path
|
189
|
+
activate_save true
|
190
|
+
|
191
|
+
data = File.new(path).read
|
192
|
+
|
193
|
+
begin
|
194
|
+
json = JSON.parse data
|
195
|
+
rescue JSON::ParserError => additional
|
196
|
+
message = _("The document contains errors\nMessage from the file reader:")
|
197
|
+
|
198
|
+
dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:close],
|
199
|
+
:type => :info, :message => message,
|
200
|
+
:title => _('Invalid Entries'),
|
201
|
+
:additional => additional.to_s
|
202
|
+
dialog.run
|
203
|
+
return
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
unless json['Etti'] == 'document file'
|
208
|
+
message = _("The document file\n\"%s\"\nis not a valid etti document") % path
|
209
|
+
dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:close],
|
210
|
+
:type => :info, :message => message,
|
211
|
+
:title => _('Invalid Entries')
|
212
|
+
dialog.run
|
213
|
+
return
|
214
|
+
end
|
215
|
+
|
216
|
+
# restore all settings
|
217
|
+
sdat = [[@dataPage, json['UserData']],
|
218
|
+
[@labelLayoutPage, json['LabelLayout']],
|
219
|
+
[@labelSelectionPage, json['PageData']]]
|
220
|
+
return if validate_settings sdat
|
221
|
+
sdat.each {|section| section[0].send :set_user_settings, section[1]}
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
def validate_settings data
|
226
|
+
data.each do |section|
|
227
|
+
ret = section[0].send :validate_user_settings, section[1]
|
228
|
+
if ret
|
229
|
+
message = _('The file could not be loaded.')
|
230
|
+
dialog = Etti::MessageDialog.new self.toplevel, :buttons => [:close],
|
231
|
+
:type => :error, :message => message,
|
232
|
+
:title => _('File load error'),
|
233
|
+
:additional => ret
|
234
|
+
dialog.run
|
235
|
+
return true
|
236
|
+
end
|
237
|
+
end
|
238
|
+
false
|
175
239
|
end
|
176
240
|
|
177
241
|
|
178
242
|
def on_save same
|
179
243
|
path = @document
|
180
244
|
unless same
|
181
|
-
fileChooser = Gtk::FileChooserDialog.new :title => _('
|
245
|
+
fileChooser = Gtk::FileChooserDialog.new :title => _('Save File'),
|
182
246
|
:parent => self.toplevel,
|
183
247
|
:action => :save,
|
184
248
|
:buttons => [[:cancel, :cancel],
|
@@ -208,11 +272,11 @@ module Etti
|
|
208
272
|
|
209
273
|
json = {'Etti' => 'document file', 'Version' => [1, 0]}
|
210
274
|
json['UserData'] = @dataPage.get_user_settings
|
211
|
-
json['PageData'] = @labelSelectionPage.
|
275
|
+
json['PageData'] = @labelSelectionPage.get_user_settings
|
212
276
|
json['LabelLayout'] = @labelLayoutPage.get_user_settings
|
213
277
|
|
214
278
|
fd = File.new path, File::CREAT|File::TRUNC|File::RDWR, 0644
|
215
|
-
fd.write JSON.pretty_generate(json)
|
279
|
+
fd.write JSON.pretty_generate(json, :indent => ' ')
|
216
280
|
fd.flush
|
217
281
|
end
|
218
282
|
|
data/lib/etti/version.rb
CHANGED
data/lib/etti.rb
CHANGED
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.
|
4
|
+
version: 0.6.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-06-
|
11
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n-toolbox
|