A weather plasmoid in python
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: