Class: EnvironmentInformation::GUI::UniversalWidgets::EnvironmentInformation

Inherits:
Base
  • Object
show all
Includes:
UniversalWidgets::BaseModule
Defined in:
lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb

Overview

EnvironmentInformation::GUI::UniversalWidgets::EnvironmentInformation

Constant Summary collapse

WIDTH =
#

WIDTH

#
'60% or minimum 1280px'
HEIGHT =
#

HEIGHT

#
'30% or minimum 880px'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cd, #commandline_arguments?, #e, #esystem, #first_argument?, #gold, #is_on_roebe?, #is_rbt_available?, #lightblue, #log_dir?, #mediumaquamarine, #report_left_right, #set_commandline_arguments

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ EnvironmentInformation

#

initialize

#


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 42

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

Class Method Details

.[](i = ARGV) ⇒ Object

#

EnvironmentInformation::GUI::UniversalWidgets::EnvironmentInformation[]

#


385
386
387
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 385

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

.heightObject

#

EnvironmentInformation::EnvironmentInformation::GUI::Gtk::EnvironmentInformation.height

#


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

def self.height
  HEIGHT
end

.run(i = ARGV) ⇒ Object

#

EnvironmentInformation::GUI::Gtk::EnvironmentInformation.run

#


368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 368

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::EnvironmentInformation::GUI::Gtk::EnvironmentInformation.new(i)
  r = ::Gtk.run
  _.set_parent_widget(r) # Must come before we enable the key-combinations.
  r << _
  r.automatic_size_then_automatic_title
  r.enable_quick_exit
  r.set_background :white
  r.top_left_then_run
end

.widthObject

#

EnvironmentInformation::EnvironmentInformation::GUI::Gtk::EnvironmentInformation.width

#


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

def self.width
  WIDTH
end

Instance Method Details

#add_status_iconObject

#

add_status_icon

#


176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 176

def add_status_icon
  if use_gtk3?
    _ = create_status_icon(:dialog_info)
    # ======================================================================= #
    # Add a menu and a quit-button too.
    # ======================================================================= #
    menu = create_menu
    quit = create_image_menu_item(:quit)
    quit.on_activate { ::Gtk.main_quit }
    menu.append(quit)
    menu.show_all
    _.signal_connect(:popup_menu) { |icon, button, time|
      menu.popup(nil, nil, button, time)
    }
    return _
  end
end

#connect_the_skeletonObject

#

connect_the_skeleton (connect tag)

#


302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 302

def connect_the_skeleton
  abort_on_exception

  outer_vbox = create_vbox

  # ======================================================================= #
  # Append the information contained in our @data variable to the
  # ListStore object next. This will yield an Array.
  # ======================================================================= #
  do_update_the_main_content_of_the_widget
  @tree_view.append('Name',    @renderer, text: 0)
  @tree_view.append('Version', @renderer, text: 1)
  @tree_view.the_headers_are_clickable
  @tree_view.is_sortable
  @tree_view.on_key_press_event { |w, event|
    case Gdk::Keyval.to_name(event.keyval)
    when 'Return','KP_Enter'
      e currently_selected
    end
  }
  vbox = create_vbox
  vbox.add(@toolbar)
  @scrolled_window = create_scrolled_window(@tree_view)
  @scrolled_window.set_size_request(600, 600)
  vbox.maximal(@scrolled_window, 2)
  outer_vbox.maximal(vbox)
  outer_vbox.minimal(add_status_icon) if use_gtk3?

  window = create_window_or_runner
  window << outer_vbox

  properly_prepare_this_window(window,
    {
      title:       title?,
      font:        font?,
      width:       width?,
      height:      height?,
      padding:     padding?,
      border_size: border_size?
    }
  )
  window.show_all
  window.top_left
  do_all_startup_related_actions
  run_main
end

#create_the_skeletonObject

#

create_the_skeleton (create tag, skeleton tag)

#


352
353
354
355
356
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 352

def create_the_skeleton
  create_the_toolbar
  create_the_tree_view
  @renderer = create_cell_renderer_text
end

#create_the_toolbarObject

#

create_the_toolbar

This will create the toolbar on top of the widget.

#


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 89

def create_the_toolbar
  @toolbar = create_toolbar
  # ======================================================================= #
  # (1) Add the refresh-button next.
  # ======================================================================= #
  button_refresh = create_button(:refresh)
  button_refresh.no_relief
  button_refresh.on_clicked {
    do_update_the_main_content_of_the_widget
  }
  button_refresh.hint = '<b>Click</b> on this button in order to '\
                        'refresh the information shown below.'
  @toolbar << button_refresh
  # ======================================================================= #
  # (2) Add a pin-emoji next, to assign to the xorg-buffer upon clicking
  #     on it.
  # ======================================================================= #
  pin_emoji = emoji(:pin)
  event_box_for_the_pin_emoji = event_box(pin_emoji)
  event_box_for_the_pin_emoji.on_clicked {
    do_assign_the_current_selection_to_the_xorg_buffer
  }
  pin_emoji.hint = '<b>Click</b> on this button to assign the '\
                   'current selection to the xorg-buffer.'
  @toolbar << event_box_for_the_pin_emoji
  # ======================================================================= #
  # (2) This belongs to the pin-emoji actually; the functionality should
  #     be regarded as a "cohesive unit".
  # ======================================================================= #
  @button_assign_to_the_xorg_buffer = button_xorg_buffer(label: 'Xorg')
  @button_assign_to_the_xorg_buffer.no_relief
  @button_assign_to_the_xorg_buffer.on_clicked {
    do_assign_the_current_selection_to_the_xorg_buffer
  }
  @toolbar << @button_assign_to_the_xorg_buffer
