Module: MultimediaParadise::GUI::Gtk::PlayVideoFromMyCollectionModule

Extended by:
Colours
Includes:
Colours, Gtk::BaseModule, MultimediaParadise::GUI
Included in:
PlayVideoFromMyCollection
Defined in:
lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
WIDTH =
#

WIDTH

#
'90%'
HEIGHT =
#

HEIGHT

#
820
MPLAYER =
#

MPLAYER

#
'mplayer -vo x11 -zoom'
MPV =
#

NPV

#
'mpv'
FILE_VIDEOCAMERA =
"/home/x/data/images/#{Cyberweb.web_images(:videocamera)}"
FROM_WHERE =
#

FROM_WHERE

#
'/home/x/video/Realvids/*'
TITLE =
#

TITLE

#
'Play Videos'
FONT_FAMILY_TO_USE =
#

FONT_FAMILY_TO_USE

#
'DejaVu Sans Mono'
FONT_SIZE =
#

FONT_SIZE

#
'20'

Constants included from MultimediaParadise::GUI

ISO, MAIN_FONT_TO_USE, N, UTF, VIDEO_COLLECTION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MultimediaParadise::GUI

#esystem, #populate_the_dataset_with_this_array, #set_gtk_font_to_use

Class Method Details

.[](i = '') ⇒ Object

#

MultimediaParadise::GUI::Gtk::PlayVideoFromMyCollectionModule[]

#


296
297
298
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 296

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

.padding?Boolean

#

PlayVideoFromMyCollection

#

Returns:

  • (Boolean)


169
170
171
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 169

def self.padding?
  12
end

.runObject

#

MultimediaParadise::GUI::Gtk::PlayFromRadioStation.run

#


370
371
372
373
374
375
376
377
378
379
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 370

def self.run
  require 'gtk_paradise/run'
  video_collection = MultimediaParadise::GUI::Gtk::PlayVideoFromMyCollection.new(ARGV)
  r = ::Gtk.run
  r << video_collection
  r.set_size_request(video_collection.width?, video_collection.height?)
  r.signal_connect(:delete_event) { |_widget| Gtk.main_quit }
  r.modify_background(:normal, :lightskyblue)
  r.top_left_then_run
end

Instance Method Details

#add_alignmentObject

#

add_alignment

The alignment will hold the @scrolled_window widgt.

#


271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 271

def add_alignment
  padding = 0.98
  @alignment = ::Gtk::Alignment.new(padding, padding, padding, padding)
  @alignment.set_padding(1,1,1,1) # oben,unten,links,rechts
  vbox = gtk_vbox
  vbox.minimal(@search_bar,       2)
  vbox.maximal(@scrolled_window, 1)
  @child_widget.maximal(vbox)
  @child_widget.set_size_request(500, 600)
  @alignment.add @child_widget
  add(@alignment)
end

#add_buttons_from_video_filesObject

#

add_buttons_from_video_files

#


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
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
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 190

