Class: Bioroebe::GUI::AntiSenseStrand

Inherits:
Object
  • Object
show all
Includes:
Bioroebe::GUI
Defined in:
lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb

Overview

Bioroebe::GUI::AntiSenseStrand

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'Sense / Anti-Sense Strand'
WIDTH =
#

WIDTH

#
840
HEIGHT =
#

HEIGHT

#
400
MAX_LENGTH =
#

MAX_LENGTH

#
50_000
IMG_DNA_HELIX =
#

IMG_DNA_HELIX

#
'/home/x/data/images/science/biology/DNA_HELIX.jpg'
USE_THIS_FONT =
#

USE_THIS_FONT

#
'Hack 20'

Constants included from Bioroebe::GUI

ARRAY_ALL_GTK_WIDGETS, FONT_SIZE, OLD_VERBOSE_VALUE, USE_THIS_FONT_FAMILY_FOR_GUI_APPLICATIONS

Instance Method Summary collapse

Methods included from Bioroebe::GUI

#disable_warnings, #enable_warnings, #log_dir?

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true, &block) ⇒ AntiSenseStrand

#

initialize

#

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 82

def initialize(
    commandline_arguments = ARGV,
    run_already           = true,
    &block
  )
  parse_this_input_for_proper_widget_support(
    commandline_arguments
  )
  register_sigint
  reset
  @use_this_as_the_options_hash = {
    margin: true
  }
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
  elsif use_gtk3?
    yielded = :use_vbox_on_the_toplevel
  else
    yielded = nil
  end
  case yielded
  # ===================================================================== #
  # === :use_vbox_on_the_toplevel
  # ===================================================================== #
  when :use_vbox_on_the_toplevel
    @use_this_as_the_options_hash.update(
      use_vbox_on_the_toplevel: true
    )
  end
  run if run_already
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)

212
213
214
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 212

def border_size?
  2
end

#colour_for(i) ⇒ Object

#

colour_for

Use this method to return a colour for the 4 nucleotides.

#

297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 297

def colour_for(i)
  case i
  when :a
    'whitesmoke'
  when :t
    'teal'
  when :c
    'slateblue'
  when :g
    'red'
  end
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#

338
339
340
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 338

def connect_skeleton
  abort_on_exception
end

#create_and_add_menuObject

#

create_and_add_menu (menu tag)

#

345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 345

def create_and_add_menu
  return # This is currently not in use. Perhaps at a later time.
  @menu_bar = gtk_menu_bar
  @menu_item1 = gtk_menu_item('Options')
  @menu_item1.set_submenu(@first_submenu = gtk_menu)
  @menu_bar.append(@menu_item1)
  @menu_actions = [
    ['FileMenu', nil, '_File'],
    ['Quit', ::Gtk::Stock::QUIT, '_Quit', 'Q', 'Quit', @callback_quit],
    ['New',  ::Gtk::Stock::NEW,  '_New',  'N', 'Create a new file', @callback_new_file]
  ]
end

#create_skeletonObject

#

create_skeleton (create tag)

#

427
428
429
430
431
432
433
434
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 427

def create_skeleton
  create_the_boxes
  create_the_main_window
  create_the_entries
  create_the_buttons # Must come before the main table
  create_the_grid
  create_and_add_menu if use_gtk3?
end

#create_the_boxesObject

#

create_the_boxes

#

194
195
196
197
198
199
200
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 194

def create_the_boxes
  # ======================================================================= #
  # === @outer_vbox
  # ======================================================================= #
  @outer_vbox = padded_vbox
  @box_with_small_buttons = padded_hbox
end

#create_the_buttonsObject

#

create_the_buttons (buttons tag, button tag)

This method will create the various buttons for this application.

#

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
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 235

