class MultimediaParadise::GUI::Gtk::Radio

Constants

DEFAULT_STREAM
#

DEFAULT_STREAM

#
FONT_FAMILY_TO_USE
#

FONT_FAMILY_TO_USE

#
FONT_SIZE
#

FONT_SIZE

#
HEIGHT
#

HEIGHT

#
HOMEPAGE_OF_THIS_PROJECT
#

HOMEPAGE_OF_THIS_PROJECT

#
SMALLER_FONT_SIZE
#

SMALLER_FONT_SIZE

#
TITLE
#

TITLE

#
WIDTH
#

WIDTH

#

Public Class Methods

[](i = ARGV) click to toggle source
#

MultimediaParadise::GUI::Gtk::Radio[]

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1240
def self.[](i = ARGV)
  new(i)
end
new( commandline_arguments = ARGV, run_already = true ) click to toggle source
#

initialize

#
Calls superclass method
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 86
def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  super(:vertical, 0)
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  if commandline_arguments and commandline_arguments.respond_to?(:first)
    set_parent(
      commandline_arguments.first
    )
  end
  run if run_already
end
run( i = ARGV ) click to toggle source
#

MultimediaParadise::GUI::Gtk::Radio.run

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1247
def self.run(
    i = ARGV
  )
  require 'gtk_paradise/app/app.rb'
  _ = new(i)
  r = ::Gtk.run
  r << _
  r.enable_context_menu_on_button_click_events
  r.signal_connect(:delete_event) { |_widget| ::Gtk.main_quit }
  _.maximize_button?.set_new_parent(r)
  # ======================================================================= #
  # Next we will add several alt+key shortcuts.
  # ======================================================================= #
  r.shortcuts {[
    [1, 'click_on_button_number(1)',  :alt],
    [2, 'click_on_button_number(3)',  :alt],
    [3, 'click_on_button_number(5)',  :alt],
    [4, 'click_on_button_number(7)',  :alt],
    [5, 'click_on_button_number(9)',  :alt],
    [6, 'click_on_button_number(11)', :alt],
    [7, 'click_on_button_number(13)', :alt],
    [8, 'click_on_button_number(15)', :alt],
    [9, 'click_on_button_number(17)', :alt]
  ]}
  r.automatic_size_then_automatic_title
  r.enable_quick_exit
  r.top_left_then_run
end
title?() click to toggle source
#

MultimediaParadise::GUI::Gtk::Radio.title?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 44
def self.title?
  TITLE
end

Public Instance Methods

border_size?() click to toggle source
#

border_size?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 301
def border_size?
  0
end
button_stop_playback?() click to toggle source
#

button_stop_playback?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 717
def button_stop_playback?
  @button_stop_playback
end
change_directory_on_roebe_systems_unless_in_depot_subdirectory( use_this_directory = '/Depot/j/' ) click to toggle source
#

change_directory_on_roebe_systems_unless_in_depot_subdirectory

This is mostly a “safeguard” on my home system, so I don’t spam random .mp3 files all over the filesystem.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 706
def change_directory_on_roebe_systems_unless_in_depot_subdirectory(
    use_this_directory = '/Depot/j/'
  )
  if is_on_roebe? and !return_pwd.include?('/Depot/')
    Dir.chdir(use_this_directory) if File.directory? use_this_directory
  end
end
check_for_the_title_after_a_brief_delay( button = @this_button_is_now_playing, delay_to_use = 2200 ) click to toggle source
#

check_for_the_title_after_a_brief_delay

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 944
def check_for_the_title_after_a_brief_delay(
    button       = @this_button_is_now_playing,
    delay_to_use = 2200
  )
  GLib::Timeout.add(delay_to_use) {
    this_radio_station = button.label.to_s.strip
    if this_radio_station =~ /^\d{1,2}$/
      # =================================================================== #
      # In this case we have to change the title. We need to access the
      # elements 0,2,4,6 and so forth, and disregard the other entries.
      # So, entry number 1 becomes 0, entry number 2 becomes 2, entry
      # number 3 becomes 4, entry number 4 becomes 6, and so forth.
      # The formula is thus: 2 * (n-1)
      # =================================================================== #
      this_radio_station = 2 * (this_radio_station.to_i - 1)
      this_radio_station = @array_buttons[this_radio_station].label.to_s
    end
    _ = "Now playing from this radio station: "\
        "#{this_radio_station}".dup
    if MultimediaParadise.title_of_the_audio_file?
      _ << "\nThe title is: #{MultimediaParadise.title_of_the_audio_file?}"
    end
    # ===================================================================== #
    # Finally, propagate our findings to the correct gtk-label in use:
    # ===================================================================== #
    @label_displaying_the_radio_station.set_text(_)
    @label_displaying_the_radio_station.make_bold
    @label_displaying_the_radio_station.make_selectable
    false
  }
end
click_on_button_number( number = 0 ) click to toggle source
#

click_on_button_number