def add_buttons_from_video_files
  # ======================================================================= #
  # Next iterate over all the available video files.
  # ======================================================================= #
  @array_all_video_files = obtain_all_video_files
  @array_all_video_files.each_with_index {|videofile, index| index += 1
    # ===================================================================== #
    # We want to show a little tooltip, so we have to return the
    # information from the yaml-file that keeps track of things.
    # ===================================================================== #
    this_entry = File.basename(videofile).split('_')
    this_entry = this_entry.first.to_i
    use_this_as_tooltip = ::MultimediaParadise.return_data_from_video_collection_file_for_this_entry(
      this_entry
    )
    name_of_the_videofile = File.basename(videofile).tr('_',' ')
    # ===================================================================== #
    # We add a button for each videofile.
    # ===================================================================== #
    button = gtk_bold_button(name_of_the_videofile, false) # False for "Do not use a shortcut".
    button.css_class('bblack1')
    button.on_clicked {|widget, event|
      play_this_videofile(videofile) # This contains the full path.
    }
    button.set_border_width(3)
    button.set_image(return_new_videocamera_image) # use the videocamera image.
    button.align_to_the_left_side
    # ===================================================================== #
    # The index button is the small button on the very left side.
    # ===================================================================== #
    index_button = gtk_bold_button("#{index.to_s.rjust(3)}")
    index_button.css_class('bblack1')
    index_button.set_size_request(90, 32)
    index_button.on_clicked {
      play_this_videofile(videofile)
    }
    if use_this_as_tooltip
      # =================================================================== #
      # === Extensive tooltip
      #
      # Add a tooltip there if it was given, but convert it into a String 
      # if it is a Hash. Furthermore, add a bit of pseudo-css as well.
      # =================================================================== #
      if use_this_as_tooltip.is_a? Hash
        if use_this_as_tooltip.has_key? 'imdb'
          imdb_URL = use_this_as_tooltip['imdb']
          button.on_right_mouse_button_clicked {
            try_to_open_the_imdb_link_in_the_browser(imdb_URL)
          }
        end
        use_this_as_tooltip = use_this_as_tooltip.map {|key, value|
          "#{key.tr('_',' ')}: #{value}"
        }.join("\n").
          sub(/title:/, '<b>title:</b>').
          sub(/release date:/, '<b>release date:</b>').
          sub(/genre:/, '<b>genre:</b>').
          sub(/addition date:/, '<b>addition date:</b>').
          sub(/imdb:/, '<b>imdb:</b>').
          sub(/language:/, '<b>language:</b>').
          sub(/my rating:/, '<b>my rating:</b>').dup
        # ================================================================= #
        # Add the file-extension as well, for additional info.
        # ================================================================= #
        use_this_as_tooltip << "\n<b>File type</b>: #{File.extname(videofile)}"
      end
      button.fancy_tooltip = use_this_as_tooltip
      index_button.fancy_tooltip = use_this_as_tooltip
    end
    button.show_all
    hbox_with_two_buttons = gtk_hbox
    hbox_with_two_buttons.minimal(index_button, 0)
    hbox_with_two_buttons.maximal(button, 0)
    @vbox_with_buttons.add(hbox_with_two_buttons)
  }
end

#add_the_scrolled_windowObject

#

add_the_scrolled_window

#


313
314
315
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 313

def add_the_scrolled_window
  @scrolled_window = gtk_scrolled_window(@vbox_with_buttons)
end

#create_skeletonObject

#

create_skeleton

#


287
288
289
290
291
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 287

def create_skeleton
  create_the_fancy_search_bar
  @vbox_with_buttons = gtk_vbox
  add_buttons_from_video_files
end

#create_the_fancy_search_barObject

#
#


456
457
458
459
460
461
462
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 456

def create_the_fancy_search_bar
  @search_bar, @search_entry = drop_down_find_box
  @search_entry.width_height(400, 50)
  @search_entry.on_enter {
    try_to_find_a_match
  }
end

#favicon?Boolean

#

favicon?

#

Returns:

  • (Boolean)


327
328
329
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 327

def favicon?
  :tabble
end

#initialize(i = nil, run_already = true) ⇒ Object

#

initialize

#


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 98

def initialize(
    i           = nil,
    run_already = true
  )
  super('')
  label_widget.set_markup(
    '<span weight="bold" size="x-large" foreground="darkblue"> '+TITLE+' </span>'
  )
  reset
  set_input(i)
  # ======================================================================= #
  # Delegate all key-press events next.
  # ======================================================================= #
  signal_connect(:key_press_event) {|widget, event|
    on_key_event(widget, event)
  }
  run if run_already
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


162
163
164
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 162

def input?
  @input
end

#is_video_file?(i) ⇒ Boolean

#

is_video_file?

#

Returns:

  • (Boolean)


146
147
148
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 146

def is_video_file?(i)
  ::MultimediaParadise.is_video_file?(i) # Delegate to the module-method here.
end

#obtain_all_video_filesObject

#

obtain_all_video_files

Simply return all video files

#


178
179
180
181
182
183
184
185
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 178