def create_the_buttons
  # ======================================================================= #
  # === @button_reset
  # ======================================================================= #
  @button_reset = bold_button('_Reset Sense Anti Sense')
  @button_reset.hint = 'Click on this button to '\
    '<b>reset</b> again to <b>the initial state '\
    'of this widget</b>.'
  @button_reset.clear_background
  @button_reset.bblack1
  @button_reset.modify_background(:active,   :lightblue)
  @button_reset.modify_background(:prelight, :steelblue)
  @button_reset.modify_background(:normal,   :lightblue)
  @button_reset.on_clicked {
    on_reset_action_called
  }
  # ======================================================================= #
  # Next add the four buttons for A, T, C and G.
  # ======================================================================= #
  @button_A = coloured_button('A_'+colour_for(:a)) 
  @button_A.on_clicked { handle_sense('A') }
  @button_A.popup_hint('Add A (for Adenine) to the sense-strand on top.')
  @button_A.bblack1
  @box_with_small_buttons.minimal(@button_A, 2)

  @button_T = coloured_button('T_'+colour_for(:t))
  @button_T.on_clicked { handle_sense('T') }
  @button_T.popup_hint('Add T (for Thymine) to the sense-strand on top.')
  @button_T.bblack1
  @box_with_small_buttons.minimal(@button_T, 2)

  @button_C = coloured_button('C_'+colour_for(:c))
  @button_C.on_clicked { handle_sense('C') }
  @button_C.popup_hint('Add C (for Cytosin) to the sense-strand on top.')
  @button_C.bblack1
  @box_with_small_buttons.minimal(@button_C, 2)

  @button_G = coloured_button('G_'+colour_for(:g))
  @button_G.on_clicked { handle_sense('G') }
  @button_G.popup_hint('Add G (for Guanine) to the sense-strand on top.')
  @button_G.bblack1
  @box_with_small_buttons.minimal(@button_G, 2)
  do_style_all_the_buttons
end

#create_the_entriesObject

#

create_the_entries (entries tag)

The Sense strand has the uppercased ATGC variant.

#

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
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 162

def create_the_entries
  # ======================================================================= #
  # === @entry_sense
  # ======================================================================= #
  @entry_sense = entry
  @entry_sense.yellow_background
  @entry_sense.bblack1
  @entry_sense.position = 12
  @entry_sense.use_this_font = USE_THIS_FONT
  @entry_sense.on_key_press_event { |w,event|
    handle_sense(event)
  }
  @entry_sense.set_max_length(MAX_LENGTH)

  # ======================================================================= #
  # === @entry_anti_sense
  # ======================================================================= #
  @entry_anti_sense = entry
  @entry_anti_sense.yellow_background
  @entry_anti_sense.bblack1
  @entry_anti_sense.editable = false
  @entry_anti_sense.use_this_font = USE_THIS_FONT
  @entry_anti_sense.set_max_length(MAX_LENGTH)
  # @entry_anti_sense.on_button_press_event { |w, e|
  #   @entry_anti_sense.do_focus
  #   # @entry_anti_sense.select_everything
  # }
end

#create_the_gridObject

#

create_the_grid (grid tag)

#

361
362
363
364
365
366
367
368
369
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 361

def create_the_grid
  # ======================================================================= #
  # Use a table for the main UI.
  # ======================================================================= #
  @grid = default_grid
  @grid.set_column_spacing(3)
  @grid.set_row_spacing(3)
  @grid.pad10px
end

#create_the_main_windowObject

#

create_the_main_window

#

219
220
221
222
223
224
225
226
227
228
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 219

def create_the_main_window
  @main_window = window(
    @title,
    @width,
    @height,
    @use_this_as_the_options_hash
  )
  @main_window.enable_free_form_css
  @main_window.try_to_use_this_font(USE_THIS_FONT)
end

#do_style_all_the_buttons(i = return_all_buttons) ⇒ Object

#

do_style_all_the_buttons

#

283
284
285
286
287
288
289
290
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 283

def do_style_all_the_buttons(
    i = return_all_buttons
  )
  i.each {|this_button|
    this_button.set_name('button1')
    this_button.bblack2
  }
end

#focus(where) ⇒ Object

#

focus

Use this method to focus.

#

326
327
328
329
330
331
332
333
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 326

def focus(where)
  case where
  when ':left'
    @entry_sense.set_focus(true) 
  when ':right'
    @entry_anti_sense.set_focus(true)
  end
end

#handle_sense(event) ⇒ Object

#

handle_sense

You can send it an event, or a string.

#

487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 487

def handle_sense(event)
  old_text = @entry_sense.text?.dup # stores old text
  # ======================================================================= #
  # Store as upcased input:
  # ======================================================================= #
  if use_gtk?
    if event.class == ::Gdk::EventKey
      event = ::Gdk::Keyval.to_name(event.keyval).upcase
    else
      event = event.upcase
    end
    case old_text
    when 'A' then event = 'A'
    when 'T' then event = 'T'
    when 'C' then event = 'C'
    when 'G' then event = 'G'
    else # do nothing 
    end
  else
    event = event.dup if event.frozen?
    event.upcase!
  end
  @entry_sense.set_text(
    "#{old_text}#{event}"
  )
  synchronize_anti_sense
end

#on_reset_action_calledObject

#

on_reset_action_called

#

313
314
315
316
317
318
319
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 313

