![]() Registered Member ![]()
|
This might not be the best way to debug Krita Ruby scripts (I think remote debugging would be better), but here is what I have done so far, and it seems to be working. I am using Ubuntu Maverick, with Krita 2.3 beta 2 (from the https://launchpad.net/~kubuntu-ppa/+archive/beta Kubuntu Beta Backports PPA).
1) Using Synaptic (or apt-get) install rubygems. 2) Using Synaptic (or apt-get) install ruby-dev. This provides the mkmf script needed in the next step. 3) Use gem to install ruby-debug, like this: sudo gem install ruby-debug 4) Create a ruby script to test. I copied the invert.rb script into my home folder, from /usr/share/kde4/apps/krita/scripts/extensions/invert.rb Using a text editor, make a few changes: The first line: " puts Kross::Object" is extraneous and can be removed. Add these lines before the require "Krita" : require 'rubygems' require 'ruby-debug' Debugger.start Debugger.interrupt And then the last line in the modified invert.rb file: Debugger.stop 5) Start Krita from a console (I used gnome-terminal), by simply typing krita. 6) In Krita, go to menu Tools->Script Manager... Click the Add... button. Select Add Script File, click Next. Browse to the modified invert.rb script, select it, click Next. In Text: type in a name like Debug Invert, and click Finish. 7) Check the checkbox by the new "Debug Invert" script, so that it will appear in the Krita menus. Click Save. (Krita crashed at this point for me, but it did manage to save, so I restart Krita...). 8 ) Draw a line so that we can see if the invert works after we invoke it. 9) Go to Tools->Scripts->Debug Invert, and select it. The Krita window refreshing will freeze, because (hopefully) the debugger is now paused in the console, with some output like: Kross: "Loading the interpreter library for ruby" Kross: "Successfully loaded Interpreter instance from library." /home/[YOUR_HOME]/invert.rb:16 require "Krita" (rdb:1) We can now talk to the debugger, for example: (rdb:1) help ruby-debug help v0.10.3 Type 'help <command-name>' for help on a specific command Available commands: backtrace delete enable help next quit show undisplay break disable eval info p reload source up catch display exit irb pp restart step var condition down finish list ps save thread where continue edit frame method putl set trace and then a listing of the ruby script lines nearby: (rdb:1) list [11, 20] in /home/bill/invert.rb 11 12 Debugger.start 13 Debugger.interrupt 14 15 # import the Krita-module. => 16 require "Krita" 17 18 # fetch the image. 19 image = Krita.image() 20 and then using the next command (8 times): (rdb:1) next /home/bill/invert.rb:26 height = layer.height() and now print out the width variable: (rdb:1) p width 640 and list all the methods of the layer class: (rdb:1) p layer.methods ["inspect", "debugger", "connect", "tap", "clone", "width", "public_methods", "__send__", "object_id", "breakpoint", "instance_variable_defined?", "equal?", "freeze", "findChild", "extend", "send", "methods", "pretty_print", "disconnect", "hash", "dup", "pretty_print_instance_variables", "to_enum", "instance_variables", "pretty_inspect", "eql?", "propertyNames", "instance_eval", "id", "singleton_methods", "toVoidPtr", "taint", "enum_for", "frozen?", "instance_variable_get", "binding_n", "instance_of?", "display", "to_a", "method", "pretty_print_cycle", "property", "type", "instance_exec", "protected_methods", "method_missing", "==", "===", "instance_variable_set", "kind_of?", "respond_to?", "to_s", "setProperty", "class", "private_methods", "=~", "tainted?", "__id__", "untaint", "nil?", "pretty_print_inspect", "is_a?"] create a variable "a", set it equal to 1, and print it back: (rdb:1) eval a = 1 1 (rdb:1) p a 1 etc, etc... and then let the script run up to the next interrupt (there are none): (rdb:1) continue At this point the Krita window should repaint (might take a second or two), and should be color inverted. Note: If you make changes to the invert.rb file, Krita will not reload it (this is undoubtedly a "bug"). You will have to restart Krita. If you just want to re-run the test script, you should be able to do that. More Notes: The lines Debugger.start, Debugger.interrupt, and Debugger.stop can be placed anywhere in the script that is needed or convenient, but they must be nested properly. You can also call them conditionally, using Ruby to it's full extent, since they are real Ruby class/methods. For more info about ruby-debug see: http://rubyforge.org/projects/ruby-debug Let me know if I missed anything, or if there are better ways to do this. |
Registered users: Bing [Bot], claydoh, Evergrowing, Google [Bot], rblackwell