Class: HowtoDialog
Constant Summary
collapse
- PDFViers =
%w"firefox opera epiphany-browser"
- @@GD =
File::expand_path(File::dirname(__FILE__) ) + File::Separator
- @@HOWTO =
$PROG_DIR.dup << '../doc/gui_howto.pdf'
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary
Attributes included from BasicLogging
#log_level, #target
Instance Method Summary
collapse
is_muted?, #log, mute, #set_level, #set_target
language, trl, #trl
Constructor Details
#initialize(options = {}) ⇒ HowtoDialog
Returns a new instance of HowtoDialog.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
|
# File 'lib/gui/HowtoDialog.rb', line 37
def initialize(options = {})
@hdialog = Gtk::Dialog.new()
reader_frame = Gtk::Frame.new(trl('Howto'))
reader_vbox = Gtk::Box.new(:vertical, 5)
reader_vbox.border_width = 5
reader_hbox = Gtk::Box.new(:horizontal, 5)
reader_hbox.border_width = 5
bl_text = trl("Please name the command which starts your PDF viewer (e.g. qpdfview, acroread, evince, display ...).")
reader_label = Gtk::Label.new(bl_text)
reader_label.wrap = true
@reader_entry = Gtk::Entry.new
@reader_entry.width_chars = 33
@reader_entry.height_request = 25
@reader_entry.text = find_reader()
@bc_button = Gtk::Button.new()
@bc_button.add(ButtonLabel.new(trl('_Choose'), "%s/gtk-open.xpm" %@@GD))
reader_vbox.pack_start(reader_label, :expand => false)
reader_hbox.pack_start(@reader_entry, :expand => false)
reader_hbox.pack_start(@bc_button, :expand => false)
reader_vbox.pack_start(reader_hbox, :expand => false)
reader_frame.add(reader_vbox)
button_box = Gtk::ButtonBox.new(:horizontal)
button_box.layout_style = :start
@cancel_button = Gtk::Button.new()
@cancel_button.add(ButtonLabel.new(trl('_Cancel'), "%s/gtk-stop.xpm" %@@GD))
@ok_button = Gtk::Button.new()
@ok_button.add(ButtonLabel.new(trl('_Accept'), "%s/gtk-execute.xpm" %@@GD))
button_box.pack_start(@ok_button, :expand => false)
button_box.pack_start(@cancel_button, :expand => false)
@hdialog.child.pack_start(reader_frame)
@hdialog.child.pack_start(button_box)
@bc_button.set_tooltip_text trl('Choose a PDF viewer')
@reader_entry.set_tooltip_text trl('Command, which starts your PDF viewer')
@cancel_button.set_tooltip_text trl('Close dialog')
@ok_button.set_tooltip_text trl('Executes your PDF-viewer and shows the Howto manual')
connect_buttons
@hdialog.set_title('HOWTO: ' << CremeFraiche::prog_info[:app_name])
@hdialog.child.show_all
@hdialog.signal_connect('response') do |dlg, resp|
debug("response %i emitted" %resp)
@adialog.destroy if(:cancel == resp)
end
if(options && options.keys.include?(:on_destroy))
@hdialog.signal_connect('destroy') {options[:on_destroy].call() }
end
@hdialog.show
end
|
Instance Method Details
#choose_reader ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/gui/HowtoDialog.rb', line 101
def choose_reader
dialog = Gtk::FileChooserDialog.new(:title => trl("set reader"),
:parent => nil,
:action => :open,
:buttons => [[:cancel, :cancel], [:accept, :accept]])
if(@reader_entry.text && ! @reader_entry.text.empty?)
debug('reader is ' << @reader_entry.text)
dialog.filename = @reader_entry.text
end
ret = dialog.run
br = (ret == Gtk::ResponseType::ACCEPT ? dialog.filename : nil)
dialog.destroy
msg = File_Checking.file_check(br, [:exist?, :file?, :executable?]) if br
if(msg)
error(msg)
msg_dialog(msg, DLG_ERROR)
br = nil
end
return br
end
|
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/gui/HowtoDialog.rb', line 124
def connect_buttons
@bc_button.signal_connect("clicked") do
br = choose_reader
@reader_entry.text = br if br
end
@cancel_button.signal_connect("clicked") do
@hdialog.destroy
end
@ok_button.signal_connect("clicked") do
run_reader(@reader_entry.text) if @reader_entry.text
end
end
|
#find_reader ⇒ Object
97
98
99
|
# File 'lib/gui/HowtoDialog.rb', line 97
def find_reader
PDFViers.detect(''){|c| $Progs.include?(c)}
end
|
#msg_dialog(msg, type) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/gui/HowtoDialog.rb', line 163
def msg_dialog(msg, type)
dialog = Gtk::MessageDialog.new(
:parent => nil,
:flags => :destroy_with_parent,
:type => type,
:message => "%s: \"%s\"" %[Translating::trl(type.to_s.upcase), msg])
dialog.set_title(DLG_INFO == type ? 'Info' : 'Error' )
dialog.run
dialog.destroy
return msg
end
|
#run_reader(br) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/gui/HowtoDialog.rb', line 138
def run_reader(br)
msg = nil
if(br && ! br.empty?)
begin
fork_sym = (RUBY_PLATFORM =~ /win/) ? '' : ' &'
exec_command = "%s %s%s" %[br, @@HOWTO, fork_sym]
debug "exec-command will be %s" %exec_command
hr = system exec_command
if(!hr)
msg = trl("Cannot open the PDF viewer!", "\n")
msg += trl("Please verify, that %s is correctly spelled or use another reader.", "\"#{br}\"")
else
@hdialog.destroy
end
rescue Exception => ex
msg = trl("Cannot open the PDF viewer %s", ex)
end
else
msg = trl('No reader selected, skipping Howto.')
end
error(msg) if msg
debug($?.to_s) if @log
msg_dialog(msg, DLG_ERROR) if msg
end
|