Class: Roebe::GUI::PingWidget

Inherits:
Base show all
Includes:
UniversalWidgets::BaseModule
Defined in:
lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb

Overview

Roebe::GUI::PingWidget

Constant Summary collapse

TITLE =
#

TITLE

#
'Ping Widget'
WIDTH =
#

WIDTH

#
'35% or minimum 250px'
HEIGHT =
#

HEIGHT

#
'20% or minimum 150px'
USE_THIS_FONT =
#

USE_THIS_FONT

#
:dejavu_condensed_19
USE_THIS_SMALLER_FONT =
#

USE_THIS_SMALLER_FONT

#
:dejavu_condensed_17
ARRAY_PREDEFINED_REMOTE_URLS =
#

ARRAY_PREDEFINED_REMOTE_URLS

#
%w(
  https://github.com/AndyObtiva/
  https://www.derstandard.at/
  https://www.linuxfromscratch.org/blfs/view/svn/introduction/changelog.html
  https://ftp.gnu.org/pub/gnu/?C=M;O=D
  https://download.gnome.org/sources/?C=M;O=D
)

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(commandline_arguments = ARGV, run_already = true) ⇒ PingWidget

#

initialize

#


87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 87

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  determine_the_GUI_to_be_used(commandline_arguments) # This must come first, even before reset().
  # super(:vertical)
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

Roebe::GUI::PingWidget[]

#


526
527
528
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 526

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

.run(i = ARGV) ⇒ Object

#

Roebe::GUI::PingWidget.run

#


533
534
535
536
537
538
539
540
541
542
543
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 533

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = Gtk::PingWidget.new(i)
  r = ::Gtk.run
  r << _
  r.automatic_size_then_automatic_title
  r.enable_quick_exit
  r.top_left_then_run
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


289
290
291
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 289

def border_size?
  2
end

#button1Object

#

button1

#


303
304
305
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 303

def button1
  e 'This is button1.'
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#


386
387
388
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 386

def connect_skeleton
  abort_on_exception
end

#create_the_buttonsObject

#

create_the_buttons (buttons tag, button tag)

#


310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 310

def create_the_buttons
  # ======================================================================= #
  # === @button_do_the_ping_action
  # ======================================================================= #
  @button_do_the_ping_action = return_button1
  # ======================================================================= #
  # === @button_open_in_the_browser
  # ======================================================================= #
  @button_open_in_the_browser = return_button2
  @button_open_in_the_browser.hint =
    'This button will attempt to open the assigned entry in the '\
    'browser. The browser that will be used is <b>'+
    ::Open.use_which_browser?+'</b>.'
  do_style_the_buttons_in_a_uniform_manner
end

#create_the_entriesObject

#

create_the_entries (entries tag, entry tag)

#


393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 393

def create_the_entries
  # ======================================================================= #
  # === @entry_use_this_URL
  # ======================================================================= #
  @entry_use_this_URL = create_entry
  @entry_use_this_URL.bblack2
  @entry_use_this_URL.yellow_background
  # @entry_use_this_URL.on_click_select_everything
  # ^^^ this does not work that well.
  @entry_use_this_URL.on_enter {
    @entry_use_this_URL.strip!
    do_the_ping_action
  }
  @entry_use_this_URL.width_height(600, 50)
  @entry_use_this_URL.respond_to_scroll_events
  @entry_use_this_URL.use_this_font = return_smaller_font
  @entry_use_this_URL.hint =
    "Input a remote URL here, which will be the URL that we wish "\
    "to check, via a ping-event.\n\n"+
    "Additional information will then be shown in the area below "\
    "this entry.\n"
  if @entry_use_this_URL.respond_to? :shadow_hint=
    # ===================================================================== #
    # This here works only on ruby-gtk3.
    # ===================================================================== #
    @entry_use_this_URL.shadow_hint = 'Input a remote URL here.'
  end
end

#create_the_labelsObject

#

create_the_labels

#


166
167
168
169
170
171
172
173
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 166

def create_the_labels
  # ======================================================================= #
  # === @label_for_the_connection_status
  # ======================================================================= #
  @label_for_the_connection_status = label
  @label_for_the_connection_status.make_selectable
  @label_for_the_connection_status.use_this_font = return_smaller_font
end

#create_the_skeletonObject Also known as: create_skeleton

#

create_the_skeleton (create tag, skeleton tag)

#


342
343
344
345
346
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 342

def create_the_skeleton
  create_the_entries # Should come first here.
  create_the_buttons
  create_the_labels
end

#do_clear_the_main_entryObject

#

do_clear_the_main_entry

#


159
160
161
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 159

def do_clear_the_main_entry
  entry_URL?.clear
end

#do_open_in_the_browser(use_this_url = @entry_use_this_URL.text?) ⇒ Object

#

do_open_in_the_browser (open tag)

#


219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 219