def obtain_all_video_files
  from_where = '/home/x/video/Realvids/*' # Hardcoded by default.
  from_where = FROM_WHERE
  results = Dir[from_where].select {|entry|
    is_video_file?(entry)
  }.sort
  return results
end

#on_key_event(widget, event) ⇒ Object

#

on_key_event

Cause the searchbar to show up.

#


386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 386

def on_key_event(
    widget, event
  )
  shortcut = ::Gtk.accelerator_get_label(event.keyval, event.state)
  # ======================================================================= #
  # Get support for Ctrl+F next:
  # ======================================================================= #
  if ['Ctrl+F', 'Ctrl+Mod2+F'].include? shortcut
    if @search_bar.search_mode?
      # =================================================================== #
      # This causes the search bar to disappear.
      # =================================================================== #
      @search_bar.disappear
    else
      # =================================================================== #
      # And appear here in this event.
      # =================================================================== #
      @search_bar.appear
    end
  end
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


320
321
322
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 320

def padding?
  8
end

#play_this_videofile(videofile) ⇒ Object Also known as: play_this_video_file

#

play_this_videofile

This is the method that will play a given videofile.

#


413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 413

def play_this_videofile(videofile)
  efancy videofile
  @thread = Thread.new {
    _ = MPV+' '+videofile
    cliner
    e sfancy(_)
    cliner
    system _
  }
  @thread.join
  @thread = nil # Unsure whether we will need this here.
end

#resetObject

#

reset (reset tag)

#


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 120

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  # ======================================================================= #
  # === @title
  # ======================================================================= #
  @title  = TITLE
  # ======================================================================= #
  # === @width
  # ======================================================================= #
  set_width(WIDTH)
  # ======================================================================= #
  # === @height
  # ======================================================================= #
  set_height(HEIGHT)
  @child_widget = gtk_vbox # This widget will hold the other variants.
  set_font(:dejagnu_20)
  append_project_css_file
end

#return_new_videocamera_imageObject

#

return_new_videocamera_image

#


303
304
305
306
307
308
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 303

def return_new_videocamera_image
  pixbuf = ::GdkPixbuf::Pixbuf.new(file: FILE_VIDEOCAMERA)
  pixbuf.scale(5, 5, :hyper)
  image = gtk_image(pixbuf)
  return image
end

#runObject

#

run (run tag)

#


342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 342

def run
  set_the_font_in_use_for_this_application
  create_skeleton
  input_field  = gtk_input_field {{ max_length: 50 }}
  result_field = gtk_input_field
  input_field.on_key_press_event { |widget, event|
    case Gdk::Keyval.to_name(event.keyval)
    when 'Return','KP_Enter'
      _ = input_field.text
      _ = FindVideo[_]
      unless _.empty?
        _.map! {|entry| entry.last }
      end
      if _.is_a? Array
        _ = _.join(', ')
      end
      result_field.set_text(_)
    end
  }
  search_box = gtk_hbox(input_field, result_field)
  @vbox_with_buttons.minimal(search_box, 0)
  add_the_scrolled_window
  add_alignment # We will put all the
end

#set_input(i = '') ⇒ Object

#

set_input

#


153
154
155
156
157
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 153

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

#try_to_find_a_matchObject

#

try_to_find_a_match

This method will try to find a corresponding match to the given search term.

#


432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 432

def try_to_find_a_match
  _ = @search_entry.text?
  possible_matches = @array_all_video_files.select {|entry|
    basename = File.basename(entry)
    basename.downcase.include? _
  }
  if possible_matches.empty?
    # ===================================================================== #
    # Show a popover in this case
    # ===================================================================== #
    popover_on(
      this_widget:      @search_entry,
      use_this_message: 'No match was found for the search '\
                        'term <b>'+_+'</b>.'
    )
  else
    first = possible_matches.first
    play_this_video_file(first)
  end
end
#
#


334
335
336
337
# File 'lib/multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb', line 334

def try_to_open_the_imdb_link_in_the_browser(i)
  require 'open'
  Open.in_browser(i)
end