This method can be used to click on any button programmatically.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 328
def click_on_button_number(
    number = 0
  )
  # ======================================================================= #
  # We modify the given number. This is necessary because we first add
  # an index-button to the playlist, hence the *2 modifier below.
  # ======================================================================= #
  number = number.to_i
  _ = return_all_buttons_except_for_the_stop_playback_button
  _[number].signal_emit(:clicked)
end
click_on_this_button_by_number( number = 0 )
connect_skeleton() click to toggle source
#

connect_skeleton (connect tag)

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1132
def connect_skeleton
  abort_on_exception
  hbox1_dragger = drag_via_left_and_right_movement_of_the_mouse(
    return_widgets_on_the_left_side,
    return_widget_containing_the_buttons_for_all_streams
  )
  hbox1_dragger.set_border_width(2)
  minimal(@header_bar)
  top_widget = create_hbox
  top_widget.maximal(hbox1_dragger)
  dragger1 = drag_via_up_and_down_mouse_movement(
    top_widget,
    return_bottom_widget
  )
  dragger1.position = '25%'
  dragger1.set_border_width(4)
  maximal(dragger1, 2)
end
create_skeleton() click to toggle source
#

create_skeleton (create tag, skeleton tag)

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 374
def create_skeleton
  create_the_statusbar  # (1)
  create_the_buttons    # (2) Must come before we create the header-bar.
  create_the_entries    # (3)
  create_the_labels     # (4)
  create_the_menu       # (5) Must come before we create the header-bar.
  create_the_header_bar # (6) Must come after create_the_menu().
  create_status_icon    # (7)
end
create_status_icon( i = FILE_RADIO_IMAGE ) click to toggle source
#

create_status_icon

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1112
def create_status_icon(
    i = FILE_RADIO_IMAGE
  )
  @status_icon = gtk_status_icon(i)
  @status_icon.hint = ' <b>Play</b> from radio station '
end
create_the_buttons() click to toggle source
#

create_the_buttons

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 387
def create_the_buttons
  create_the_stop_playback_button
  create_the_maximize_button
end
create_the_entries() click to toggle source
#

create_the_entries (entries tag)

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1049
def create_the_entries
  # ======================================================================= #
  # === @entry_stream
  # ======================================================================= #
  @entry_stream = create_entry
  @entry_stream.width_height(920, 44)
  @entry_stream.center
  @entry_stream.set_text(DEFAULT_STREAM)
  @entry_stream.pad2px
  @entry_stream.yellow_background
  @entry_stream.bblack1
  @entry_stream.set_font(smaller_font?)
  @entry_stream.hint = 'Input the main URL here for the radio '\
    'stream in use. Alternatively click on one of the buttons '\
    'above; the current remote URL in use will then be shown '\
    'in the entry above.'
  @entry_stream.on_enter {
    do_all_actions_associated_when_an_actionable_radio_button_was_clicked
  }
  # ======================================================================= #
  # === @entry_status_bar
  # ======================================================================= #
  @entry_status_bar = create_entry
  @entry_status_bar.on_click_event { :select_everything }
  @entry_status_bar.make_bold
  @entry_status_bar.center
  @entry_status_bar.bblack1
  @entry_status_bar.pad8px
  @entry_status_bar.css_class('BG_lightblue')
  @entry_status_bar.width_height(250, 20)
  @entry_status_bar.hint =
    'This entry will show the URL to the remote stream, if one is playing '\
    'currently, so that the user can quickly copy/paste this URL.'
end
create_the_header_bar() click to toggle source
#

create_the_header_bar (top tag)

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1012
def create_the_header_bar
  # ======================================================================= #
  # === @header_bar
  # ======================================================================= #
  @header_bar = default_header
  # @header_bar.main_text = 'Radio'
  @header_bar.add_left(
    return_the_menu_bar
  )
  @header_bar.add_right(
    return_the_quit_button
  )
  @header_bar.add_right(
    return_the_mini_clock
  )
  @header_bar.add_right(
    return_the_maximize_button
  )
  @header_bar.add_right(
    return_the_widget_for_muting_and_unmuting_the_audio
  )
  @header_bar.pad5px
  @header_bar.spacing = 10
end
Also aliased as: create_the_top_bar
create_the_labels() click to toggle source
#

create_the_labels

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 811
def create_the_labels
  @label_displaying_the_radio_station = text
end
create_the_maximize_button() click to toggle source
#

create_the_maximize_button

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 404
def create_the_maximize_button
  # ======================================================================= #
  # === @maximize_button
  # ======================================================================= #
  @maximize_button = ::Gtk::MaximizeButton.new(main_window?)
  @maximize_button.can_focus = false
  @maximize_button.no_relief
end
create_the_menu() click to toggle source
#

create_the_menu (menu tag)

