Class: RulesDebuger::BetsGUI
- Inherits:
-
Object
- Object
- RulesDebuger::BetsGUI
- Defined in:
- lib/bets.rb
Instance Method Summary collapse
- #buffer_connect_tags(buffer) ⇒ Object
- #buffer_syntax_highlight(buffer, filename) ⇒ Object
- #build(filename) ⇒ Object
- #cmd(command) ⇒ Object
-
#debug_callback(lex) ⇒ Object
Функция обратного вызова для VM (вызываеться на каждый шаг программы).
- #debuger_reset ⇒ Object
- #dialog_ok_cancel(message) ⇒ Object
- #dialog_saveall_yes_no_cancel(message) ⇒ Object
- #dialog_yes_no_cancel(message) ⇒ Object
- #edt_buffer_new ⇒ Object
- #edt_openfile(filename, bg = false) ⇒ Object
- #edt_pop_state ⇒ Object
- #edt_push_state ⇒ Object
- #edt_save_changes ⇒ Object
- #edt_set_curr_filename(filename) ⇒ Object
- #error_puts(errors) ⇒ Object
- #error_select(errors) ⇒ Object
- #gtk_main_quit ⇒ Object
-
#initialize ⇒ BetsGUI
constructor
A new instance of BetsGUI.
- #message_out(message) ⇒ Object
- #on_end_user_action(widget) ⇒ Object
- #on_menu_activate(widget) ⇒ Object
- #on_toolbutton_clicked(widget) ⇒ Object
- #on_trv_files_cursor_changed(widget) ⇒ Object
- #on_wnd_main_configure_event(widget, event) ⇒ Object
- #on_wnd_main_delete_event(widget, event) ⇒ Object
- #on_wnd_main_destroy ⇒ Object
- #progress_callback(perc) ⇒ Object
- #progress_reset ⇒ Object
- #refresh_console ⇒ Object
- #refresh_files ⇒ Object
- #refresh_modified(value = false) ⇒ Object
- #refresh_stack_state ⇒ Object
- #refresh_vars_state ⇒ Object
- #stdout_redirect ⇒ Object
- #stdout_restore ⇒ Object
- #stdout_stream_recreate ⇒ Object
Constructor Details
#initialize ⇒ BetsGUI
Returns a new instance of BetsGUI.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 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 116 117 118 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 |
# File 'lib/bets.rb', line 10 def initialize @dbg_buffers = {} @edt_buffers = {} @state = [] stdout_stream_recreate @options = {} @options[:curr_filename] = '' @options[:curr_extension] = '' # Загрузка сценария RAD Gtk.init builder = Gtk::Builder.new builder.add_from_file(File.join(File.dirname(__FILE__), 'bets.glade')) builder.connect_signals {|handler| method(handler) } @imi_new = builder.get_object('imi_new') @imi_open = builder.get_object('imi_open') @imi_save = builder.get_object('imi_save') @imi_save_as = builder.get_object('imi_save_as') @mi_close = builder.get_object('mi_close') @imi_quit = builder.get_object('imi_quit') @mi_console = builder.get_object('mi_console') @mi_files = builder.get_object('mi_files') @mi_build = builder.get_object('mi_build') @mi_debug = builder.get_object('mi_debug') @mi_reset = builder.get_object('mi_reset') @mi_play = builder.get_object('mi_play') @mi_pause = builder.get_object('mi_pause') @mi_slow = builder.get_object('mi_slow') @mi_overstep = builder.get_object('mi_overstep') @mi_step = builder.get_object('mi_step') # toolbar @tb_new = builder.get_object('tb_new') @tb_open = builder.get_object('tb_open') @tb_save = builder.get_object('tb_save') @bt_close = builder.get_object('bt_close') @tb_build = builder.get_object('tb_build') @tbt_debug = builder.get_object('tbt_debug') @tb_reset = builder.get_object('tb_reset') @tbt_play = builder.get_object('tbt_play') @tbt_pause = builder.get_object('tbt_pause') @sb_delay = builder.get_object('sb_delay') @adj_delay = builder.get_object('adj_delay') @tbt_slow = builder.get_object('tbt_slow') @tb_step = builder.get_object('tb_step') @tb_overstep = builder.get_object('tb_overstep') # Область состояния переменных @trv_variables = builder.get_object('trv_variables') renderer = Gtk::CellRendererText.new column = Gtk::TreeViewColumn.new("Переменная", renderer, :text => 0) @trv_variables.append_column(column) column = Gtk::TreeViewColumn.new("Значение", renderer, :text => 1) @trv_variables.append_column(column) @ls_variables = Gtk::ListStore.new(String, String) @trv_variables.model = @ls_variables # Область файлов @scw_files = builder.get_object('scw_files') @trv_files = builder.get_object('trv_files') @trv_files.modify_base(Gtk::STATE_NORMAL,Gdk::Color.parse('#EEEEEE')) # @trv_files.modify_text(Gtk::STATE_NORMAL,Gdk::Color.parse('#FFFFFF')) renderer = Gtk::CellRendererText.new column = Gtk::TreeViewColumn.new("Файл", renderer, :text => 0) @trv_files.append_column(column) column = Gtk::TreeViewColumn.new("filename", renderer, :text => 1) column.visible = false @trv_files.append_column(column) @ts_files = Gtk::TreeStore.new(String, String) @trv_files.model = @ts_files @hp_files = builder.get_object('hp_files') # Область программы @txv_program = builder.get_object('txv_program') @tb_program = builder.get_object('tb_program') # @txv_program.modify_base(Gtk::STATE_NORMAL,Gdk::Color.parse('#000000')) # @txv_program.modify_text(Gtk::STATE_NORMAL,Gdk::Color.parse('#FFFFFF')) @txv_program.modify_font(Pango::FontDescription.new('Monospace 12')) @lb_filename = builder.get_object('lb_filename') @hp_vars = builder.get_object('hp_vars') # Область состояния стека @txv_stack = builder.get_object('txv_stack') @tb_stack = builder.get_object('tb_stack') @txv_limit = builder.get_object('txv_limit') @tb_limit = builder.get_object('tb_limit') # Вывод консоли @vb_stack = builder.get_object('vb_stack') @txv_console = builder.get_object('txv_console') @tb_console = builder.get_object('tb_console') @vp_console = builder.get_object('vp_console') @vb_footer = builder.get_object('vb_footer') # Строка состояния @pb_progress = builder.get_object('pb_progress') # Окно @wnd_main = builder.get_object('wnd_main') cmd(:start) begin @options = File.open(File.join(File.dirname(__FILE__), "options.dat"), "rb") {|f| Marshal.load(f)} rescue Exception => e puts e end files = @options[:files] if files != nil and files.length > 0 files.each do |f| edt_openfile(f, true) end edt_openfile(@options[:curr_filename]) refresh_files cmd(:editor) end @wnd_main.move(@options[:pos_x], @options[:pos_y]) if !@options[:pos_x].nil? and !@options[:pos_y].nil? @wnd_main.set_default_size(@options[:width], @options[:heigh]) if !@options[:width].nil? and !@options[:heigh].nil? @wnd_main.maximize if @options[:maximized] @wnd_main.show # @wnd_catalog = builder.get_object('wnd_catalog') # @wnd_catalog.show # Сброс # Gtk::main_iteration_do(blocking = false) while Gtk::events_pending? # on_tb_reset_clicked(@tb_reset) # Основной цикл @hp_files.position = @options[:hp_files] unless @options[:hp_files].nil? @hp_vars.position = @hp_vars.max_position - @options[:hp_vars] unless @options[:hp_vars].nil? @vp_console.position = @options[:vp_console] unless @options[:vp_console].nil? Gtk.main end |
Instance Method Details
#buffer_connect_tags(buffer) ⇒ Object
882 883 884 885 886 887 888 889 890 891 892 893 894 |
# File 'lib/bets.rb', line 882 def (buffer) buffer.create_tag("blue", {"underline" => Pango::UNDERLINE_SINGLE}) buffer.create_tag("number", {"foreground" => "#000000"}) buffer.create_tag("label", {"foreground" => "#000000"}) buffer.create_tag("brace", {"foreground" => "#000000"}) buffer.create_tag("operation", {"foreground" => "#000000"}) buffer.create_tag("var", {"foreground" => "#000000"}) buffer.create_tag("operator", {"foreground" => "#000099"}) buffer.create_tag("string", {"foreground" => "#777777"}) buffer.create_tag("word", {"foreground" => "#d93503"}) buffer.create_tag("comment", {"foreground" => "#004400"}) buffer.create_tag("error", {"foreground" => "#990000", "underline" => Pango::UNDERLINE_SINGLE }) end |
#buffer_syntax_highlight(buffer, filename) ⇒ Object
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'lib/bets.rb', line 896 def buffer_syntax_highlight(buffer, filename) case @options[:curr_extension] when 'rules' hl_lexical = Rules::Lexical.new hl_lexical.analyze(buffer.text, filename) buffer.(buffer.start_iter, buffer.end_iter) hl_lexical.result.each do |l| next if l[:filename] != filename b = buffer.get_iter_at_offset(l[:begin]) e = buffer.get_iter_at_offset(l[:begin]+l[:length]) case l[:lexem] when :label, :proc buffer.apply_tag("label", b, e) when :number, :float, :unary_minus buffer.apply_tag("number", b, e) when :l_brace, :r_brace buffer.apply_tag("brace", b, e) when :plus, :minus, :mul, :div buffer.apply_tag("operation", b, e) when :var,:wvar buffer.apply_tag("var", b, e) when :if_yes, :if_no, :else, :semicolon, :ret, :include, :true, :false, :ruby, :limiter buffer.apply_tag("operator", b, e) when :word buffer.apply_tag("word", b, e) when :string buffer.apply_tag("string", b, e) when :comment buffer.apply_tag("comment", b, e) end end end end |
#build(filename) ⇒ Object
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
# File 'lib/bets.rb', line 644 def build(filename) begin filename = File.(filename) text = File.open(filename, "r:UTF-8").read rescue Exception => e puts e end progress_reset lexical = Rules::Lexical.new lexical.set_progress_callback(self, :progress_callback) lexical.analyze(text, filename) syntax = Rules::Syntax.new syntax.set_progress_callback(self, :progress_callback) syntax.analyze(lexical.result) if lexical.errors.length + syntax.errors.length > 0 progress_reset return lexical.errors + syntax.errors end translator = Rules::Translator.new translator.set_progress_callback(self, :progress_callback) translator.translate(lexical.result, File.dirname(filename)) if translator.errors.length > 0 return translator.errors progress_reset end @ids_map = translator.ids @data_seg = translator.data_seg @code_seg = translator.code_seg @debug = translator.debug @includes = translator.includes return [] end |
#cmd(command) ⇒ Object
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 299 300 301 302 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 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 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 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 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 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/bets.rb', line 269 def cmd(command) case command when :start @mode = :start @imi_new.sensitive = @tb_new.sensitive = @imi_open.sensitive = @tb_open.sensitive = true @mi_play.active = @tbt_play.active = @mi_pause.active = @tbt_pause.active = @mi_slow.active = @tbt_slow.active = @imi_save.sensitive = @tb_save.sensitive = @imi_save_as.sensitive = @mi_close.sensitive = @bt_close.sensitive = @mi_build.sensitive = @tb_build.sensitive = @mi_debug.sensitive = @tbt_debug.sensitive = @mi_reset.sensitive = @tb_reset.sensitive = @mi_play.sensitive = @tbt_play.sensitive = @mi_pause.sensitive = @tbt_pause.sensitive = @mi_slow.sensitive = @tbt_slow.sensitive = @mi_step.sensitive = @tb_step.sensitive = @mi_overstep.sensitive = @tb_overstep.sensitive = @sb_delay.sensitive = @txv_program.sensitive = @txv_console.sensitive = @vb_stack.visible = @scw_files.visible = false @lb_filename.text = '' @txv_program.buffer = @tb_program progress_reset when :editor @vm.halt unless @vm.nil? edt_pop_state @mode = :edit # вкл @imi_new.sensitive = @tb_new.sensitive = @imi_open.sensitive = @tb_open.sensitive = @imi_save_as.sensitive = @mi_close.sensitive = @bt_close.sensitive = @mi_build.sensitive = @tb_build.sensitive = @mi_debug.sensitive = @tbt_debug.sensitive = @txv_program.sensitive = @txv_console.sensitive = @scw_files.visible = true # выкл @tbt_debug.active = @mi_play.active = @tbt_play.active = @mi_pause.active = @tbt_pause.active = @mi_slow.active = @tbt_slow.active = @mi_reset.sensitive = @tb_reset.sensitive = @mi_play.sensitive = @tbt_play.sensitive = @mi_pause.sensitive = @tbt_pause.sensitive = @sb_delay.sensitive = @mi_slow.sensitive = @tbt_slow.sensitive = @mi_step.sensitive = @tb_step.sensitive = @mi_overstep.sensitive = @tb_overstep.sensitive = @trv_variables.visible = @vb_stack.visible = false edt_openfile(@options[:curr_filename]) @tb_save.sensitive = @txv_program.buffer.modified? # Прервать текущую отладку @debuger_mode = :default @pause_flag = true progress_reset when :new dialog = Gtk::FileChooserDialog.new("Save File", @wnd_main, Gtk::FileChooser::ACTION_SAVE, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]) result = (dialog.run == Gtk::Dialog::RESPONSE_ACCEPT) filename = dialog.filename dialog.destroy return unless result return if File.exist?(filename) and !dialog_ok_cancel("Файл с таким именем уже существует! Перезаписать?") edt_openfile(filename) File.open(filename, 'wb') { |f| f.write(@txv_program.buffer.text) } cmd(:editor) cmd(:not_modified) refresh_files when :load # Прочее dialog = Gtk::FileChooserDialog.new("Open File", @wnd_main, Gtk::FileChooser::ACTION_OPEN, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT]) if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT edt_openfile(dialog.filename) refresh_files cmd(:editor) cmd(:not_modified) end dialog.destroy when :save filename = @options[:curr_filename] unless File.exist?(filename) dialog = Gtk::FileChooserDialog.new("Save File", @wnd_main, Gtk::FileChooser::ACTION_SAVE, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]) result = (dialog.run == Gtk::Dialog::RESPONSE_ACCEPT) filename = dialog.filename dialog.destroy return unless result buffer = @edt_buffers[@options[:curr_filename]] @edt_buffers.delete @options[:curr_filename] @edt_buffers[filename] = buffer edt_set_curr_filename(filename) end File.open(filename, 'wb') { |f| f.write(@txv_program.buffer.text) } unless filename.empty? cmd(:not_modified) refresh_files when :save_as dialog = Gtk::FileChooserDialog.new("Save File", @wnd_main, Gtk::FileChooser::ACTION_SAVE, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]) result = (dialog.run == Gtk::Dialog::RESPONSE_ACCEPT) filename = dialog.filename dialog.destroy return unless result buffer = @edt_buffers[@options[:curr_filename]] @edt_buffers.delete @options[:curr_filename] @edt_buffers[filename] = buffer edt_set_curr_filename(filename) File.open(filename, 'wb') { |f| f.write(@txv_program.buffer.text) } unless filename.empty? cmd(:not_modified) refresh_files when :close if @edt_buffers[@options[:curr_filename]].modified? result = dialog_yes_no_cancel("Файл #{@options[:curr_filename]} не сохранен! Cохранить?") case result when Gtk::RESPONSE_YES File.open(@options[:curr_filename], 'wb') { |f| f.write(@txv_program.buffer.text) } when Gtk::RESPONSE_CANCEL return end end a = [] a = @edt_buffers.map { |f,b| f } p = 0 a.each_index do |i| p = i if a[i] == @options[:curr_filename] end if a[p+1].nil? if a.length == 1 cmd(:start) else edt_openfile(a[p-1]) end else edt_openfile(a[p+1]) end @edt_buffers.delete(a[p]) refresh_files when :build return unless edt_save_changes stdout_stream_recreate errors = build(@options[:curr_filename]) error_select(errors) error_puts(errors) when :debug @vm.halt unless @vm.nil? unless edt_save_changes cmd(:editor) return end edt_push_state @mode = :debug stdout_stream_recreate # вкл @tbt_debug.active = @tbt_pause.active = @mi_pause.active = @mi_reset.sensitive = @tb_reset.sensitive = @mi_play.sensitive = @tbt_play.sensitive = @sb_delay.sensitive = @mi_step.sensitive = @tb_step.sensitive = @mi_slow.sensitive = @tbt_slow.sensitive = @mi_overstep.sensitive = @tb_overstep.sensitive = @trv_variables.visible = @vb_stack.visible = true # выкл @tbt_play.active = @mi_play.active = @tbt_slow.active = @mi_slow.active = @imi_new.sensitive = @tb_new.sensitive = @imi_open.sensitive = @tb_open.sensitive = @imi_save.sensitive = @tb_save.sensitive = @imi_save_as.sensitive = @mi_close.sensitive = @bt_close.sensitive = @mi_build.sensitive = @tb_build.sensitive = @mi_pause.sensitive = @tbt_pause.sensitive = @txv_program.sensitive = @scw_files.visible = false debuger_reset progress_reset when :reset cmd(:debug) when :play # вкл @mi_play.active = @tbt_play.active = @mi_pause.sensitive = @tbt_pause.sensitive = @mi_slow.sensitive = @tbt_slow.sensitive = true # выкл @mi_pause.active = @tbt_pause.active = @mi_slow.active = @tbt_slow.active = @mi_play.sensitive = @tbt_play.sensitive = @mi_step.sensitive = @tb_step.sensitive = @mi_overstep.sensitive = @tb_overstep.sensitive = @mi_slow.active = @tbt_slow.active = false # Прочее @delay = 0 @pause_flag = false @debuger_mode = :start when :slow # вкл @mi_slow.active = @tbt_slow.active = @mi_pause.sensitive = @tbt_pause.sensitive = @mi_play.sensitive = @tbt_play.sensitive = true # выкл @mi_pause.active = @tbt_pause.active = @mi_play.active = @tbt_play.active = @mi_play.sensitive = @tbt_play.sensitive = @mi_slow.sensitive = @tbt_slow.sensitive = @mi_step.sensitive = @tb_step.sensitive = @mi_overstep.sensitive = @tb_overstep.sensitive = false # Прочее @debuger_mode = :default @delay = @adj_delay.value @pause_flag = false when :pause # вкл @tbt_pause.active = @mi_pause.active = @mi_play.sensitive = @tbt_play.sensitive = @mi_slow.sensitive = @tbt_slow.sensitive = @mi_step.sensitive = @tb_step.sensitive = @mi_overstep.sensitive = @tb_overstep.sensitive = true # выкл @mi_play.active = @tbt_play.active = @mi_slow.active = @tbt_slow.active = @mi_pause.sensitive = @tbt_pause.sensitive = false # Прочее @debuger_mode = :default @pause_flag = true when :step @delay = 0 @debuger_mode = :step @pause_flag = false when :overstep @delay = 0 @debuger_mode = :overstep @pause_flag = false when :stop # вкл @mi_pause.active = @tbt_pause.active = true # выкл @mi_play.active = @tbt_play.active = @mi_slow.active = @tbt_slow.active = @mi_pause.sensitive = @tbt_pause.sensitive = @mi_slow.sensitive = @tbt_slow.sensitive = @mi_play.sensitive = @tbt_play.sensitive = @mi_step.sensitive = @tb_step.sensitive = @mi_overstep.sensitive = @tb_overstep.sensitive = false # Прочее ("[Выполнение программы окончено]") refresh_vars_state when :modified refresh_modified(true) progress_reset when :not_modified @edt_buffers[@options[:curr_filename]].modified = false refresh_modified when :quit gtk_main_quit end end |
#debug_callback(lex) ⇒ Object
Функция обратного вызова для VM (вызываеться на каждый шаг программы)
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 |
# File 'lib/bets.rb', line 990 def debug_callback(lex) return if @debuger_mode == :start and lex[:lexem] != :stop # Файл текущей лексемыg filename = lex[:filename] buffer = @dbg_buffers[filename] if buffer.nil? # Создать новый буфер @dbg_buffers[filename] = buffer = Gtk::TextBuffer.new (buffer) buffer.signal_connect("changed") { || on_end_user_action(); } buffer.text = File.open(lex[:filename], "r:UTF-8").read buffer_syntax_highlight buffer, lex[:filename] # Переключить отображение на созданный буффер unless @debuger_mode == :overstep @txv_program.buffer = buffer @lb_filename.text = filename end end # Извлечь итераторы предыдущей лексемы и удалить на ней тег выделения @old_lex_iter[:buffer].remove_tag("blue", @old_lex_iter[:begin], @old_lex_iter[:end]) unless @old_lex_iter.nil? # Выделить текущую лексему b = buffer.get_iter_at_offset(lex[:begin]) e = buffer.get_iter_at_offset(lex[:begin]+lex[:length]) buffer.apply_tag("blue", b, e) @txv_program.scroll_to_iter(b, 0.25, false, 0, 0) # Сохранить буфер и итераторы текущей лексемы для последующей очистки от тегов @old_lex_iter = {buffer: buffer, begin: b, end: e} # Если предыдущая лексема переменная, обновить ее значение в таблице переменных if !@old_lex.nil? and (@old_lex[:lexem] == :var or @old_lex[:lexem] == :wvar) @ls_variables.each do |m,p,i| value = (@old_lex[:lexem] == :wvar ? @old_lex[:value][1..-1] : @old_lex[:value]) if value == i.get_value(0) i[1] = @vm.data[@ids_map[i.get_value(0)][:addr]].to_s end end Gtk::main_iteration_do(blocking = false) while Gtk::events_pending? end # Обновить содержимое окна состояния стека refresh_stack_state # Обработка режимов отладки case @debuger_mode when :step @debuger_mode = :default @ip = nil @pause_flag = true when :overstep if !@ip.nil? and @vm.ip != @ip @pause_flag = false else @pause_flag = true @ip = nil end @ip = @vm.ip + 2 if lex[:lexem] == :var and @ids_map[lex[:value]][:type] == :proc end # Если отладчик не в автоматическом режиме, подключить буфер к виджету if @pause_flag or @delay != 0 @txv_program.buffer = buffer @lb_filename.text = filename end # Если лексема :stop, перевести отладчи в конечное состояние cmd(:stop) if lex[:lexem] == :stop # Сохранить текущую лексему @old_lex = lex # Задержка автоматического обхода if @delay > 0 sleep @delay Gtk::main_iteration_do(blocking = false) while Gtk::events_pending? end refresh_console # Ожидания действий пользователя sleep 0.1 while @pause_flag; end |
#debuger_reset ⇒ Object
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |
# File 'lib/bets.rb', line 677 def debuger_reset # Прервать текущую отладку @debuger_mode = :default @call_stack = [] @old_lex = nil @old_lex_iter = nil @dbg_buffers = {} @delay = 0 @ip = nil @pause_flag = true errors = build(@options[:curr_filename]) if errors.length > 0 error_puts errors error_select errors cmd(:editor) return end @vm = Rules::VM.new(@data_seg, @code_seg, @debug) @vm.set_debug_callback(self, :debug_callback) $export = [] errors = [] begin @includes.each do |f| load Gem::find_files("#{f}_rules.rb").last @vm.extend(self.class.const_get("#{f.capitalize}Rules")) end rescue Exception => e errors << {message: "Ошибка модуля: #{e}"} error_puts errors cmd(:editor) return end refresh_vars_state refresh_stack_state @vm.run end |
#dialog_ok_cancel(message) ⇒ Object
932 933 934 935 936 937 938 939 940 941 |
# File 'lib/bets.rb', line 932 def dialog_ok_cancel() dialog = Gtk::MessageDialog.new(@wnd_main, Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::QUESTION, Gtk::MessageDialog::BUTTONS_OK_CANCEL, ) result = (dialog.run == Gtk::Dialog::RESPONSE_OK) dialog.destroy return result end |
#dialog_saveall_yes_no_cancel(message) ⇒ Object
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 |
# File 'lib/bets.rb', line 959 def dialog_saveall_yes_no_cancel() dialog = Gtk::MessageDialog.new(@wnd_main, Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::QUESTION, Gtk::MessageDialog::BUTTONS_NONE, ) dialog.( ["Сохранить все", Gtk::Dialog::RESPONSE_APPLY], [Gtk::Stock::YES, Gtk::Dialog::RESPONSE_YES], [Gtk::Stock::NO, Gtk::Dialog::RESPONSE_NO], [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL]) result = dialog.run dialog.destroy return result end |
#dialog_yes_no_cancel(message) ⇒ Object
943 944 945 946 947 948 949 950 951 952 953 954 955 956 |
# File 'lib/bets.rb', line 943 def dialog_yes_no_cancel() dialog = Gtk::MessageDialog.new(@wnd_main, Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::QUESTION, Gtk::MessageDialog::BUTTONS_NONE, ) dialog.( [Gtk::Stock::YES, Gtk::Dialog::RESPONSE_YES], [Gtk::Stock::NO, Gtk::Dialog::RESPONSE_NO], [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL]) result = dialog.run dialog.destroy return result end |
#edt_buffer_new ⇒ Object
737 738 739 740 741 742 |
# File 'lib/bets.rb', line 737 def edt_buffer_new buffer = Gtk::TextBuffer.new (buffer) buffer.signal_connect("changed") { || on_end_user_action() } return buffer end |
#edt_openfile(filename, bg = false) ⇒ Object
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
# File 'lib/bets.rb', line 750 def edt_openfile(filename, bg = false) filename = File.(filename) buffer = @edt_buffers[filename] if buffer.nil? @edt_buffers[filename] = buffer = edt_buffer_new if File.exist?(File.(filename)) buffer.text = File.open(File.(filename), "r:UTF-8").read end edt_set_curr_filename(filename) unless bg buffer_syntax_highlight buffer, filename buffer.modified = false end unless bg edt_set_curr_filename(filename) @txv_program.buffer = buffer @imi_save.sensitive = @tb_save.sensitive = buffer.modified? end end |
#edt_pop_state ⇒ Object
791 792 793 794 795 796 |
# File 'lib/bets.rb', line 791 def edt_pop_state return unless @state.length > 0 state = @state.pop @txv_program.buffer = state[:buffer] @lb_filename.text = state[:filename] end |
#edt_push_state ⇒ Object
783 784 785 786 787 788 789 |
# File 'lib/bets.rb', line 783 def edt_push_state state = { :buffer => @txv_program.buffer, :filename => @options[:curr_filename] } @state.push state end |
#edt_save_changes ⇒ Object
770 771 772 773 774 775 776 777 778 779 780 781 |
# File 'lib/bets.rb', line 770 def edt_save_changes if @lb_filename.text =~ /.*?\*/ if dialog_ok_cancel("Сохранить изменения в файле '%s' ?" % @options[:curr_filename]) cmd(:save) return true else return false end else return true end end |
#edt_set_curr_filename(filename) ⇒ Object
744 745 746 747 748 |
# File 'lib/bets.rb', line 744 def edt_set_curr_filename(filename) @options[:curr_filename] = filename @options[:curr_extension] = filename.scan(/.*?\.([a-zA-z0-9]*)$/).flatten(1)[0] refresh_modified end |
#error_puts(errors) ⇒ Object
849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/bets.rb', line 849 def error_puts(errors) stdout_redirect if errors.length > 0 errors.each do |e| puts "[ошибка]: '#{e[:message]}' в строке #{e[:lexem][:line]}" end else puts '[ошибок нет]' end refresh_console stdout_restore end |
#error_select(errors) ⇒ Object
836 837 838 839 840 841 842 843 844 845 846 847 |
# File 'lib/bets.rb', line 836 def error_select(errors) return unless errors.length > 0 puts errors error = errors[0][:lexem] edt_openfile(error[:filename]) refresh_files buffer = @txv_program.buffer b = buffer.get_iter_at_offset(error[:begin]) e = buffer.get_iter_at_offset(error[:begin]+error[:length]) buffer.apply_tag('error',b,e) @txv_program.scroll_to_iter(b, 0.25, false, 0, 0) end |
#gtk_main_quit ⇒ Object
185 186 187 |
# File 'lib/bets.rb', line 185 def gtk_main_quit Gtk.main_quit() end |
#message_out(message) ⇒ Object
862 863 864 865 866 867 |
# File 'lib/bets.rb', line 862 def () stdout_redirect puts refresh_console stdout_restore end |
#on_end_user_action(widget) ⇒ Object
729 730 731 732 733 734 735 |
# File 'lib/bets.rb', line 729 def on_end_user_action() cmd(:modified) if @mode == :edit begin buffer_syntax_highlight , @options[:curr_filename] rescue end end |
#on_menu_activate(widget) ⇒ Object
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 |
# File 'lib/bets.rb', line 231 def () case .builder_name when "imi_new" cmd(:new) when "imi_open" cmd(:load) when "imi_save" cmd(:save) when "imi_save_as" cmd(:save_as) when "mi_close" cmd(:close) when "imi_quit" cmd(:quit) when "mi_console" @vb_footer.visible = .active? when "mi_files" @scw_files.visible = .active? when "mi_build" cmd(:build) when "mi_debug" cmd(.active? ? :debug : :editor) when "mi_reset" cmd(:reset) when "mi_play" cmd(:play) if .active? when "mi_pause" cmd(:pause) if .active? when "mi_slow" cmd(:slow) if .active? when "mi_step" cmd(:step) when "mi_overstep" cmd(:overstep) end end |
#on_toolbutton_clicked(widget) ⇒ Object
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 |
# File 'lib/bets.rb', line 199 def () case .builder_name when "tb_new" @imi_new.activate when "tb_open" @imi_open.activate when "tb_save" @imi_save.activate when "tb_save_as" @imi_save_as.activate when "bt_close" @mi_close.activate when "tb_build" @mi_build.activate when "tbt_debug" @mi_debug.activate if .active? != @mi_debug.active? when "tb_reset" @mi_reset.activate when "tbt_play" @mi_play.active = true if .active? != @mi_play.active? when "tbt_pause" @mi_pause.active = true if .active? != @mi_pause.active? when "tbt_slow" @mi_slow.active = true if .active? != @mi_slow.active? when "tb_step" @mi_step.activate when "tb_overstep" @mi_overstep.activate end end |
#on_trv_files_cursor_changed(widget) ⇒ Object
723 724 725 726 727 |
# File 'lib/bets.rb', line 723 def on_trv_files_cursor_changed() path, c = .cursor iter = @ts_files.get_iter(path) edt_openfile(iter[1]) end |
#on_wnd_main_configure_event(widget, event) ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'lib/bets.rb', line 189 def on_wnd_main_configure_event(, event) mask = Gdk::EventWindowState::MAXIMIZED @options[:maximized] = @wnd_main.window.state & mask == mask unless @options[:maximized] @options[:width], @options[:heigh] = event.width, event.height @options[:pos_x], @options[:pos_y] = event.x, event.y end false end |
#on_wnd_main_delete_event(widget, event) ⇒ Object
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 |
# File 'lib/bets.rb', line 152 def on_wnd_main_delete_event(, event) @options[:files] = [] auto = false result = nil # Это корректирует глюк ruby интерпретатора @edt_buffers.each do |k,v| @options[:files] << k if v.modified? result = dialog_saveall_yes_no_cancel("Файл #{k} не сохранен! Сохранить?") unless auto case result when Gtk::Dialog::RESPONSE_CANCEL return true when Gtk::Dialog::RESPONSE_YES File.open(k, 'wb') { |f| f.write(v.text) } when Gtk::Dialog::RESPONSE_APPLY File.open(k, 'wb') { |f| f.write(v.text) } auto = true end end end @options[:hp_files] = @hp_files.position @options[:hp_vars] = @hp_vars.max_position - @hp_vars.position @options[:vp_console] = @vp_console.position begin File.open(File.join(File.dirname(__FILE__), "options.dat"), "wb") {|f| Marshal.dump(@options, f)} rescue Exception => e puts e end return false end |
#on_wnd_main_destroy ⇒ Object
719 720 721 |
# File 'lib/bets.rb', line 719 def on_wnd_main_destroy gtk_main_quit end |
#progress_callback(perc) ⇒ Object
975 976 977 978 979 980 981 982 |
# File 'lib/bets.rb', line 975 def progress_callback(perc) if (perc % @a == 0) or (perc == 100) @pb_progress.text = "#{perc}%" @pb_progress.fraction = perc * 0.01 Gtk::main_iteration_do(blocking = false) while Gtk::events_pending? @a = Random.rand(2...10) end end |
#progress_reset ⇒ Object
984 985 986 987 988 |
# File 'lib/bets.rb', line 984 def progress_reset @pb_progress.text = " " @pb_progress.fraction = 0 @a = 1 end |
#refresh_console ⇒ Object
830 831 832 833 834 |
# File 'lib/bets.rb', line 830 def refresh_console @mi_console.active = true @txv_console.buffer.text = @stdout_stream.string.encode('UTF-8') @txv_console.scroll_to_iter(@txv_console.buffer.end_iter, 0.25, false, 0, 0) end |
#refresh_files ⇒ Object
805 806 807 808 809 810 811 812 813 |
# File 'lib/bets.rb', line 805 def refresh_files @ts_files.clear @edt_buffers.each do |key, value| item = @ts_files.append(nil) item[0] = File.basename(key) item[1] = key @trv_files.selection.select_iter(item) if key == @options[:curr_filename] end end |
#refresh_modified(value = false) ⇒ Object
798 799 800 801 802 803 |
# File 'lib/bets.rb', line 798 def refresh_modified(value = false) modified = (value ? true : @edt_buffers[@options[:curr_filename]].modified?) @imi_save.sensitive = @tb_save.sensitive = modified @lb_filename.text = @options[:curr_filename] + ( modified ? '*' : '') end |
#refresh_stack_state ⇒ Object
825 826 827 828 |
# File 'lib/bets.rb', line 825 def refresh_stack_state @tb_stack.text = @vm.data_stack.reverse.to_s @tb_limit.text = @vm.limit_stack.reverse.to_s end |
#refresh_vars_state ⇒ Object
815 816 817 818 819 820 821 822 823 |
# File 'lib/bets.rb', line 815 def refresh_vars_state @ls_variables.clear @ids_map.each do |key, value| next unless value[:type] == :var item = @ls_variables.append item[0] = key item[1] = @vm.data[@ids_map[key][:addr]].to_s end end |
#stdout_redirect ⇒ Object
874 875 876 |
# File 'lib/bets.rb', line 874 def stdout_redirect $stdout = @stdout_stream end |
#stdout_restore ⇒ Object
878 879 880 |
# File 'lib/bets.rb', line 878 def stdout_restore $stdout = @stdout_store end |
#stdout_stream_recreate ⇒ Object
869 870 871 872 |
# File 'lib/bets.rb', line 869 def stdout_stream_recreate @stdout_stream = StringIO.new @stdout_store = $stdout end |