Cross-platform game and app development for new programmers
Dynamic Screens
Ren'Py supports custom screen layouts that can have labels, text, buttons, and bar charts. In a visual novel, a custom screen could be a small box at the top of the application that shows items like inventory, money, or percent complete.
For the next example, I use Python code with Ren'Py to find some PC hardware readings and present the information on a large custom screen.
The Linux sensors
[5] command can be used to show current hardware information:
$ sensors dell_smm-virtual-0 Adapter: Virtual device Processor Fan: 2721 RPM CPU: +46.0 C Ambient: +39.0 C ...
By adding some Bash/Awk code, the CPU and ambient temperature values can be extracted:
# use show Bash/Awk code to get temps $ sensors | grep CPU | awk '{ printf "%d\n" , $2}' 46 $ sensors | grep Ambient | awk '{ printf "%d\n" , $2}' 39
Python calls Bash scripts with the subprocess.check_output
method, which is part of the subprocess library (Listing 2).
Listing 2
subprocess.check_output
$ python Python 2.7.15+ (default, Oct 7 2019, 17:39:04) [GCC 7.4.0] on linux2 >>> import subprocess >>> subprocess.check_output("sensors | grep CPU | awk '{ printf \"%d\" , $2}'", shell=True) '46' >>> >>> subprocess.check_output("sensors | grep Ambient | awk '{ printf \"%d\" , $2}'", shell=True) '39'
Listing 3 shows the code required for the CPU statistics application (Figure 8). The screen cpu_data():
statement creates a user interface (line 3) that can contain both Python blocks and display elements.
Listing 3
Dynamic CPU Stats Screen
01 # script.rpy - create a Ren'Py screen that shows CPU sensor information 02 03 screen cpu_data(): 04 05 python: # Use Python to get sensor variables 06 now = datetime.now() 07 nowtime = now.strftime("%H:%M:%S") 08 ctemp = subprocess.check_output("sensors | grep CPU | awk '{ printf \"%d\" , $2}'", shell=True) 09 atemp = subprocess.check_output("sensors | grep Ambient | awk '{ printf \"%d\" , $2}'", shell=True) 10 11 frame: # create a frame with text, values and a bar 12 has vbox 13 label "CPU Stats" text_size 120 14 15 vbox: 16 text "Time : [nowtime]" size 80 17 text "Ambient temp: [atemp] C \n" size 80 18 text " CPU temp : [ctemp] C " size 60 19 hbox: 20 vbox: 21 text "0 " size 40 22 vbox: 23 bar value atemp range 60 xalign 50 yalign 50 xmaximum 600 ymaximum 50 left_bar "#FF0000" 24 vbox: 25 text " 60 " size 40 26 27 init python: 28 # Define Libaries and any system variables 29 import subprocess 30 from datetime import datetime 31 32 label start: 33 34 # Start with Weather screen 35 show screen cpu_data() 36 37 define cycle = "True" 38 # Cycle every 2 seconds 39 while cycle == "True" : 40 $ renpy.pause(2) 41 42 return
![](/var/linux_magazin/storage/images/issues/2021/252/ren-py/figure-8/793830-1-eng-US/Figure-8_large.png)
The Python block (lines 5-9), start with a python:
statement, and the succeeding lines are indented per the Python standard. CPU and ambient temperature variables (lines 8-9) are created with the subprocess.check_output()
call and the earlier Bash sensors
statements.
For this screen, a frame:
(line 11) is used to group the elements together. Vertical boxes (vbox:
) and horizontal boxes (hbox:
) are used for further groupings. Python variables are inserted into text output strings with square brackets (lines 16-18). A horizontal bar (line 23) shows the ambient temperature (atemp
) with a range of 0-60.
The application begins at label start:
(line 32) by showing the cpu_data
screen (line 35). An inline Python statement (line 40) pauses the execution for two seconds within a while
loop. The screen logic is refreshed after each renpy.pause()
iteration.
Building Applications
The Ren'Py IDE has a Launch Project button that allows testing in the native operating system environment. The IDE's Build option allows you to create a variety of different packages (Figure 9).
![](/var/linux_magazin/storage/images/issues/2021/252/ren-py/figure-9/793833-1-eng-US/Figure-9_large.png)
The HTML5 build is still in beta; it appears to work well for standard visual novel apps, but I found that it had issues with some Python library calls. The HTML5 build creates a separate directory structure for the Ren'Py application that needs to be mapped into your web server configuration.
If you are looking to do some simple testing, a Python standalone web server (Figure 10) can be run from the project's web directory:
# Run a python standalone server on port 8042 python3 -m http.server 8042
![](/var/linux_magazin/storage/images/issues/2021/252/ren-py/figure-10/793836-1-eng-US/Figure-10_large.png)
Final Thoughts
If you're looking to create some simple cross-platform visual presentation apps, Ren'Py is a good fit, it is super easy to learn, and doesn't require strong programming skills. I found the first-time call-up for Android was longer than expected, but I was impressed with the final result.
Ren'Py supports simple screens that can have dynamic bars and text; however, if you're looking to incorporate gauges or line charts. Ren'Py probably isn't the best fit.
Infos
- Ren'Py: https://www.renpy.org
- Download Ren'Py: https://www.renpy.org/latest.html
- Character Creator: https://charactercreator.org
- Bruce Peninsula, Ontario: https://visitbrucepeninsula.ca
- lm_sensors (sensors) documentation: https://wiki.archlinux.org/title/lm_sensors
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.