This is the toplevel menubar, captured onto @menu_bar.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 614
def create_the_menu
  # ======================================================================= #
  # === @menu_bar
  # ======================================================================= #
  @menu_bar = gtk_menu_bar
  filemenu1 = gtk_menu
  # ======================================================================= #
  # === 1) First menu drop-down interface
  # ======================================================================= #
  filem1 = create_menu_item('File') {{ submenu: filemenu1 }}
  # ======================================================================= #
  # === Add the 'Reset the Widget' entry next:
  # ======================================================================= #
  reset_the_widget = create_menu_item('Reset the widget')
  reset_the_widget.fancy_tooltips = '<b>Clicking</b> on this item will '\
    '<b>reset</b> the main widget to its initial state, as if you would '\
    'have just started this application.'
  reset_the_widget.on_activate {
    do_reset_the_widget
  }
  filemenu1 << reset_the_widget
  filemenu1.append_separator
  # ======================================================================= #
  # === Add the 'Exit' entry next:
  # ======================================================================= #
  exit = create_menu_item('Exit') { :on_activate_quit }
  filemenu1 << exit
  # ======================================================================= #
  # === (2) Second menu drop-down interface
  # ======================================================================= #
  filemenu2 = gtk_menu
  filem2 = create_menu_item('Capture the stream') {{ submenu: filemenu2 }}
  # ======================================================================= #
  # === Add the 'Shall the stream be captured' entry next:
  # ======================================================================= #
  capture_the_stream_yes = ::Gtk::RadioMenuItem.new(nil, 'Yes')
  capture_the_stream_yes.on_activate { @capture_the_stream = true }
  capture_the_stream_no  = ::Gtk::RadioMenuItem.new(capture_the_stream_yes, 'No')
  capture_the_stream_no.on_activate  { @capture_the_stream = false }
  if is_on_roebe?
    capture_the_stream_no.activate
  end
  filemenu2 << capture_the_stream_yes
  filemenu2 << capture_the_stream_no
  # ======================================================================= #
  # === (3) The info widget
  # ======================================================================= #
  filemenu3 = gtk_menu
  filem3 = create_menu_item('Info') {{ submenu: filemenu3 }}
  # ======================================================================= #
  # === Add the 'Show all URLs' entry next:
  # ======================================================================= #
  show_all_URLs = create_menu_item('Show all URLs to the radio station')
  show_all_URLs.on_activate {
    do_show_all_URLs
  }
  filemenu3 << show_all_URLs
  # ======================================================================= #
  # === Add the 'Show more info about this widget' entry next:
  # ======================================================================= #
  show_more_info = create_menu_item('Show more info about this widget')
  show_more_info.on_activate { do_show_more_info_about_this_widget }
  filemenu3 << show_more_info
  # ======================================================================= #
  # === Add the 'Debug' widget next:
  # ======================================================================= #
  debug_this_widget = create_menu_item('Debug this widget')
  debug_this_widget.on_activate { do_debug_this_widget }
  filemenu3 << debug_this_widget
  # ======================================================================= #
  # Next, add the file-menu parts to the menu bar.
  # ======================================================================= #
  @menu_bar.add_these(
    filem1, gtk_separator_menu_item,
    filem2, gtk_separator_menu_item,
    filem3, gtk_separator_menu_item
  )
end
create_the_statusbar() click to toggle source
#

create_the_statusbar

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1122
def create_the_statusbar
  # ======================================================================= #
  # === @status_bar
  # ======================================================================= #
  @status_bar = status_bar
end
create_the_stop_playback_button() click to toggle source
#

create_the_stop_playback_button (stop tag)

The “stop playback” button is situated closer towards the bottom of the main widget, right above the two buttons that can be used to modify the audio volume on a linux system.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 225
def create_the_stop_playback_button
  # ======================================================================= #
  # Create the "stop playback" button next.
  # ======================================================================= #
  @button_stop_playback = bold_button('Stop playback')
  @button_stop_playback.bblack2
  @button_stop_playback.grey_out
  @button_stop_playback.background_colour = :lightblue
  @button_stop_playback.paleturquoise
  # ======================================================================= #
  # Add a tooltip next.
  # ======================================================================= #
  @button_stop_playback.hint =
    "Click this button to stop the current song that is "\
    "played (if a song is currently playing that is).\n\n"\
    "If no radio-station is used then the button is "\
    "not functional yet.\n\n"\
    "Otherwise, clicking on the button will also re-enable "\
    "clicking on the actionable play-from-a-stream buttons."
  @button_stop_playback.on_clicked {
    do_all_the_actions_associated_when_the_button_stop_playback_was_clicked
  }
end
create_the_top_bar()
disable_all_main_buttons()
do_all_actions_associated_when_an_actionable_radio_button_was_clicked( use_this_remote_URL = @entry_stream.text?, capture_into_this_file = :pwd_or_user_supplied_value, button = nil ) click to toggle source
#

do_all_actions_associated_when_an_actionable_radio_button_was_clicked (clicked tag)

