A weather plasmoid in python
Ever since I heard about plasma I was eager to find ways to write my own plasmoid. But for the development of binary plasmoids, it is necessary to compile at least a part of kde4, at least this is what I understood from the prerequisite listed on the official tutorial. This discouraged me a bit. Moreover, I think that installation of the binary gadgets also requires to either package them properly according to the distribution you want to distribute for or you need to provide the sources that requires the users to build them. This in my opinion is really a huge overhead for small applications like desktop gadgets / widgets. Then I found that it is also possible to develop plasmoids with script languages like python, ruby and javascript.
Even though, I didn’t know PyQT4 or PyKDE4 libraries at all, I decided to write my first plasmoid in python. This is an exremely simple plasmoid, the core of which was put together in a few hours on a rainy weekend. I have to admit that being a java developer, my code is not pythonic enough.
It can be downloaded from: kde-look.
Here the source code: plasma_pyweather.
The layout is based on my conky setup described here. I have tried to keep it as compact as possible including most of the provided information, if not all. I don’t want the weather information to cover most of the screen. The initial version of the plasmoid was written using the QT4 widgets, but was looking ugly.
The weather information is fetched from google weather api. The location and the unit are configurable. The api provides forecast only for the next 3 days, so the number of forecast days were not made configurable. Some how for google weather api the locale and so the unit is connected to the language, therefor I had to convert the units myself. To keep the display compact I rounded the temperatures to integers.
I got to learn PyQT4 and PyKDE4 libraries while writing this. Especially PyQT4 is a very powerful gui library for python. It is fun programming with it. I have used eclipse + pydev for developing. In the beginning I didn’t have the auto-completion for PyQT4 as well as PyKDE4 in this environment, because they are not installed as pure python source code files. I could fix this with following answer.
The other interesting things, I learned was to use the qt-designer tool for creating gui. It is a nice WYSIWYG tool for designing complex guis. The configuration form is designed using this tool. The qt-designer creates a .ui file, which is an xml file. The .ui file can be converted to the python source code using the pyuic4 tool in the following way.
pyuic4 -o configForm_ui.py ../ui/configForm.ui
I also learned to use the .qrc file for resources like images. The .qrc file can be converted into python source code using pyrcc4 tool
pyrcc4 -o images_rc.py images.qrc
The qrc file is also an xml file which contains the references to the images used. It can be created by just editing.
<RCC>
<qresource prefix="/images">
<file alias="sunny.svgz">../images/sunny.svgz</file>
<file alias="showers.svgz">../images/showers.svgz</file>
<file alias="not-available.svgz">../images/not-available.svgz</file>
<file alias="cloudy.svgz">../images/cloudy.svgz</file>
<file alias="thunderstorms.svgz">../images/thunderstorms.svgz</file>
<file alias="haze.svgz">../images/haze.svgz</file>
<file alias="windy.svgz">../images/windy.svgz</file>
</qresource>
</RCC>
I decided to write this weather plasmoid in python, because all the other weather plasmoids I found were binaries. I have also tried to keep the data and presentation layer separate, I hope I succeeded in that. In fact plasma framework provides a very good way of doing that in terms of data engines. I would also like to use the data engines, may be with this or other plasmoid I may develop.
The svg images for weather conditions are taken from kde-look. The credit goes to the original artist, painkiller10. I have considered only a number of weather conditions, so If you see a question mark image as the weather condition, let me know which condition it is, so I can update the code to consider it.
Please feel free to report any bugs or suggestions for improvement. I am sure there is a big room of improvement from code point of view as well as functionality. I am also open for changing the layout or changing the information displayed if someone comes with a better suggestion than the current one.
Some more screen shots:

Looks almost like conky with the seamless theme.

