Komodo

Using RSync with Projects

Question: 

How do I publish file in my local project to a remote system?

Answer: 

One of the questions that has come up a few times through the development of Komodo 4.0, is "Why don't we have project publish features?" Well, to be honest, it was one of the features that got left behind for the time being. But there is a good way to add publishing capabilities on your own, and I'll show how in this article.

The simplest way to do this is with rsync. "rsync is an open source utility that provides fast incremental file transfer." It can synchronize files in a directory between two machines. For security, rsync can be combined with the use of ssh.

Attached is a project template that allows you to create new projects that support RSync over SSH. There are two simple commands to upload and download. I'm sure more could be added.

You can import the project into the toolbox to look at it, but preferably drop it into your project templates directory.

OSX:
~/Library/Application Support/Komodo/4.0/project-templates/My Templates/rsync.kpz

Linux:
~/.komodo/4.0/project-templates/My Templates/rsync.kpz

Windows:
%APPDATA%/ActiveState/Komodo/4.0/project-templates/My Templates/rsync.kpz

Some software you may need

* rsync: http://samba.anu.edu.au/rsync/
* ssh: http://www.openssh.com

OSX:
* ssh key agents (only one of the following)
- http://www.sshkeychain.org/
- http://www.phil.uu.nl/~xges/ssh/
- http://www.versiontracker.com/dyn/moreinfo/macosx/13221

Windows:
- http://www.chiark.greenend.org.uk/~sgtatham/putty/

Dialogs from Python Macros

Question: 

How do I show an alert dialog from a python macro in the toolbox?

Answer: 

For all the dirty details, you can look at the WindowWatcher and Prompt service in Mozilla:

http://lxr.mozilla.org/mozilla1.8/source/embedding/components/windowwatc...
http://lxr.mozilla.org/mozilla1.8/source/netwerk/base/public/nsIPrompt.idl

Below is a quick and dirty example. This
uses all the standard moz dialogs rather than our own dialogs, but it
should be good enough for most stuff.

If you do this from threads, you need to proxy it to the main UI thread,
search our python files for use of nsIProxyService for examples of that.

from xpcom import components
wwatch = components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(components.interfaces.nsIWindowWatcher)
prompt = wwatch.getNewPrompter(wwatch.activeWindow)
prompt.alert("this is the title", "this is my message")

Creating Project Templates

Question: 

Why would I want to create a project template?

Answer: 

In my quest to create some screen shots of Komodo I decided to use Django for the sample application. Since I've never looked at Django, I figured I'd also make a project template at the same time.

Why would I want a project template? Well, the template system provides a way for me to have repetitive functionality for a given type of project. I can setup macros, run commands, snippets, etc. that are specific to the type of project I want to create. Then they are always available whenever I create the new project. I can also have the project initialize some basic items when it is created.

So here is what I did:

1. Download and install Django (from www.djangoproject.com). I followed the install instructions at http://www.djangoproject.com/documentation/install/. I also had to symlink django-admin.py into my /usr/local/bin directory.

2. Create a new project called "djangotemplate".

3. Create a folder called "project", though it can be whatever name you would like.

4. Create a macro in the project folder called "oncreate". This is a special name for project templates. When you create a new project from a template, if this macro is in the project, it gets executed right away.

In this macro I have the following JavaScript code:

var project = komodo.macro.project;
var name = /^(.*?;)(\.kpf)?;$/(project.name)[1];
var startproject = project.getChildByAttributeValue('name','startproject', 1);
Run_RunCommand(window, "django-admin.py startproject "+name, "%p", null,
               false, false, true, "command-output-window");

This code runs the django-admin.py script when the project is created. You will then see a folder in your new project that has the same name as the project file itself. This contains the base scripts for your new Django project.

5. I then created a new macro for the template, called "runserver". This macro contains the following code:

var project = komodo.macro.project;
var name = /^(.*?;)(\.kpf)?;$/(project.name)[1];
Run_RunCommand(window, "%(python) manage.py runserver", "%p/"+name, null,
               false, false, true, "new-console");

This macro basically executes the built in Django webserver.

6. Now you need to save the project as a template. Go to the Project menu, and choose to "Create Template from Project". Call it Django.

7. Now you want to test your template. Go to the File->New menu, and choose "New Project from Template". Select a directory and name for the project and click OK.

There you go, a new Django project. You can use the runserver macro to start the server, and test the basic setup with your web browser.

Using these simple steps, you've created some new functionality for Komodo that you can use over and over. Try adding more Django commands to the template and see what you can come up with!

