Class: Roebe::OnScreenDisplay

Inherits:
Base show all
Defined in:
lib/roebe/classes/on_screen_display.rb

Overview

Roebe::OnScreenDisplay

Constant Summary

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #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, #opnn, #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, #show_help, #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

Methods included from Base::CommandlineArguments

#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(the_string_to_use = 'testing string ...', display_sys_cmd = true, run_already = true) ⇒ OnScreenDisplay

#

initialize

If display_sys_cmd is false, we dont show it.

#


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/roebe/classes/on_screen_display.rb', line 28

def initialize(
    the_string_to_use = 'testing string ...', 
    display_sys_cmd   = true,
    run_already       = true
  )
  reset
  @display_sys_cmd = display_sys_cmd
  set_string(the_string_to_use)
  @sys_cmd << 'osd_cat '
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

Roebe::OnScreenDisplay[]

#


309
310
311
# File 'lib/roebe/classes/on_screen_display.rb', line 309

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#display_sys_cmd?Boolean

#

display_sys_cmd?

#

Returns:

  • (Boolean)


253
254
255
# File 'lib/roebe/classes/on_screen_display.rb', line 253

def display_sys_cmd?
  @display_sys_cmd
end

#generate_random_string(n_times = 6) ⇒ Object

#

generate_random_string

the following method can be used to generate a random string.

#


71
72
73
74
75
76
# File 'lib/roebe/classes/on_screen_display.rb', line 71

def generate_random_string(n_times = 6)
  @string = ''.dup
  n_times.times {
    @string << ALPHABET.sample
  }
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


62
63
64
# File 'lib/roebe/classes/on_screen_display.rb', line 62

def input?
  @input
end

#random_colour?Boolean

#

random_colour?

#

Returns:

  • (Boolean)


81
82
83
# File 'lib/roebe/classes/on_screen_display.rb', line 81

def random_colour?
  ::Colours.random_html_colour?
end

#random_displayObject Also known as: display

#

random_display (random tag rand tag)

Does do random stuff EXCEPT setting the text to send. As you see, the first param doesnt matter at all and can be arbitrary.

#


285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/roebe/classes/on_screen_display.rb', line 285

def random_display
  set_colour('x',true)
  set_position('x',true)
  set_align('x',true)
  set_offset('x',true)
  set_indent('x',true)
  set_indent('x',true)
  set_delay('x',true)
  set_shadowcolour('x',true)
  # set_font('x',T) disabled as of FEB 2011
  set_text
  run_sys_cmd
end

#resetObject

#

reset (reset tag)

#


43
44
45
46
47
48
# File 'lib/roebe/classes/on_screen_display.rb', line 43

def reset
  super()
  infer_the_namespace
  @debug = false # if true we will display more information.
  @sys_cmd = ''.dup
end

#runObject

#

run (run tag)

#


302
303
304
# File 'lib/roebe/classes/on_screen_display.rb', line 302

def run
  generate_random_string if @string.nil?
end

#run_sys_cmdObject

#

run_sys_cmd

#


260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/roebe/classes/on_screen_display.rb', line 260

def run_sys_cmd
  # ======================================================================= #
  # If @display_sys_cmd is false, we dont run the following to the user.
  # ======================================================================= #
  if display_sys_cmd?
    e ' => Running this sys cmd via IO.popen:' if @debug
    e @sys_cmd
  end
  begin
    @osd = IO.popen(@sys_cmd,'w+')
    @osd.puts @string
    @osd.flush
    @osd.close_write
  rescue Errno::ENOENT
    e 'osd_cat does not exist. Consider installing it (Package: xosd).'
    esystem(@sys_cmd)
  end
end

#set_align(which_align = 'left', be_random = false) ⇒ Object

#

set_align

Possible values are left|right|center

#


167
168
169
170
171
172
173
174
175
176
177
# File 'lib/roebe/classes/on_screen_display.rb', line 167

def set_align(which_align = 'left', be_random = false)
  if be_random
    case rand(3)
    when 0 then @sys_cmd << '--align=left '
    when 1 then @sys_cmd << '--align=center '
    when 2 then @sys_cmd << '--align=right '
    end
  else
    @sys_cmd << '--align=' << which_align << ' '
  end
end

#set_colour(which_colour = 'green', be_random = false) ⇒ Object

#

set_colour

#


88
89
90
91
92
93
94
95
96
# File 'lib/roebe/classes/on_screen_display.rb', line 88

def set_colour(
    which_colour = 'green',
    be_random    = false
  )
  if be_random
    which_colour = random_colour?
  end
  @sys_cmd << '--color=' << which_colour << ' '
end

#set_delay(which_delay = '1', be_random = false) ⇒ Object

#

set_delay

Sets time.

#


134
135
136
137
138
139
140
# File 'lib/roebe/classes/on_screen_display.rb', line 134

