Module: ChemistryParadise::GUI::Gtk::ShowPeriodicTableModule

Includes:
Gtk::BaseModule
Included in:
ShowPeriodicTable
Defined in:
lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb

Overview

ChemistryParadise::GUI::Gtk::ShowPeriodicTableModule

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'Show Periodic Table'
FILE_ATOMGEWICHTE =
#

FILE_ATOMGEWICHTE

#
ChemistryParadise::Constants::FILE_ATOMGEWICHTE
WIDTH =
#

WIDTH

#
1020
HEIGHT =
#

HEIGHT

#
500
USE_THIS_FONT =
#

USE_THIS_FONT

#
:dejavu_condensed_20

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(i = ARGV) ⇒ Object

#

GtkParadise::GUI::Gtk::ShowPeriodicTableModule.run

#


219
220
221
222
223
224
225
226
227
228
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 219

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::ChemistryParadise::GUI::Gtk::ShowPeriodicTable.new(i)
  r = ::Gtk.run
  r << _
  r.automatic
  r.top_left_then_run
end

Instance Method Details

#active_button?Boolean Also known as: active?

#

active_button?

This method will return the currently selected, active button.

#

Returns:

  • (Boolean)


141
142
143
144
145
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 141

def active_button?
  return_all_toggle_buttons.select {|another_button|
    another_button.active?
  }
end

#active_element?Boolean

#

active_element?

This method will either return nil, or it will return the String indicating which element is currently active, such as “Co” for “Cobalt”.

#

Returns:

  • (Boolean)


206
207
208
209
210
211
212
213
214
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 206

def active_element?
  _ = active_button?
  if _
    _ = _.first if _.is_a? Array
    return _.text?
  else
    return _
  end
end

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


110
111
112
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 110

def border_size?
  0
end

#calculate_the_weight_for_entry2Object

#

calculate_the_weight_for_entry2

#


293
294
295
296
297
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 293

def calculate_the_weight_for_entry2
  _ = @entry1.text?
  result = ChemistryParadise.atomic_mass_of(_)  
  @entry2.set_text(result.to_s)
end

#clear_the_toggle_state_of_all_buttons_but_this_one(this_button) ⇒ Object

#

clear_the_toggle_state_of_all_buttons_but_this_one

We invoke this method only when the toggle-button’s state is set to active.

#


185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 185

def clear_the_toggle_state_of_all_buttons_but_this_one(
    this_button
  )
  all_toggle_buttons = return_all_toggle_buttons
  _ = all_toggle_buttons.reject {|another_button|
    another_button == this_button
  }
  _.each {|another_button|
    another_button.is_inactive
    another_button.remove_this_css_class('bblack3')
    another_button.add_this_css_class('bblack2')
  }
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#


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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 233

def connect_skeleton
  abort_on_exception
  dataset = return_the_dataset_from_the_file_atomgewichte
  outer_vbox = gtk_vbox

  index = 0

  dataset.each_slice(10).each {|row|
    hbox = gtk_hbox
    row.each {|name_of_the_element, molecular_weight|
      index += 1
      button = gtk_toggle_button(name_of_the_element)
      button.clear_background
      button.bblack2
      button.set_size_request(84, 84)
      button.set_width_request(84)
      button.set_height_request(84)
      _ = return_random_html_colour
      button.override_background_colour(
        return_colour_based_on_index(index)
      )
      button.disallow_resizing
      # =================================================================== #
      # On click action for the toggle-button, do this:
      # =================================================================== #
      button.signal_connect(:button_press_event) {
        output_the_name_of_this_element_and_this_molecular_weight(
          name_of_the_element, molecular_weight
        )
        @entry1.append_text(name_of_the_element.to_s)
        calculate_the_weight_for_entry2
        if button.active?
          button.remove_this_css_class('bblack2')
          button.remove_this_css_class('bblack3')
          clear_the_toggle_state_of_all_buttons_but_this_one(button)
          button.bblack3
        end
      }
      hbox.minimal(button, 1)
    }
    outer_vbox.minimal(hbox, 2)
  }
  outer_vbox.set_border_width(20)
  outer_vbox.minimal(return_lower_widget_containing_the_user_input_entry, 2)
  maximal(outer_vbox, 15)
end

#create_skeletonObject

#

create_skeleton (create tag)

#


117
118
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 117

def create_skeleton
end

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

#

initialize

#


65
66
67
68
69
70
71
72
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 65

def initialize(
    optional_file = nil,
    run_already   = true
  )
  super(:vertical)
  reset
  run if run_already
end

#output_the_name_of_this_element_and_this_molecular_weight(name_of_the_element, molecular_weight) ⇒ Object

#

output_the_name_of_this_element_and_this_molecular_weight

#


283
284
285
286
287
288
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 283

def output_the_name_of_this_element_and_this_molecular_weight(
      name_of_the_element,
      molecular_weight
    )
  e name_of_the_element+' '+molecular_weight.to_s+' ame'
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


103
104
105
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 103

def padding?
  0
end

#resetObject

#

reset (reset tag)

#


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 77

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  # ======================================================================= #
  # === @title
  # ======================================================================= #
  @title  = TITLE
  # ======================================================================= #
  # === @width
  # ======================================================================= #
  set_width(WIDTH)
  # ======================================================================= #
  # === @height
  # ======================================================================= #
  set_height(HEIGHT)
  set_use_this_font(USE_THIS_FONT)
  use_gtk_paradise_project_css_file
  infer_the_size_automatically
end

#return_colour_based_on_index(i) ⇒ Object

#

return_colour_based_on_index

#


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 157

def return_colour_based_on_index(i)
  case i
  when 0 .. 10
    :darkseagreen
  when 11 .. 20
    :cornsilk
  when 21 .. 30
    :lightgreen
  when 31 .. 40
    :skyblue
  when 41 .. 50
    :yellow
  when 51 .. 60
    :steelblue
  when 61 .. 70
    :magenta
  else
    e 'Not handled above 70 right now, but this should be changed '\
      'eventually. The value was: '+i.to_s
  end
end

#return_lower_widget_containing_the_user_input_entryObject

#

return_lower_widget_containing_the_user_input_entry

#


302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 302

def return_lower_widget_containing_the_user_input_entry
  vbox = gtk_vbox
  @entry1 = gtk_entry
  @entry1.bblack1
  @entry1.center
  @entry1.on_enter { calculate_the_weight_for_entry2 }
  @entry1.yellow_background
  vbox.minimal(@entry1, 2)
  @entry2 = gtk_entry
  @entry2.bblack1
  @entry2.center
  @entry2.yellow_background
  vbox.minimal(@entry2, 2)
  return vbox
end

#return_random_html_colourObject

#

return_random_html_colour

#


150
151
152
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 150

def return_random_html_colour
  ::Colours.random_html_colour
end

#return_the_dataset_from_the_file_atomgewichte(use_this_file = ::ChemistryParadise.file_atomgewichte) ⇒ Object

#

return_the_dataset_from_the_file_atomgewichte

#


123
124
125
126
127
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 123

def return_the_dataset_from_the_file_atomgewichte(
    use_this_file = ::ChemistryParadise.file_atomgewichte
  )
  YAML.load_file(use_this_file) if File.exist? use_this_file
end

#runObject

#

run (run tag)

#


132
133
134
# File 'lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb', line 132

def run
  create_skeleton_then_connect_skeleton
end