This method bundles together all actions associated with the main button-click event. It will play the remote URL stream upon a button-click event.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 822
def do_all_actions_associated_when_an_actionable_radio_button_was_clicked(
    use_this_remote_URL    = @entry_stream.text?,
    capture_into_this_file = :pwd_or_user_supplied_value,
    button                 = nil
  )
  do_all_the_actions_associated_when_the_button_stop_playback_was_clicked
  case capture_into_this_file
  # ======================================================================= #
  # === :pwd_or_user_supplied_value
  # ======================================================================= #
  when :pwd_or_user_supplied_value,
       :default,
       :default_capture_stream
    capture_into_this_file = return_capture_into_the_default_file
    _ = save_the_stream_into_which_file?
    if _ and !_.empty?
      capture_into_this_file = _.dup
    end
  # ======================================================================= #
  # === :pwd
  # ======================================================================= #
  when :pwd
    capture_into_this_file = return_capture_into_the_default_file
  end
  # ======================================================================= #
  # Next, make the stop-playback button clickable again.
  # ======================================================================= #
  make_the_stop_playback_button_clickable_again
  e
  e
  e "#{rev}#{tomato('The remote URL is:')}"
  e
  e steelblue("  #{use_this_remote_URL}")
  e
  # ======================================================================= #
  # The next line of code changes the gtk-entry where the user stores
  # the .mp3 file, but since as of 30.09.2020 the user is able to
  # control it. Only if it is empty will a sane default value be
  # used.
  # ======================================================================= #
  if @entry_save_into_this_file.empty?
    @entry_save_into_this_file.set_text(capture_into_this_file)
  end
  check_for_the_title_after_a_brief_delay(button) if button
  set_url_to_use(use_this_remote_URL)
  set_status_bar_message(use_this_remote_URL)
  if button
    this_button_is_now_playing(button)
    _ = "Radio station: #{button.label}".dup
    if MultimediaParadise.title_of_the_audio_file? and
      !MultimediaParadise.title_of_the_audio_file?.empty?
      _ << "\nTitle is: #{MultimediaParadise.title_of_the_audio_file?}"
    end
    @label_displaying_the_radio_station.set_text(_)
    @label_displaying_the_radio_station.make_bold
    @label_displaying_the_radio_station.center
  end
  do_play_from_this_stream(use_this_remote_URL, capture_into_this_file)
  # The next line was disabled as of May 2022:
  # do_grey_out_all_buttons_except_for_the_stop_playback_button
end
do_all_the_actions_associated_when_the_button_stop_playback_was_clicked() click to toggle source
#

do_all_the_actions_associated_when_the_button_stop_playback_was_clicked

This method bundles together the actions that are associated with the user clicking on the “stop playback” button.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1002
def do_all_the_actions_associated_when_the_button_stop_playback_was_clicked
  do_stop_playing_the_current_song
  @button_stop_playback.grey_out # Reset it again.
  @label_displaying_the_radio_station.set_text ''
  set_status_bar_message(:clear)
end
do_debug_this_widget() click to toggle source
#

do_debug_this_widget

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 749
def do_debug_this_widget
  e 'Currently this functionality is not implemented '\
    '(January 2021) - somehow class Gtk::DebugWidget'
  e 'has to be improved be found ...'
  # ::Gtk::DebugWidget.new
end
do_grey_out_all_buttons_except_for_the_stop_playback_button() click to toggle source
#

do_grey_out_all_buttons_except_for_the_stop_playback_button

This method used to be called when a new button has been clicked for playing a radio-stream. It was disabled as of May 2022, though, as it is better to NOT grey out the buttons.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 898
def do_grey_out_all_buttons_except_for_the_stop_playback_button
  these_buttons_are_to_be_greyed_out = 
    return_all_buttons_except_for_the_stop_playback_button
  these_buttons_are_to_be_greyed_out.each {|button|
    button.grey_out
  }
end
Also aliased as: disable_all_main_buttons
do_kill_the_mpv_process( use_this_pid = @pid ) click to toggle source
#

do_kill_the_mpv_process

This method will simply kill the passed PID - use with care.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 345
def do_kill_the_mpv_process(
    use_this_pid = @pid
  )
  if use_this_pid
    if is_on_roebe?
      e "Now killing the pid: #{::Colours.steelblue(use_this_pid.to_s)}\n\n"
    end
    begin
      case use_this_pid
      when Process.pid # Protect against self-killing here.
        e 'Can not kill the PID of this process.'
      else
        Process.kill('HUP', use_this_pid)
      end
    rescue Exception => error
      if is_on_roebe?
        e 'An error happened in Process.kill() '\
          'at line '+__LINE__.to_s+', in the method '+__method__.to_s
      end
      pp error
    end
  end
end
do_mute_the_audio() click to toggle source
#

do_mute_the_audio

Use ALSA to mute the audio.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 254
def do_mute_the_audio
  system 'amixer set Master mute'
end
do_play_from_this_stream( i = @entry_stream.text?, capture_into_this_file = nil ) click to toggle source
#