def on_reset_action_called
  # e 'Cleaning up.' # <- If we want to be extra-chatty.
  @entry_sense.set_text('')
  @entry_anti_sense.set_text('')
  @entry_sense.set_focus(true)
  @entry_sense.position = 12
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)

205
206
207
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 205

def padding?
  4
end

#populate_the_gridObject

#

populate_the_grid

#

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 374

def populate_the_grid
  label_sense = bold_label('SENSE')
  @grid.left(label_sense)
  @grid.right(@entry_sense)
  label_antisense = bold_label('ANTISENSE')
  # Next comes a hbox with an image, which is located in the middle.
  hbox_with_entry_sense_and_image = hbox
  hbox_with_entry_sense_and_image.add(label_antisense)
  # The image in the middle.
  @image = image(IMG_DNA_HELIX)
  if @image
    @eventbox = event_box(@image)
    # ======================================================================= #
    # === @eventbox
    #
    # It is associated with an Eventbox. When we click with a mouse button
    # on that image in the middle, the following code will be run.
    # ======================================================================= #
    @eventbox.signal_connect(:event) { |widget, event|
      case event.event_type.name.to_s
      when 'GDK_BUTTON_PRESS'
        if    event.button == 1 # left   mouse click
          _ = @entry_sense.text # Feedback the current content.
          e _
          if Object.const_defined? :XorgBuffer
            XorgBuffer[_.chomp]
          end
        elsif event.button == 2 # middle mouse click
        elsif event.button == 3 # right  mouse click
          _ = @entry_anti_sense.text
          e _
        end
        if respond_to? :gdk_selection_clipboard
          @clipboard = widget.get_clipboard(gdk_selection_clipboard)
          @clipboard.text = _
          @clipboard.request_text { |clipboard, text, data|
            # p text # zb label.set_text(text)
          }
          @entry_anti_sense.paste_clipboard
        end
      end
    }
    hbox_with_entry_sense_and_image.add(@eventbox)
  end
  @grid.left(hbox_with_entry_sense_and_image)
  @grid.right(@entry_anti_sense)
  @grid.left(@box_with_small_buttons)
  @grid.right(@button_reset)
end

#resetObject

#

reset (reset tag)

#

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 120

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  title_width_height(TITLE, WIDTH, HEIGHT)
  use_gtk_paradise_project_css_file
  append_project_CSS_file
  # ======================================================================= #
  # === @callback_quit
  # ======================================================================= #
  @callback_quit = Proc.new { quit }
  # ======================================================================= #
  # === @callback_new_file
  # ======================================================================= #
  @callback_new_file = Proc.new { e 'This is supposed to create a new file.' }
end

#runObject

#

run (run tag)

#

439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 439

def run
  if use_gtk3?
    require 'gtk_paradise/requires/require_the_base_module.rb'
    # extend ::Gtk::BaseModule
  end
  create_skeleton
  # if use_gtk3?
  #   @outer_vbox.minimal(@menu_bar,   5) # Keep the menu bar small.
  # end
  @outer_vbox.minimal(hsep)
  text_on_top = text(TITLE)
  text_on_top.align_to_the_left
  @outer_vbox.minimal(text_on_top)

  # ======================================================================= #
  # === Handle libui first
  # ======================================================================= #
  if is_libui_in_use?
  elsif is_gtk_in_use?
  end

  populate_the_grid
  @outer_vbox.maximal(@grid, 5)
  @main_window.add(@outer_vbox)
  @main_window.try_to_add_default_CSS_rules
  @main_window.intelligent_exit
  @main_window.show_all
  connect_skeleton
  set_use_this_font(USE_THIS_FONT) if use_gtk3?
  infer_the_size_automatically
  if use_gtk3?
    require 'gtk_paradise/run'
    _ = @main_window
    r = ::Gtk.run
    r << _
    r.background_colour(:linen)
    r.automatic_size_then_automatic_title
    r.top_left_then_run
  else
    run_main
  end
end

#synchronize_anti_senseObject

#

synchronize_anti_sense

Will fetch content and synchronize the @entry_anti_sense

#

144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/bioroebe/gui/unified_widgets/anti_sense_strand/anti_sense_strand.rb', line 144

def synchronize_anti_sense
  this_text = ''.dup
  @entry_sense.text?.each_char { |char|
    case char
    when 'A' then this_text << 'T'
    when 'T' then this_text << 'A'
    when 'C' then this_text << 'G'
    when 'G' then this_text << 'C'
    end
  }
  @entry_anti_sense.set_text(this_text)
end