Articles

Bluefish 2.2.15 released

In Uncategorized on March 27, 2024 by oli4444 Tagged: ,

Bluefish 2.2.15 is a minor maintenance release. It has one completely new feature: it can highlight the indenting level with a vertical line, which is very useful during python programming and helps with a lot more programming languages. It also adds a retry button when opening files from a remote location (which is useful if you open a file over a very slow link, and you get a timeout the first time because you need a reconnect). The 2.2.15 release fixes zencoding for python releases newer than 3.12. This release has a tiny performance improvement when scrolling. It also fixes a bug in the bookmarks function and the visible indenting function that potentially could lead to a crash. The perl syntax detection has been greatly improved in this release, and YAML syntax detection has been added. The code has several fixes to make it compile on modern Mac OSX releases and to make it compile with the latest version of the clang compiler.

Articles

Writing small GUI applications on Linux

In Gnome shell, gtk+, Programming on November 14, 2020 by oli4444 Tagged: , ,

Last years I had little time for programming. Most of that time was spent maintaining Bluefish and Jailkit. Last month I wanted to write some small utilities.

First utility I wrote was a gnome-shell extension to track how the time on the computer was spent. The extension polls the current active application and it’s window title every 10 seconds and appends that to a logfile. Although I have some experience with Javascript in websites, I found it very hard. Hardest was to find examples and documentation. A simple thing like how to append a single line to a logfile took me a lot of time.