do_play_from_this_stream

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 181
def do_play_from_this_stream(
    i                      = @entry_stream.text?,
    capture_into_this_file = nil
  )
  # ======================================================================= #
  # Build up the command we wish to use next.
  # ======================================================================= #
  use_this_command = "mpv #{i}".dup
  if capture_into_this_file
    use_this_command << ' --stream-record="'+capture_into_this_file+'"'
  end
  e steelblue(use_this_command)
  # @pid = spawn(use_this_command)
  io_object = IO.popen(use_this_command, 'r+')
  @pid = io_object.pid
  if is_on_roebe?
    e 'The PID is: '+steelblue(@pid)
  end
  Thread.new {
    # Process.wait(@pid)
    io_object.each { |line|
      if line.start_with? ' icy-title: '
        ::MultimediaParadise.register_title_of_this_audio_file(line)
      end
      e line
    }
    io_object.close
  }
end
do_show_all_URLs( radio_stations = radio_stations? ) click to toggle source
#

do_show_all_URLs

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 569
def do_show_all_URLs(
    radio_stations = radio_stations?
  )
  # ======================================================================= #
  # First, create a widget.
  # ======================================================================= #
  vbox = create_vbox
  vbox.set_border_width(20)
  # ======================================================================= #
  # Second, show them on the commandline.
  # ======================================================================= #
  radio_stations.values.map {|hash| hash['url'] }.each {|remote_URL|
    e remote_URL
    text = left_aligned_text(
      '<a href="remote_URL">'+remote_URL+'</a>'
    )
    text.do_markify
    vbox.minimal(
      text, 2
    )
  }
  scrolled_window = scrolled_window(vbox) { :always }
  scrolled_window.set_border_width(20)
  scrolled_window.width_height(800, 900)
  scrolled_window.bblack2
  return_popover(
    'Remote URLs.',
    header_bar?,
    5,
    scrolled_window
  ).popup
end
do_show_more_info_about_this_widget() click to toggle source
#

do_show_more_info_about_this_widget

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 766
def do_show_more_info_about_this_widget
  about_dialog = gtk_about_dialog
  author = ['Robert A. Heiler']
  about_dialog.artists = author
  about_dialog.authors = author
  about_dialog.comments =
    "\nThis widget can be used to listen to radio streams. \n\n"\
    "The mpv player will be used for this functionality. The "\
    "radio stations are kept in the .yml file, at "\
    "radio_stations.yml."
  about_dialog.copyright = 'Copyright (C) 2021+ Robert A. Heiler'
  about_dialog.documenters = ['Robert A. Heiler']
  about_dialog.license = 'Please see the homepage on rubygems '\
    'for the licence of this gem called multimedia_paradise.'
  about_dialog.name = 'Gtk::Radio'
  about_dialog.program_name = 'gtk-radio'
  about_dialog.translator_credits = "Robert A. Heiler\n"
  about_dialog.version = "Version: #{::MultimediaParadise::VERSION}"
  about_dialog.website = HOMEPAGE_OF_THIS_PROJECT
  about_dialog.website_label = 'MultimediaParadise Homepage'
  about_dialog.logo = pixbuf_from_file(::MultimediaParadise::FILE_RADIO_IMAGE)
  about_dialog.run
  # about_dialog.destroy
end
do_stop_playing_the_current_song( use_this_pid = @pid )
do_unmute_the_audio() click to toggle source
#

do_unmute_the_audio

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 261
def do_unmute_the_audio
  system 'amixer set Master unmute'
end
handle_CSS() click to toggle source
#

handle_CSS (css tag)

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 160
  def handle_CSS
    use_gtk_paradise_project_css_file
    more_CSS_then_apply_it '

button #default {
  background-image: none;
  color: blue;
  background-color: yellow;
}

button:hover {
  transition: 1000ms linear;
  background-color: darkblue;
}

'
  end
header_bar?() click to toggle source
#

header_bar?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 605
def header_bar?
  @header_bar
end
increase_decrease_volume()
kill_this_pid( use_this_pid = @pid )
kill_this_process( use_this_pid = @pid )
main_window?() click to toggle source
#

main_window?

This method must yield the parent Gtk::Window.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 397
def main_window?
  @parent
end
make_the_stop_playback_button_clickable_again() click to toggle source
#

make_the_stop_playback_button_clickable_again

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 319
def make_the_stop_playback_button_clickable_again
  @button_stop_playback.grey_in
end
maximize_button?() click to toggle source
#

maximize_button?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 759
def maximize_button?
  @maximize_button
end
open_this_url_via_the_browser(url) click to toggle source
#

open_this_url_via_the_browser

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 979
def open_this_url_via_the_browser(url)
  unless Object.const_defined? :Open
    begin
      require 'open'
    rescue LoadError; end
  end
  e steelblue(url)
  Open.in_browser(url)
end
padding?() click to toggle source
#

padding?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 294
def padding?
  0
end
radio_stations?() click to toggle source
#

radio_stations?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 32
def radio_stations?
  MultimediaParadise.radio_stations?
end
remote_radio_stations?() click to toggle source
#

remote_radio_stations?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 416
def remote_radio_stations?
  dataset = YAML.load_file(
    MultimediaParadise.file_radio_stations
  )
  # ======================================================================= #
  # The entries will look like this:
  #
  #   "Radio Wien"=>
  #
  #   {"url"=>"http://mp3stream2.apasf.apa.at:8000/listen.pls",
  #    "homepage"=>"https://wien.orf.at/player",
  #    "genre"=>"austrian",
  #    "country"=>"Austria"},
  #
  # ======================================================================= #
  return dataset
