Module: ChemistryParadise::GUI::WetterModule
- Included in:
- Gtk::Wetter, LibUI::Wetter, UnifiedWidgets::WheatherApp
- Defined in:
- lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb
Constant Summary collapse
- TITLE =
#
TITLE
#
'Wetter-Application'
- WIDTH =
#
WIDTH
#
'40% or minimum 260px'
- HEIGHT =
#
HEIGHT
#
'30% or minimum 220px'
- USE_THIS_FONT =
#
USE_THIS_FONT
#
'Hack 18'
- SMALLER_FONT =
#
SMALLER_FONT
#
'Hack 16'
- SMALLEST_FONT =
#
SMALLEST_FONT
#
'Hack 12'
Instance Method Summary collapse
-
#attach_temperature_value_to_the_main_label ⇒ Object
# === attach_temperature_value_to_the_main_label.
-
#border_size? ⇒ Boolean
# === border_size? ========================================================================= #.
-
#connect_skeleton ⇒ Object
# === connect_skeleton (connect tag) ========================================================================= #.
-
#create_skeleton ⇒ Object
# === create_skeleton (create tag).
-
#create_the_buttons ⇒ Object
# === create_the_buttons (buttons tag) ========================================================================= #.
-
#create_the_labels ⇒ Object
# === create_the_labels ========================================================================= #.
-
#create_the_main_window ⇒ Object
# === create_the_main_window ========================================================================= #.
-
#determine_which_smiley_should_be_used(i = :infer) ⇒ Object
# === determine_which_smiley_should_be_used.
-
#do_the_actions_associated_with_the_update_button ⇒ Object
# === do_the_actions_associated_with_the_update_button ========================================================================= #.
-
#main_window? ⇒ Boolean
# === main_window? ========================================================================= #.
-
#padding? ⇒ Boolean
# === padding? ========================================================================= #.
-
#reset_the_shared_module ⇒ Object
# === reset_the_shared_module ========================================================================= #.
-
#return_the_temperature_string(i = @temperature) ⇒ Object
# === return_the_temperature_string ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#smaller_font? ⇒ Boolean
# === smaller_font? ========================================================================= #.
-
#smallest_font? ⇒ Boolean
# === smallest_font? ========================================================================= #.
-
#update_the_temperature_listing ⇒ Object
(also: #update_the_temperature)
# === update_the_temperature_listing ========================================================================= #.
Instance Method Details
#attach_temperature_value_to_the_main_label ⇒ Object
#
attach_temperature_value_to_the_main_label
Note that this has to be called once upon start-up.
#
300 301 302 303 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 300 def attach_temperature_value_to_the_main_label update_the_temperature_listing @label_showing_the_temperature.make_bold end |
#border_size? ⇒ Boolean
#
border_size?
#
94 95 96 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 94 def border_size? 2 end |
#connect_skeleton ⇒ Object
#
connect_skeleton (connect tag)
#
174 175 176 177 178 179 180 181 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 174 def connect_skeleton if use_gtk? abort_on_exception @main_window.add(@scrolled_window) @main_window.show_all minimal(@main_window) end end |
#create_skeleton ⇒ Object
#
create_skeleton (create tag)
For libui to call this method, the main-window must have been defined already.
#
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 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 227 def create_skeleton create_the_labels create_the_main_window a_hbox = padded_hbox if use_gtk? # ===================================================================== # # Add a cute little weather-icon next, for ruby-gtk3. # ===================================================================== # weather_icon = ::Gtk.image(:weather_icon) event_box = ::Gtk.eventbox(weather_icon) event_box.signal_connect(:event) { |, event| if (event) attach_temperature_value_to_the_main_label end } a_hbox.minimal(event_box, 4) end a_hbox.minimal(@label_current_temperature_in_vienna, 4) a_hbox.minimal(@label_showing_the_temperature, 4) a_hbox.minimal(@small_label_showing_an_emoji, 4) outer_vbox = padded_vbox outer_vbox.minimal(a_hbox) tiny_hbox = hbox tiny_hbox.minimal(@button_update) tiny_hbox.horizontal_center tiny_hbox.width_height(200, 45) tiny_hbox.set_size_request(220, 50) outer_vbox.minimal(tiny_hbox, 4) if use_gtk? this_file = ::ChemistryParadise.project_base_dir?+ 'images/vienna_map.png' if File.exist? this_file image_of_vienna = gtk_image(this_file) image_of_vienna.pad8px image_of_vienna.horizontal_center outer_vbox.minimal(image_of_vienna, 8) end end # ========================================================================= # # Put it into a scrolled-window next. # ========================================================================= # @main_window.enable_free_form_css @main_window.try_to_use_this_font(USE_THIS_FONT) @main_window.set_border_width(8) if use_gtk? @main_window.signal_connect(:destroy) { ::Gtk.main_quit } end if use_gtk? @scrolled_window = ::Gtk.scrolled_window(outer_vbox) { :always_scrollbars } @scrolled_window.set_size_request(560, 280) @scrolled_window.show_all elsif use_libui? outer_vbox.add_hsep outer_vbox.minimal() @main_window.minimal(outer_vbox) end @main_window.try_to_add_default_CSS_rules @main_window.show_all end |
#create_the_buttons ⇒ Object
#
create_the_buttons (buttons tag)
#
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 202 def # ======================================================================= # # === @button_update (update tag) # ======================================================================= # @button_update = ('_Update') @button_update.clear_background @button_update.use_this_font = smaller_font? @button_update.bblack3 @button_update.pad8px @button_update.on_hover(:lightblue) @button_update.width_height(150, 40) @button_update.hint = '<b>Clicking</b> on this button will '\ '<b>update the temperature display value</b> '\ 'shown above.' @button_update.on_click_event { } end |
#create_the_labels ⇒ Object
#
create_the_labels
#
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 101 def create_the_labels # ======================================================================= # # === @label_showing_the_temperature # ======================================================================= # @label_showing_the_temperature = bold_label # ======================================================================= # # === @label_current_temperature_in_vienna # ======================================================================= # @label_current_temperature_in_vienna = bold_label('Current temperature in Vienna:') # ======================================================================= # # === @small_label_showing_an_emoji # ======================================================================= # @small_label_showing_an_emoji = label if use_gtk? @small_label_showing_an_emoji.set_text(::Gtk::Emojis::SMILEY_6) @small_label_showing_an_emoji.use_this_font = smallest_font? end end |
#create_the_main_window ⇒ Object
#
create_the_main_window
#
155 156 157 158 159 160 161 162 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 155 def create_the_main_window @main_window = window_or_vbox( @title, @width, @height, margin: true ) end |
#determine_which_smiley_should_be_used(i = :infer) ⇒ Object
#
determine_which_smiley_should_be_used
This method is used to determine which smiley should be used.
#
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 125 def determine_which_smiley_should_be_used( i = :infer ) if use_gtk? case i when :infer if @temperature.to_i < 8 # Below 8°C it is quite cold. i = :cold else # This is the default. Apply it above 8°C. i = :warm end end case i # ======================================================================= # # === :warm # ======================================================================= # when :warm @small_label_showing_an_emoji.set_text(::Gtk::Emojis::SMILEY_6) # ======================================================================= # # === :cold # ======================================================================= # when :cold @small_label_showing_an_emoji.set_text(::Gtk::Emojis::SMILEY_15) end end end |
#do_the_actions_associated_with_the_update_button ⇒ Object
#
do_the_actions_associated_with_the_update_button
#
291 292 293 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 291 def update_the_temperature_listing end |
#main_window? ⇒ Boolean
#
main_window?
#
167 168 169 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 167 def main_window? @main_window end |
#padding? ⇒ Boolean
#
padding?
#
87 88 89 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 87 def padding? 4 end |
#reset_the_shared_module ⇒ Object
#
reset_the_shared_module
#
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 66 def reset_the_shared_module # ======================================================================= # # === Set title, width height and font in one go # ======================================================================= # title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT) # ======================================================================= # # === @favicon # ======================================================================= # @favicon = :tabble # ======================================================================= # # === @temperature # # Grab the current temperature next. Note that this can take a while # since a remote website is queried for the information. # ======================================================================= # @temperature = nil end |
#return_the_temperature_string(i = @temperature) ⇒ Object
#
return_the_temperature_string
#
186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 186 def return_the_temperature_string( i = @temperature ) case i when nil result = ' [querying the temperature ... wait a moment]' else result = @temperature.to_s.dup result << ' °C' end return result end |
#run ⇒ Object
#
run (run tag)
#
332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 332 def run if defined?(super) super() else # else we have to call the required methods on our own here. create_skeleton end attach_temperature_value_to_the_main_label @main_window.intelligent_exit if use_libui? run_main end end |
#smaller_font? ⇒ Boolean
#
smaller_font?
#
52 53 54 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 52 def smaller_font? SMALLER_FONT end |
#smallest_font? ⇒ Boolean
#
smallest_font?
#
59 60 61 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 59 def smallest_font? SMALLEST_FONT end |
#update_the_temperature_listing ⇒ Object Also known as: update_the_temperature
#
update_the_temperature_listing
#
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb', line 308 def update_the_temperature_listing @temperature = nil # Reset it here. _ = return_the_temperature_string @label_showing_the_temperature.set_text(_) @label_showing_the_temperature.set_colour(:royalblue) @label_showing_the_temperature.make_bold # ======================================================================= # # We need to use a thread here so it does not block the main application. # ======================================================================= # Thread.new { @temperature = ::ChemistryParadise::Wetter.return_temperature @label_showing_the_temperature.set_text(return_the_temperature_string) @label_showing_the_temperature.set_colour(:royalblue) @label_showing_the_temperature.make_bold # ===================================================================== # # We will also updated the smiley. # ===================================================================== # determine_which_smiley_should_be_used } end |