To get a shell in your GUI, you don’t have to reinvent the wheel - just use
the KonsolePart provided by KDE KParts. If you use the KDE environment
you already know the libkonsolepart, because Dolphin, Konqueror, Kate, Yakuake,
etc. take usage of it.
To get this small demo run, you need a KDE version already containing SVN
commit 1085699 (ttanks no Arno, who made the Part accessable within ruby).
The opensuse buildservice should provide a package ruby-kde4 in Factory Repo,
but I build I didn’t test it.
Just copy both files in the same directory, make the main.rb executable and run it.
The example contains a little bit more than neccessary, because it implements
a fully customizable menus/toolbars via KXmlWindow and shows how to use
actions and slots.
To get only the KonsolePart widget, you only have to look at the KonsolePart
class. The class itself bases on a short code example from Arno. Kudos to him!
For further explanation just take a look
at the source code.
You can change the working directory for the built-in shell
by a nice dialog and can execute some command by the lineedit. To send your command
to the shell, you have to press enter.
I know there are a lot of bugs. But it is just a quick and dirty demo.
After some blog posts on my old blog about KDE programming with Ruby
I decided to bring the content a little bit more to the people. Here I am.
Two days before yesterday I got a mail concerning a problem related to creating
plasmoids with Ruby. I never had the wish to create my own plasmoid. I thought
it would be difficult, but while getting a closer look, I’ve noticed how easy it
is - in the case of using Ruby.
Member variables begins with an @ sign. There are different aliases for KDE and
Qt methods. You can omit brackets in a lot of cases. You don’t need any header
files. You don’t need to compile.
require'plasma_applet'moduleRubyTestAppletclassMain<PlasmaScripting::Appletslots:addTextdefinitset_minimum_size150,150@layout=Qt::GraphicsLinearLayout.newQt::Vertical,selfself.layout=@layout@label=Plasma::Label.email@example.com='This plasmoid will copy the text you enter below to the firstname.lastname@example.org_item@label@line_edit=Plasma::LineEdit.newselfbegin@line_edit.clear_button_shown=true# not supported in early plasma versionsrescuenil# but that doesn't email@example.com_item@line_edit@button=Plasma::PushButton.firstname.lastname@example.org='Copy to email@example.com_item@buttonQt::Object.connect(@button,SIGNAL(:clicked),self,SLOT(:addText))Qt::Object.connect(@line_edit,SIGNAL(:returnPressed),self,SLOT(:addText))enddefaddTextQt::Application.clipboard.text=@line_edit.text@line_edit.text=""endendend# kate: remove_trailing_space on; replace-trailing-space-save on; indent-width 2; indent-mode ruby;
The second file you need is the metadata.desktop containing all the meta data.
[Desktop Entry]Name=Simple Ruby appletComment=This is a simple applet written in RubyIcon=chronometerType=ServiceServiceTypes=Plasma/AppletX-Plasma-API=ruby-scriptX-Plasma-MainScript=code/main.rbX-KDE-PluginInfo-Author=MeX-KDE-PluginInfo-Emailfirstname.lastname@example.orgX-KDE-PluginInfo-Name=ruby-testX-KDE-PluginInfo-Version=0.1X-KDE-PluginInfo-Website=http://plasma.kde.org/X-KDE-PluginInfo-Category=ExamplesX-KDE-PluginInfo-Depends=X-KDE-PluginInfo-License=GPLX-KDE-PluginInfo-EnabledByDefault=true
What do you think? So easy, isn’t it? If you have ever played a little
bit with Ruby and Qt or KDE you should know enough to create your own plasmoid
within a quarter of an hour!
After using the static website generator webgen I started to appreciate the idea not
to depend on special hosts with php, mysql and so on enabled. You can put all files on a CD
and it will works nevertheless. Like in the good old days, when there was only the notepad and
the Netscape Navigator.
My last blog was powered by Movable Type. A really good, full-featured engine, but editing in
the ajax backend was damn slow, because I hosted Movable Type myself via a dynamic dns service. And
at home the provided upload rate is not good enough to host a page serious. I don’t want to pay for
websites. There is so much static webspace in the www. So I switched over to the ruby1 driven Jekyll
and got in addtion the hosting for free on http://github.com.
While editing the files I found some usefull tricks you, you maybe googled for.
CSS selector for elements without class attribute
I wanted a template which allows to use nice CSS formatted <code> and <pre> tags for source code,
but on the other hand I didn’t want to change the style of included code snippets from http://pastie.org or
So I found out how to change only these html tags in the source code, which doesn’t have an class attribute, because
that is exactly the difference between these pastie-snippets and my own pre-elements.
First I define some basic font styles for all kind of code. After that I define styles for the code, which isn’t
in a pre-element and at last follows the style for the pygments-generated in-built code.
Integrating other static pages
As BSc physics student I got a userpage on the IT system of the physics institute, where I store some files.
Furthermore I have an account at DESY, from where I also get a userpage. So I thought it would
be nice to integrate both pages.
In the end I got it by defining a special header and footer in the .htaccess file for the Apache auto-generated directory index.
For testing some parts of the korundum bindings, that allow the usage of KDE in Ruby, i wrote a small and lightweight application with only the necessary parts.
Maybe you can take it also to do some testings or just as a little example.
With its 12 lines (17 lines minus 3 empty lines minus Shebang line and $KCode line, that are not really required) of code it is perhaps the smalles KDE application you will find.
Of course, every Qt app would be a few lines smaller, because you dont need the KAbout object.
#!/usr/bin/env ruby$KCODE='u'require'korundum4'about=KDE::AboutData.new("ktest","",KDE.ki18n("KTest"),"0.1")KDE::CmdLineArgs.init(ARGV,about)a=KDE::Application.neww=KDE::PushButton.new("Click me to quit")doconnect(SIGNAL:clicked)doputs"Do something else"KDE::Application.instance.quitendendw.showa.exec
Keep going!Keep going ×2!Give me more!Thank you, thank youFar too kind!Never gonna give me up?Never gonna let me down?Turn around and desert me!You're an addict!Son of a clapper!No wayGo back to work!This is getting out of handUnbelievablePREPOSTEROUSI N S A N I T YFEED ME A STRAY CAT