Use an Android smartphone as a Raspberry Pi screen
Call Me
If you use the Raspbian Pixel desktop, an X server is already running and all programs send the graphic output to this local server. However, this can be easily changed for individual programs, because each program checks the DISPLAY
environment variable. You can change this value by specifying the value at the command line for one program only (line 1) or for all subsequent commands (line 2):
$ DISPLAY=192.168.2.34:0 xeyes $ export DISPLAY=192.168.2.34:0
The syntax of the DISPLAY
variable always follows the pattern <IP address>:<X>.<Y>. On most systems the suffix (i.e., the display/screen number) is 0.0
, or simply 0
. You can also use the hostname of the target device instead of the IP address.
If you always use the same device in combination with the Rasp Pi, you should enter the display variable in the /etc/profile
file, which sets the variable globally. However, this setting only applies to new sessions, and you do not want to do this for Pixel systems, because the output of the desktop on the locally connected screen requires the default value DISPLAY=:0.0
.
Superficial
Creating a graphical user interface for a program is one of the most complex tasks in IT. Everyone can and wants to have a say, and everyone has a different idea of what a beautiful interface or ergonomic design is. This topic is non-trivial, because you need to keep the program operable even if it is busy doing other things (e.g., computing).
Fortunately, many libraries exist that make your life simple. The example here uses the Python programming language. Originally, the modern Kivy [5] was intended as a graphics library, but it uses highly efficient OpenGL for direct rendering, which does not work over the network. The project is now based on wxPython, a wrapper for the wxWidgets toolkit implemented in C++.
For your Raspberry Pi, you need to create a program that simulates a multiline liquid crystal display with control buttons (Figure 3). At the push of a button, you can request various items of system information, and the results end up in a text box. The whole thing can be implemented with surprisingly few lines of code.
Before programming, you have to install the required Python library:
$ sudo apt-get update $ sudo apt-get -y install python-wxgtk3.0
On Raspbian Lite, the command also installs all the necessary auxiliary libraries for running graphical applications (i.e., the X client), so don't worry if the package list looks very long.
If required, also set up the wx3.0-examples package with examples in C++. Because method calls in C++ and Python are almost identical, the examples can be transferred easily to the Python world.
wxPython
The basic architecture of a wxPython program is no different from any other program with a graphical user interface. The main part consists of an infinite loop, known as the event loop.
Every interaction with the program, such as pressing a button, entering text, or moving the window, triggers an event. The event loop processes the interaction by passing it to the appropriate Python methods. The sample program has three buttons and, thus, three methods for processing.
In Listing 1, you can see the most important sections of the WxVlcdApp.py
program, which you can find in my GitHub repository [6]. The event loop described can be found in the last line, which is where the program calls the MainLoop()
method of the WxVlcdApp
application class defined earlier.
Listing 1
WxVlcdApp.py (Excerpt)
The class extends the wx.App
class and consists here of only a single method, OnInit()
, which generates the application's user interface. To do this, a separate class, AppFrame
, is defined (line 22) that constitutes the main part of the program.
The AppFrame
constructor first creates the graphical elements in the create_controls()
method (line 35), for which you use a BoxSizer()
– known from other toolkits as BoxLayout()
, or something similar.
This layout element aligns its children vertically; in the example these are the output text boxes and the buttonbar. The parameters of the Add()
method define which child is allowed to expand and how it aligns itself. Further details can be found in the documentation for wxPython. Similarly, the create_buttons()
method (starting in line 45) creates the toolbar. Here, three buttons are arranged in a horizontal BoxSizer()
.
Additionally, lines 50 through 52 determine which methods the program executes when the individual buttons are pressed. To add more buttons, simply copy and paste the lines in question.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
KDE Plasma 5.27 Beta is Ready for Testing
The latest beta iteration of the KDE Plasma desktop is now available and includes some important additions and fixes.
-
Netrunner OS 23 Is Now Available
The latest version of this Linux distribution is now based on Debian Bullseye and is ready for installation and finally hits the KDE 5.20 branch of the desktop.
-
New Linux Distribution Built for Gamers
With a Gnome desktop that offers different layouts and a custom kernel, PikaOS is a great option for gamers of all types.
-
System76 Beefs Up Popular Pangolin Laptop
The darling of open-source-powered laptops and desktops will soon drop a new AMD Ryzen 7-powered version of their popular Pangolin laptop.
-
Nobara Project Is a Modified Version of Fedora with User-Friendly Fixes
If you're looking for a version of Fedora that includes third-party and proprietary packages, look no further than the Nobara Project.
-
Gnome 44 Now Has a Release Date
Gnome 44 will be officially released on March 22, 2023.
-
Nitrux 2.6 Available with Kernel 6.1 and a Major Change
The developers of Nitrux have officially released version 2.6 of their Linux distribution with plenty of new features to excite users.
-
Vanilla OS Initial Release Is Now Available
A stock GNOME experience with on-demand immutability finally sees its first production release.
-
Critical Linux Vulnerability Found to Impact SMB Servers
A Linux vulnerability with a CVSS score of 10 has been found to affect SMB servers and can lead to remote code execution.
-
Linux Mint 21.1 Now Available with Plenty of Look and Feel Changes
Vera has arrived and although it is still using kernel 5.15, there are plenty of improvements sure to please everyone.