def do_open_in_the_browser(
    use_this_url = @entry_use_this_URL.text?
  )
  begin
    try_to_require_the_open_gem unless Object.const_defined?(:Open)
    if use_this_url.empty?
      notify_the_user_that_the_URL_may_not_be_empty
    else
      Open.in_browser(use_this_url)
    end
  rescue LoadError
    e 'The open gem is not available. Please install it.'
  end
end

#do_style_the_buttons_in_a_uniform_mannerObject

#

do_style_the_buttons_in_a_uniform_manner

This will include and on-hover-ligthblue-colour and bblack3.

#


331
332
333
334
335
336
337
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 331

def do_style_the_buttons_in_a_uniform_manner
  return_all_buttons.each {|this_button|
    this_button.clear_background
    this_button.on_hover(:lightblue)
    this_button.bblack3
  }
end

#do_the_ping_action(use_this_url = remote_URL? ) ⇒ Object

#

do_the_ping_action

#


351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 351

def do_the_ping_action(
    use_this_url = remote_URL?
  )
  start_the_spinner
  Thread.new {
    unless use_this_url.empty?
      @array_we_pinged_these_remote_URLs << use_this_url
    end
    up_or_down = is_it_up?(use_this_url)
    case up_or_down
    # === :up
    when true,  :up
      the_signal_image_is_now_green
    # === :down
    when false, :down
      the_signal_image_is_now_red
    end
    _ = 'Is a connection available to <b>'+
        remote_URL?+'</b>? <span weight="bold" color="darkblue">'+
        VerboseTruth[up_or_down].to_s+
        '</span>'.dup
    if up_or_down
      _ << return_string_for_remote_address(remote_URL?)+"\n"
    end
    # _ << return_information_obtained_via_curl(@the_IP_is)
    _ = 'Please assign a remote host in the input area above.' if use_this_url.empty?
    @label_for_the_connection_status.set_text(_)
    @label_for_the_connection_status.do_markify
    @spinner.stop_spinning
  }
end

#entry_URL?Boolean Also known as: entry_use_this_URL?, main_entry?

#

entry_URL?

#

Returns:

  • (Boolean)


201
202
203
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 201

def entry_URL?
  @entry_use_this_URL
end

#handle_CSS_rulesObject

#

handle_CSS_rules

#


152
153
154
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 152

def handle_CSS_rules
  use_gtk_paradise_project_css_file
end

#is_it_up?(host) ⇒ Boolean

#

is_it_up?

#

Returns:

  • (Boolean)


237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 237

def is_it_up?(host)
  if Object.const_defined? :Net
    check = Net::Ping::External.new(host)
    return check.ping?
  else
    use_this_text = text("Net::Ping::External is unavailable. "\
      "Has the <b>net-ping gem</b> been installed?\n\n"\
      "Consider installing it via:\n\n  <b>gem install net-ping</b>\n\n"\
      "Alternatively click the button below, which will "\
      "try to invoke that command.\n"
    )
    use_this_text.make_selectable
    _ = @base_box.popup_this_text_over_that_widget(
      use_this_text,
      entry_use_this_URL?
    )
    use_this_text.deselect
    vbox = create_vbox
    # === button_gem_install_net_ping
    button_gem_install_net_ping = button('gem install net-ping')
    button_gem_install_net_ping.on_clicked {
      esystem button_gem_install_net_ping.text?
      try_to_require_net_ping
    }
    vbox.add(button_gem_install_net_ping)
    vbox.show_all
    _.children.first.add(vbox)
    _.margin = 6
    _.bblack3
    _.pad10px
    _.use_this_font = :hack_18
    _.popup
  end
end

#let_the_main_entry_respond_to_scroll_eventsObject

#

let_the_main_entry_respond_to_scroll_events

#


209
210
211
212
213
214
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 209

def let_the_main_entry_respond_to_scroll_events
  @entry_use_this_URL.on_scrolling {
    sample_result = ARRAY_PREDEFINED_REMOTE_URLS.sample
    set_main_URL(sample_result) 
  }
end

#notify_the_user_that_the_URL_may_not_be_emptyObject

#

notify_the_user_that_the_URL_may_not_be_empty

#


133
134
135
136
137
138
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 133

def notify_the_user_that_the_URL_may_not_be_empty
  @base_box.popup_this_text_over_that_widget(
    ' Please provide a remote URL here. ',
    entry_URL?
  )
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


282
283
284
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 282

def padding?
  4
end

#remote_URL?Boolean

#

remote_URL?

#

Returns:

  • (Boolean)


425
426
427
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 425

def remote_URL?
  @entry_use_this_URL.text.to_s.strip # We don't want leading or trailing ' ' here.
end

#resetObject

#

reset (reset tag)

#


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 103