end
reset() click to toggle source
#

reset (reset tag)

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 106
def reset
  reset_the_internal_variables
  infer_the_namespace
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, namespace?]
  # ======================================================================= #
  # === Set the title, width, height and the font in use.
  # ======================================================================= #
  title_width_height_font(
    TITLE, WIDTH, HEIGHT, "#{FONT_FAMILY_TO_USE} #{FONT_SIZE}"
  )
  handle_CSS 
  infer_the_size_automatically
  # ======================================================================= #
  # === @use_this_colour_for_the_tooltip_url
  #
  # Denote the colour for the tooltip URL.
  # ======================================================================= #
  @use_this_colour_for_the_tooltip_url = :steelblue
  # ======================================================================= #
  # === @this_button_is_now_playing
  # ======================================================================= #
  @this_button_is_now_playing = nil
  # ======================================================================= #
  # === @capture_the_stream
  #
  # By default we will NOT capture the audio stream. On roebe-systems
  # we will, though.
  # ======================================================================= #
  if ::MultimediaParadise.is_on_roebe?
    @capture_the_stream = true
  else # else for other users, this is the default
    @capture_the_stream = false
  end
  # ======================================================================= #
  # === @pid
  #
  # The PID will be stored in this variable.
  # ======================================================================= #
  @pid = nil
  # ======================================================================= #
  # === @use_this_player_for_capturing_the_audio_stream
  #
  # This variable specifies which audio-player is used for capturing
  # the remote stream.
  # ======================================================================= #
  @use_this_player_for_capturing_the_audio_stream = :mpv # :mplayer
end
reset_all_gtk_labels() click to toggle source
#

reset_all_gtk_labels

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 887
def reset_all_gtk_labels
  @label_displaying_the_radio_station.clear
end
return_all_buttons_except_for_the_stop_playback_button() click to toggle source
#

return_all_buttons_except_for_the_stop_playback_button

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 992
def return_all_buttons_except_for_the_stop_playback_button
  return_all_buttons.reject {|button| button == button_stop_playback? }
end
return_bottom_widget() click to toggle source
#

return_bottom_widget (bottom tag)

The bottom widget will, among other widgets, contain these:

- text to show where the stream will be saved into, locally
- entry to allow the user to change where the stream will be stored
- text to show the main entry for the streams
- entry to allow the designation of the streams
#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1192
def return_bottom_widget
  grid1 = default_grid
  grid1.spacing = 12
  grid1.pad5px
  grid1.set_column_spacing(4)
  grid1.set_row_spacing(4)
  grid1.reset_the_counter
  grid1.full_row(gtk_horizontal_spacer)
  grid1.left(return_the_label_where_the_stream_is_saved_locally)
  grid1.right(return_the_entry_where_the_stream_is_saved_locally)
  grid1.left(return_the_label_containing_the_main_entry_for_the_streams)
  grid1.right(return_the_main_entry_for_the_streams)
  grid1.full_row(@status_bar)
  grid1.hcenter
  return grid1
end
return_capture_into_the_default_file( use_this_directory_as_the_base_directory = return_pwd ) click to toggle source
#

return_capture_into_the_default_file

This method has one side-effect: we will cd into the base directory.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 270
def return_capture_into_the_default_file(
    use_this_directory_as_the_base_directory = return_pwd
  )
  if is_on_roebe?
    change_directory_on_roebe_systems_unless_in_depot_subdirectory
    use_this_directory_as_the_base_directory = return_pwd
  end
  return use_this_directory_as_the_base_directory.squeeze('/')+
         'captured_stream_'+
         Time.now.strftime('%d.%m.%Y')+
         '.mp3'
end
return_middle_part() click to toggle source
#

return_middle_part

