Ruby GTK3移行後のメインリポジトリ
Revisión | fe6e2c7f8739c7094c5ef8af829eaa588370f690 (tree) |
---|---|
Tiempo | 2015-03-21 23:13:08 |
Autor | Shyouzou Sugitani <shy@user...> |
Commiter | Shyouzou Sugitani |
update error checking(2)
@@ -100,7 +100,7 @@ module DLL | ||
100 | 100 | for line in req.split("\n") |
101 | 101 | line = line.force_encoding(@charset).strip.encode("UTF-8", :invalid => :replace) |
102 | 102 | if line.empty? |
103 | - continue | |
103 | + next | |
104 | 104 | end |
105 | 105 | if req_type == nil |
106 | 106 | for request in ['EXECUTE', 'GET Version'] ## FIXME |
@@ -111,7 +111,7 @@ module DLL | ||
111 | 111 | next |
112 | 112 | end |
113 | 113 | if line.index(':') == nil |
114 | - continue | |
114 | + next | |
115 | 115 | end |
116 | 116 | key, value = line.split(':', 2) |
117 | 117 | key = key.strip() |
@@ -26,13 +26,13 @@ require "ninix/version" | ||
26 | 26 | |
27 | 27 | module Install |
28 | 28 | |
29 | -# class InstallError(Exception) | |
30 | -# # pass | |
31 | -# end | |
29 | + class InstallError < Exception | |
30 | + #pass | |
31 | + end | |
32 | 32 | |
33 | 33 | def self.fatal(error) |
34 | - logging.error(error) # XXX | |
35 | - raise InstallError(error) | |
34 | + #logging.error(error) # XXX | |
35 | + raise InstallError.new(error) | |
36 | 36 | end |
37 | 37 | |
38 | 38 | class Installer |
@@ -75,7 +75,7 @@ module Install | ||
75 | 75 | if ['.nar', '.zip'].include?(ext) |
76 | 76 | # pass |
77 | 77 | else |
78 | - fatal('unknown archive format') | |
78 | + Install.fatal('unknown archive format') | |
79 | 79 | end |
80 | 80 | end |
81 | 81 |
@@ -86,7 +86,7 @@ module Install | ||
86 | 86 | begin |
87 | 87 | FileUtils.mkdir_p(tmpdir) |
88 | 88 | rescue # except: |
89 | - fatal('cannot make temporary directory') | |
89 | + Install.fatal('cannot make temporary directory') | |
90 | 90 | end |
91 | 91 | url = nil |
92 | 92 | if filename.start_with?('http:') or filename.start_with?('ftp:') |
@@ -94,7 +94,7 @@ module Install | ||
94 | 94 | filename = download(filename, tmpdir) |
95 | 95 | if filename == nil |
96 | 96 | FileUtils.remove_entry_secure(tmpdir) |
97 | - fatal('cannot download the archive file') | |
97 | + Install.fatal('cannot download the archive file') | |
98 | 98 | end |
99 | 99 | else |
100 | 100 | check_archive(filename) |
@@ -119,7 +119,7 @@ module Install | ||
119 | 119 | zf.close() |
120 | 120 | rescue # except: |
121 | 121 | FileUtils.remove_entry_secure(tmpdir) |
122 | - fatal('cannot extract files from the archive') | |
122 | + Install.fatal('cannot extract files from the archive') | |
123 | 123 | end |
124 | 124 | Dir.glob(tmpdir) { |path| |
125 | 125 | if File.directory?(path) |
@@ -131,7 +131,6 @@ module Install | ||
131 | 131 | File.chmod(st_mode | 128 | 256, path) |
132 | 132 | end |
133 | 133 | } |
134 | -# print("EXTRACT: ", tmpdir, "\n") | |
135 | 134 | rename_files(tmpdir) |
136 | 135 | return tmpdir |
137 | 136 | end |
@@ -146,7 +145,7 @@ module Install | ||
146 | 145 | elsif File.exists?(File.join(tmpdir, 'plugin.txt')) |
147 | 146 | filetype = 'plugin' |
148 | 147 | else |
149 | - fatal('cannot read install.txt from the archive') | |
148 | + Install.fatal('cannot read install.txt from the archive') | |
150 | 149 | end |
151 | 150 | else |
152 | 151 | filetype = inst.get('type') |
@@ -275,15 +274,13 @@ module Install | ||
275 | 274 | end |
276 | 275 | |
277 | 276 | def rename_files(basedir) |
278 | -# print("RENAME: ", basedir, "\n") | |
279 | -# if os.name == 'nt' # XXX | |
280 | -# return | |
281 | -# end | |
277 | + if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|cygwin|bccwin/ # XXX | |
278 | + return | |
279 | + end | |
282 | 280 | Dir.foreach(basedir) { |filename| |
283 | 281 | next if /^\.+$/ =~ filename |
284 | 282 | filename2 = filename.downcase |
285 | 283 | path = File.join(basedir, filename2) |
286 | -# print("PATH: ", path, "\n") | |
287 | 284 | if filename != filename2 |
288 | 285 | File.rename(File.join(basedir, filename), path) |
289 | 286 | end |
@@ -338,9 +335,9 @@ module Install | ||
338 | 335 | end |
339 | 336 | |
340 | 337 | def lower_files(top_dir) |
341 | -# if os.name == 'nt' # XXX | |
342 | -# return | |
343 | -# end | |
338 | + if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|cygwin|bccwin/ # XXX | |
339 | + return | |
340 | + end | |
344 | 341 | n = 0 |
345 | 342 | Dir.foreach(top_dir) { |filename| |
346 | 343 | next if /^\.+$/ =~ filename |
@@ -348,8 +345,8 @@ module Install | ||
348 | 345 | path = File.join(top_dir, filename2) |
349 | 346 | if filename != filename2 |
350 | 347 | File.rename(File.join(top_dir, filename), path) |
351 | -# logging.info( | |
352 | -# 'renamed {0}'.format(File.join(top_dir, filename))) | |
348 | + #logging.info( | |
349 | + # 'renamed {0}'.format(File.join(top_dir, filename))) | |
353 | 350 | n += 1 |
354 | 351 | end |
355 | 352 | if File.directory?(path) |
@@ -380,13 +377,13 @@ module Install | ||
380 | 377 | |
381 | 378 | def select(candidates) |
382 | 379 | #assert len(candidates) >= 1 |
383 | - if len(candidates) == 1 | |
380 | + if candidates.length == 1 | |
384 | 381 | return candidates[0] |
385 | 382 | end |
386 | 383 | ls = @treeview.get_model() |
387 | 384 | ls.clear() |
388 | 385 | for i, item in enumerate(candidates) |
389 | - ls.append([i, item]) | |
386 | + ls << [i, item] | |
390 | 387 | end |
391 | 388 | ts = @treeview.get_selection() |
392 | 389 | ts.select_iter(ls.get_iter_first()) |
@@ -402,13 +399,12 @@ module Install | ||
402 | 399 | def install_ghost(archive, tmpdir, homedir) |
403 | 400 | # find install.txt |
404 | 401 | inst = Home.read_install_txt(tmpdir) |
405 | -# print("INST: ", inst, "\n") | |
406 | 402 | if inst == nil |
407 | - fatal('install.txt not found') | |
403 | + Install.fatal('install.txt not found') | |
408 | 404 | end |
409 | 405 | target_dir = inst.get('directory') |
410 | 406 | if target_dir == nil |
411 | - fatal('"directory" not found in install.txt') | |
407 | + Install.fatal('"directory" not found in install.txt') | |
412 | 408 | end |
413 | 409 | prefix = File.join(homedir, 'ghost', target_dir) |
414 | 410 | ghost_src = File.join(tmpdir, 'ghost', 'master') |
@@ -448,7 +444,6 @@ module Install | ||
448 | 444 | end |
449 | 445 | balloon_name = nil |
450 | 446 | if balloon_dir |
451 | -# print("BALLOON DIR: ", balloon_dir, "\n") | |
452 | 447 | balloon_dir = Home.get_normalized_path(balloon_dir) |
453 | 448 | balloon_dst = File.join(homedir, 'balloon', balloon_dir) |
454 | 449 | if inst |
@@ -459,7 +454,6 @@ module Install | ||
459 | 454 | else |
460 | 455 | balloon_src = balloon_dir |
461 | 456 | end |
462 | -# print("INSTALL.TXT(B): ", File.join(tmpdir, balloon_src), "\n") | |
463 | 457 | inst_balloon = Home.read_install_txt( |
464 | 458 | File.join(tmpdir, balloon_src)) |
465 | 459 | if Dir.exists?(balloon_dst) and \ |
@@ -483,7 +477,7 @@ module Install | ||
483 | 477 | end |
484 | 478 | if Dir.exists?(prefix) |
485 | 479 | inst_dst = Home.read_install_txt(prefix) |
486 | - if inst.get('refresh', 0).to_i | |
480 | + if inst.get('refresh', 0).to_i != 0 | |
487 | 481 | # uninstall older versions of the ghost |
488 | 482 | if confirm_refresh(prefix, 'ghost') |
489 | 483 | mask = [] |
@@ -502,7 +496,7 @@ module Install | ||
502 | 496 | end |
503 | 497 | end |
504 | 498 | # install files |
505 | -# logging.info('installing {0} (ghost)'.format(archive)) | |
499 | + #logging.info('installing {0} (ghost)'.format(archive)) | |
506 | 500 | install_files(filelist) |
507 | 501 | # create SETTINGS |
508 | 502 | path = File.join(prefix, 'SETTINGS') |
@@ -514,7 +508,7 @@ module Install | ||
514 | 508 | end |
515 | 509 | rescue # except IOError as e: |
516 | 510 | code, message = e.args |
517 | -# logging.error('cannot write {0}'.format(path)) | |
511 | + #logging.error('cannot write {0}'.format(path)) | |
518 | 512 | ensure |
519 | 513 | f.close() |
520 | 514 | end |
@@ -528,7 +522,7 @@ module Install | ||
528 | 522 | def install_supplement(archive, tmpdir, homedir) |
529 | 523 | inst = Home.read_install_txt(tmpdir) |
530 | 524 | if inst and inst.include?('accept') |
531 | - logging.info('searching supplement target ...') | |
525 | + #logging.info('searching supplement target ...') | |
532 | 526 | candidates = [] |
533 | 527 | begin |
534 | 528 | dirlist = Dir.entries(File.join(homedir, 'ghost')) |
@@ -538,7 +532,7 @@ module Install | ||
538 | 532 | for dirname in dirlist |
539 | 533 | path = File.join(homedir, 'ghost', dirname) |
540 | 534 | if File.exists?(File.join(path, 'shell', 'surface.txt')) |
541 | - continue # ghost.inverse(obsolete) | |
535 | + next # ghost.inverse(obsolete) | |
542 | 536 | end |
543 | 537 | desc = Home.read_descript_txt( |
544 | 538 | File.join(path, 'ghost', 'master')) |
@@ -546,8 +540,8 @@ module Install | ||
546 | 540 | candidates << dirname |
547 | 541 | end |
548 | 542 | end |
549 | - if not candidates | |
550 | - logging.info('not found') | |
543 | + if candidates.empty? | |
544 | + #logging.info('not found') | |
551 | 545 | return nil, nil, 4 |
552 | 546 | else |
553 | 547 | target = self.select(candidates) |
@@ -560,7 +554,7 @@ module Install | ||
560 | 554 | path = File.join(path, 'shell', inst['directory']) |
561 | 555 | else |
562 | 556 | if not inst.include?('type') |
563 | -# logging.error('supplement type not specified') | |
557 | + #logging.error('supplement type not specified') | |
564 | 558 | else |
565 | 559 | # logging.error('unsupported supplement type: {0}'.format(inst['type'])) |
566 | 560 | end |
@@ -582,11 +576,11 @@ module Install | ||
582 | 576 | # find install.txt |
583 | 577 | inst = Home.read_install_txt(srcdir) |
584 | 578 | if inst == nil |
585 | - fatal('install.txt not found') | |
579 | + Install.fatal('install.txt not found') | |
586 | 580 | end |
587 | 581 | target_dir = inst.get('directory') |
588 | 582 | if target_dir == nil |
589 | - fatal('"directory" not found in install.txt') | |
583 | + Install.fatal('"directory" not found in install.txt') | |
590 | 584 | end |
591 | 585 | dstdir = File.join(homedir, 'balloon', target_dir) |
592 | 586 | filelist = [] |
@@ -616,7 +610,7 @@ module Install | ||
616 | 610 | end |
617 | 611 | end |
618 | 612 | # install files |
619 | -# logging.info('installing {0} (balloon)'.format(archive)) | |
613 | + #logging.info('installing {0} (balloon)'.format(archive)) | |
620 | 614 | install_files(filelist) |
621 | 615 | return target_dir, inst.get('name'), 0 |
622 | 616 | end |
@@ -631,7 +625,7 @@ module Install | ||
631 | 625 | path = File.join(homedir, 'plugin', subdir) |
632 | 626 | plugin = Home.read_plugin_txt(path) |
633 | 627 | if plugin == nil |
634 | - continue | |
628 | + next | |
635 | 629 | end |
636 | 630 | plugin_name, plugin_dir, startup, menu_items = plugin |
637 | 631 | if plugin_name == name |
@@ -648,7 +642,7 @@ module Install | ||
648 | 642 | # find plugin.txt |
649 | 643 | plugin = Home.read_plugin_txt(srcdir) |
650 | 644 | if plugin == nil |
651 | - fatal('failed to read plugin.txt') | |
645 | + Install.fatal('failed to read plugin.txt') | |
652 | 646 | end |
653 | 647 | plugin_name, plugin_dir, startup, menu_items = plugin |
654 | 648 | # find files |
@@ -662,7 +656,7 @@ module Install | ||
662 | 656 | # uninstall older versions of the plugin |
663 | 657 | uninstall_plugin(homedir, plugin_name) |
664 | 658 | # install files |
665 | -# print('installing {0} (plugin)'.format(archive)) | |
659 | + #logging.info('installing {0} (plugin)'.format(archive)) | |
666 | 660 | install_files(filelist) |
667 | 661 | return plugin_dir, plugin_name, 0 |
668 | 662 | end |
@@ -677,7 +671,7 @@ module Install | ||
677 | 671 | path = File.join(homedir, 'kinoko', subdir) |
678 | 672 | kinoko = Home.read_kinoko_ini(path) |
679 | 673 | if kinoko == nil |
680 | - continue | |
674 | + next | |
681 | 675 | end |
682 | 676 | kinoko_name = kinoko['title'] |
683 | 677 | if kinoko_name == name |
@@ -693,7 +687,7 @@ module Install | ||
693 | 687 | # find kinoko.ini |
694 | 688 | kinoko = Home.read_kinoko_ini(srcdir) |
695 | 689 | if kinoko == nil |
696 | - fatal('failed to read kinoko.ini') | |
690 | + Install.fatal('failed to read kinoko.ini') | |
697 | 691 | end |
698 | 692 | kinoko_name = kinoko['title'] |
699 | 693 | if kinoko['extractpath'] != nil |
@@ -713,7 +707,7 @@ module Install | ||
713 | 707 | # uninstall older versions of the kinoko |
714 | 708 | uninstall_kinoko(homedir, kinoko_name) |
715 | 709 | # install files |
716 | -# logging.info('installing {0} (kinoko)'.format(archive)) | |
710 | + #logging.info('installing {0} (kinoko)'.format(archive)) | |
717 | 711 | install_files(filelist) |
718 | 712 | return dstdir, [kinoko_name, kinoko['ghost'], kinoko['category']], 0 |
719 | 713 | end |
@@ -732,11 +726,11 @@ module Install | ||
732 | 726 | # find install.txt |
733 | 727 | inst = Home.read_install_txt(srcdir) |
734 | 728 | if inst == nil |
735 | - fatal('install.txt not found') | |
729 | + Install.fatal('install.txt not found') | |
736 | 730 | end |
737 | 731 | target_dir = inst.get('directory') |
738 | 732 | if target_dir == nil |
739 | - fatal('"directory" not found in install.txt') | |
733 | + Install.fatal('"directory" not found in install.txt') | |
740 | 734 | end |
741 | 735 | dstdir = File.join(homedir, 'nekodorif', 'skin', target_dir) |
742 | 736 | # find files |
@@ -751,7 +745,7 @@ module Install | ||
751 | 745 | # uninstall older versions of the skin |
752 | 746 | uninstall_nekoninni(homedir, target_dir) |
753 | 747 | # install files |
754 | -# logging.info('installing {0} (nekodorif skin)'.format(archive)) | |
748 | + #logging.info('installing {0} (nekodorif skin)'.format(archive)) | |
755 | 749 | install_files(filelist) |
756 | 750 | return target_dir, inst.get('name'), 0 |
757 | 751 | end |
@@ -770,11 +764,11 @@ module Install | ||
770 | 764 | # find install.txt |
771 | 765 | inst = Home.read_install_txt(srcdir) |
772 | 766 | if inst == nil |
773 | - fatal('install.txt not found') | |
767 | + Install.fatal('install.txt not found') | |
774 | 768 | end |
775 | 769 | target_dir = inst.get('directory') |
776 | 770 | if target_dir == nil |
777 | - fatal('"directory" not found in install.txt') | |
771 | + Install.fatal('"directory" not found in install.txt') | |
778 | 772 | end |
779 | 773 | dstdir = File.join(homedir, 'nekodorif', 'katochan', target_dir) |
780 | 774 | # find files |
@@ -789,7 +783,7 @@ module Install | ||
789 | 783 | # uninstall older versions of the skin |
790 | 784 | uninstall_katochan(homedir, target_dir) |
791 | 785 | # install files |
792 | -# logging.info('installing {0} (nekodorif katochan)'.format(archive)) | |
786 | + #logging.info('installing {0} (nekodorif katochan)'.format(archive)) | |
793 | 787 | install_files(filelist) |
794 | 788 | return target_dir, inst.get('name'), 0 |
795 | 789 | end |
@@ -814,7 +808,6 @@ module Install | ||
814 | 808 | if not Dir.exists?(dirname) |
815 | 809 | FileUtils.mkdir_p(dirname) |
816 | 810 | end |
817 | -# print("INSTALL FILES: ", from_path, " to ", to_path, "\n") | |
818 | 811 | FileUtils.copy(from_path, to_path) |
819 | 812 | end |
820 | 813 | end |
@@ -52,7 +52,6 @@ module Kinoko | ||
52 | 52 | '', lambda {|a, b| return @parent.handle_request('NOTIFY', 'close')}], |
53 | 53 | '/ui/popup/Exit'], |
54 | 54 | } |
55 | - @__skin_list = nil | |
56 | 55 | actions = Gtk::ActionGroup.new('Actions') |
57 | 56 | entry = [] |
58 | 57 | for value in @__menu_list.values() |
@@ -81,14 +80,13 @@ module Kinoko | ||
81 | 80 | |
82 | 81 | def set_skin_menu(list) ## FIXME |
83 | 82 | key = 'skin' |
84 | - if list | |
85 | - menu = Gtk.Menu() | |
83 | + if not list.empty? | |
84 | + menu = Gtk::Menu.new | |
86 | 85 | for skin in list |
87 | - item = Gtk.MenuItem(skin['title']) | |
88 | - item.signal_connect( | |
89 | - 'activate', | |
90 | - lambda {|a, k| return @parent.handle_request('NOTIFY', 'select_skin', k)}, | |
91 | - [skin]) | |
86 | + item = Gtk::MenuItem.new(skin['title']) | |
87 | + item.signal_connect('activate', skin) do |a, k| | |
88 | + @parent.handle_request('NOTIFY', 'select_skin', k) | |
89 | + end | |
92 | 90 | menu.add(item) |
93 | 91 | item.show() |
94 | 92 | end |
@@ -119,42 +117,42 @@ module Kinoko | ||
119 | 117 | |
120 | 118 | def finalize() |
121 | 119 | @__running = false |
122 | - self.target.detach_observer(self) | |
123 | - if self.skin != nil | |
124 | - self.skin.destroy() | |
120 | + @target.detach_observer(self) | |
121 | + if @skin != nil | |
122 | + @skin.destroy() | |
125 | 123 | end |
126 | 124 | end |
127 | 125 | |
128 | 126 | def observer_update(event, args) |
129 | - if self.skin == nil | |
127 | + if @skin == nil | |
130 | 128 | return |
131 | 129 | end |
132 | 130 | if ['set position', 'set surface'].include?(event) |
133 | - self.skin.set_position() | |
134 | - self.skin.show() | |
131 | + @skin.set_position() | |
132 | + @skin.show() | |
135 | 133 | elsif event == 'set scale' |
136 | - scale = self.target.get_surface_scale() | |
137 | - self.skin.set_scale(scale) | |
134 | + scale = @target.get_surface_scale() | |
135 | + @skin.set_scale(scale) | |
138 | 136 | elsif event == 'hide' |
139 | 137 | side = args |
140 | 138 | if side == 0 # sakura side |
141 | - self.skin.hide() | |
139 | + @skin.hide() | |
142 | 140 | end |
143 | 141 | elsif event == 'iconified' |
144 | - self.skin.hide() | |
142 | + @skin.hide() | |
145 | 143 | elsif event == 'deiconified' |
146 | - self.skin.show() | |
144 | + @skin.show() | |
147 | 145 | elsif event == 'finalize' |
148 | - self.finalize() | |
146 | + finalize() | |
149 | 147 | elsif event == 'move surface' |
150 | 148 | side, xoffset, yoffset = args |
151 | 149 | if side == 0 # sakura side |
152 | - self.skin.set_position(xoffset, yoffset) | |
150 | + @skin.set_position(xoffset, yoffset) | |
153 | 151 | end |
154 | 152 | elsif event == 'raise' |
155 | 153 | side = args |
156 | 154 | if side == 0 # sakura side |
157 | - self.skin.set_position() ## FIXME | |
155 | + @skin.set_position() ## FIXME | |
158 | 156 | end |
159 | 157 | else |
160 | 158 | ##logging.debug('OBSERVER(kinoko): ignore - {0}'.format(event)) |
@@ -164,21 +162,25 @@ module Kinoko | ||
164 | 162 | def load_skin() |
165 | 163 | scale = @target.get_surface_scale() |
166 | 164 | @skin = Skin.new(@accelgroup) |
167 | - @skin.set_responsible(@target) | |
165 | + @skin.set_responsible(self) | |
168 | 166 | @skin.load(@data, scale) |
169 | - print("SKIN: ", @skin, "\n") | |
170 | 167 | end |
171 | 168 | |
172 | 169 | def handle_request(event_type, event, *arglist, **argdict) |
173 | 170 | #assert ['GET', 'NOTIFY'].include?(event_type) |
174 | 171 | handlers = { |
175 | - 'get_target_window' => lambda {|a| return self.target.surface.window[0].window}, # XXX | |
176 | - 'get_kinoko_position' => self.target.get_kinoko_position, | |
172 | + 'get_target_window' => lambda { return @target.get_window }, # XXX | |
173 | + 'get_kinoko_position' => lambda { return @target.get_kinoko_position } | |
177 | 174 | } |
178 | - handler = handlers.get(event, | |
179 | - getattr(self, event, | |
180 | - lambda {|a| return nil})) ## FIXME | |
181 | - result = handler(*arglist, **argdict) | |
175 | + if handlers.include?(event) | |
176 | + result = handlers[event].call # no argument | |
177 | + else | |
178 | + if Kinoko.method_defined?(event) | |
179 | + result = method(event).call(*arglist) | |
180 | + else | |
181 | + result = nil | |
182 | + end | |
183 | + end | |
182 | 184 | if event_type == 'GET' |
183 | 185 | return result |
184 | 186 | end |
@@ -193,7 +195,7 @@ module Kinoko | ||
193 | 195 | if @skin == nil |
194 | 196 | return 0 |
195 | 197 | else |
196 | - self.send_event('OnKinokoObjectCreate') | |
198 | + send_event('OnKinokoObjectCreate') | |
197 | 199 | end |
198 | 200 | @__running = true |
199 | 201 | GLib::Timeout.add(10) { do_idle_tasks } # 10[ms] |
@@ -209,8 +211,8 @@ module Kinoko | ||
209 | 211 | end |
210 | 212 | |
211 | 213 | def close() |
212 | - self.finalize() | |
213 | - self.send_event('OnKinokoObjectDestroy') | |
214 | + finalize() | |
215 | + send_event('OnKinokoObjectDestroy') | |
214 | 216 | end |
215 | 217 | |
216 | 218 | def send_event(event) |
@@ -232,14 +234,14 @@ module Kinoko | ||
232 | 234 | end |
233 | 235 | |
234 | 236 | def select_skin(args) |
235 | - self.send_event('OnKinokoObjectChanging') | |
236 | - self.skin.destroy() | |
237 | - self.data = args | |
238 | - self.load_skin() | |
239 | - if self.skin == nil | |
237 | + send_event('OnKinokoObjectChanging') | |
238 | + @skin.destroy() | |
239 | + @data = args | |
240 | + load_skin() | |
241 | + if @skin == nil | |
240 | 242 | return 0 |
241 | 243 | else |
242 | - self.send_event('OnKinokoObjectChanged') | |
244 | + send_event('OnKinokoObjectChanged') | |
243 | 245 | end |
244 | 246 | return 1 |
245 | 247 | end |
@@ -263,18 +265,18 @@ module Kinoko | ||
263 | 265 | @parent = parent |
264 | 266 | end |
265 | 267 | |
266 | - def handle_request(event_type, event, *arglist, **argdict) | |
268 | + def handle_request(event_type, event, *arglist) | |
267 | 269 | #assert ['GET', 'NOTIFY'].include?(event_type) |
268 | 270 | handlers = { |
269 | 271 | } |
270 | -# handler = handlers.get(event, getattr(self, event, nil)) | |
271 | -# if handler == nil | |
272 | - if not handlers.include?(event) | |
273 | - result = @parent.handle_request(event_type, event, *arglist, **argdict) | |
272 | + if handlers.include?(event) | |
273 | + result = handlers[event].call # no argument | |
274 | 274 | else |
275 | -# result = handler(*arglist, **argdict) | |
276 | - ## FIXME | |
277 | - result = class_eval(event) #( *arglist, **argdict) | |
275 | + if Skin.method_defined?(event) | |
276 | + result = method(event).call(*arglist) | |
277 | + else | |
278 | + result = @parent.handle_request(event_type, event, *arglist) | |
279 | + end | |
278 | 280 | end |
279 | 281 | if event_type == 'GET' |
280 | 282 | return result |
@@ -306,11 +308,9 @@ module Kinoko | ||
306 | 308 | actors = {'' => []} |
307 | 309 | end |
308 | 310 | end |
309 | - print("ACTORS: ", actors, "\n") | |
310 | 311 | @seriko = Seriko::Controller.new(actors) |
311 | 312 | @seriko.set_responsible(self) ## FIXME |
312 | 313 | path = File.join(@data['dir'], @data['base']) |
313 | - print("PATH: ", path, "\n") | |
314 | 314 | begin |
315 | 315 | @image_surface = Pix.create_surface_from_file(path) |
316 | 316 | w = [8, (@image_surface.width * @__scale / 100).to_i].max |
@@ -319,7 +319,6 @@ module Kinoko | ||
319 | 319 | @parent.handle_request('NOTIFY', 'close') |
320 | 320 | return |
321 | 321 | end |
322 | - print("SURFACE: ", w, " , ", h, "\n") | |
323 | 322 | @path = path |
324 | 323 | @w, @h = w, h |
325 | 324 | @darea = @window.darea # @window.get_child() |
@@ -434,16 +433,14 @@ module Kinoko | ||
434 | 433 | end |
435 | 434 | |
436 | 435 | def update_frame_buffer() |
437 | - print("UPDATE FRAME: ", @seriko.get_base_id, "\n") | |
438 | 436 | new_surface = create_image_surface(@seriko.get_base_id) |
439 | 437 | #assert new_surface != nil |
440 | 438 | # draw overlays |
441 | 439 | for surface_id, x, y, method in @seriko.iter_overlays() |
442 | - print("OVERLAY: ", surface_id, x, y, method, "\n") | |
443 | - if 1#begin | |
440 | + begin | |
444 | 441 | overlay_surface = get_image_surface(surface_id) |
445 | - else#rescue #except: | |
446 | - continue | |
442 | + rescue #except: | |
443 | + next | |
447 | 444 | end |
448 | 445 | # overlay surface |
449 | 446 | cr = Cairo::Context.new(new_surface) |
@@ -451,7 +448,7 @@ module Kinoko | ||
451 | 448 | cr.mask(overlay_surface, x, y) |
452 | 449 | #del cr |
453 | 450 | end |
454 | - #self.darea.queue_draw_area(0, 0, w, h) | |
451 | + #@darea.queue_draw_area(0, 0, w, h) | |
455 | 452 | @image_surface = new_surface |
456 | 453 | @darea.queue_draw() |
457 | 454 | end |
@@ -499,7 +496,7 @@ module Kinoko | ||
499 | 496 | @seriko.invoke(self, actor_id, update) |
500 | 497 | end |
501 | 498 | |
502 | - def delete() #widget, event) | |
499 | + def delete() | |
503 | 500 | @parent.handle_request('NOTIFY', 'close') |
504 | 501 | end |
505 | 502 |
@@ -184,25 +184,20 @@ module Nekodorif | ||
184 | 184 | return 1 |
185 | 185 | end |
186 | 186 | |
187 | - def handle_request(event_type, event, *arglist, **argdict) | |
187 | + def handle_request(event_type, event, *arglist) | |
188 | 188 | ##assert ['GET', 'NOTIFY'].include?(event_type) |
189 | 189 | handlers = { |
190 | 190 | 'get_katochan_list' => lambda { return @katochan_list }, |
191 | 191 | 'get_mode' => lambda { return @mode }, |
192 | 192 | } |
193 | -# handler = handlers.get(event, | |
194 | -# getattr(self, event, | |
195 | -# lambda {|a| return nil})) ## FIXME | |
196 | -# result = handler(*arglist, **argdict) | |
197 | -# if not handlers.include?(event) | |
198 | -# result = @parent.handle_request(event_type, event, *arglist, **argdict) | |
199 | -# else | |
200 | 193 | if handlers.include?(event) |
201 | - result = handlers[event].call #( *arglist, **argdict) | |
194 | + result = handlers[event].call # no argument | |
202 | 195 | else |
203 | - ## FIXME | |
204 | - print("REQ: ", Nekoninni.method_defined?(event), " , ", *arglist, "\n") | |
205 | - result = method(event).call(*arglist)#, **argdict) | |
196 | + if Nekoninni.method_defined?(event) | |
197 | + result = method(event).call(*arglist) | |
198 | + else | |
199 | + result = nil # XXX | |
200 | + end | |
206 | 201 | end |
207 | 202 | if event_type == 'GET' |
208 | 203 | return result |
@@ -217,7 +212,7 @@ module Nekodorif | ||
217 | 212 | if @katochan != nil |
218 | 213 | @katochan.update() |
219 | 214 | end |
220 | - #self.process_script() | |
215 | + #process_script() | |
221 | 216 | return true |
222 | 217 | end |
223 | 218 |
@@ -350,16 +345,18 @@ module Nekodorif | ||
350 | 345 | @parent = parent |
351 | 346 | end |
352 | 347 | |
353 | - def handle_request(event_type, event, *arglist, **argdict) | |
348 | + def handle_request(event_type, event, *arglist) | |
354 | 349 | ##assert ['GET', 'NOTIFY'].include?(event_type) |
355 | 350 | handlers = { |
356 | 351 | } |
357 | -# handler = handlers.get(event, getattr(self, event, nil)) | |
358 | -# if handler == nil | |
359 | 352 | if not handlers.include?(event) |
360 | - result = @parent.handle_request(event_type, event, *arglist, **argdict) | |
353 | + result = @parent.handle_request(event_type, event, *arglist) | |
361 | 354 | else |
362 | - result = method(event).call(*arglist)#, **argdict) | |
355 | + if Skin.method_defined?(event) | |
356 | + result = method(event).call(*arglist) | |
357 | + else | |
358 | + result = nil | |
359 | + end | |
363 | 360 | end |
364 | 361 | if event_type == 'GET' |
365 | 362 | return result |
@@ -442,11 +439,11 @@ module Nekodorif | ||
442 | 439 | |
443 | 440 | def set_position(reset=0) |
444 | 441 | left, top, scrn_w, scrn_h = Pix.get_workarea() |
445 | - if reset | |
442 | + if reset != 0 | |
446 | 443 | @x = left |
447 | 444 | @y = top + scrn_h - @h |
448 | 445 | else |
449 | - if not @omni | |
446 | + if @omni != 0 | |
450 | 447 | @y = top + scrn_h - @h |
451 | 448 | end |
452 | 449 | end |
@@ -455,7 +452,7 @@ module Nekodorif | ||
455 | 452 | |
456 | 453 | def move(x_delta, y_delta) |
457 | 454 | @x = @x + x_delta |
458 | - if @omni | |
455 | + if @omni != 0 | |
459 | 456 | @y = @y + y_delta |
460 | 457 | end |
461 | 458 | set_position() |
@@ -499,7 +496,6 @@ module Nekodorif | ||
499 | 496 | else |
500 | 497 | x, y, state = event.x, event.y, event.state |
501 | 498 | end |
502 | - #x, y = self.window.winpos_to_surfacepos(x, y, self.__scale) | |
503 | 499 | if state & Gdk::Window::ModifierType::BUTTON1_MASK |
504 | 500 | if @x_root != nil and \ |
505 | 501 | @y_root != nil |
@@ -601,11 +597,8 @@ module Nekodorif | ||
601 | 597 | end |
602 | 598 | |
603 | 599 | def redraw(widget, cr) |
604 | - scale = @__scale | |
605 | - cr.scale(scale / 100.0, scale / 100.0) | |
606 | - cr.set_source(@image_surface, 0, 0) | |
607 | - cr.set_operator(Cairo::OPERATOR_SOURCE) | |
608 | - cr.paint() | |
600 | + @window.set_surface(cr, @image_surface, @__scale) | |
601 | + @window.set_shape(cr) | |
609 | 602 | end |
610 | 603 | |
611 | 604 | def set_movement(timing) |
@@ -690,7 +683,6 @@ module Nekodorif | ||
690 | 683 | end |
691 | 684 | @w, @h = w, h |
692 | 685 | @window.update_size(@w, @h) |
693 | - #self.darea.queue_draw_area(0, 0, self.w, self.h) | |
694 | 686 | @image_surface = new_surface |
695 | 687 | @darea.queue_draw() |
696 | 688 | end |
@@ -701,9 +693,9 @@ module Nekodorif | ||
701 | 693 | set_state('before') |
702 | 694 | if @data.include?('category') |
703 | 695 | category = @data['category'].split(',') |
704 | - if category | |
696 | + if not category.empty? | |
705 | 697 | if not CATEGORY_LIST.include?(category[0]) |
706 | - logging.warning('WARNING: unknown major category - {0}'.format(category[0])) | |
698 | + #logging.warning('WARNING: unknown major category - {0}'.format(category[0])) | |
707 | 699 | ##self.data['category'] = self.CATEGORY_LIST[-1] |
708 | 700 | end |
709 | 701 | else |
@@ -847,7 +839,7 @@ module Nekodorif | ||
847 | 839 | if @settings['state'] == 'fall' |
848 | 840 | update_surface() |
849 | 841 | update_position() |
850 | - if check_collision() | |
842 | + if check_collision() != 0 | |
851 | 843 | set_state('hit') |
852 | 844 | @hit = 1 |
853 | 845 | if @parent.handle_request('GET', 'get_mode') == 1 |
@@ -858,11 +850,16 @@ module Nekodorif | ||
858 | 850 | #pass ## FIXME |
859 | 851 | end |
860 | 852 | end |
861 | - if check_mikire() | |
853 | + if check_mikire() != 0 | |
862 | 854 | set_state('dodge') |
863 | 855 | end |
864 | 856 | elsif @settings['state'] == 'hit' |
865 | - if @hit_stop >= @data.get('hit.waittime', 0) | |
857 | + if @data.include?('hit.waittime') | |
858 | + wait_time = @data['hit.waittime'] | |
859 | + else | |
860 | + wait_time = 0 | |
861 | + end | |
862 | + if @hit_stop >= wait_time | |
866 | 863 | set_state('after') |
867 | 864 | set_movement('after') |
868 | 865 | if @parent.handle_request('GET', 'get_mode') == 1 |
@@ -879,7 +876,7 @@ module Nekodorif | ||
879 | 876 | elsif @settings['state'] == 'after' |
880 | 877 | update_surface() |
881 | 878 | update_position() |
882 | - if check_mikire() | |
879 | + if check_mikire() != 0 | |
883 | 880 | set_state('end') |
884 | 881 | end |
885 | 882 | elsif @settings['state'] == 'end' |
@@ -798,21 +798,20 @@ module NGM | ||
798 | 798 | @parent = parent |
799 | 799 | end |
800 | 800 | |
801 | - def handle_request(event_type, event, *arglist, **argdict) | |
801 | + def handle_request(event_type, event, *arglist) | |
802 | 802 | #assert event_type in ['GET', 'NOTIFY'] |
803 | 803 | handlers = { |
804 | - 'get_home_dir' => lambda { return @home_dir }, | |
805 | - 'network_update' => lambda { return network_update }, | |
806 | - 'get' => lambda { return get(arglist[0]) } | |
804 | + 'get_home_dir' => lambda {|*a| return @home_dir }, | |
805 | + 'network_update' => lambda {|*a| return network_update }, | |
806 | + 'get' => lambda {|*a| return get(a[0]) } | |
807 | 807 | } |
808 | 808 | if handlers.include?(event) |
809 | - result = handlers[event].call #( *arglist, **argdict) | |
809 | + result = handlers[event].call(*arglist) | |
810 | 810 | else |
811 | 811 | begin |
812 | 812 | result = public_send(event, *arglist) |
813 | 813 | rescue |
814 | - result = @parent.handle_request( | |
815 | - event_type, event, *arglist, **argdict) | |
814 | + result = @parent.handle_request(event_type, event, *arglist) | |
816 | 815 | end |
817 | 816 | end |
818 | 817 | if event_type == 'GET' |
@@ -17,8 +17,9 @@ module NinixTest | ||
17 | 17 | @win.set_default_size(@surface.width, @surface.height) |
18 | 18 | @win.show_all |
19 | 19 | kinoko_list = Home.search_kinoko() |
20 | + print("K: ", kinoko_list, "\n") | |
20 | 21 | kinoko = Kinoko::Kinoko.new(kinoko_list) |
21 | - print("K: ", kinoko, "\n") | |
22 | + #print("K: ", kinoko, "\n") | |
22 | 23 | kinoko.load(kinoko_list.sample, self) |
23 | 24 | Gtk.main |
24 | 25 | end |
@@ -26,10 +27,16 @@ module NinixTest | ||
26 | 27 | def notify_event(event, *args) # dummy |
27 | 28 | end |
28 | 29 | |
30 | + def get_window # dummy | |
31 | + return @win | |
32 | + end | |
33 | + | |
34 | + def get_kinoko_position # dummy | |
35 | + return 100, 200 | |
36 | + end | |
37 | + | |
29 | 38 | def handle_request(type, event, *a) # dummy |
30 | - if event == 'get_kinoko_position' | |
31 | - return 0, 0 | |
32 | - elsif event == 'get_preference' and a[0] == 'animation_quality' | |
39 | + if event == 'get_preference' and a[0] == 'animation_quality' | |
33 | 40 | return 1 |
34 | 41 | end |
35 | 42 | end |