def reset
  super() if respond_to?(:super)
  reset_the_internal_variables
  infer_the_namespace
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, namespace?]
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  # ======================================================================= #
  # === @array_we_pinged_these_remote_URLs
  #
  # Keep track of all pinged remote URLs. Perhaps we may save this one
  # day. For now it is not in use otherwise, though.
  # ======================================================================= #
  @array_we_pinged_these_remote_URLs = []
  # ======================================================================= #
  # === @the_IP_is
  # ======================================================================= #
  @the_IP_is = nil
  try_to_require_the_open_gem unless Object.const_defined?(:Open)
  try_to_load_a_corresponding_yaml_file_from_the_same_directory
  use_gtk_paradise_css_files
  handle_CSS_rules 
  infer_the_size_automatically
end

#return_information_obtained_via_curl(remote_URL) ⇒ Object

#

return_information_obtained_via_curl

#


453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 453

def return_information_obtained_via_curl(
    remote_URL
  )
  result = ''.dup
  cmd_to_use = "curl -I #{remote_URL} 2>&1"
  _ = `#{cmd_to_use}`
  if _
    if result.include? 'HTTP'
      result << _.scan(/^HTTP(.+)/).flatten.first.to_s+"\n"
    end
    if result.include? 'server'
      result << _.scan(/^server:(.+)/).flatten.first.to_s+"\n"
    end
  end
  return result
end

#return_smaller_fontObject

#

return_smaller_font

#


275
276
277
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 275

def return_smaller_font
  USE_THIS_SMALLER_FONT
end

#return_string_for_remote_address(use_this_URL = remote_URL? ) ⇒ Object

#

return_string_for_remote_address

#


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 178

def return_string_for_remote_address(
    use_this_URL = remote_URL?
  )
  _ = ''.dup
  result = `host -t a #{use_this_URL} 2>&1`
  if result.include? 'command not found'
    # Notify the user that host is not available.
    @base_box.popup_this_text_over_that_widget(
      'The command "host" is not available.',
      main_entry?
    )
  elsif result.include? ' '
    @the_IP_is = result.split(' ').last.to_s
    _ << " The remote IP associated with this URL\n"\
         "is <span weight=\"bold\" color=\"darkgreen\">"\
         "#{@the_IP_is}</span>."
  end
  return _
end

#return_the_signal_image(base_box = nil) ⇒ Object

#

return_the_signal_image

#


473
474
475
476
477
478
479
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 473

def return_the_signal_image(
    base_box = nil
  )
  @signal_image = base_box.image
  the_signal_image_is_now_red
  return @signal_image
end

#runObject

#

run (run tag)

#


484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 484

def run
  run_super
  @base_box = gtk_base_module_box
  @base_box.reset_the_internal_variables
  @base_box.infer_the_namespace
  hbox = create_hbox
  image = @base_box.image_network_cellular_connected_symbolic_symbolic
  event_box = event_box(image)
  event_box.on_clicked {
    do_clear_the_main_entry
  }
  hbox.minimal(event_box, 10)
  hbox.minimal(return_the_signal_image(@base_box), 10)
  @spinner = @base_box.return_inactive_spinner
  hbox.minimal(@spinner, 10)
  # ======================================================================= #
  # === Address
  # ======================================================================= #
  label = @base_box.left_aligned_label('Address')
  hbox.minimal(label, 10)
  @base_box.width  = width?
  @base_box.height = height?
  hbox.minimal(entry_use_this_URL?,         8)
  hbox.minimal(@button_do_the_ping_action,  5) # Add the button-ping action here.
  hbox.minimal(@button_open_in_the_browser, 5)
  @base_box.minimal(hbox, 1)
  hbox2 = create_hbox
  hbox2.minimal(@label_for_the_connection_status, 15)
  @base_box.minimal(hbox2, 8)
  window = create_window_or_runner(@base_box)
  window.set_title(title?)
  window.set_font(font?)
  window.set_size_request(width?, height?)
  window.show_all
  window.top_left
  let_the_main_entry_respond_to_scroll_events # This should come late.
  run_main
end

#set_main_URL(i) ⇒ Object

#

set_main_URL

#


296
297
298
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 296

def set_main_URL(i)
  entry_URL?.set_text(i.to_s)
end

#start_the_spinnerObject

#

start_the_spinner

#


432
433
434
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 432

def start_the_spinner
  @spinner.start_spinning
end

#the_signal_image_is_now_greenObject

#

the_signal_image_is_now_green

#


439
440
441
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 439

def the_signal_image_is_now_green
  @signal_image.set_file(FILE_GREEN_CIRCLE)
end

#the_signal_image_is_now_redObject

#

the_signal_image_is_now_red

#


446
447
448
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 446

def the_signal_image_is_now_red
  @signal_image.set_file(FILE_RED_CIRCLE)
end

#try_to_require_net_pingObject

#

try_to_require_net_ping

#


143
144
145
146
147
# File 'lib/roebe/gui/universal_widgets/ping_widget/ping_widget.rb', line 143

def try_to_require_net_ping
  begin
    require 'net/ping'
  rescue LoadError; end
end