This method will obtain and create the various radio-stations and assign a customized, clickable button to each such radio station.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 440
def return_middle_part
  vbox = create_vbox
  index = 0
  # ======================================================================= #
  # Next, obtain all available radio stations, then add a button for
  # each of these stations.
  #
  # The data structure may look like this:
  #
  #   ["ORF Radio Wien", {"url"=>"http://185.85.29.149:8000/", "genre"=>"austrian"}]
  #
  # ======================================================================= #
  remote_radio_stations?.each_pair {|this_radio_station, inner_hash| index += 1
    outer_mini_hbox = create_hbox
    url, _homepage, genre, country = inner_hash.values_at('url','homepage','genre','country')
    padded_index = index.to_s.rjust(3, ' ')
    # ===================================================================== #
    # Next, the radio-image is added to the very left hand side. This
    # is actually an event-box that the user can click. It will then
    # open the remote URL to the homepage of this radio-station.
    # ===================================================================== #
    radio_image = gtk_image(::MultimediaParadise::FILE_RADIO_IMAGE)
    event_box = gtk_event_box(radio_image)
    # ===================================================================== #
    # Use a tooltip:
    # ===================================================================== #
    event_box.hint =
      'Click on this to open the remote URL '\
      '<span weight="bold" foreground="gold">'+url+'</span>.'
    event_box.signal_connect(:event) { |widget, event|
      _ = event.event_type.name
      case _
      when 'GDK_BUTTON_PRESS'
        open_this_url_via_the_browser(url)
      end
    }
    outer_mini_hbox.minimal(event_box)

    index_button = gtk_button(padded_index)
    index_button.make_bold
    index_button.on_hover(:limegreen)
    # ===================================================================== #
    # === Small index button
    #
    # We also use a small index-button. The main idea here is to keep
    # a small number for the radio station, so the user knows which
    # entry is used.
    # ===================================================================== #
    index_button.on_clicked {
      do_all_actions_associated_when_an_actionable_radio_button_was_clicked(
        url, :default_capture_stream, index_button
      )
    }
    outer_mini_hbox.minimal(index_button) # Add the index_button here.

    button = bold_button(this_radio_station)
    button.remove_background
    button.lightgreen
    # ===================================================================== #
    # Next, add code so that the button for the radio-station can play
    # from the remote audio stream.
    # ===================================================================== #
    button.on_clicked {
      do_all_actions_associated_when_an_actionable_radio_button_was_clicked(
        url, :default, button
      )
    }
    # ======================================================================= #
    # Add a tooltip next. This will have bold markup, in colour.
    # ======================================================================= #
    button.tooltip_markup = ""\
      "<span weight=\"bold\">#{padded_index}</span> "\
      "#{this_radio_station}\n\n  → "\
      "<span weight=\"bold\" foreground=\"#{@use_this_colour_for_the_tooltip_url}\">#{url}</span>"\
      "\n"
    # button.css_class('small_button')
    outer_mini_hbox.maximal(button)
    # ===================================================================== #
    # Next we need to handle radio stations from different countries
    # a bit differently. Also, we allow for genre-entries without a
    # country tag to be handled here.
    # ===================================================================== #
    case genre
    when 'Trance'
      country = 'Trance'
    end
    case country
    when 'Austria',
         'Germany',
         'UK',
         'France',
         'USA',
         'Trance' # This is not a country - see explanation above.
      # =================================================================== #
      # In this event show a cute little "banner" image.
      # =================================================================== #
      # =================================================================== #
      # Pack the small austrian flag into that hbox:
      # =================================================================== #
      case country
      when 'Trance'
        flag_image = gtk_image(::MultimediaParadise.project_base_dir?+'images/trance.png')
      when 'USA'
        flag_image = gtk_image(::MultimediaParadise.project_base_dir?+'images/US_flag.png')
      when 'France'
        flag_image = gtk_image(::MultimediaParadise.project_base_dir?+'images/french_flag.png')
      when 'UK'
        flag_image = gtk_image(::MultimediaParadise.project_base_dir?+'images/UK_flag.png')
      when 'Austria'
        flag_image = gtk_image(::MultimediaParadise.project_base_dir?+'images/austrian_flag.png')
      when 'Germany'
        flag_image = gtk_image(::MultimediaParadise.project_base_dir?+'images/german_flag.png')
      end
      frame = create_frame(flag_image)
      frame.modify_background :default, :lightgrey
      outer_mini_hbox.minimal(frame, 0)
    end
    vbox.maximal(outer_mini_hbox, 1)
  }
  _ = scrolled_window(vbox)# { :up_and_down }
  _.width_height(500, 500)
  _.bblack2
  _.set_name('scrollbar3') # The name is #scrollbar3.
  return _
end
return_the_entry_where_the_stream_is_saved_locally() click to toggle source
#

return_the_entry_where_the_stream_is_saved_locally

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1087
def return_the_entry_where_the_stream_is_saved_locally
  @entry_save_into_this_file = create_entry
  if ::Gtk.is_on_roebe?
    @entry_save_into_this_file.set_text(
      return_capture_into_the_default_file
    )
  end
  @entry_save_into_this_file.yellow_background
  @entry_save_into_this_file.pad2px
  @entry_save_into_this_file.bblack1
  @entry_save_into_this_file.center
  @entry_save_into_this_file.set_font(smaller_font?)
  return @entry_save_into_this_file
end
return_the_increase_and_decrease_the_volume_widget_as_well_as_the_stop_playback_button() click to toggle source
#

return_the_increase_and_decrease_the_volume_widget_as_well_as_the_stop_playback_button

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1170
def return_the_increase_and_decrease_the_volume_widget_as_well_as_the_stop_playback_button
  outer_vbox = vbox
  increase_decrease_volume_widget = hbox(increase_decrease_volume)
  increase_decrease_volume_widget.make_bold
  outer_vbox.minimal(hbox(button_stop_playback?).hcenter)
  outer_vbox.minimal(gtk_hsep)
  outer_vbox.minimal(increase_decrease_volume_widget)
  outer_vbox.hcenter
  return outer_vbox
end
return_the_label_containing_the_main_entry_for_the_streams() click to toggle source
#

