chemistry_paradise 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chemistry_paradise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +522 -0
- data/bin/chemistry_paradise +7 -0
- data/bin/wetter +7 -0
- data/chemistry_paradise.gemspec +46 -0
- data/doc/README.gen +518 -0
- data/doc/bugs/BUGS.md +16 -0
- data/doc/formulas/biochemical_calculations.md +5 -0
- data/doc/todo/todo_for_the_chemistry_paradise_project.md +33 -0
- data/doc/todo/todo_for_the_wetter_project.md +7 -0
- data/lib/chemistry_paradise/base/base.rb +215 -0
- data/lib/chemistry_paradise/base/colours.rb +93 -0
- data/lib/chemistry_paradise/commandline/help.rb +40 -0
- data/lib/chemistry_paradise/commandline/menu.rb +88 -0
- data/lib/chemistry_paradise/commandline/parse_commandline.rb +94 -0
- data/lib/chemistry_paradise/constants/constants.rb +77 -0
- data/lib/chemistry_paradise/constants/file_constants.rb +33 -0
- data/lib/chemistry_paradise/constants/german_names_of_elements_to_element_symbol.rb +157 -0
- data/lib/chemistry_paradise/converters/celsius_to_fahrenheit.rb +143 -0
- data/lib/chemistry_paradise/converters/celsius_to_kelvin.rb +125 -0
- data/lib/chemistry_paradise/converters/fahrenheit_to_celsius.rb +132 -0
- data/lib/chemistry_paradise/converters/shared.rb +21 -0
- data/lib/chemistry_paradise/gui/gtk3/calculate_molecular_weight/calculate_molecular_weight.rb +34 -0
- data/lib/chemistry_paradise/gui/gtk3/show_periodic_table/show_periodic_table.rb +34 -0
- data/lib/chemistry_paradise/gui/gtk3/temperature_converter/temperature_converter.rb +112 -0
- data/lib/chemistry_paradise/gui/gtk3/wetter/wetter.rb +119 -0
- data/lib/chemistry_paradise/gui/libui/temperature_converter/temperature_converter.rb +100 -0
- data/lib/chemistry_paradise/gui/libui/wetter/wetter.rb +47 -0
- data/lib/chemistry_paradise/gui/shared_code/calculate_molecular_weight/calculate_molecular_weight_module.rb +171 -0
- data/lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb +318 -0
- data/lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb +192 -0
- data/lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb +349 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter$1.class +0 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter.class +0 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter.java +133 -0
- data/lib/chemistry_paradise/gui/unified_widgets/wetter/wetter.rb +62 -0
- data/lib/chemistry_paradise/images/show_periodic_table.png +0 -0
- data/lib/chemistry_paradise/images/vienna_map.png +0 -0
- data/lib/chemistry_paradise/interactive_chemistry_shell.rb +246 -0
- data/lib/chemistry_paradise/project/project.rb +24 -0
- data/lib/chemistry_paradise/requires/common_external_requires.rb +17 -0
- data/lib/chemistry_paradise/requires/require_the_project.rb +21 -0
- data/lib/chemistry_paradise/requires/require_the_project_including_the_graphical_user_interface.rb +7 -0
- data/lib/chemistry_paradise/requires/require_the_project_including_the_web_interface.rb +4 -0
- data/lib/chemistry_paradise/shared.rb +130 -0
- data/lib/chemistry_paradise/show_electron_configuration.rb +250 -0
- data/lib/chemistry_paradise/show_element.rb +145 -0
- data/lib/chemistry_paradise/sinatra/sinatra.rb +131 -0
- data/lib/chemistry_paradise/sinatra/wetter/app.rb +68 -0
- data/lib/chemistry_paradise/sinatra/wetter/start_sinatra_interface.rb +31 -0
- data/lib/chemistry_paradise/split_molecule_names.rb +228 -0
- data/lib/chemistry_paradise/toplevel_methods/atomgewichte.rb +31 -0
- data/lib/chemistry_paradise/toplevel_methods/convert_parens.rb +64 -0
- data/lib/chemistry_paradise/toplevel_methods/display_where_the_molmasses_are_kept.rb +24 -0
- data/lib/chemistry_paradise/toplevel_methods/e.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/kelvin.rb +34 -0
- data/lib/chemistry_paradise/toplevel_methods/language.rb +50 -0
- data/lib/chemistry_paradise/toplevel_methods/misc.rb +147 -0
- data/lib/chemistry_paradise/toplevel_methods/periodic_table.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/remove_this_molecule_from.rb +63 -0
- data/lib/chemistry_paradise/toplevel_methods/roebe.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb +26 -0
- data/lib/chemistry_paradise/utility_scripts/calculate_atomic_mass.rb +559 -0
- data/lib/chemistry_paradise/utility_scripts/combustion_analysis.rb +207 -0
- data/lib/chemistry_paradise/utility_scripts/electron_negativity_chart.rb +78 -0
- data/lib/chemistry_paradise/utility_scripts/equalize_chemical_formula.rb +84 -0
- data/lib/chemistry_paradise/utility_scripts/equation_solver.rb +130 -0
- data/lib/chemistry_paradise/utility_scripts/orbitals.rb +70 -0
- data/lib/chemistry_paradise/utility_scripts/show_electron_negativity_of_this_element.rb +103 -0
- data/lib/chemistry_paradise/verbose_chemical_calculation.rb +21 -0
- data/lib/chemistry_paradise/version/version.rb +19 -0
- data/lib/chemistry_paradise/wetter/wetter.rb +539 -0
- data/lib/chemistry_paradise/www/wetter/embeddable_interface.rb +78 -0
- data/lib/chemistry_paradise/www/wetter/wetter.cgi +28 -0
- data/lib/chemistry_paradise/yaml/atomgewichte.yml +113 -0
- data/lib/chemistry_paradise/yaml/colours_for_the_elements.yml +13 -0
- data/lib/chemistry_paradise/yaml/dichte.yml +21 -0
- data/lib/chemistry_paradise/yaml/electron_negativity_chart.yml +111 -0
- data/lib/chemistry_paradise/yaml/molecular_formula_of_different_molecules.yml +13 -0
- data/lib/chemistry_paradise/yaml/periodic_table_of_the_elements.yml +125 -0
- data/lib/chemistry_paradise.rb +1 -0
- data/test/testing_chemistry_paradise.rb +49 -0
- metadata +173 -0
@@ -0,0 +1,318 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::GUI::Gtk::ShowPeriodicTableModule
|
6
|
+
#
|
7
|
+
# If you need to determine the currently selected (active) element
|
8
|
+
# then you could use the method .active_element?().
|
9
|
+
# =========================================================================== #
|
10
|
+
# require 'chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb'
|
11
|
+
# include ::ChemistryParadise::GUI::Gtk::ShowPeriodicTableModule
|
12
|
+
# =========================================================================== #
|
13
|
+
module ChemistryParadise
|
14
|
+
|
15
|
+
module GUI
|
16
|
+
|
17
|
+
module Gtk
|
18
|
+
|
19
|
+
module ShowPeriodicTableModule # === ChemistryParadise::GUI::Gtk::ShowPeriodicTableModule
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'colours'
|
23
|
+
rescue LoadError; end
|
24
|
+
|
25
|
+
require 'chemistry_paradise/constants/file_constants.rb'
|
26
|
+
require 'chemistry_paradise/toplevel_methods/atomgewichte.rb'
|
27
|
+
require 'chemistry_paradise/utility_scripts/calculate_atomic_mass.rb'
|
28
|
+
|
29
|
+
require 'gtk_paradise/requires/require_the_base_module.rb'
|
30
|
+
include ::Gtk::BaseModule
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === NAMESPACE
|
34
|
+
# ========================================================================= #
|
35
|
+
NAMESPACE = inspect
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === TITLE
|
39
|
+
# ========================================================================= #
|
40
|
+
TITLE = 'Show Periodic Table'
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === FILE_ATOMGEWICHTE
|
44
|
+
# ========================================================================= #
|
45
|
+
FILE_ATOMGEWICHTE = ChemistryParadise::Constants::FILE_ATOMGEWICHTE
|
46
|
+
|
47
|
+
# ========================================================================= #
|
48
|
+
# === WIDTH
|
49
|
+
# ========================================================================= #
|
50
|
+
WIDTH = 1020
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === HEIGHT
|
54
|
+
# ========================================================================= #
|
55
|
+
HEIGHT = 500
|
56
|
+
|
57
|
+
# ========================================================================= #
|
58
|
+
# === USE_THIS_FONT
|
59
|
+
# ========================================================================= #
|
60
|
+
USE_THIS_FONT = :dejavu_condensed_20
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === initialize
|
64
|
+
# ========================================================================= #
|
65
|
+
def initialize(
|
66
|
+
optional_file = nil,
|
67
|
+
run_already = true
|
68
|
+
)
|
69
|
+
super(:vertical)
|
70
|
+
reset
|
71
|
+
run if run_already
|
72
|
+
end
|
73
|
+
|
74
|
+
# ========================================================================= #
|
75
|
+
# === reset (reset tag)
|
76
|
+
# ========================================================================= #
|
77
|
+
def reset
|
78
|
+
reset_the_internal_variables
|
79
|
+
# ======================================================================= #
|
80
|
+
# === @configuration
|
81
|
+
# ======================================================================= #
|
82
|
+
@configuration = [true, __dir__, NAMESPACE]
|
83
|
+
# ======================================================================= #
|
84
|
+
# === @title
|
85
|
+
# ======================================================================= #
|
86
|
+
@title = TITLE
|
87
|
+
# ======================================================================= #
|
88
|
+
# === @width
|
89
|
+
# ======================================================================= #
|
90
|
+
set_width(WIDTH)
|
91
|
+
# ======================================================================= #
|
92
|
+
# === @height
|
93
|
+
# ======================================================================= #
|
94
|
+
set_height(HEIGHT)
|
95
|
+
set_use_this_font(USE_THIS_FONT)
|
96
|
+
use_gtk_paradise_project_css_file
|
97
|
+
infer_the_size_automatically
|
98
|
+
end
|
99
|
+
|
100
|
+
# ========================================================================= #
|
101
|
+
# === padding?
|
102
|
+
# ========================================================================= #
|
103
|
+
def padding?
|
104
|
+
0
|
105
|
+
end
|
106
|
+
|
107
|
+
# ========================================================================= #
|
108
|
+
# === border_size?
|
109
|
+
# ========================================================================= #
|
110
|
+
def border_size?
|
111
|
+
0
|
112
|
+
end
|
113
|
+
|
114
|
+
# ========================================================================= #
|
115
|
+
# === create_skeleton (create tag)
|
116
|
+
# ========================================================================= #
|
117
|
+
def create_skeleton
|
118
|
+
end
|
119
|
+
|
120
|
+
# ========================================================================= #
|
121
|
+
# === return_the_dataset_from_the_file_atomgewichte
|
122
|
+
# ========================================================================= #
|
123
|
+
def return_the_dataset_from_the_file_atomgewichte(
|
124
|
+
use_this_file = ::ChemistryParadise.file_atomgewichte
|
125
|
+
)
|
126
|
+
YAML.load_file(use_this_file) if File.exist? use_this_file
|
127
|
+
end
|
128
|
+
|
129
|
+
# ========================================================================= #
|
130
|
+
# === run (run tag)
|
131
|
+
# ========================================================================= #
|
132
|
+
def run
|
133
|
+
create_skeleton_then_connect_skeleton
|
134
|
+
end
|
135
|
+
|
136
|
+
# ========================================================================= #
|
137
|
+
# === active_button?
|
138
|
+
#
|
139
|
+
# This method will return the currently selected, active button.
|
140
|
+
# ========================================================================= #
|
141
|
+
def active_button?
|
142
|
+
return_all_toggle_buttons.select {|another_button|
|
143
|
+
another_button.active?
|
144
|
+
}
|
145
|
+
end; alias active? active_button? # === active?
|
146
|
+
|
147
|
+
# ========================================================================= #
|
148
|
+
# === return_random_html_colour
|
149
|
+
# ========================================================================= #
|
150
|
+
def return_random_html_colour
|
151
|
+
::Colours.random_html_colour
|
152
|
+
end
|
153
|
+
|
154
|
+
# ========================================================================= #
|
155
|
+
# === return_colour_based_on_index
|
156
|
+
# ========================================================================= #
|
157
|
+
def return_colour_based_on_index(i)
|
158
|
+
case i
|
159
|
+
when 0 .. 10
|
160
|
+
:darkseagreen
|
161
|
+
when 11 .. 20
|
162
|
+
:cornsilk
|
163
|
+
when 21 .. 30
|
164
|
+
:lightgreen
|
165
|
+
when 31 .. 40
|
166
|
+
:skyblue
|
167
|
+
when 41 .. 50
|
168
|
+
:yellow
|
169
|
+
when 51 .. 60
|
170
|
+
:steelblue
|
171
|
+
when 61 .. 70
|
172
|
+
:magenta
|
173
|
+
else
|
174
|
+
e 'Not handled above 70 right now, but this should be changed '\
|
175
|
+
'eventually. The value was: '+i.to_s
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# ========================================================================= #
|
180
|
+
# === clear_the_toggle_state_of_all_buttons_but_this_one
|
181
|
+
#
|
182
|
+
# We invoke this method only when the toggle-button's state is set
|
183
|
+
# to active.
|
184
|
+
# ========================================================================= #
|
185
|
+
def clear_the_toggle_state_of_all_buttons_but_this_one(
|
186
|
+
this_button
|
187
|
+
)
|
188
|
+
all_toggle_buttons = return_all_toggle_buttons
|
189
|
+
_ = all_toggle_buttons.reject {|another_button|
|
190
|
+
another_button == this_button
|
191
|
+
}
|
192
|
+
_.each {|another_button|
|
193
|
+
another_button.is_inactive
|
194
|
+
another_button.remove_this_css_class('bblack3')
|
195
|
+
another_button.add_this_css_class('bblack2')
|
196
|
+
}
|
197
|
+
end
|
198
|
+
|
199
|
+
# ========================================================================= #
|
200
|
+
# === active_element?
|
201
|
+
#
|
202
|
+
# This method will either return nil, or it will return the String
|
203
|
+
# indicating which element is currently active, such as "Co" for
|
204
|
+
# "Cobalt".
|
205
|
+
# ========================================================================= #
|
206
|
+
def active_element?
|
207
|
+
_ = active_button?
|
208
|
+
if _
|
209
|
+
_ = _.first if _.is_a? Array
|
210
|
+
return _.text?
|
211
|
+
else
|
212
|
+
return _
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# ========================================================================= #
|
217
|
+
# === GtkParadise::GUI::Gtk::ShowPeriodicTableModule.run
|
218
|
+
# ========================================================================= #
|
219
|
+
def self.run(
|
220
|
+
i = ARGV
|
221
|
+
)
|
222
|
+
require 'gtk_paradise/run'
|
223
|
+
_ = ::ChemistryParadise::GUI::Gtk::ShowPeriodicTable.new(i)
|
224
|
+
r = ::Gtk.run
|
225
|
+
r << _
|
226
|
+
r.automatic
|
227
|
+
r.top_left_then_run
|
228
|
+
end
|
229
|
+
|
230
|
+
# ========================================================================= #
|
231
|
+
# === connect_skeleton (connect tag)
|
232
|
+
# ========================================================================= #
|
233
|
+
def connect_skeleton
|
234
|
+
abort_on_exception
|
235
|
+
dataset = return_the_dataset_from_the_file_atomgewichte
|
236
|
+
outer_vbox = gtk_vbox
|
237
|
+
|
238
|
+
index = 0
|
239
|
+
|
240
|
+
dataset.each_slice(10).each {|row|
|
241
|
+
hbox = gtk_hbox
|
242
|
+
row.each {|name_of_the_element, molecular_weight|
|
243
|
+
index += 1
|
244
|
+
button = gtk_toggle_button(name_of_the_element)
|
245
|
+
button.clear_background
|
246
|
+
button.bblack2
|
247
|
+
button.set_size_request(84, 84)
|
248
|
+
button.set_width_request(84)
|
249
|
+
button.set_height_request(84)
|
250
|
+
_ = return_random_html_colour
|
251
|
+
button.override_background_colour(
|
252
|
+
return_colour_based_on_index(index)
|
253
|
+
)
|
254
|
+
button.disallow_resizing
|
255
|
+
# =================================================================== #
|
256
|
+
# On click action for the toggle-button, do this:
|
257
|
+
# =================================================================== #
|
258
|
+
button.signal_connect(:button_press_event) {
|
259
|
+
output_the_name_of_this_element_and_this_molecular_weight(
|
260
|
+
name_of_the_element, molecular_weight
|
261
|
+
)
|
262
|
+
@entry1.append_text(name_of_the_element.to_s)
|
263
|
+
calculate_the_weight_for_entry2
|
264
|
+
if button.active?
|
265
|
+
button.remove_this_css_class('bblack2')
|
266
|
+
button.remove_this_css_class('bblack3')
|
267
|
+
clear_the_toggle_state_of_all_buttons_but_this_one(button)
|
268
|
+
button.bblack3
|
269
|
+
end
|
270
|
+
}
|
271
|
+
hbox.minimal(button, 1)
|
272
|
+
}
|
273
|
+
outer_vbox.minimal(hbox, 2)
|
274
|
+
}
|
275
|
+
outer_vbox.set_border_width(20)
|
276
|
+
outer_vbox.minimal(return_lower_widget_containing_the_user_input_entry, 2)
|
277
|
+
maximal(outer_vbox, 15)
|
278
|
+
end
|
279
|
+
|
280
|
+
# ========================================================================= #
|
281
|
+
# === output_the_name_of_this_element_and_this_molecular_weight
|
282
|
+
# ========================================================================= #
|
283
|
+
def output_the_name_of_this_element_and_this_molecular_weight(
|
284
|
+
name_of_the_element,
|
285
|
+
molecular_weight
|
286
|
+
)
|
287
|
+
e name_of_the_element+' '+molecular_weight.to_s+' ame'
|
288
|
+
end
|
289
|
+
|
290
|
+
# ========================================================================= #
|
291
|
+
# === calculate_the_weight_for_entry2
|
292
|
+
# ========================================================================= #
|
293
|
+
def calculate_the_weight_for_entry2
|
294
|
+
_ = @entry1.text?
|
295
|
+
result = ChemistryParadise.atomic_mass_of(_)
|
296
|
+
@entry2.set_text(result.to_s)
|
297
|
+
end
|
298
|
+
|
299
|
+
# ========================================================================= #
|
300
|
+
# === return_lower_widget_containing_the_user_input_entry
|
301
|
+
# ========================================================================= #
|
302
|
+
def return_lower_widget_containing_the_user_input_entry
|
303
|
+
vbox = gtk_vbox
|
304
|
+
@entry1 = gtk_entry
|
305
|
+
@entry1.bblack1
|
306
|
+
@entry1.center
|
307
|
+
@entry1.on_enter { calculate_the_weight_for_entry2 }
|
308
|
+
@entry1.yellow_background
|
309
|
+
vbox.minimal(@entry1, 2)
|
310
|
+
@entry2 = gtk_entry
|
311
|
+
@entry2.bblack1
|
312
|
+
@entry2.center
|
313
|
+
@entry2.yellow_background
|
314
|
+
vbox.minimal(@entry2, 2)
|
315
|
+
return vbox
|
316
|
+
end
|
317
|
+
|
318
|
+
end; end; end; end
|
data/lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::GUI::TemperatureConverterModule
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb'
|
8
|
+
# include ChemistryParadise::GUI::TemperatureConverterModule
|
9
|
+
# =========================================================================== #
|
10
|
+
module ChemistryParadise
|
11
|
+
|
12
|
+
module GUI
|
13
|
+
|
14
|
+
module TemperatureConverterModule # === ChemistryParadise::GUI::TemperatureConverterModule
|
15
|
+
|
16
|
+
require 'chemistry_paradise/toplevel_methods/kelvin.rb'
|
17
|
+
require 'chemistry_paradise/converters/celsius_to_fahrenheit.rb'
|
18
|
+
require 'chemistry_paradise/converters/fahrenheit_to_celsius.rb'
|
19
|
+
|
20
|
+
# ========================================================================= #
|
21
|
+
# === NAMESPACE
|
22
|
+
# ========================================================================= #
|
23
|
+
NAMESPACE = inspect
|
24
|
+
|
25
|
+
# ========================================================================= #
|
26
|
+
# === TITLE
|
27
|
+
# ========================================================================= #
|
28
|
+
TITLE = 'Temperature Converter'
|
29
|
+
|
30
|
+
# ========================================================================= #
|
31
|
+
# === WIDTH
|
32
|
+
# ========================================================================= #
|
33
|
+
WIDTH = '35% or minimum 540px'
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === HEIGHT
|
37
|
+
# ========================================================================= #
|
38
|
+
HEIGHT = '20% or minimum 250px'
|
39
|
+
|
40
|
+
# ========================================================================= #
|
41
|
+
# === USE_THIS_FONT
|
42
|
+
# ========================================================================= #
|
43
|
+
USE_THIS_FONT = :dejavu_condensed_22
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === reset_the_shared_module
|
47
|
+
# ========================================================================= #
|
48
|
+
def reset_the_shared_module
|
49
|
+
title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
|
50
|
+
end
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === padding?
|
54
|
+
# ========================================================================= #
|
55
|
+
def padding?
|
56
|
+
8
|
57
|
+
end
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# === border_size?
|
61
|
+
# ========================================================================= #
|
62
|
+
def border_size?
|
63
|
+
0
|
64
|
+
end
|
65
|
+
|
66
|
+
# ========================================================================= #
|
67
|
+
# === create_the_entries (entries tag, entry tag)
|
68
|
+
# ========================================================================= #
|
69
|
+
def create_the_entries
|
70
|
+
# ======================================================================= #
|
71
|
+
# === @entry_celsius
|
72
|
+
# ======================================================================= #
|
73
|
+
@entry_celsius = entry
|
74
|
+
@entry_celsius.center
|
75
|
+
@entry_celsius.yellow_background
|
76
|
+
# @entry_celsius.accept_only_numbers_as_input
|
77
|
+
@entry_celsius.on_enter {
|
78
|
+
calculate_fahrenheit_and_set_the_correct_value
|
79
|
+
}
|
80
|
+
callback = proc { |ptr|
|
81
|
+
last_character = @entry_celsius.text?[-1, 1]
|
82
|
+
case last_character
|
83
|
+
when /\d+/ # is a number
|
84
|
+
calculate_fahrenheit_and_set_the_correct_value
|
85
|
+
when nil, ''
|
86
|
+
set_all_entries_to('')
|
87
|
+
end
|
88
|
+
}
|
89
|
+
@entry_celsius.on_changed { callback }
|
90
|
+
# ======================================================================= #
|
91
|
+
# === @entry_fahrenheit
|
92
|
+
# ======================================================================= #
|
93
|
+
@entry_fahrenheit = entry
|
94
|
+
@entry_fahrenheit.center
|
95
|
+
@entry_fahrenheit.yellow_background
|
96
|
+
@entry_fahrenheit.on_enter {
|
97
|
+
calculate_celsius_and_set_the_correct_value
|
98
|
+
}
|
99
|
+
# ======================================================================= #
|
100
|
+
# === @entry_kelvin
|
101
|
+
# ======================================================================= #
|
102
|
+
@entry_kelvin = entry
|
103
|
+
@entry_kelvin.center
|
104
|
+
@entry_kelvin.yellow_background
|
105
|
+
@entry_kelvin.on_enter {
|
106
|
+
calculate_kelvin_and_set_the_correct_value
|
107
|
+
}
|
108
|
+
# ======================================================================= #
|
109
|
+
# Style the various entries next in an uniform manner.
|
110
|
+
# ======================================================================= #
|
111
|
+
return_all_entries.each {|this_entry|
|
112
|
+
this_entry.bblack1
|
113
|
+
this_entry.width_height(350, 44)
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
# ========================================================================= #
|
118
|
+
# === calculate_celsius_and_set_the_correct_value
|
119
|
+
# ========================================================================= #
|
120
|
+
def calculate_celsius_and_set_the_correct_value(
|
121
|
+
i = @entry_fahrenheit.text?
|
122
|
+
)
|
123
|
+
i = ChemistryParadise::FahrenheitToCelsius.new(i).celsius?.to_s.delete('`').to_f.round(2).to_s
|
124
|
+
@entry_celsius.set_text(i.to_s)
|
125
|
+
end
|
126
|
+
|
127
|
+
# ========================================================================= #
|
128
|
+
# === calculate_kelvin_and_set_the_correct_value
|
129
|
+
# ========================================================================= #
|
130
|
+
def calculate_kelvin_and_set_the_correct_value(
|
131
|
+
i = @entry_celsius.text?
|
132
|
+
)
|
133
|
+
i = ChemistryParadise.kelvin(i)
|
134
|
+
@entry_celsius.set_text(i.to_s)
|
135
|
+
end
|
136
|
+
|
137
|
+
# ========================================================================= #
|
138
|
+
# === return_n_kelvin
|
139
|
+
# ========================================================================= #
|
140
|
+
def return_n_kelvin(
|
141
|
+
i = @entry_celsius.text?
|
142
|
+
)
|
143
|
+
result = ChemistryParadise.kelvin(i)
|
144
|
+
result = 0 if result.to_f < 0 # Kelvin can never be below 0.
|
145
|
+
return result
|
146
|
+
end
|
147
|
+
|
148
|
+
# ========================================================================= #
|
149
|
+
# === calculate_fahrenheit_and_set_the_correct_value
|
150
|
+
#
|
151
|
+
# This is the to_fahrenheit conversion.
|
152
|
+
# ========================================================================= #
|
153
|
+
def calculate_fahrenheit_and_set_the_correct_value(
|
154
|
+
i = @entry_celsius.text?
|
155
|
+
)
|
156
|
+
# ======================================================================= #
|
157
|
+
# Also set the value of n Kelvin.
|
158
|
+
# ======================================================================= #
|
159
|
+
@entry_kelvin.set_text(
|
160
|
+
return_n_kelvin(i).to_s.to_f.round(2).to_s
|
161
|
+
)
|
162
|
+
i = ChemistryParadise::CelsiusToFahrenheit.new(i).fahrenheit?
|
163
|
+
@entry_fahrenheit.set_text(i.to_s)
|
164
|
+
end
|
165
|
+
|
166
|
+
# ========================================================================= #
|
167
|
+
# === set_all_entries_to
|
168
|
+
# ========================================================================= #
|
169
|
+
def set_all_entries_to(i = '')
|
170
|
+
return_all_entries.each {|this_entry| this_entry.set_text(i.to_s) }
|
171
|
+
end
|
172
|
+
|
173
|
+
# ========================================================================= #
|
174
|
+
# === return_the_title_as_label
|
175
|
+
# ========================================================================= #
|
176
|
+
def return_the_title_as_label
|
177
|
+
left_aligned_bold_label(TITLE)
|
178
|
+
end
|
179
|
+
|
180
|
+
# ========================================================================= #
|
181
|
+
# === create_the_grid
|
182
|
+
# ========================================================================= #
|
183
|
+
def create_the_grid
|
184
|
+
# ======================================================================= #
|
185
|
+
# === @grid
|
186
|
+
# ======================================================================= #
|
187
|
+
@grid = grid { :default }
|
188
|
+
@grid.pad10px
|
189
|
+
@grid.spacing = 8
|
190
|
+
end
|
191
|
+
|
192
|
+
end; end; end
|