Next utility I needed was a tool to parse the window activity logfile and show useful statistics. Because of the bad experience with Javascript I choose Python. I didn’t use Glade for years, but I decided to use it for the GUI. I was very surprised with the state of Python Gtk bindings and the combination of Python and Glade. It was excellent to see how quick one can write an application with the combination of python and glade. The documentation on Python and Gtk is good (https://python-gtk-3-tutorial.readthedocs.io/en/latest/) which helps. It surprises me that Glade is mentioned only in chapter 21 of that tutorial. I would have made it chapter 2, and I would have uses it everywhere else in the tutorial.

Because the combination worked very well for me, I also used it for my next utility: saving laptop batteries. Most of my family members keep their laptops always connected to the power at home (which currently is most of the time). I have a few Sonoff switches around with self-written firmware that I can switch on/off with a JSON call. The laptops now automatically switch off their power when their batteries are >95% charged, and switch on the power when their batteries reach < 10%. Then I improved the utility to read the status of the smart meter in house, so now the laptops prefer to charge when I have excess power from my solar panels.

I used pydbus to read the battery state from the system dbus. Paho MQTT was used to read the status of my Smart meter (I have a Raspberry Pi connected to it’s serial port that puts the values on an MQTT bus). Normal python libraries like requests for the JSON call and configparser for config file loading/saving. And again the combination of Glade with Gobject introspection for Gtk and Libnotify and I got everything working in < 250 lines of code. Very happy with the result ๐Ÿ™‚

Articles

From “power on” to “gtk GUI usable” as fast as possible

In gtk+, Programming, raspberry pi on November 22, 2015 by oli4444

In my Raspberry Pi + Hifiberry-amp + Pitft project I’ve been looking how to speed up the boot process.

[edit] I updated various parts of this post with suggestions from the comments. [/edit]

The original boot process took around 60 seconds from “power on” until my gtk app was visible and responding. I used the original (Wheezy based) raspbian, with autologon on tty1, and in the .bash_profile I called startx. In /home/pi/.xinitrc I started my application without starting a display manager:
#!/bin/sh
PYTHONIOENCODING=utf_8
export PYTHONIOENCODING
exec /usr/bin/python /home/pi/sqgui2.py

(b.t.w. the PYTHONIOENCODING is there otherwise python will give an exception when calling print with a non-ascii unicode character)

By removing a few services from the init process I removed 10 seconds from the boot process. Still 50 seconds. But further options on Raspbian Wheezy are limited.

Next step was to move to Raspbian Jessie, which has systemd. This gave an unwanted side effect: the hifiberry was detected correctly, but did not produce any sound anymore. Removing a line added for the pitft device_tree=bcm2708-rpi-b-plus.dtb from /boot/config.txt fixed this problem. And the pitft is still working.

In systemd I can start X11 as soon as userspace is running. However this generated an error – the touchscreen device has to be available first. The touchscreen input is in udev configured as /dev/input/touchscreen. I created /etc/systemd/system/xinit-login.service with the following content:
[Unit]
Wants=dev-input-touchscreen.device
After=dev-input-touchscreen.device
DefaultDependencies=false
[Service]
Type=simple
ExecStart=/bin/su pi -l -c /usr/bin/xinit -- VT08
WorkingDirectory=/home/pi/
[Install]
WantedBy=local-fs.target

[edit] with suggestions from the comments in now looks like:

[Unit]
Wants=dev-input-touchscreen.device
After=dev-input-touchscreen.device
DefaultDependencies=false
[Service]
Type=simple
ExecStart=/usr/bin/xinit
WorkingDirectory=/home/pi/
User=pi
Group=Users
Environment=PYTHONIOENCODING=utf_8
[Install]
WantedBy=local-fs.target

and .xinitrc is now a hardlink to the gtk application sqgui.py [/edit]

This makes my xinit session start directly after the touchscreen device is available. This reduced the startup time to 28 seconds. Much better! (b.t.w. I haven’t look if all entries in xinit-login.service are correct, perhaps the contents can be improved).

Systemd has a good tool called systemd-analyze which analyzes the boot process. That way you can easily see which parts take too much time. That helped me to strip off another 2 seconds. An interesting question is how the udev config can be improved to create the touchscreen device earlier in the boot process. Another interesting question is how X11 can be configured to start faster, or how python + gtk3 can be configured to start faster. If you have any suggestions please leave them in the comments.

Next thing was to make the system readonly. I installed busybox-syslogd instead of rsyslogd, since it can do in-memory logging. [edit] I now switched to systemd-journald for in memory logging [/edit]

I analyzed which directories changed after a reboot, and moved those to a tmpfs in-memory filesystem. The /etc/fstab now looks like:
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults,ro 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime,ro 0 1
tmpfs /tmp tmpfs defaults,noatime 0 0
tmpfs /var/lock tmpfs defaults,noatime 0 0
tmpfs /var/lib/dhcpcd5 tmpfs defaults,noatime 0 0
tmpfs /var/log tmpfs defaults,noatime 0 0

Possibly this can be optimized with a single tmpfs mount and symlinks to reduce the mount time of 4 tmpfs filesystems.

[edit] did that, they are all symlinks to /tmp now [/edit]

The only remaining issue that I didn’t solve yet is handling of /etc/resolv.conf when moving the setup to a different network. Because /etc/ is readonly the resolv.conf is now fixed for my local wifi network.

[edit] disabling the UART, and moving from the debian networking scripts to systemd-networkd reduced the boot time to 21 seconds! [/edit]

Articles

A search interface in a 320×240 touchscreen

In gtk+, open source, Programming, raspberry pi on October 24, 2015 by oli4444

Last evenings I spent some time on my raspberry pi + hifiberry amp + piTFT + squeezebox project. Previously I created the interface to load a predefined playlist, and to control basics like volume and time. I also finished the integration of the display in the top of the Mission 731i speaker and placed the pi and amp inside the box (will post some pictures soon).

gui

This time I wanted to extend the user interface with a feature to search and browse in the mp3 collection. But that immediately raised the question: what kind of interface works best for a small screen size (320×240) and touch input (no keyboard, no mouse)? A possibility was a virtual keyboard with a entry or a combo, but my first mockup in glade resulted in 300×140 pixels just for the keyboard – leaving very little space for the search results. So I tried a treeview so the user can quickly scroll through the results. To reduce the number of results I added a combo with a prefix (a-z0-9) to the top.
search gui
The results work reasonably well, but there are some issues to resolve.

First of all the scrolling in the GtkTreeView is not using “kinetic scrolling” (you can’t scroll like you normally do on a touchscreen) although I enabled kinetic scrolling for the GtkScrolledWindow parent in glade. Scrolling using the scrollbar on the side works, but kinetic scrolling would work better.

Second, most touchscreen users kind of expect the context menu when you hold your finger for a while. I hoped this was automatically translated to a right-click, but that doesn’t work. So I have to find a way now to catch these events for the context menu’s (anybody a hint how to do this?).

The last issue I have is not related to the touchscreen. I have some scaling layout issues, sometimes a multiline label with a long text forces some buttons off the screen.
screenshot
So I also have to find out how ellipsize works with multiline labels.

Articles

raspberry pi, hifiberry, piTFT with gtk GUI

In Uncategorized on September 22, 2015 by oli4444

I bought a hifiberry amp (a 2x25W class D amplifier with a fully digital path from the raspberry) and a PiTFT 2.8″ touchscreen. I’m planning to integrate them with my raspberry pi model B inside in a set of Mission 731i speakers. That will give me a set of powered speakers that can stream music over a wifi network, with a touchscreen interface.

First thing to do was to connect both the hifiberry amp and and pitft to the same raspberry. They are designed to run exclusively on top of a raspberry, but they use different pins, except for the 5V power pin. So after wiring them carefully with jumper cables I managed to run them simultaneously.

raspberry-pi-rev2-gpio-pinout-pitft-hifiberry-amp

The raspberry will run squeezelite, so it will act as a squeezebox player. Squeezelite is a headless application, so it does not provide any interface that can be controlled from the touchscreen. The sqeezelite player is controlled by a squeezebox server (also called logitech media server).

I decided to build a GTK app with glade and python to run on the touchscreen (and obviously I’ll use Bluefish to do the python coding). I previously used pygtk or gtk with C, so first I had to learn the new way to use gtk3 in python, but that turned out to be fairly simple. I start the app in .xinitrc without any window manager or decorations, so it runs fullscreen without any possibility to switch to another application. Startx is called from .profile if the tty is tty1, and tty1 is set for auto-logon – so power on means boot, X and then the app.

The app also has to control the squeezelite process. I created an gtk timer callback check_processes() that is called every second and checks if the squeezelite process is still running:

   def start_procsqueezelite(self):
            try:
                    self.procsqueezelite = subprocess.Popen([config['squeezelite'], '-n', 'SqueezeSpeaker'])
            except OSError as err:
                    print 'error starting',config['squeezelite'],err                

    def check_processes(self):
            if (self.procsqueezelite):
                    ret = self.procsqueezelite.poll()
            else:
                    ret = 255
            if (ret != None):
                    self.start_procsqueezelite()
            return 1

Second challenge was to control the squeezebox server from the app. Luckily the squeezebox server uses a very simple protocol, a tcp connection to port 9090 with ascii line based commands and urlencoded results. The next button can simply send the command “aa:bb:cc:dd:ee:ff playlist index +1”, pause sends “aa:bb:cc:dd:ee:ff playlist mode pause”, etc. Basic functionality was working quickly.

However, any squeezebox player can be controlled from any device (smartphone, tablet, etc.), so another device might be changing the volume, pressing pause, etc. and my app should display the new corresponding status. The squeezebox server has a “listen” command for that, this will send any event over the tcp connection, again line based and urlencoded. I chose to open a second tcp connection. To make the application respond quickly, both when doing socket I/O and responding to GUI events, I run the connections in separate threads. The commands are put into a python Queue, and the threads send their results to the mainloop using an idle callback. In the idle callback I use regex matching to find the interesting events and update the GUI accordingly.

Something that took me some time (and then turned out to be very simple) was how to load the album covers in the GTK GUI. The Squeezeserver has them available over http. The dirty approach was to download them, and then load them from file. The nice way is to download them to memory and load them into the widget. The http loading has again a separate thread, which again sends the loaded data with an idle callback to the mainloop. This is the idle callback:

       def artwork_handler(self,imgdata):
                image = self.builder.get_object('coverimage')
                pbl = GdkPixbuf.PixbufLoader()
                pbl.set_size(80,80)
                try:
                        pbl.write(imgdata)
                        image.set_from_pixbuf(pbl.get_pixbuf())
                except:
                        print 'artwork_handler, failed to parse image data'
                pbl.close()
                return 0

The resulting app looks like this when running on my desktop:
screenshot

I’ll probably use a dark theme when running on the PiTFT. More on this project later, and I’ll publish the full code soon.

Statuses

backwards rendering compatibility

In Bluefish, gtk+, open source, Programming on July 3, 2015 by oli4444

The last year I didn’t keep up with the latest GTK versions. With less time to code, installing new software was not my priority, so I did most of my programming on a machine running Ubuntu LTS.

Last week I had some spare time and I installed the latest Fedora. I installed the same Bluefish version (the latest, 2.2.7) but to my surprise some bits didn’t look as good anymore. Bluefish has a sidebar with several plugins, each in a GtkNotebook tab. This normally looks like this:

small_icons_tabs

But on the latest and greatest Fedora, it looks like this, instead of showing all the icons, only two are visible, unless you make the sidebar extremely wide:

sidebar-new-gtk

This makes me wonder if GTK has something like “backwards rendering compatibility testing”: see if applications that were not developed for the latest GTK release still look good and function properly. I have no idea if this could be done in an automatic way, but there are probably brighter people around that do have an idea how to do this.

b.t.w. I haven’t found a way yet to change my code in such a way that all icons become visible again. If anybody is willing to drop me a hint how to get all icons back in the original space I will be happy ๐Ÿ™‚

Statuses

Bluefish 2.2.7 released

In Bluefish, open source on February 6, 2015 by oli4444

Bluefish 2.2.7 is mostly a bug fix release. It fixes rare crashes in the autocompletion, the filebrowser, the htmlbar plugin preferences, in file-load-cancel, and fixes a rare case of broken syntax highlighting after multiple search/replace actions. It furthermore displays better error/warning output when parsing language files. It also finally fixes javascript regex syntax highlighting. The loading of files with corrupt encoding or non-printable characters (such as binary files) has been improved, and project loading over sftp has been improved. Various HTML5 tags have been added, and HTML5 is the default now for php, cfml and other languages that can include html syntax. Saving and loading of UTF-16 encoded files was broken and has been fixed. Various languages have better syntax support, such as javascript, css, html, pascal/deplhi, and html has improved autocompletion. On OSX the charmap plugin is finally included, the keys for tab switching no longer confict with some keyboard layouts, and behavior at shutdown was improved. The upload/download feature has a new option to ignore backup files. The home/end keys now work better on wrapped tekst. And finally the search and replace dialog correctly shows the number of results when searching in files on disk.

Statuses

Cross-platform keyboard issues

In Bluefish, gtk+, Programming on October 5, 2014 by oli4444

We often receive bugreports from windows or OSX users with keyboard problems. For example on windows changing the keys ” to ยจ and ‘ to ยด. Or on OSX the square brackets [] are not possible on a German keyboard layout (see https://bugzilla.gnome.org/show_bug.cgi?id=737547), or curly braces not on AZERTY layout (see https://bugzilla.gnome.org/show_bug.cgi?id=692721).

From what I understood this is caused by gtk handling the keyboard events itself, instead of waiting for the key-value that the operating system provides.

Is there a way how this can be fixed? Either in Bluefish or in GTK?

Articles

Reducing desktop power usage while idle

In Gnome, Linux desktop, open source on July 14, 2014 by oli4444

While remotely monitoring my desktop session with powertop while it was idle (screensaver active) I noticed that a few processes cause a lot of activity, and keeping the CPU from going into the PC7 state (the complete cpu package deepest sleep state). Most notably firefox and it’s plugin-container cause frequent wakeups.

I wrote a short script that listens on dbus for screensaver ActiveChanged messages, and either sends a STOP or a CONT signal to firefox and the plugin-container. This script makes my desktop go from 20W to 19W of power when I am not using it.


import subprocess
import datetime

import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop

stoplist = ['firefox', 'plugin-container', 'steam']
def msg2_cb(msg):
	dt = datetime.datetime.now()
	if (msg):
		for name in stoplist:
			subprocess.call(["killall", "-STOP", name])
	else:
		for name in stoplist:
			subprocess.call(["killall", "-CONT", name])

if __name__ == '__main__':
	DBusGMainLoop(set_as_default=True)
	bus = dbus.SessionBus()
	bus.add_signal_receiver(msg2_cb, 'ActiveChanged', None, None, '/org/gnome/ScreenSaver')
	mainloop = gobject.MainLoop ()
	mainloop.run ()

The obvious caveat is that any downloads by firefox are also stopped if the screensaver becomes active.

Articles

Computer hardware

In Hardware on May 21, 2014 by oli4444

I built a new computer last week to replace my old one. My computer is running 24h a days, so I focused on low power hardware with good peak performance. Next to a low-power computer I have a computer built for performance (gaming and heavy development). Because the low power computer is always on, I tend to use it for some quick development as well. Switch on the display, change a few lines of Bluefish code and compile.

The old low power computer, an Athlon X2 2700MHz, idles at about 55W. Compiling Bluefish takes 43s. The performance computer, a Core2 duo 3.3GHz idles at about 83W. Compiling Bluefish takes 25s.

The new computer, a Haswell core i5 3.2Ghz with turbo to 3.6GHz idles at about 20W (if I stop a few services I can get it to 16W!). Compiling Bluefish takes 11s. This basically means I can replace two computers at once! It’s much lower power than my low-power computer, but much faster than my performance computer!

For those interested in building a low-power/high-performance computer the build specs:

  • Intel Core i5 4570
  • ASRock B85M Pro4 (see this review for low power haswell boards, text in Dutch, but the graphs speak for themselves)
  • WD Red SATA 6 Gb/s WD30EFRX, 3TB
  • 16Gb Crucial Ballistix Sport DDR3-1600
  • be quiet! Pure Power L8 300W (see this and this review for power supplies that are efficient in the very low power ranges.)
  • Crucial M500 2,5″ 240GB
  • Gelid Solutions Tranquillo Rev.2
  • Fractal Design Core 1000 USB 3.0