return_the_label_containing_the_main_entry_for_the_streams

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1229
def return_the_label_containing_the_main_entry_for_the_streams
  _ = text('Use this stream:', 8)
  _.left_align
  _.set_font(smaller_font?)
  _.make_bold
  return _
end
return_the_label_where_the_stream_is_saved_locally() click to toggle source
#

return_the_label_where_the_stream_is_saved_locally

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1212
def return_the_label_where_the_stream_is_saved_locally
  @label_save_the_stream_into_this_file = label(
    'Save the stream into this file:'
  )
  @label_save_the_stream_into_this_file.hint = 
    'This will denote <b>into</b> which file the stream is to be '\
    'stored, e. g. <b>a local path</b> for a <b>.mp3 file</b>. '\
    'Take note that this will <b>overwrite</b> the old file, '\
    'should such a file exist.'
  @label_save_the_stream_into_this_file.set_font(smaller_font?)
  @label_save_the_stream_into_this_file.make_bold
  return @label_save_the_stream_into_this_file
end
return_the_main_entry_for_the_streams() click to toggle source
#

return_the_main_entry_for_the_streams

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1105
def return_the_main_entry_for_the_streams
  return @entry_stream
end
return_the_maximize_button() click to toggle source
#

return_the_maximize_button

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 724
def return_the_maximize_button
  return @maximize_button
end
return_the_menu_bar() click to toggle source
#

return_the_menu_bar

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 696
def return_the_menu_bar
  return @menu_bar
end
return_the_mini_clock() click to toggle source
#

return_the_mini_clock

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 801
def return_the_mini_clock
  return ::Gtk::MiniClock.widget {{
    make_bold:        true,
    use_this_colour: :indigo # olive
  }}
end
return_the_quit_button() click to toggle source
#

return_the_quit_button

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 909
def return_the_quit_button
  the_quit_button = image_application_exit
  the_quit_button.hint = 'This button will exit the application.'
  the_quit_button.can_focus = false
  event_box_for_the_quit_button = create_event_box(the_quit_button)
  event_box_for_the_quit_button.on_clicked {
    exit_the_application
  }
  return event_box_for_the_quit_button
end
return_the_widget_for_muting_and_unmuting_the_audio() click to toggle source
#

return_the_widget_for_muting_and_unmuting_the_audio

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 731
def return_the_widget_for_muting_and_unmuting_the_audio
  button_mute = check_button('Mute')
  button_mute.hint = 'Click on this button to mute/unmute the audio.'
  button_mute.label_widget.darkblue
  button_mute.label_widget.make_bold
  button_mute.on_clicked {
    if button_mute.active?
      do_mute_the_audio
    else
      do_unmute_the_audio
    end
  }
  return button_mute
end
return_the_widget_increase_or_decrease_audio() click to toggle source
#

return_the_widget_increase_or_decrease_audio

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 214
def return_the_widget_increase_or_decrease_audio
  ::MultimediaParadise::GUI::Gtk::WidgetIncreaseOrDecreaseAudio.new
end
Also aliased as: increase_decrease_volume
return_widget_containing_the_buttons_for_all_streams()
Alias for: return_middle_part
return_widgets_on_the_left_side() click to toggle source
#

return_widgets_on_the_left_side (left tag)

This will also hold the increase-and-decrease widget.

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1156
def return_widgets_on_the_left_side
  vbox_on_the_left_side = create_vbox
  vbox_on_the_left_side.same_minimal(
    1,
    return_the_increase_and_decrease_the_volume_widget_as_well_as_the_stop_playback_button,
    @label_displaying_the_radio_station,
    @entry_status_bar
  )
  return vbox_on_the_left_side
end
run() click to toggle source
#

run (run tag)

#
Calls superclass method
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 1040
def run
  super()
  change_directory_on_roebe_systems_unless_in_depot_subdirectory
  run_in_the_background
end
save_the_stream_into_which_file?() click to toggle source
#

save_the_stream_into_which_file?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 937
def save_the_stream_into_which_file?
  @entry_save_into_this_file.text?
end
set_parent(i) click to toggle source
#

set_parent

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 286
def set_parent(i)
  i = first if i.is_a? Array
  @parent = i
end
set_status_bar_message(i = '') click to toggle source
#

set_status_bar_message

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 308
def set_status_bar_message(i = '')
  case i
  when :clear
    i = ''
  end
  @entry_status_bar.set_text(i)
end
set_url_to_use(i) click to toggle source
#

set_url_to_use

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 930
def set_url_to_use(i)
  @entry_stream.set_text(i.to_s)
end
smaller_font?() click to toggle source
#

smaller_font?

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 794
def smaller_font?
  "#{FONT_FAMILY_TO_USE} #{SMALLER_FONT_SIZE}"
end
this_button_is_now_playing(button) click to toggle source
#

this_button_is_now_playing

#
# File lib/multimedia_paradise/gui/gtk3/radio/radio.rb, line 923
def this_button_is_now_playing(button)
  @this_button_is_now_playing = button
end