Module: HardwareInformation::GUI::Gtk::PurchasedHardwareModule

Includes:
Gtk::BaseModule, PurchasedHardware
Included in:
PurchasedHardware
Defined in:
lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
N =
#

N

#
"\n"
IMG_DIR =
#

IMG_DIR

Specify the path to the local images here.

#
'/home/x/data/images/'
TITLE =
#

TITLE

#
'Purchased Hardware'
WIDTH =
#

WIDTH

#
'60% or minimum 1000px'
HEIGHT =
#

HEIGHT

#
800
USE_THIS_FONT =
#

USE_THIS_FONT

#
:dejavu_condensed_18

Constants included from PurchasedHardware

PurchasedHardware::COLOUR_PURCHASED_AT_THIS_DATE, PurchasedHardware::LINUX_YAML, PurchasedHardware::MAIN_DIV

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PurchasedHardware

add_bought_at, add_to_the_total_cost, body_css_class, body_css_style, bought_at?, file_my_hardware, hash_yearly_purchases_made?, linux_yaml_directory?, #main_dataset?, my_hardware, return_dataset_from_the_file_computer_hardware, title?, total_cost?

Class Method Details

.run(i = ARGV) ⇒ Object

#

HardwareInformation::GUI::Gtk::PurchasedHardwareModule.run

#


272
273
274
275
276
277
278
279
280
281
# File 'lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb', line 272

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::HardwareInformation::GUI::Gtk::PurchasedHardware.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)


104
105
106
# File 'lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb', line 104

def border_size?
  8
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#


119
120
121
122
123
124
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
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
# File 'lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb', line 119

def connect_skeleton
  abort_on_exception
  vbox_containing_the_hardware_entries = gtk_vbox
  hbox = create_hbox
  hbox.minimal(
    text('♥️ ').red
  )
  hbox.maximal(@header_on_top)
  vbox_containing_the_hardware_entries.add(hbox)
  hbox.add(gtk_horizontal_spacer)
  # ======================================================================= #
  # Next, go through the dataset and add the relevant entries:
  # ======================================================================= #
  dataset = main_dataset?
  dataset.each_pair {|name_of_the_hardware, inner_dataset|
    this_label = h3("# {name_of_the_hardware}")
    if name_of_the_hardware.include? 'id='
      this_label.set_name(
        name_of_the_hardware.scan(/id=(.+)/).flatten.first.to_s
      )
      name_of_the_hardware = Roebe.remove_html(name_of_the_hardware)
      this_label.set_text(name_of_the_hardware)
    end
    this_label.left_align
    this_label.make_bold
    this_label.make_selectable

    mini_vbox_containing_the_description_for_the_hardware_at_hand = gtk_vbox
    _ = ''.dup
    # ===================================================================== #
    # === image or draggable_image:
    #
    # The first entry contains the desired information.
    #
    # Example:
    #
    #   draggable_image:
    #   - HARDWARE/DRUCKER/HP_OfficeJet_Pro_6230.jpg
    #   - mar1em
    #
    # ===================================================================== #
    if inner_dataset.include?('image') or inner_dataset.include?('draggable_image')
      if inner_dataset.has_key?('draggable_image')
        target = IMG_DIR+inner_dataset['draggable_image'][0]
      elsif inner_dataset.has_key?('draggable_images')
        target = IMG_DIR+inner_dataset['draggable_images'][0]
      else
        target = IMG_DIR+inner_dataset['image'][0]
      end
      this_image = create_image(target)
      this_image.align_to_the_left
      this_image.set_name('image1')
      this_image.pad5px
      this_image.bblack1
      this_image.hint = "Path:\n\n  #{target}\n"
      this_image.set_border_width(8) if this_image.respond_to?(:set_border_width)
      mini_vbox_containing_the_description_for_the_hardware_at_hand.minimal(
        this_image
      )
    end
    # ===================================================================== #
    # === description
    # ===================================================================== #
    if inner_dataset.include? 'description'
      _ << '<b>Beschreibung</b>: '+
           Roebe.remove_html(
             inner_dataset['description'].to_s.
             gsub(/<br><br>/,"\n<br>").
             gsub(/<br>/,"")
           )+N
    end
    # ===================================================================== #
    # === cost
    # ===================================================================== #
    if inner_dataset.include? 'cost'
      cost = inner_dataset['cost'].to_s
      _ << '<b>cost</b>: <span weight="bold" foreground="darkgreen">'+
           cost+' Euro</span>'+N
      HardwareInformation::PurchasedHardware.add_to_total_cost(
        cost.to_f
      )
    end
    # ===================================================================== #
    # === bought_at
    #
    # Add information when the particular hardware at hand was purchased.
    # ===================================================================== #
    if inner_dataset.include? 'bought_at'
      _ << '<b>erstanden am</b>: '+
           '<span weight="bold" foreground="darkblue">'+
           inner_dataset['bought_at'].to_s+
           '</span>'+
           N
    end
    # ===================================================================== #
    # Next comes the description ("Beschreibung"), which may be really
    # long.
    # ===================================================================== #
    if _.include? '<a href' # Add support for hyperlinks here.
      _ = parse_hyperlinks(_)
    end
    description_for_the_hardware_at_hand = label(_)
    description_for_the_hardware_at_hand.left_align
    description_for_the_hardware_at_hand.make_selectable
    mini_vbox_containing_the_description_for_the_hardware_at_hand.maximal(
      description_for_the_hardware_at_hand, 5
    )
    name_of_the_hardware = Roebe.remove_html(name_of_the_hardware)
    this_label.set_text(name_of_the_hardware)
    tiny_hbox_containing_computer_image_and_the_big_label = gtk_hbox
    # ===================================================================== #
    # Next we will add the tiny computer-image, with some padding.
    # ===================================================================== #
    tiny_hbox_containing_computer_image_and_the_big_label.minimal(
      image_computer, 12
    )
    tiny_hbox_containing_computer_image_and_the_big_label.maximal(
      this_label
    )
    vbox_containing_the_hardware_entries.add(
      tiny_hbox_containing_computer_image_and_the_big_label
    )
    vbox_containing_the_hardware_entries.add(
      mini_vbox_containing_the_description_for_the_hardware_at_hand
    )
    vbox_containing_the_hardware_entries.add(gtk_horizontal_spacer)
  }
  text = '<b>Gesamtkosten</b>: <b>'+
         HardwareInformation::PurchasedHardware.total_cost?.to_s.to_f.round(2).to_s+
         ' Euro</b>'
  _ = h2(text).align_left
  _.make_selectable
  vbox_containing_the_hardware_entries.add(
    _
  )
  # ======================================================================= #
  # Add the big vbox into a scrolled-window interface.
  # ======================================================================= #
  scrolled_window = create_scrolled_window(vbox_containing_the_hardware_entries) { :only_up_and_down }
  scrolled_window.set_size_request(1400, 800)
  maximal(scrolled_window, 8)
end

#create_skeletonObject

#

create_skeleton (create tag)

#


111
112
113
114
# File 'lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb', line 111

def create_skeleton
  @header_on_top = h1('Meine Hardware')
  @header_on_top.left_align
end

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

#

initialize

#


71
72
73
74
75
76
77
78
# File 'lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb', line 71

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

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


97
98
99
# File 'lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb', line 97

def padding?
  4
end

#resetObject

#

reset (reset tag)

#


83
84
85
86
87
88
89
90
91
92
# File 'lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb', line 83

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  use_gtk_project_css_file
  infer_the_size_automatically
end

#runObject

#

run (run tag)

#


265
266
267
# File 'lib/hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb', line 265

def run
  super()
end