Module: Roebe::GUI::SimpleClockModule

Includes:
UniversalWidgets::BaseModule
Included in:
SimpleClock
Defined in:
lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb

Overview

Roebe::GUI::SimpleClockModule

Constant Summary collapse

TITLE =
#

TITLE

#
'A simple clock'
MAIN_FONT_SIZE =
#

MAIN_FONT_SIZE

#
32
WIDTH =
#

WIDTH

#
320
HEIGHT =
#

HEIGHT

#
220

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(i = ARGV) ⇒ Object

#

GtkParadise::GUI::Gtk::SimpleClockModule.run

#


200
201
202
203
204
205
206
207
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 200

def self.run(i = ARGV)
  require 'gtk_paradise/run'
  _ = ::Roebe::GUI::SimpleClock.new(i)
  r = ::Gtk.run
  r << _
  r.set_size_request(_.width?,_.height?)
  r.top_left_then_run
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


111
112
113
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 111

def border_size?
  2
end

#create_skeletonObject

#

create_skeleton (skeleton tag)

#


186
187
188
189
190
191
192
193
194
195
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 186

def create_skeleton
  create_the_entries
  create_the_buttons
  # ======================================================================= #
  # The next label is the main "workhorse" for this widget - it will
  # show the current time.
  # ======================================================================= #
  @label_showing_the_current_time = text(return_current_time)
  @label_showing_the_current_time.set_font_size(MAIN_FONT_SIZE)
end

#create_the_buttonsObject

#

create_the_buttons

#


168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 168

def create_the_buttons
  # ======================================================================= #
  # === @button_for_applying_the_modifier
  # ======================================================================= #
  @button_for_applying_the_modifier = bold_button(
    'Modify the clock by n seconds'
  )
  @button_for_applying_the_modifier.hint = 'This will '\
    'modify the display of the clock by <b>n seconds</b>. It '\
    'is an ad-hoc way to correct the time.'
  @button_for_applying_the_modifier.on_clicked {
    do_modify_the_time
  }
end

#create_the_entriesObject

#

create_the_entries (entries tag)

#


158
159
160
161
162
163
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 158

def create_the_entries
  # ======================================================================= #
  # === @entry_for_n_seconds
  # ======================================================================= #
  @entry_for_n_seconds = create_entry
end

#do_modify_the_timeObject

#

do_modify_the_time

#


139
140
141
142
143
144
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 139

def do_modify_the_time
  # ======================================================================= #
  # === @apply_this_modifier
  # ======================================================================= #
  @apply_this_modifier = @entry_for_n_seconds.text.to_f
end

#modify_the_label_of_the_frameObject

#

modify_the_label_of_the_frame

#


149
150
151
152
153
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 149

def modify_the_label_of_the_frame
  label_widget.set_markup(
    %Q(<span weight="bold" size="xx-large" foreground="darkslategrey">#{TITLE}</span>) 
  ) if use_gtk3?
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


104
105
106
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 104

def padding?
  2
end

#resetObject

#

reset (reset tag)

#


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 52

def reset
  super() if respond_to?(:super)
  # reset_the_internal_variables
  create_the_internal_hash_unless_it_already_exists
  infer_the_namespace
  # ======================================================================= #
  # === @use_a_small_icon_showing_a_clock
  #
  # If the following variable is set to true then a small clock will
  # be shown, on the left-hand side.
  #
  # Since as of December 2020 this is the default.
  # ======================================================================= #
  @use_a_small_icon_showing_a_clock = true
  # ======================================================================= #
  # === @apply_this_modifier
  #
  # This modifier can be used to modify the time of the clock.
  # ======================================================================= #
  @apply_this_modifier = nil
  # ======================================================================= #
  # === @use_top_label
  # ======================================================================= #
  @use_top_label = true
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  title_width_height(TITLE, WIDTH, HEIGHT)
  use_gtk_paradise_project_css_file
  infer_the_size_automatically
end

#return_current_time(apply_this_modifier = @apply_this_modifier) ⇒ Object

#

return_current_time

An optional modifier, as an Integer, can be given, which modifies the time.

#


91
92
93
94
95
96
97
98
99
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 91

def return_current_time(
    apply_this_modifier = @apply_this_modifier
  )
  _ = ::Time.now
  if apply_this_modifier
    _ = "#{_}#{apply_this_modifier}"
  end
  _.strftime('%H:%M:%S')
end

#update_current_time(i = return_current_time) ⇒ Object

#

update_current_time

#


118
119
120
121
122
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 118

def update_current_time(
    i = return_current_time
  )
  @label_showing_the_current_time.set_text(i)
end

#update_label_continuallyObject

#

update_label_continually

#


127
128
129
130
131
132
133
134
# File 'lib/roebe/gui/shared_code/simple_clock/simple_clock_module.rb', line 127

def update_label_continually
  Thread.new {
    loop {
      sleep 1
      update_current_time
    }
  }
end