With settings dialog box
Paolo 3:18 pm on September 2, 2009 Permalink |
Beautiful! BTW, could you internationalize your plasmoid? (in order to translate messages in other languages) Thanks.
hardikmehta 9:45 am on September 3, 2009 Permalink |
Thanks.
I have plans to internationalize it, as soon as I get enough time to work on it.
arun kamath 5:04 am on September 13, 2009 Permalink |
I checked your source code at github. Instructions are for linux users. Can you please tell me how to run your program in windows?
Raffaele 2:06 pm on January 13, 2010 Permalink |
I like your plasmoid a lot, I’m enjoying it for months
Here is the patch
)
Recently (maybe) google API changed a bit, because I got an error on wind string that halted my plasmoid
http://pastebin.ca/1749545
Where did you learn graphic widget programming for PyQt? I’d also like to, but I find the official doc inadequate (compared to Java’s for example… I’m a JStudent, too
Cheers
hardikmehta 10:18 pm on January 13, 2010 Permalink |
Raffaele, thanks a lot. I have committed the patch to the repo and updated the package on kde-look. The incorrect format appears only for certain cities like Hong Kong. I tried to learn PyQT from the official documentation and also studying code of some existing plasmoids. It is true that compared to java, there is little help for learning PyQt or Python in general. I am a java developer just found python interesting. I am not sure about how pythonic my code is though
Cheers.
DeltaKilo 4:10 pm on January 17, 2010 Permalink |
Good work! It is the first plasmoid showing weather in Russia!
One little issue. SI unit for temperature isn’t °C but °K (Kelvin). It would be better to use imperial/metric switch.
DeltaKilo 4:11 pm on January 17, 2010 Permalink |
& kmph of course.. In SI should be mps
hardikmehta 12:05 pm on January 18, 2010 Permalink |
Thanks for using the plasmoid. Also thanks for pointing out the mistake. I corrected the names of the units and uploaded a new version with the new names. If you upgrade don’t for get to select the new units from the settings dialog box.
Raffaele 6:01 pm on April 8, 2010 Permalink |
Hi, I’m continuing enjoying your plasmoid
I found another little bug (actually a typo error) which sometimes prevents pyweather initialization. The problem occurs in weather.py http://pastebin.com/vX6HtkGb
I don’t know if it’s fixed in most recent version, neither why sometimes it doesn’t fail. Happy coding!
hardikmehta 2:30 pm on April 20, 2010 Permalink |
Thanks for pointing out. I corrected and committed in the repo. Do you think we need a release for this ? I would rather wait and try to pack some feature with the bug fix.
Rick 5:16 pm on April 21, 2010 Permalink |
Hi, Thanks for the great plasmoid.
Has everything my wife and I want except the ability to change font color. We noticed that the initial install will put in a dark or light font color (contrasting) according to the wallpaper used at that time. Would like to change the contrast when a different wallpaper is used. Is that possible?
Thanks again.
hardikmehta 7:47 pm on April 21, 2010 Permalink |
Hi,
Thanks for using the plasmoid.
Actually, I just set the default font color for text which is selected by the current KDE theme. So, changing the font color with the current version of the plasmoid is only possible if you change the kde theme, which of course will change many other things. I liked your suggestion and would try to implement the font-color as config properties.
cheers,
Hardik
AmFreak 3:29 am on June 2, 2010 Permalink |
Hi,
im planning to write a Plasmoid myself but i have a question.
Is there a way to start the Plasmoid from Eclipse or do u have to run a script everytime u want to test it, like seen in the Getting Started Tutorial (http://techbase.kde.org/Development/Tutorials/Plasma/Python/GettingStarted) ?
Thanks in advance.
AmFreak
hardikmehta 6:43 am on June 2, 2010 Permalink |
I think pydev plugin provides ways to start any python script from eclipse, but I didn’t use that feature so cannot say how to do it. The recommended way to test is with plasmoidviewer, the application which comes as part of plasma environment.
AmFreak 2:34 am on June 5, 2010 Permalink |
But how can you debug a plasmoid if you only can test it with plasmoidviewer ?
luis 6:11 am on November 24, 2010 Permalink |
Thanks yu very much for the plasmoid, I found it really useful and very stylish.
One question? is there a way to change the default Munich location? every time that I have to restart or crash, it automatically changes to the default
Giorgos Komninos (@giokom) 5:50 pm on March 18, 2012 Permalink |
I found a bug and it’s solution
check my comment :
http://opendesktop.org/content/show.php?content=110137&forumpage=3
hardikmehta 10:38 am on March 19, 2012 Permalink |
Hi Giorgos,
Thanks for finding and fixing the issue. I will correct and release a new version as soon as I get some time.
regards,
Hardik
mike welder 1:12 am on September 3, 2012 Permalink |
as of recently I have not been able to start this “script initialization failed” is the message I get.it was working fine then I had a few updates and the above message started.It’s hard for me to tell which update did it as my computer stays on for weeks at a time with out logout or restart unless I have to so it’s hard for me to tell which update did it and when but it did start after a restart.I’m using fedora 17 kde.dam shame the one reason I’ve been with kde since fedora 15 is the great weather widget and a few others.Great work by the way.It’s not only your work there are a few others with the same message.