NOTE: I've attached a kpz file that you can either import into the toolbox, or drop into the following locations:

OSX:
~/Library/Application Support/Komodo/4.0/project-templates/My Templates/django.kpz

Linux:
~/.komodo/4.0/project-templates/My Templates/django.kpz

Windows:
%APPDATA%/ActiveState/Komodo/4.0/project-templates/My Templates/django.kpz

What version of Komodo should I use with Windows Vista?

Question: 

What version of Komodo should I use with Windows Vista?

Answer: 

Komodo 3.5 and earlier will not work with Vista. You will need to run Komodo 4.1.1 or later.

Should you run into any issues, please file a bug report at:

http://bugs.activestate.com/

How do I get PHP remote debugging working under Komodo?

Question: 

How do I get PHP remote debugging working under Komodo?

Answer: 

There are a couple of things you need to make sure of in order to get PHP remote debugging working:

1. xdebug must be configured correctly. The php.ini that your web server is using should contain statements like this:

; xdebug config for Linux and Mac OS X
zend_extension=/usr/share/php5/debug/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=foo.bar.com
xdebug.remote_port=9000
xdebug.idekey=kyla

Note in particular that remote_host needs to be the hostname or ip address of the machine Komodo is running on, and remote_port needs to be the same as the remote port Komodo is using. You can check this by creating a script like this:

<?php phpinfo(); ?>

...and looking at the xdebug section in the output page.

2. Komodo must be configured correctly. At

Preferences / Debugger / Proxy

...set the field 'Listen for debug connections on port' to 9000 as above. Close the preferences and make sure that

Debug / Listen for remote debugger

...has a checkmark beside it.

3. You need to explicitly initiate a debugger session by adding the XDEBUG_SESSION_START get variable to the url in your browser:

http://baz.bar.com/script.php?XDEBUG_SESSION_START=1

If everything is correct, Komodo should pop-up a dialog inidicating that a remote application has requested a debugging session. If you click on 'OK', Komodo will step in to the first line of code in that script.

If this is still not working, some things to check are:

- can you ping the machine Komodo is running on form your web server?
- is the machine Komodo is on running some sort of software firewall that might be blocking the debugger requests?

Komodo stops working after moving .app

Question: 

I moved Komodo.app to a different directly on my Mac, and now it doesn't work. The menus are unresponsove and any file I open just says 'unknown' in the tab title.

Answer: 

This is a known issue with Komodo on OS X where, if you have already run Komodo, moving the .app application bundle will cause these problems. For now the only workaround is to open the .dmg disk image you downloaded and install a new copy of Komodo.app to the desired location.

Posting Code Snippets to the forum

Question: 

How do I format code snippets in my Forum posts?

Answer: 

There are a couple of different ways to do this currently, each with their own use:

1. Inline code. If you just want to style something in fixed font inside a paragraph, use the <code/> tag. Example:

This:

This is my <code>Inline code sample</code> right here.

...will get you this:

This is my Inline code sample right here.

2. Blocks of fixed text. If you just want to dump in a block of fixed text with no special styling (for example, a log file excerpt) use the pre tag with the css class of 'code'. Example:

This:

<pre class="code">
komodo.view.setFocus();
try {
    komodo.editor.wordLeftExtend();
    var snippet = komodo.interpolate('%s');
    var tmpl = komodo.findPart("snippet", snippet, "container");
    if(tmpl) {
        Snippet_insert(tmpl);
    } else {
        var msg = "no snippet found named " + snippet;
        StatusBar_AddMessage(msg,"debugger",5000,true);
    }
} catch(e) {
    alert(e);
}
</pre>

Will give you this:

komodo.view.setFocus();
try {
    komodo.editor.wordLeftExtend();
    var snippet = komodo.interpolate('%s');
    var tmpl = komodo.findPart("snippet", snippet, "container");
    if(tmpl) {
        Snippet_insert(tmpl);
    } else {
        var msg = "no snippet found named " + snippet;
        StatusBar_AddMessage(msg,"debugger",5000,true);
    }
} catch(e) {
    alert(e);
}

Komodo on Ubuntu AMD64

Question: 

How do I make Komodo work under Ubuntu

Answer: 

Trying to make Komodo work with Ubuntu and related distributions on the x86_64 architecture was somewhat difficult prior to Ubuntu Edgy Eft 6.10. It required some custom configuration of Pango to be done and a shell script to be created and used each time to run Komodo. Thankfully, these days are behind us now.