def set_delay(
    which_delay = '1',
    be_random   = false
  )
  which_delay = rand(35)+10 if be_random
  @sys_cmd << '--delay=' << which_delay.to_s << ' '
end

#set_font(this_font = '-misc-fixed-medium-r-normal--12-100-75-75-c-60-iso8859-1', be_random = true) ⇒ Object

#

set_font

Is handled by –font. Font tag.

Q: How do I find out all fonts on my system?
A: use xfontsel
#


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/roebe/classes/on_screen_display.rb', line 221

def set_font(
    this_font = '-misc-fixed-medium-r-normal--12-100-75-75-c-60-iso8859-1',
    be_random = true
  )
  if be_random
    case rand(4)
    when 0
      @sys_cmd << '--font='<<'-misc-fixed-bold-r-normal--*-*-*-*-c-*-*-*'
    when 1
      @sys_cmd << '--font='<<'-misc-fixed-medium-r-semicondensed--*-*-*-*-c-*-*-*'
    when 2
      @sys_cmd << '--font='<<'-adobe-helvetica-*-*-*-*-26-*-*-*-*-*-*-*'
    #when 3 then @sys_cmd << '--font='<<'-adobe-helvetica-*-*-*-*-38-*-*-*-*-*-*-*'
    when 3
      @sys_cmd << '--font='<<'-*-courier-bold-*-*-*-24-*-*-*-*-*-*-*'
    end
  else
    @sys_cmd << '--font=' << this_font
  end
end

#set_indent(which_indent = '40', be_random = false) ⇒ Object

#

set_indent

#


203
204
205
206
207
208
209
210
211
# File 'lib/roebe/classes/on_screen_display.rb', line 203

def set_indent(which_indent = '40', be_random = false)
  if be_random
    # between 0 and 800 in 20-steps
    which_indent = (which_indent * (rand(3)+1)).to_s
    @sys_cmd << '--indent=' << which_indent << ' '
  else
    @sys_cmd << '--indent=' << which_indent << ' '
  end
end

#set_input(i = '') ⇒ Object

#

set_input

#


53
54
55
56
57
# File 'lib/roebe/classes/on_screen_display.rb', line 53

def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i
end

#set_offset(which_offset = '170', be_random = false) ⇒ Object

#

set_offset

#


182
183
184
185
186
187
188
189
190
# File 'lib/roebe/classes/on_screen_display.rb', line 182

def set_offset(which_offset = '170', be_random = false)
  if be_random
    # between 0 and 800 in 20-steps
    which_offset = which_offset * (rand(35)+1)
    @sys_cmd << '--offset=' << which_offset << ' '
  else
    @sys_cmd << '--offset=' << which_offset << ' '
  end
end

#set_position(which_position = 'top', be_random = false) ⇒ Object

#

set_position

pos tag. Possible arguments are top middle or bottom.

#


147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/roebe/classes/on_screen_display.rb', line 147

def set_position(
    which_position = 'top',
    be_random      = false
  )
  if be_random
    case rand(3)
    when 0 then @sys_cmd << '--pos=top '
    when 1 then @sys_cmd << '--pos=middle '
    when 2 then @sys_cmd << '--pos=bottom '
    end
  else
    @sys_cmd << '--pos=' << which_position << ' '
  end
end

#set_shadow(shadow_size = '1', be_random = false) ⇒ Object

#

set_shadow

Sets shadow size.

#


118
119
120
121
122
123
124
125
126
127
# File 'lib/roebe/classes/on_screen_display.rb', line 118

def set_shadow(
    shadow_size = '1',
    be_random   = false
  )
  if be_random
    limes = 8
    shadow_size = (1..limes).to_a.sample.to_s
  end
  @sys_cmd << '--shadow=' << shadow_size << ' '
end

#set_shadowcolour(which_shadowcolour = '1', be_random = false) ⇒ Object

#

set_shadowcolour

Sets the shadow colour.

#


103
104
105
106
107
108
109
110
111
# File 'lib/roebe/classes/on_screen_display.rb', line 103

def set_shadowcolour(
    which_shadowcolour = '1',
    be_random          = false
  )
  if be_random
    which_shadowcolour = random_colour?
  end
  @sys_cmd << '--shadowcolour=' << which_shadowcolour << ' '
end

#set_string(i) ⇒ Object

#

set_string

#


245
246
247
248
# File 'lib/roebe/classes/on_screen_display.rb', line 245

def set_string(i)
  i = i.join ' ' if i.is_a? Array
  @string = i
end

#set_textObject

#

set_text

#


195
196
197
198
# File 'lib/roebe/classes/on_screen_display.rb', line 195

def set_text
  string_to_be_added = '"'+@string+'" '
  @sys_cmd << '--text='+string_to_be_added
end