Class: Roebe::TakeScreenshot
- Inherits:
-
Base
show all
- Defined in:
- lib/roebe/classes/take_screenshot.rb
Overview
Constant Summary
collapse
- SLEEP_FOR_N_SECONDS =
1.8
- DEFAULT_OUTPUT_FILE =
'screenshot.png'
- SHOW_CLASS_NAME =
true
- OPEN_WITH_THIS_APPLICATION =
#
OPEN_WITH_THIS_APPLICATION
Can be :krita or :gimp or :kolourpaint.
#
:gimp
Constants inherited
from Base
Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE
Class Method Summary
collapse
-
.[](i = ARGV) ⇒ Object
# === Roebe::TakeScreenshot[] ========================================================================= #.
Instance Method Summary
collapse
Methods inherited from Base
#actions, #append_this_onto_that_file, #append_what_into, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow
#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments
Constructor Details
#initialize(i = nil, run_already = true, &block) ⇒ TakeScreenshot
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/roebe/classes/take_screenshot.rb', line 54
def initialize(
i = nil,
run_already = true,
&block
)
register_sigint
reset
if i.to_s.include? 'dont'
i = nil
run_already = false
end
set_input(i)
if block_given?
yielded = yield
if yielded.is_a? Hash
if yielded.has_key? :use_colours
@use_colours = yielded.delete(:use_colours)
elsif yielded.has_key? :use_colors
@use_colours = yielded.delete(:use_colors)
end
if yielded.has_key? :may_we_exit
@shall_we_exit_if_the_import_binary_was_not_found = yielded.delete(:may_we_exit)
end
end
end
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
#
Roebe::TakeScreenshot[]
#
382
383
384
|
# File 'lib/roebe/classes/take_screenshot.rb', line 382
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#be_quiet ⇒ Object
Also known as:
be_silent
144
145
146
|
# File 'lib/roebe/classes/take_screenshot.rb', line 144
def be_quiet
@be_verbose = false
end
|
#be_verbose? ⇒ Boolean
172
173
174
|
# File 'lib/roebe/classes/take_screenshot.rb', line 172
def be_verbose?
@be_verbose
end
|
#check_whether_the_import_binary_exists(shall_we_exit_if_the_import_binary_was_not_found = @shall_we_exit_if_the_import_binary_was_not_found) ⇒ Object
#
check_whether_the_import_binary_exists
#
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
# File 'lib/roebe/classes/take_screenshot.rb', line 352
def check_whether_the_import_binary_exists(
shall_we_exit_if_the_import_binary_was_not_found =
@shall_we_exit_if_the_import_binary_was_not_found
)
does_it_exist = false
path?.each {|this_path|
does_it_exist = true if File.exist?("#{this_path}/import")
}
unless does_it_exist
msg = "No `#{sfancy('import')}` binary was found.".dup
msg << " Exiting now." if shall_we_exit_if_the_import_binary_was_not_found
opne msg
if shall_we_exit_if_the_import_binary_was_not_found
exit
end
end
end
|
#delay=(i) ⇒ Object
Also known as:
set_sleep, set_delay
225
226
227
|
# File 'lib/roebe/classes/take_screenshot.rb', line 225
def delay=(i)
@for_n_seconds = i
end
|
#do_make_screenshot(name_of_the_file = output_file?
) ⇒ Object
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/roebe/classes/take_screenshot.rb', line 270
def do_make_screenshot(
name_of_the_file = output_file?
)
_ = "import -window root #{name_of_the_file}"
esystem _
optimize_this_png_file(name_of_the_file)
if open_with_gimp?
if File.exist? name_of_the_file open_this_file(name_of_the_file)
end
else
open_this_file_with_the_default_application(name_of_the_file)
end
end
|
#do_not_open_in_gimp ⇒ Object
165
166
167
|
# File 'lib/roebe/classes/take_screenshot.rb', line 165
def do_not_open_in_gimp
@open_with_this_application = :krita
end
|
#do_not_open_with_gimp(be_verbose = true) ⇒ Object
#
do_not_open_with_gimp
#
132
133
134
135
136
137
138
139
|
# File 'lib/roebe/classes/take_screenshot.rb', line 132
def do_not_open_with_gimp(
be_verbose = true
)
@open_with_this_application = :krita
if be_verbose
opne 'The image will not be opened via gimp.'
end
end
|
#filename? ⇒ Boolean
Also known as:
input?
196
197
198
|
# File 'lib/roebe/classes/take_screenshot.rb', line 196
def filename?
@input
end
|
#for_n_seconds? ⇒ Boolean
151
152
153
|
# File 'lib/roebe/classes/take_screenshot.rb', line 151
def for_n_seconds?
@for_n_seconds
end
|
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
# File 'lib/roebe/classes/take_screenshot.rb', line 307
def (i)
if i.is_a? Array
i = i.join(' ').strip
end
case i.to_s when /^-?-?no(-|_)?open$/i
@open_with_this_application = nil when /^-?-?no(-|_)?gimp$/i,
'no_gimp'
do_not_open_with_gimp
when /^-?-?delay=(\d+)/
set_delay($1.to_s.dup)
when 'no_gimp_no_sleep'
do_not_open_with_gimp
set_sleep 0
when /^-?-?help$/i
show_help
exit
else
if i and i.include?('.')
_ = File.absolute_path(i)
e "Storing into `#{sfile(_)}`."
set_output_filename(_)
end
end
end
|
#open_this_file(i) ⇒ Object
Also known as:
open_this_file_with_the_default_application
261
262
263
264
265
|
# File 'lib/roebe/classes/take_screenshot.rb', line 261
def open_this_file(i)
if @open_with_this_application
esystem "#{which_application?} #{i}"
end
end
|
#open_with_gimp? ⇒ Boolean
158
159
160
|
# File 'lib/roebe/classes/take_screenshot.rb', line 158
def open_with_gimp?
@open_with_this_application == :gimp
end
|
#open_with_this_application? ⇒ Boolean
Also known as:
which_application?
#
open_with_this_application?
#
125
126
127
|
# File 'lib/roebe/classes/take_screenshot.rb', line 125
def open_with_this_application?
@open_with_this_application
end
|
215
216
217
218
219
220
|
# File 'lib/roebe/classes/take_screenshot.rb', line 215
def opnn
super(
use_colours: @use_colours,
namespace: namespace?
)
end
|
#optimize_this_png_file(i) ⇒ Object
#
optimize_this_png_file
#
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/roebe/classes/take_screenshot.rb', line 179
def optimize_this_png_file(i)
if File.exist? i
if be_verbose?
opnn if SHOW_CLASS_NAME
e "Next optimizing the file `#{sfile(i)}`."
end
ImageParadise::Optimizer.new(i) {{ use_colours: @use_colours }} else
opnn if SHOW_CLASS_NAME
e "Trying to optimize the file at #{sfile(i)} but no "\
"such file exists."
end
end
|
#output_file? ⇒ Boolean
Also known as:
file_location?
254
255
256
|
# File 'lib/roebe/classes/take_screenshot.rb', line 254
def output_file?
@store_into_this_file
end
|
#path? ⇒ Boolean
243
244
245
246
247
248
249
|
# File 'lib/roebe/classes/take_screenshot.rb', line 243
def path?
_ = ENV['PATH'].dup
if _.is_a?(String) and _.include?(':')
_ = _.split(':')
end
return _
end
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/roebe/classes/take_screenshot.rb', line 100
def reset
super()
infer_the_namespace
store_into_this_file(DEFAULT_OUTPUT_FILE)
@for_n_seconds = SLEEP_FOR_N_SECONDS
@open_with_this_application = OPEN_WITH_THIS_APPLICATION
yes_be_verbose
do_use_colours
end
|
373
374
375
376
377
|
# File 'lib/roebe/classes/take_screenshot.rb', line 373
def run
check_whether_the_import_binary_exists
sleep_now
do_make_screenshot
end
|
233
234
235
236
237
238
|
# File 'lib/roebe/classes/take_screenshot.rb', line 233
def set_input(i = '')
i = i.first if i.is_a? Array
i = i.to_s.dup if i
(i)
@input = i end
|
#show_help ⇒ Object
203
204
205
206
207
208
209
210
|
# File 'lib/roebe/classes/take_screenshot.rb', line 203
def show_help
e
' --name # save the name'
' --delay=5 # delay 5 seconds rather than '\
'the default (use any other value here if you want to)'
' --no-gimp # do not use gimp to edit the image afterwards'
e
end
|
#sleep_now ⇒ Object
288
289
290
291
292
293
294
295
|
# File 'lib/roebe/classes/take_screenshot.rb', line 288
def sleep_now
_ = for_n_seconds?.to_i if _ > 0 e "#{rev}Sleeping for #{simp(for_n_seconds?.to_s)} "\
"seconds before taking a screenshot ..."
end
sleep _
end
|
#store_into_this_file(i = DEFAULT_OUTPUT_FILE) ⇒ Object
Also known as:
set_output_filename
300
301
302
|
# File 'lib/roebe/classes/take_screenshot.rb', line 300
def store_into_this_file(i = DEFAULT_OUTPUT_FILE)
@store_into_this_file = i.to_s
end
|