Komodo will work on Kubuntu 6.10 by installing the ia32-libs and ia32-libs-gtk packages. I would expect this to be the same for any Ubuntu 6.10 derivative.

To install the packages you can do the following on the command line:

sudo apt-get install ia32-libs-gtk ia32-libs

Update: Komodo seems to work fine on UBuntu 8.04 ( 'Hardy Heron' ) systems as well. A user suggested installing these packages specifically:

sudo apt-get install binfmt-support ia32-libs ia32-libs-gtk libc6-i386

The binfmt support package is a kernel level module that does cool tricks with interpreter selection, sort of a 'super-shebang'. For more info:

http://packages.ubuntu.com/hardy/admin/binfmt-support

Komodo 4.0 Extensions

Question: 

How do I create an extension for Komodo 4.0?

Answer: 

This FAQ is aimed towards advanced users who have some prior knowledge of XUL, XBL and Firefox extensions. It may also be useful for first time extension developers.

Komodo is based on the Mozilla code base just like Firefox. This enables us to use the extension mechanism that Firefox uses. There are some slight differences in what needs to be done, but you can otherwise follow instructions for building Firefox extensions. The following websites are great references:

http://developer.mozilla.org
http://www.xulplanet.com

The following will guide you through creating a very simple "Hello World" extension for Komodo, and list a few extra Komodo specific features of extensions.

You first need to create three files.

.../myproject/install.rdf
.../myproject/chrome.manifest
.../myproject/content/overlay.xul

install.rdf is used by Komodo to collect basic information about the extension.

chrome.manifest is used by Komodo to know how to overlay the extension UI into the Komodo UI.

overlay.xul is required to add new UI elements to Komodo.

There will be more details on those files below, but first we'll show how to wrap these up into an XPI file that can be installed into Komodo.

The steps are simple (may require some modification for different platforms)

cd myproject
zip -Dr myproject.jar content
zip -Dr myproject-1.0.xpi myproject.jar install.rdf chrome.manifest

You now have an XPI file that can be installed into Komodo. If you have added other directories to your extension, the first zip command should include those directories.

example: zip -Dr myproject.jar content skin locale components

Now to the dirty details of those files. I've attached files to this FAQ that you can look at.

The important differences between an extension for Firefox and for Komodo is the targetApplication information for install.rdf, and the overlay elements in overlay.xul.

In install.rdf, the targetApplication element should use the id of {36E66FA0-F259-11D9-850E-000D935D3368}. The minVersion should be 4.0, and I would suggest 4.0.* for the maxVersion.

The chrome.manifest file is required if you are overlaying any new UI elements, such as a menu, into the Komodo UI. Here is an example:

content myproject jar:myproject.jar!/content/ xpcnativewrappers=yes
overlay chrome://komodo/content/komodo.xul chrome://myproject/content/overlay.xul

The overlay file for a simple hello world is best looked at in the attached file. The important part is the element id attributes, which need to match id attributes in komodo.xul. You can open komodo.xul from your Komodo installation to see what is available, but if you just need to attach a menu to the tools menu, use a menuitem element with the id "menu_ToolsPopup"

There are a few customizations of the extension directory structure for Komodo.

1. you can have a components directory (as you can in Firefox), but with Komodo you can use Python components through PyXPCOM (JavaScript components are also supported). See the PyXPCOM documentation on developer.mozilla.org for details. You can dig through the components directory in Komodo for examples, or use the Python PyXPCOM file template in Komodo (menu: File->New File...) to create a simple skeleton component.

2. you can have a "templates" directory where you can store new file templates that appear in the New File dialog.

3. you can have a "project-templates" directory where you can store new project kpz files that appear in the New Project dialog.

4. a "lexers" directory is used for adding the UDL lexres files, used for defining custom syntax coloring for languages in Komodo. There are utilities for creating UDL extensions.

We will be adding more special directories in the future on an as need basis.

How to launch PPM4 Gui from Komodo

Question: 

I used to use VPM to install Perl modules from the Komodo Pro interface, but this doesn't work for ActivePerl 819. How can I launch the new PPM4 Gui from Komodo?

Answer: 

Komodo's VPM utility is incompatible with ActivePerl 5.8.8 Build 819, and the preferred method is to use the PPM4 Gui client instead.

Future versions of Komodo will feature an option to launch the ppm client from a toolbar button; to do this in Komodo 3.5.3 simply add a new custom toolbar to your toolbox, add a new run command to that toolbar and for the command, put

C:\Perl\bin\wperl.exe -x "C:\Perl\bin\ppm.bat"

For the 'Run In' field, select 'No Console (Gui Application)'