Class: Studium::GUI::Gtk::CurriculumViewer
- Inherits:
-
Gtk::Box
- Object
- Gtk::Box
- Studium::GUI::Gtk::CurriculumViewer
- Includes:
- Gtk::BaseModule
- Defined in:
- lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb
Overview
Studium::GUI::Gtk::CurriculumViewer
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect- TITLE =
#
TITLE
#
'Curriculum Viewer'- WIDTH =
#
WIDTH
#
1080- HEIGHT =
#
HEIGHT
#
1140- USE_THIS_FONT =
#
USE_THIS_FONT
#
'Sans 17'
Class Method Summary collapse
-
.run(i = ARGV) ⇒ Object
# === Studium::GUI::Gtk::CurriculumViewer.run ========================================================================= #.
Instance Method Summary collapse
-
#border_size? ⇒ Boolean
# === border_size? ========================================================================= #.
-
#connect_skeleton ⇒ Object
# === connect_skeleton (connect tag) ========================================================================= #.
-
#create_bold_cell_renderer ⇒ Object
# === create_bold_cell_renderer ========================================================================= #.
-
#create_cell_renderers ⇒ Object
# === create_cell_renderers.
-
#create_entries ⇒ Object
# === create_entries (entries tag, entry tag) ========================================================================= #.
-
#create_menu ⇒ Object
# === create_menu.
-
#create_skeleton ⇒ Object
# === create_skeleton (create tag) ========================================================================= #.
-
#create_the_tree_view ⇒ Object
# === create_the_tree_view ========================================================================= #.
-
#do_open_this_url(i) ⇒ Object
# === dop_open_this_url ========================================================================= #.
-
#enable_custom_sorting_for_the_main_list_store ⇒ Object
# === enable_custom_sorting_for_the_main_list_store ========================================================================= #.
-
#handle_CSS_related_aspects ⇒ Object
# === handle_CSS_related_aspects (CSS tag) ========================================================================= #.
-
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ CurriculumViewer
constructor
# === initialize ========================================================================= #.
-
#main_dataset? ⇒ Boolean
# === main_dataset? ========================================================================= #.
-
#padding? ⇒ Boolean
# === padding? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#return_widget_on_the_bottom_holding_statistical_information_about_this_curriculum ⇒ Object
# === return_widget_on_the_bottom_holding_statistical_information_about_this_curriculum ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#update_the_tree_view_with_this_curriculum(i) ⇒ Object
# === update_the_tree_view_with_this_curriculum (update tag) ========================================================================= #.
Constructor Details
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ CurriculumViewer
#
initialize
#
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 60 def initialize( commandline_arguments = ARGV, run_already = true ) super(:vertical) reset set_commandline_arguments( commandline_arguments ) run if run_already end |
Class Method Details
.run(i = ARGV) ⇒ Object
#
Studium::GUI::Gtk::CurriculumViewer.run
#
495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 495 def self.run( i = ARGV ) require 'gtk_paradise/run' _ = ::Studium::GUI::Gtk::CurriculumViewer.new(i) r = ::Gtk.run r << _ r.automatic_size_then_automatic_title r.show_all r.top_left_then_run end |
Instance Method Details
#border_size? ⇒ Boolean
#
border_size?
#
109 110 111 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 109 def border_size? 8 end |
#connect_skeleton ⇒ Object
#
connect_skeleton (connect tag)
#
239 240 241 242 243 244 245 246 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 239 def connect_skeleton hpane = gtk_draggable_hpane( @vbox, ) hpane.position = 900 add(hpane) end |
#create_bold_cell_renderer ⇒ Object
#
create_bold_cell_renderer
#
226 227 228 229 230 231 232 233 234 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 226 def create_bold_cell_renderer @bold_renderer = gtk_cell_renderer_text @bold_renderer.editable = true @bold_renderer.set_property('background', 'white') @bold_renderer.set_cell_background('darkblue') # This makes the blue border. @bold_renderer.set_markup( '<span weight="bold">'+@bold_renderer.text.to_s+'</span>' ) end |
#create_cell_renderers ⇒ Object
#
create_cell_renderers
This creates the default cell-renderer used.
#
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 212 def create_cell_renderers @renderer = gtk_cell_renderer_text @renderer.editable = true @renderer.set_property('background', 'white') @renderer.set_cell_background('darkblue') # This makes the blue border. @renderer_green = gtk_cell_renderer_text @renderer_green.editable = true @renderer_green.set_property('foreground','darkgreen') create_bold_cell_renderer end |
#create_entries ⇒ Object
#
create_entries (entries tag, entry tag)
#
484 485 486 487 488 489 490 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 484 def create_entries @entry_n_ECTS_in_total = gtk_entry('') @entry_n_ECTS_in_total.do_center @entry_n_ECTS_in_total.bblack1 @entry_n_ECTS_in_total.very_light_yellowish_background @entry_n_ECTS_in_total.make_bold end |
#create_menu ⇒ Object
#
create_menu
This is the toplevel menubar.
#
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 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 137 def @menu_bar = = # ======================================================================= # # === 1) First menu drop-down interface # ======================================================================= # filem1 = ('File') {{ submenu: }} # ======================================================================= # # === Add the 'Show all URLs' entry next: # ======================================================================= # show_all_URLs = ('Show all URLs to the radio station') show_all_URLs.on_activate { do_show_all_URLs } << show_all_URLs # ======================================================================= # # === Add the 'Reset the Widget' entry next: # ======================================================================= # = ('Reset the widget') .hint = 'Clicking on this item will reset '\ 'the main widget to its initial state, as if you would '\ 'have just started this application.' .on_activate { } << .append_separator # ======================================================================= # # === Add the 'Exit' entry next: # ======================================================================= # exit = ('Exit') { :on_activate_quit } << exit # ======================================================================= # # === 2) Second menu drop-down interface # ======================================================================= # = filem2 = ('Not yet in use') {{ submenu: }} # ======================================================================= # # === Add the 'Shall the stream be captured' entry next: # ======================================================================= # yes = ::Gtk::RadioMenuItem.new(nil, 'Yes') yes.on_activate { @capture_the_stream = true } no = ::Gtk::RadioMenuItem.new(yes, 'No') no.on_activate { @capture_the_stream = false } << yes << no # ======================================================================= # # === 3) The info widget # ======================================================================= # = filem3 = ('Info') {{ submenu: }} # ======================================================================= # # === Add the 'Shall the stream be captured' entry next: # ======================================================================= # # show_more_info = gtk_menu_item('Show more info about this widget') # show_more_info.on_activate { do_show_more_info_about_this_widget } # filemenu3 << show_more_info # ======================================================================= # # Next, add the file-menu parts to the menu bar. # ======================================================================= # @menu_bar.add_these(filem1, filem2, filem3) end |
#create_skeleton ⇒ Object
#
create_skeleton (create tag)
#
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 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 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 303 def create_skeleton create_entries create_cell_renderers # ======================================================================= # # The relevant entries should be: # # (1) the LVA-ID of the lecture at hand # (2) name of the lecture at hand # (3) number of ECTS points # (4) the given semester # (5) already solved or not (Boolean) # # ======================================================================= # @list_store = ::Gtk::ListStore.new( String, String, String, String, String # Don't forget to sync this here. ) # ======================================================================= # # Obtain the dataset from the curriculum-file. # ======================================================================= # bachelor_vektor_dataset = ::Studium.read_dataset_from_a_curriculum_file( @use_this_curriculum, :remove_comments_and_title ) main_dataset = main_dataset? bachelor_vektor_dataset.each {|this_entry| this_entry = this_entry.dup if this_entry.frozen? this_entry.squeeze!(' ') if main_dataset.has_key? this_entry pointer = main_dataset[this_entry] n_ects = pointer[:ects].to_s.rjust(8) which_semester = pointer[:semester].to_s iter = @list_store.append splitted = this_entry.split(' ') lva_id = splitted.first raw_name_of_the_lecture = splitted[1 .. -1].join(' ') already_solved = pointer[:already_solved] if already_solved already_solved_or_not = 'Yes' else already_solved_or_not = 'No' end iter.set_value(0, lva_id) iter.set_value(1, raw_name_of_the_lecture) iter.set_value(2, n_ects) iter.set_value(3, which_semester) iter.set_value(4, already_solved_or_not) else e 'The dataset does not contain the key: '+steelblue(this_entry.to_s) end } create_the_tree_view # Next follows the top-label: label = gtk_label( ::Studium.return_title_from_this_curriculum_file( @use_this_curriculum ) ) label.make_bold # ======================================================================= # # === Add a scrolled window next: # ======================================================================= # scrolled_window = gtk_scrolled_window {{ use_this_widget: @tree_view }} scrolled_window. scrolled_window.set_size_request(700, 800) @vbox = gtk_vbox @vbox.minimal(label, 0) combo_box = gtk_dropdown_box( ::Studium.array_available_curricula ) combo_box.active = 9 # React on the combo-box being changed: # combo_box.signal_connect(:changed) { # if combo_box.active_iter # e "#{combo_box.active_iter[0]}" # end # } mini_hbox_containing_the_combo_box = gtk_hbox mini_hbox_containing_the_combo_box.maximal(combo_box) # The update-button is created next = ('_Update') .bblack1 .pad4px .hint = ' Update the <b>curriculum info</b> below. ' .on_clicked { update_the_tree_view_with_this_curriculum(combo_box.active_iter[0]) } .on_hover {{ colour: :lightgreen }} .modify_background :normal, :steelblue mini_hbox_containing_the_combo_box.minimal() enable_custom_sorting_for_the_main_list_store # ======================================================================= # # Next, add the elements into a vbox. # ======================================================================= # @vbox.minimal(@menu_bar, 0) @vbox.minimal(mini_hbox_containing_the_combo_box, 0) @vbox.maximal(scrolled_window, 0) end |
#create_the_tree_view ⇒ Object
#
create_the_tree_view
#
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 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 251 def create_the_tree_view # ======================================================================= # # === @tree_view # # Build up our main tree-view widget next. # ======================================================================= # @tree_view = gtk_tree_view(@list_store) { :clickable_headers } @tree_view.enable_search = true @tree_view.hadjustment = ::Gtk::Adjustment.new(0.0, 0.0, 105.0, 0.2, 1.0, 1.0) @tree_view.make_reorderable @tree_view.the_header_can_be_resized @tree_view.all_are_sortable # ======================================================================= # # Fill the tree-view widget with relevant data. # ======================================================================= # @tree_view.append('LVA-ID', @renderer, text: 0) @tree_view.append('Name of the lecture', @bold_renderer, text: 1) @tree_view.append('n ECTS', @renderer, text: 2) @tree_view.append('semester', @renderer, text: 3) @tree_view.append('already solved?', @renderer_green, text: 4) @tree_view.signal_connect(:button_press_event) { |, event| case event.event_type when Gdk::Event::BUTTON2_PRESS # =================================================================== # # double-click event is handled here: # =================================================================== # selection = .selection.selected lva_id = selection[0] name_of_the_lecture = selection[1] # =================================================================== # # This is triggered when the user clicks on the column. # =================================================================== # e steelblue(name_of_the_lecture) lva_id_and_name_of_the_lecture = "#{lva_id} #{name_of_the_lecture}" remote_url = @dataset_from_the_file_lecture_information[ lva_id_and_name_of_the_lecture ][:homepage].to_s do_open_this_url(remote_url) when Gdk::Event::BUTTON_PRESS # normal mouse button case event. when 1 # left mouse button. when 2 # mitte when 3 # right click will be doing unselect-action. @tree_view.selection.unselect_all end end } end |
#do_open_this_url(i) ⇒ Object
#
dop_open_this_url
#
128 129 130 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 128 def do_open_this_url(i) Open.in_browser(i) end |
#enable_custom_sorting_for_the_main_list_store ⇒ Object
#
enable_custom_sorting_for_the_main_list_store
#
406 407 408 409 410 411 412 413 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 406 def enable_custom_sorting_for_the_main_list_store # ======================================================================= # # Sort the file-size entry a bit differently. # ======================================================================= # @list_store.set_sort_func(2) { |_model, iter1, iter2| iter1[2].strip.to_f <=> iter2[2].strip.to_f } end |
#handle_CSS_related_aspects ⇒ Object
#
handle_CSS_related_aspects (CSS tag)
#
468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 468 def use_gtk_paradise_project_css_file append_project_css_file add_custom_CSS_rules ' treeview.view header button { color: royalblue; font-size: 1.25em; font-weight: bold; } ' do_apply_the_CSS_rules end |
#main_dataset? ⇒ Boolean
#
main_dataset?
#
203 204 205 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 203 def main_dataset? @dataset_from_the_file_lecture_information end |
#padding? ⇒ Boolean
#
padding?
#
102 103 104 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 102 def padding? 0 end |
#reset ⇒ Object
#
reset (reset tag)
#
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 75 def reset reset_the_internal_variables # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, NAMESPACE] title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT) ::Studium.set_runmode :gui # Make it known that we use the gui-runmode in this case. # ======================================================================= # # === @dataset_from_the_file_lecture_information # ======================================================================= # @dataset_from_the_file_lecture_information = ::Studium.return_sanitized_dataset_from_the_file_lecture_information # ======================================================================= # # === @use_this_curriculum # # Which curriculum to use. Currently this is hardcoded; in the # future this should be based on whatever dataset is loaded. # ======================================================================= # @use_this_curriculum = :bachelor_vektor infer_the_size_automatically end |
#return_widget_on_the_bottom_holding_statistical_information_about_this_curriculum ⇒ Object
#
return_widget_on_the_bottom_holding_statistical_information_about_this_curriculum
#
116 117 118 119 120 121 122 123 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 116 def = gtk_vbox mini_hbox = gtk_hbox mini_hbox.minimal(bold_label('n ECTS in total:'), 2) mini_hbox.minimal(@entry_n_ECTS_in_total, 2) .minimal(mini_hbox, 2) return end |
#run ⇒ Object
#
run (run tag)
#
418 419 420 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 418 def run create_skeleton_then_connect_skeleton end |
#update_the_tree_view_with_this_curriculum(i) ⇒ Object
#
update_the_tree_view_with_this_curriculum (update tag)
#
425 426 427 428 429 430 431 432 433 434 435 436 437 438 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 |
# File 'lib/studium/gui/gtk3/curriculum_viewer/curriculum_viewer.rb', line 425 def update_the_tree_view_with_this_curriculum(i) i = i.first.to_s if i.is_a? Array i = i.to_sym @use_this_curriculum = i # ======================================================================= # # Obtain the dataset from the curriculum-file. # ======================================================================= # curriculum_dataset = ::Studium.read_dataset_from_a_curriculum_file( @use_this_curriculum, :remove_comments_and_title ) e "Now using the curriculum `#{::Colours.steelblue(i)}`." main_dataset = main_dataset? @list_store.clear n_ECTS_in_total = 0 curriculum_dataset.each {|this_entry| this_entry = this_entry.dup if this_entry.frozen? this_entry.squeeze!(' ') pointer = main_dataset[this_entry] n_ects = pointer[:ects].to_s.rjust(8) n_ECTS_in_total += n_ects.strip.to_f which_semester = pointer[:semester].to_s iter = @list_store.append splitted = this_entry.split(' ') lva_id = splitted.first raw_name_of_the_lecture = splitted[1 .. -1].join(' ') already_solved = pointer[:already_solved] if already_solved already_solved_or_not = 'Yes' else already_solved_or_not = 'No' end iter.set_value(0, lva_id) iter.set_value(1, raw_name_of_the_lecture) iter.set_value(2, n_ects) iter.set_value(3, which_semester) iter.set_value(4, already_solved_or_not) } @entry_n_ECTS_in_total.set_text(n_ECTS_in_total.to_s) end |