chemistry_paradise 1.1.26
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 +419 -0
- data/bin/chemistry_paradise +7 -0
- data/chemistry_paradise.gemspec +46 -0
- data/doc/BUGS.md +16 -0
- data/doc/README.gen +391 -0
- data/doc/todo/TODO.md +26 -0
- data/lib/chemistry_paradise/base/base.rb +101 -0
- data/lib/chemistry_paradise/base/colours.rb +65 -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 +52 -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/fahrenheit_to_celsius.rb +132 -0
- data/lib/chemistry_paradise/converters/shared.rb +15 -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 +249 -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/images/show_periodic_table.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 +19 -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/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 +128 -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/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/www/chemistry/chemistry.cgi +7 -0
- data/lib/chemistry_paradise/www/chemistry/chemistry.rb +1526 -0
- data/lib/chemistry_paradise/www/chemistry/chemistry.sinatra +56 -0
- data/lib/chemistry_paradise/www/organic_chemistry/organic_chemistry.md +16 -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 +155 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::FahrenheitToCelsius
|
6
|
+
#
|
7
|
+
# Usage example:
|
8
|
+
#
|
9
|
+
# ChemistryParadise::FahrenheitToCelsius.new
|
10
|
+
#
|
11
|
+
# =========================================================================== #
|
12
|
+
# require 'chemistry_paradise/converters/fahrenheit_to_celsius.rb'
|
13
|
+
# =========================================================================== #
|
14
|
+
module ChemistryParadise
|
15
|
+
|
16
|
+
class FahrenheitToCelsius # === ChemistryParadise::FahrenheitToCelsius
|
17
|
+
|
18
|
+
require 'chemistry_paradise/converters/shared.rb'
|
19
|
+
|
20
|
+
begin
|
21
|
+
require 'opn'
|
22
|
+
rescue LoadError; end
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'colours'
|
26
|
+
include Colours
|
27
|
+
rescue LoadError; end
|
28
|
+
|
29
|
+
include ChemistryParadise::Converters
|
30
|
+
|
31
|
+
# ========================================================================= #
|
32
|
+
# === NAMESPACE
|
33
|
+
# ========================================================================= #
|
34
|
+
NAMESPACE = inspect
|
35
|
+
|
36
|
+
# ========================================================================= #
|
37
|
+
# === initialize
|
38
|
+
# ========================================================================= #
|
39
|
+
def initialize(
|
40
|
+
fahrenheit = 0,
|
41
|
+
run_already = true
|
42
|
+
)
|
43
|
+
reset
|
44
|
+
set_fahrenheit(fahrenheit)
|
45
|
+
run if run_already
|
46
|
+
end
|
47
|
+
|
48
|
+
# ========================================================================= #
|
49
|
+
# === reset (reset tag)
|
50
|
+
# ========================================================================= #
|
51
|
+
def reset
|
52
|
+
set_fahrenheit
|
53
|
+
end
|
54
|
+
|
55
|
+
# ========================================================================= #
|
56
|
+
# === set_fahrenheit
|
57
|
+
# ========================================================================= #
|
58
|
+
def set_fahrenheit(i = 0)
|
59
|
+
i = i.first if i.is_a? Array
|
60
|
+
i = i.to_s.dup
|
61
|
+
i = i.to_f
|
62
|
+
@fahrenheit = i
|
63
|
+
end
|
64
|
+
|
65
|
+
# ========================================================================= #
|
66
|
+
# === do_the_calculation
|
67
|
+
#
|
68
|
+
# We determine how many Fahrenheit we have here, by using the
|
69
|
+
# specific formula.
|
70
|
+
# ========================================================================= #
|
71
|
+
def do_the_calculation
|
72
|
+
@celsius = (@fahrenheit - 32) / FAHRENHEIT_TO_CELSIUS_CONVERSION_FACTOR
|
73
|
+
end
|
74
|
+
|
75
|
+
# ========================================================================= #
|
76
|
+
# === fahrenheit?
|
77
|
+
# ========================================================================= #
|
78
|
+
def fahrenheit?
|
79
|
+
@fahrenheit
|
80
|
+
end; alias n_fahrenheit fahrenheit? # === fahrenheit?
|
81
|
+
|
82
|
+
# ========================================================================= #
|
83
|
+
# === input?
|
84
|
+
# ========================================================================= #
|
85
|
+
def celsius?
|
86
|
+
@celsius
|
87
|
+
end; alias n_celsius celsius? # === n_celsius
|
88
|
+
|
89
|
+
# ========================================================================= #
|
90
|
+
# === run (run tag)
|
91
|
+
# ========================================================================= #
|
92
|
+
def run
|
93
|
+
do_the_calculation
|
94
|
+
end
|
95
|
+
|
96
|
+
# ========================================================================= #
|
97
|
+
# === report_result
|
98
|
+
# ========================================================================= #
|
99
|
+
def report_result
|
100
|
+
opnn if use_opn?
|
101
|
+
e n_fahrenheit.to_s+'° '+simp('Fahrenheit')+' are '+n_celsius.round(2).to_s+
|
102
|
+
'° '+simp('Celsius')+'.'
|
103
|
+
end; alias report report_result # === report
|
104
|
+
|
105
|
+
# ========================================================================= #
|
106
|
+
# === use_opn?
|
107
|
+
# ========================================================================= #
|
108
|
+
def use_opn?
|
109
|
+
false
|
110
|
+
end
|
111
|
+
|
112
|
+
# ========================================================================= #
|
113
|
+
# === opnn
|
114
|
+
# ========================================================================= #
|
115
|
+
def opnn
|
116
|
+
Opn.opn(use_this_as_namespace: NAMESPACE)
|
117
|
+
end
|
118
|
+
|
119
|
+
# ========================================================================= #
|
120
|
+
# === ChemistryParadise::FahrenheitToCelsius[]
|
121
|
+
# ========================================================================= #
|
122
|
+
def self.[](i)
|
123
|
+
_ = FahrenheitToCelsius.new(i)
|
124
|
+
_.report
|
125
|
+
end
|
126
|
+
|
127
|
+
end; end
|
128
|
+
|
129
|
+
if __FILE__ == $PROGRAM_NAME
|
130
|
+
_ = ChemistryParadise::FahrenheitToCelsius.new(ARGV)
|
131
|
+
_.report_result
|
132
|
+
end # fahrenheittocelsius2 50
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ChemistryParadise # require 'chemistry_paradise/converters/shared.rb'
|
2
|
+
|
3
|
+
module Converters # === include ChemistryParadise::Converters
|
4
|
+
|
5
|
+
# ========================================================================= #
|
6
|
+
# === CELSIUS_TO_FAHRENHEIT_CONVERSION_FACTOR
|
7
|
+
# ========================================================================= #
|
8
|
+
CELSIUS_TO_FAHRENHEIT_CONVERSION_FACTOR = 1.8000
|
9
|
+
|
10
|
+
# ========================================================================= #
|
11
|
+
# === FAHRENHEIT_TO_CELSIUS_CONVERSION_FACTOR
|
12
|
+
# ========================================================================= #
|
13
|
+
FAHRENHEIT_TO_CELSIUS_CONVERSION_FACTOR = 1 / ( 5.0 / 9)
|
14
|
+
|
15
|
+
end; end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::GUI::Gtk::CalculateMolecularWeight
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'chemistry_paradise/gui/gtk3/chemistry_paradise/chemistry_paradise.rb'
|
8
|
+
# ChemistryParadise::GUI::Gtk::CalculateMolecularWeight.run
|
9
|
+
# =========================================================================== #
|
10
|
+
require 'gtk_paradise/require_gtk3'
|
11
|
+
|
12
|
+
module ChemistryParadise
|
13
|
+
|
14
|
+
module GUI
|
15
|
+
|
16
|
+
module Gtk
|
17
|
+
|
18
|
+
class CalculateMolecularWeight < ::Gtk::Box
|
19
|
+
|
20
|
+
require 'chemistry_paradise/gui/shared_code/calculate_molecular_weight/calculate_molecular_weight_module.rb'
|
21
|
+
include ::ChemistryParadise::GUI::Gtk::CalculateMolecularWeightModule
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === ChemistryParadise::GUI::Gtk::CalculateMolecularWeight.run
|
25
|
+
# ========================================================================= #
|
26
|
+
def self.run
|
27
|
+
::ChemistryParadise::GUI::Gtk::CalculateMolecularWeightModule.run
|
28
|
+
end
|
29
|
+
|
30
|
+
end; end; end; end
|
31
|
+
|
32
|
+
if __FILE__ == $PROGRAM_NAME
|
33
|
+
ChemistryParadise::GUI::Gtk::CalculateMolecularWeight.run
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::GUI::Gtk::ShowPeriodicTable
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'chemistry_paradise/gui/gtk3/show_periodic_table/show_periodic_table.rb'
|
8
|
+
# ChemistryParadise::GUI::Gtk::ShowPeriodicTable.run
|
9
|
+
# =========================================================================== #
|
10
|
+
require 'gtk_paradise/require_gtk3'
|
11
|
+
|
12
|
+
module ChemistryParadise
|
13
|
+
|
14
|
+
module GUI
|
15
|
+
|
16
|
+
module Gtk
|
17
|
+
|
18
|
+
class ShowPeriodicTable < ::Gtk::Box
|
19
|
+
|
20
|
+
require 'chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb'
|
21
|
+
include ::ChemistryParadise::GUI::Gtk::ShowPeriodicTableModule
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === ChemistryParadise::GUI::Gtk::ShowPeriodicTable.run
|
25
|
+
# ========================================================================= #
|
26
|
+
def self.run
|
27
|
+
::ChemistryParadise::GUI::Gtk::ShowPeriodicTableModule.run
|
28
|
+
end
|
29
|
+
|
30
|
+
end; end; end; end
|
31
|
+
|
32
|
+
if __FILE__ == $PROGRAM_NAME
|
33
|
+
ChemistryParadise::GUI::Gtk::ShowPeriodicTable.run
|
34
|
+
end
|
@@ -0,0 +1,249 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::GUI::Gtk::TemperatureConverter
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'chemistry_paradise/gui/gtk3/temperature_converter/temperature_converter.rb'
|
8
|
+
# ChemistryParadise::GUI::Gtk::TemperatureConverter.run
|
9
|
+
# =========================================================================== #
|
10
|
+
require 'gtk_paradise/require_gtk3'
|
11
|
+
|
12
|
+
module ChemistryParadise
|
13
|
+
|
14
|
+
module GUI
|
15
|
+
|
16
|
+
module Gtk
|
17
|
+
|
18
|
+
class TemperatureConverter < ::Gtk::Box # === ChemistryParadise::GUI::Gtk::TemperatureConverter
|
19
|
+
|
20
|
+
require 'gtk_paradise/requires/require_the_base_module.rb'
|
21
|
+
include ::Gtk::BaseModule
|
22
|
+
|
23
|
+
require 'chemistry_paradise/toplevel_methods/kelvin.rb'
|
24
|
+
require 'chemistry_paradise/converters/celsius_to_fahrenheit.rb'
|
25
|
+
require 'chemistry_paradise/converters/fahrenheit_to_celsius.rb'
|
26
|
+
|
27
|
+
# ========================================================================= #
|
28
|
+
# === NAMESPACE
|
29
|
+
# ========================================================================= #
|
30
|
+
NAMESPACE = inspect
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === TITLE
|
34
|
+
# ========================================================================= #
|
35
|
+
TITLE = 'Temperature Converter'
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === WIDTH
|
39
|
+
# ========================================================================= #
|
40
|
+
WIDTH = 1280
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === HEIGHT
|
44
|
+
# ========================================================================= #
|
45
|
+
HEIGHT = 600
|
46
|
+
|
47
|
+
# ========================================================================= #
|
48
|
+
# === USE_THIS_FONT
|
49
|
+
# ========================================================================= #
|
50
|
+
USE_THIS_FONT = :dejavu_condensed_22
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === initialize
|
54
|
+
# ========================================================================= #
|
55
|
+
def initialize(
|
56
|
+
commandline_arguments = ARGV,
|
57
|
+
run_already = true
|
58
|
+
)
|
59
|
+
super(:vertical)
|
60
|
+
reset
|
61
|
+
set_commandline_arguments(
|
62
|
+
commandline_arguments
|
63
|
+
)
|
64
|
+
run if run_already
|
65
|
+
end
|
66
|
+
|
67
|
+
# ========================================================================= #
|
68
|
+
# === reset (reset tag)
|
69
|
+
# ========================================================================= #
|
70
|
+
def reset
|
71
|
+
reset_the_internal_variables
|
72
|
+
# ======================================================================= #
|
73
|
+
# === @configuration
|
74
|
+
# ======================================================================= #
|
75
|
+
@configuration = [true, __dir__, NAMESPACE]
|
76
|
+
# ======================================================================= #
|
77
|
+
# === @title
|
78
|
+
# ======================================================================= #
|
79
|
+
@title = TITLE
|
80
|
+
# ======================================================================= #
|
81
|
+
# === @width
|
82
|
+
# ======================================================================= #
|
83
|
+
set_width(WIDTH)
|
84
|
+
# ======================================================================= #
|
85
|
+
# === @height
|
86
|
+
# ======================================================================= #
|
87
|
+
set_height(HEIGHT)
|
88
|
+
set_use_this_font(USE_THIS_FONT)
|
89
|
+
use_gtk_paradise_project_css_file # or use use_project_css_file
|
90
|
+
infer_the_size_automatically
|
91
|
+
end
|
92
|
+
|
93
|
+
# ========================================================================= #
|
94
|
+
# === padding?
|
95
|
+
# ========================================================================= #
|
96
|
+
def padding?
|
97
|
+
0
|
98
|
+
end
|
99
|
+
|
100
|
+
# ========================================================================= #
|
101
|
+
# === border_size?
|
102
|
+
# ========================================================================= #
|
103
|
+
def border_size?
|
104
|
+
0
|
105
|
+
end
|
106
|
+
|
107
|
+
# ========================================================================= #
|
108
|
+
# === create_skeleton (create tag)
|
109
|
+
# ========================================================================= #
|
110
|
+
def create_skeleton
|
111
|
+
create_the_grid
|
112
|
+
end
|
113
|
+
|
114
|
+
# ========================================================================= #
|
115
|
+
# === connect_skeleton (connect tag)
|
116
|
+
# ========================================================================= #
|
117
|
+
def connect_skeleton
|
118
|
+
abort_on_exception
|
119
|
+
minimal(
|
120
|
+
gtk_left_aligned_bold_label(TITLE), 5
|
121
|
+
)
|
122
|
+
add(@grid)
|
123
|
+
end
|
124
|
+
|
125
|
+
# ========================================================================= #
|
126
|
+
# === create_the_grid
|
127
|
+
# ========================================================================= #
|
128
|
+
def create_the_grid
|
129
|
+
# ======================================================================= #
|
130
|
+
# === @grid
|
131
|
+
# ======================================================================= #
|
132
|
+
@grid = gtk_grid { :default }
|
133
|
+
@grid.css_class('pad10px')
|
134
|
+
@grid.left(text('Celsius:'))
|
135
|
+
# ======================================================================= #
|
136
|
+
# === @entry_celsius
|
137
|
+
# ======================================================================= #
|
138
|
+
@entry_celsius = gtk_entry
|
139
|
+
@entry_celsius.center
|
140
|
+
@entry_celsius.yellow_background
|
141
|
+
@entry_celsius.on_enter {
|
142
|
+
calculate_fahrenheit_and_set_the_correct_value
|
143
|
+
}
|
144
|
+
@grid.right(@entry_celsius)
|
145
|
+
@grid.new_row
|
146
|
+
@grid.left(text('Fahrenheit:'))
|
147
|
+
# ======================================================================= #
|
148
|
+
# === @entry_fahrenheit
|
149
|
+
# ======================================================================= #
|
150
|
+
@entry_fahrenheit = gtk_entry
|
151
|
+
@entry_fahrenheit.center
|
152
|
+
@entry_fahrenheit.yellow_background
|
153
|
+
@entry_fahrenheit.on_enter {
|
154
|
+
calculate_celsius_and_set_the_correct_value
|
155
|
+
}
|
156
|
+
@grid.right(@entry_fahrenheit)
|
157
|
+
@grid.new_row
|
158
|
+
@grid.left(text('Kelvin:'))
|
159
|
+
# ======================================================================= #
|
160
|
+
# === @entry_kelvin
|
161
|
+
# ======================================================================= #
|
162
|
+
@entry_kelvin = gtk_entry
|
163
|
+
@entry_kelvin.center
|
164
|
+
@entry_kelvin.yellow_background
|
165
|
+
@entry_kelvin.on_enter {
|
166
|
+
calculate_kelvin_and_set_the_correct_value
|
167
|
+
}
|
168
|
+
@grid.right(@entry_kelvin)
|
169
|
+
# ======================================================================= #
|
170
|
+
# Style the various entries next in an uniform manner.
|
171
|
+
# ======================================================================= #
|
172
|
+
return_all_entries.each {|this_entry|
|
173
|
+
this_entry.bblack1
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
# ========================================================================= #
|
178
|
+
# === calculate_fahrenheit_and_set_the_correct_value
|
179
|
+
#
|
180
|
+
# This is the to_fahrenheit conversion.
|
181
|
+
# ========================================================================= #
|
182
|
+
def calculate_fahrenheit_and_set_the_correct_value(
|
183
|
+
i = @entry_celsius.text?
|
184
|
+
)
|
185
|
+
# ======================================================================= #
|
186
|
+
# Also set the value of n Kelvin.
|
187
|
+
# ======================================================================= #
|
188
|
+
@entry_kelvin.set_text(
|
189
|
+
return_n_kelvin(i).to_s
|
190
|
+
)
|
191
|
+
i = ChemistryParadise::CelsiusToFahrenheit.new(i).fahrenheit?
|
192
|
+
@entry_fahrenheit.set_text(i.to_s)
|
193
|
+
end
|
194
|
+
|
195
|
+
# ========================================================================= #
|
196
|
+
# === calculate_celsius_and_set_the_correct_value
|
197
|
+
# ========================================================================= #
|
198
|
+
def calculate_celsius_and_set_the_correct_value(
|
199
|
+
i = @entry_fahrenheit.text?
|
200
|
+
)
|
201
|
+
i = ChemistryParadise::FahrenheitToCelsius.new(i).celsius?.to_s.delete('`').to_f.round(2).to_s
|
202
|
+
@entry_celsius.set_text(i.to_s)
|
203
|
+
end
|
204
|
+
|
205
|
+
# ========================================================================= #
|
206
|
+
# === calculate_kelvin_and_set_the_correct_value
|
207
|
+
# ========================================================================= #
|
208
|
+
def calculate_kelvin_and_set_the_correct_value(
|
209
|
+
i = @entry_celsius.text?
|
210
|
+
)
|
211
|
+
i = ChemistryParadise.kelvin(i)
|
212
|
+
@entry_celsius.set_text(i.to_s)
|
213
|
+
end
|
214
|
+
|
215
|
+
# ========================================================================= #
|
216
|
+
# === return_n_kelvin
|
217
|
+
# ========================================================================= #
|
218
|
+
def return_n_kelvin(
|
219
|
+
i = @entry_celsius.text?
|
220
|
+
)
|
221
|
+
return ChemistryParadise.kelvin(i)
|
222
|
+
end
|
223
|
+
|
224
|
+
# ========================================================================= #
|
225
|
+
# === run (run tag)
|
226
|
+
# ========================================================================= #
|
227
|
+
def run
|
228
|
+
create_skeleton_then_connect_skeleton
|
229
|
+
end
|
230
|
+
|
231
|
+
# ========================================================================= #
|
232
|
+
# === ChemistryParadise::GUI::Gtk::TemperatureConverter.run
|
233
|
+
# ========================================================================= #
|
234
|
+
def self.run(
|
235
|
+
i = ARGV
|
236
|
+
)
|
237
|
+
require 'gtk_paradise/run'
|
238
|
+
_ = ::ChemistryParadise::GUI::Gtk::TemperatureConverter.new(i)
|
239
|
+
r = ::Gtk.run
|
240
|
+
r << _
|
241
|
+
r.automatic_size_then_automatic_title
|
242
|
+
r.top_left_then_run
|
243
|
+
end
|
244
|
+
|
245
|
+
end; end; end; end
|
246
|
+
|
247
|
+
if __FILE__ == $PROGRAM_NAME
|
248
|
+
ChemistryParadise::GUI::Gtk::TemperatureConverter.run
|
249
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::GUI::Gtk::CalculateMolecularWeightModule
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'chemistry_paradise/gui/shared_code/calculate_molecular_weight/calculate_molecular_weight_module.rb'
|
8
|
+
# include ::ChemistryParadise::GUI::Gtk::CalculateMolecularWeightModule
|
9
|
+
# =========================================================================== #
|
10
|
+
module ChemistryParadise
|
11
|
+
|
12
|
+
module GUI
|
13
|
+
|
14
|
+
module Gtk
|
15
|
+
|
16
|
+
module CalculateMolecularWeightModule
|
17
|
+
|
18
|
+
require 'chemistry_paradise/utility_scripts/calculate_atomic_mass.rb'
|
19
|
+
|
20
|
+
require 'gtk_paradise/requires/require_the_base_module.rb'
|
21
|
+
include ::Gtk::BaseModule
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === NAMESPACE
|
25
|
+
# ========================================================================= #
|
26
|
+
NAMESPACE = inspect
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === TITLE
|
30
|
+
# ========================================================================= #
|
31
|
+
TITLE = 'Calculate the molecular weight of a compound'
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === WIDTH
|
35
|
+
# ========================================================================= #
|
36
|
+
WIDTH = 1200
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === HEIGHT
|
40
|
+
# ========================================================================= #
|
41
|
+
HEIGHT = 500
|
42
|
+
|
43
|
+
# ========================================================================= #
|
44
|
+
# === USE_THIS_FONT
|
45
|
+
# ========================================================================= #
|
46
|
+
USE_THIS_FONT = :dejavu_condensed_21
|
47
|
+
|
48
|
+
# ========================================================================= #
|
49
|
+
# === initialize
|
50
|
+
# ========================================================================= #
|
51
|
+
def initialize(
|
52
|
+
commandline_arguments = ARGV,
|
53
|
+
run_already = true
|
54
|
+
)
|
55
|
+
super(:vertical)
|
56
|
+
reset
|
57
|
+
set_commandline_arguments(
|
58
|
+
commandline_arguments
|
59
|
+
)
|
60
|
+
run if run_already
|
61
|
+
end
|
62
|
+
|
63
|
+
# ========================================================================= #
|
64
|
+
# === reset (reset tag)
|
65
|
+
# ========================================================================= #
|
66
|
+
def reset
|
67
|
+
reset_the_internal_variables
|
68
|
+
# ======================================================================= #
|
69
|
+
# === @configuration
|
70
|
+
# ======================================================================= #
|
71
|
+
@configuration = [true, __dir__, NAMESPACE]
|
72
|
+
# ======================================================================= #
|
73
|
+
# === @title
|
74
|
+
# ======================================================================= #
|
75
|
+
@title = TITLE
|
76
|
+
# ======================================================================= #
|
77
|
+
# === @width
|
78
|
+
# ======================================================================= #
|
79
|
+
set_width(WIDTH)
|
80
|
+
# ======================================================================= #
|
81
|
+
# === @height
|
82
|
+
# ======================================================================= #
|
83
|
+
set_height(HEIGHT)
|
84
|
+
set_use_this_font(USE_THIS_FONT)
|
85
|
+
use_gtk_paradise_project_css_file
|
86
|
+
infer_the_size_automatically
|
87
|
+
end
|
88
|
+
|
89
|
+
# ========================================================================= #
|
90
|
+
# === padding?
|
91
|
+
# ========================================================================= #
|
92
|
+
def padding?
|
93
|
+
2
|
94
|
+
end
|
95
|
+
|
96
|
+
# ========================================================================= #
|
97
|
+
# === border_size?
|
98
|
+
# ========================================================================= #
|
99
|
+
def border_size?
|
100
|
+
0
|
101
|
+
end
|
102
|
+
|
103
|
+
# ========================================================================= #
|
104
|
+
# === create_the_entry
|
105
|
+
# ========================================================================= #
|
106
|
+
def create_the_entry
|
107
|
+
# ======================================================================= #
|
108
|
+
# === @entry_for_the_chemical_formula
|
109
|
+
# ======================================================================= #
|
110
|
+
@entry_for_the_chemical_formula = gtk_entry
|
111
|
+
@entry_for_the_chemical_formula.bblack1
|
112
|
+
@entry_for_the_chemical_formula.yellow_background
|
113
|
+
@entry_for_the_chemical_formula.center
|
114
|
+
@entry_for_the_chemical_formula.hint = 'Input the chemical formula here, '\
|
115
|
+
'then press enter. The atomic mass will be shown.'
|
116
|
+
@entry_for_the_chemical_formula.shadow_text =
|
117
|
+
'Input a chemical formula here.'
|
118
|
+
@entry_for_the_chemical_formula.on_enter_key {
|
119
|
+
_ = @entry_for_the_chemical_formula.text?
|
120
|
+
result = ChemistryParadise::CalculateAtomicMass.new(_) {{
|
121
|
+
verbosity: :be_quiet,
|
122
|
+
may_we_exit: false
|
123
|
+
}}.result?
|
124
|
+
@text_result.set_text(
|
125
|
+
result.to_f.round(3).to_s+' ame'
|
126
|
+
)
|
127
|
+
@text_result.make_bold
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
# ========================================================================= #
|
132
|
+
# === create_skeleton (create tag)
|
133
|
+
# ========================================================================= #
|
134
|
+
def create_skeleton
|
135
|
+
create_the_entry
|
136
|
+
end
|
137
|
+
|
138
|
+
# ========================================================================= #
|
139
|
+
# === connect_skeleton (connect tag)
|
140
|
+
# ========================================================================= #
|
141
|
+
def connect_skeleton
|
142
|
+
abort_on_exception
|
143
|
+
@text_result = gtk_text
|
144
|
+
minimal bold_text('Chemical formula:'), 3
|
145
|
+
minimal @entry_for_the_chemical_formula, 3
|
146
|
+
minimal @text_result, 3
|
147
|
+
end
|
148
|
+
|
149
|
+
# ========================================================================= #
|
150
|
+
# === run (run tag)
|
151
|
+
# ========================================================================= #
|
152
|
+
def run
|
153
|
+
create_skeleton_then_connect_skeleton
|
154
|
+
end
|
155
|
+
|
156
|
+
# ========================================================================= #
|
157
|
+
# === ChemistryParadise::GUI::Gtk::CalculateMolecularWeightModule.run
|
158
|
+
# ========================================================================= #
|
159
|
+
def self.run(
|
160
|
+
i = ARGV
|
161
|
+
)
|
162
|
+
require 'gtk_paradise/run'
|
163
|
+
_ = ::ChemistryParadise::GUI::Gtk::CalculateMolecularWeight.new(i)
|
164
|
+
r = ::Gtk.run
|
165
|
+
r << _
|
166
|
+
r.set_size_request(_.width?, _.height?)
|
167
|
+
r.automatic_title
|
168
|
+
r.top_left_then_run
|
169
|
+
end
|
170
|
+
|
171
|
+
end; end; end; end
|