Current Examples
Prev
Next

Current Examples

These examples reflect the most recent development state of Kommander. In its current state Kommander has few limitations for developing small to medium applications. It certainly is not suitable for building a KWord clone, but for a simple editor, database frontend, GUI for commandline programs or any application in the spirit of Unix/Linux small applications it is a good choice. The examples presented here are intended to show the potential as well as how to work around limitations. There are some useful tricks included in these if you want to do a more capable small application with Kommander. Remember Kommander is not intended to do everything, but to do most things. For this concession you should be able to build something in Kommander faster than other alternatives ad add GUI to scripting languages not otherwise supported in KDE.

Note

The examples are installed to $TDEDIR/share/apps/kmdr-editor/editor. In case you do not have them there, get from our home page, by downloading the latest release.

editor-poc.kmdr

The little dialog that grew into a Mainwindow. As Kommander does not have a native MainWindow widget it has been assumed it only does dialogs. In fact only dialogs are officially supported... but you can run MainWindows in Kommander. This is an example editor. If you want to create a MainWindow application in Kommander just open Qt Designer and make one, save it and rename the *.ui file to a *.kmdr file. Now open it in Kommander and do what you would do normally.

Note

As of this writing what is known not to work on the Kommander side is the settings read and write. There is no Initialize or Destroy section as there is no Kommander Text, however there are signals for this on the window, so the functionality is intact. On the MainWindow side it is not possible to talk to any actions via DCOP as these are QActions from Designer and TDEActions are not derived from QActions in KDE 3.x. This means a DCOP call to list actions or set states will not work. It is also not possible to talk to the Statusbar. Also submenus on the menubar and dropdown actions on the Toolbar will not work. Even though this is not a Kommander widget, or officicially supported, it seems suitable for many small application uses.

There is a quick help dialog this editor launches that discusses in depth what is happening inside.

kevaluecombo.kmdr

Kommander can be used with databases and has an optional database plugin. One shortcoming is not being able to store key/value pairs in the ComboBox. An ingenious trick was realized for this. It requires only that the content of the ComboBox not be changed unless it is done using the arrays that go with it. As this is commonly used with SQL in small data sets it's quite fast even to reload the whole Combobox. The inherent problem is that Kommander does not have internally indexed arrays by default. This is compounded by the fact that to accommodate shell commands that return lines separated by newlines Kommander's array functions will load what is effectively an array of keys. Such an array can only be accessed with a foreach loop. This is the reason new indexed array functions were added. It is important to remember that these arrays are not self maintaining, but their insert and delete functions will help you.

Getting back to the ComboBox, it will return selected text, but it also will return the current index. It does rigidly maintain a contiguous zero based array. That's the key. We loop through a data set with a zero based index counter and create two arrays, as Kommander also cannot create arrays of arrays. It can however use an array value to represent a key just like any value could. .If you look at the included dialog the code actually managing this is in “ScriptObject36”. We will extract the key code here.

c = ListBox1.count-1
for i = 0 to c do
  array_indexedFromString("x", ListBox1.item(i))
  _a[x[0]] = x[1]
  _b[i] = x[0]
  ComboBox10.insertItem(_a[_b[i]], i)
end

There is more going on, like checking for duplicate keys, but this is the core. You can right click on the ListBox and try menu items. The net result is that it is using keyed index by proxy and returning both the key and the value. Use this code if you want to be 100% certain your key/value relationship is accurate.

Kpart demo

As of Kommander 1.3 Kommander automatically makes KParts using the libkommander_part.la. In addition to this there is a KPart plugin which allows Kommander to load plugins. Being curious developers we tried loading a Kommander part into Kommander. Why do that? Why not? The results were interesting and are demonstrated here. One interesting thing is the parent part can directly access all of the child part. While this is handy it has a down side. Any child widget being called with the same name as a parent widget will cause a lock up! In addition to that the DCOP interface is generated all over again for the part which wipes out the parent interface and disables most of the old parser functionality as well as Kommander specific DCOP to the parent. This is too difficult to fix for the remaining life of the KDE3 version. Even with these limitations and cautions this can be useful, if used carefully. The example files to look at this are in the current examples as kpartmwframe.kmdr and kpartpart.kmdr. Remember you will need the KPart plugin to fully run this example.

You can also load KMail, KOrganizer and many other TDE applications right into Kommander, of course without the problems. TDEHTML and KDE's file manager widgets seem not to have some functionality but there is a special TDEHTML plugin if you really want to incorporate a browser.

passvariables.kmdr

As of Kommander 1.3 you can pass and return variables with scripts. This dialog demonstrates that. Look carefully at the content of the buttons. You will see that neither button directly writes to any of the LineEdit boxes receiving text from the script. While one is written directly from the script another is written with the content passed from the button. The third is not written at all but passed back in a return() function where it is received by the button and written. This is also shown on the right side using PHP so you can see how this might work with Python, Ruby, Perl or even a less commonly used language like Rexx. Languages that Speak DCOP can do a lot more in Kommander too. The point of this demo is the freedom provided. Kommander does not have functions, yet it does. Create a script, declare some globals if you like, pass some parameters to another script and return a value. For an intentionally simplified GUI scripting tool that is capable behavior. This behavior is only in the new parser and is documented here.

tableselect.kmdr

This example demonstrates how to use the new select function in the table widget. It is now possible to get four coordinates to enable a block selection. This also shows how it would have had to be done prior to this function. and how to use the parameters passed to a script. In addition this demonstrates a simple block copy and paste function for a table as well as summation of a block.

Prev
Next
Home


Would you like to comment or contribute an update to this page?
Send feedback to the TDE Development Team