end

#create_the_tree_viewObject

#

create_the_tree_view

The TreeView widget is the main widget which allows the user to display environment-related information about installed programs.

#


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
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 201

def create_the_tree_view
  @tree_view = ::Gtk::TreeView.new(@list_store) # rf ruby gtk_TreeView
  @tree_view.do_select_multiple # Allow multiple selections.
  @tree_view.use_clickable_headers
  # ======================================================================= #
  # ruby-gtk3
  # ======================================================================= #
  @tree_view.enable_model_drag_source(
    :button1_mask,
    [ ['GTK_TREE_MODEL_ROW', 0, 0] ],
    Gdk::DragAction::COPY|Gdk::DragAction::MOVE
  )
  @tree_view.enable_model_drag_dest([
    ['GTK_TREE_MODEL_ROW', 0, 0] ],
    Gdk::DragAction::COPY|Gdk::DragAction::MOVE
  )
  @tree_view.signal_connect(:row_activated) {
    # puts "hello"
  } 
  # ========================================================================= #
  # Respond to mouse-button press events. This is currently not in use 
  # really.
  # ========================================================================= #
  @tree_view.on_button_press_event { |widget, event|
    if mouse_button_double_click?(event)
      # e 'MouseButton: double click event.'
      # ^^^ Currently we do not handle this event.
    elsif left_mouse_button_clicked?(event)
      # e 'MouseButton: left-click event (once).'
    elsif right_mouse_button_clicked?(event)
      # e 'MouseButton: right-click event (once).'
    end
  }
  @tree_view.selection.set_mode(::Gtk::SelectionMode::MULTIPLE)
  @tree_view.selection.signal_connect(:changed) {|entry|
    entry.each {|model, path, inner_array|
      if @display_information_on_the_commandline
        if inner_array[0]
          name_of_the_program  = inner_array[0].strip
        else
          name_of_the_program  = '(unknown'
        end
        version_of_the_program = inner_array[1]
        result = Colours.steelblue(
          name_of_the_program.ljust(25)
        ).dup
        if ::EnvironmentInformation.is_this_a_registered_program?(name_of_the_program)
          result << 'Version: '
        end
        result << Colours.lightgreen(version_of_the_program.to_s)
        e result
      end
    }
  }
  @tree_view.resizable_headers
end

#currently_selectedObject Also known as: return_the_current_selection_of_the_treeview_widget

#

currently_selected

Will show both key and version.

#


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 131

def currently_selected
  _ = ''.dup
  if @tree_view and @tree_view.selection
    @tree_view.selection.selected_each {|list_store, tree_path, tree_iter|
      if tree_iter[0]
        name_of_the_program = tree_iter[0].strip
      else
        name_of_the_program = 'unknown'
      end
      version_of_the_program = tree_iter[1]
      _ << "#{name_of_the_program} #{version_of_the_program}"
    }
  end
  return _
end
#
#


296
297
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 296

def do_all_startup_related_actions
end

#do_assign_the_current_selection_to_the_xorg_buffer(i = return_the_current_selection_of_the_treeview_widget) ⇒ Object

#

do_assign_the_current_selection_to_the_xorg_buffer

#


150
151
152
153
154
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 150

def do_assign_the_current_selection_to_the_xorg_buffer(
    i = return_the_current_selection_of_the_treeview_widget
  )
  @button_assign_to_the_xorg_buffer.attach(i)
end

#do_update_the_main_content_of_the_widgetObject

#

do_update_the_main_content_of_the_widget

#


159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 159

def do_update_the_main_content_of_the_widget
  assign_the_environment_information_dataset_to_the_data_variable
  @list_store.clear
  @data.each {|line|
    name, version = *line # Decompose line.
    iter = @list_store.append
    if version.nil? or version.to_s.empty?
      version = '[Not installed.]'
    end
    iter.set_value(0, name)
    iter.set_value(1, version)
  }
end

#handle_CSS_rulesObject

#

handle_CSS_rules (CSS tag)

#


261
262
263
264
265
266
267
268
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 261

def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_css_file
  more_CSS_then_apply_it '


'
end

#resetObject

#

reset (reset tag)

#


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 59

def reset
  super() if respond_to?(:super)
  reset_the_shared_module # This can come early.
  reset_the_base_module
  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, "Mono #{FONT_SIZE}")
  if use_gtk3?
    handle_CSS_rules
  end
  infer_the_size_automatically
  reset_the_variables
  # ======================================================================= #
  # === @list_store
  # ======================================================================= #
  @list_store = ::Gtk::ListStore.new(String, String)
end

#reset_the_shared_moduleObject

#

reset_the_shared_module

This method can be used for ruby-gtk3 and ruby-libui, among other toolkits.

#


276
277
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 276

def reset_the_shared_module
end

#runObject

#

run (run tag)

#


361
362
363
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 361

def run
  run_super
end