Gtk / python and portability

How do programmers write portable user interface code that runs on multiple distributions? I am considering desktop distributions and non-specialized / built-in distributions. To write user interface applications, you must assume that certain things will be available on the platform either as standard ones or with added dependencies. Is there a β€œminimal” interface / widget standard that belongs to Linux distributions?

How is Gnome vs KDE distributed when you write code?

I have a python script that uses Gtk and Webkit. Listed below are the imports that my script uses.

import os import threading from gi.repository import WebKit from gi.repository import Gtk from gi.repository import GLib, GObject 

What will be the best source to find out on which distributions my code will work?

+4
source share
2 answers

To write a cross-distribution interface, you do not need much attention.
In fact, the only incompatibility problem that I remember is:

Icon icon or notification area or application indicator (called Ubuntu)
For example, the standard tray icon (created by gtk.StatusIcon does not work in Ubuntu Unity by default

It is better to use appindicator.Indicator if the appindicator module was found, otherwise just use the classic StatusIcon

And if you pay too much attention to the style / theme of your program, you may have problems with other environments such as KDE
If you are not using suitable engines to act as a bridge, see:
https://wiki.archlinux.org/index.php/Uniform_Look_for_Qt_and_GTK_Applications

To find out about / OS distribution, I wrote a function like this:

 def getOsFullDesc(): name = '' if os.path.isfile('/etc/lsb-release'): lines = open('/etc/lsb-release').read().split('\n') for line in lines: if line.startswith('DISTRIB_DESCRIPTION='): name = line.split('=')[1] if name[0]=='"' and name[-1]=='"': return name[1:-1] if os.path.isfile('/suse/etc/SuSE-release'): return open('/suse/etc/SuSE-release').read().split('\n')[0] try: import platform return ' '.join(platform.dist()).strip().title() #return platform.platform().replace('-', ' ') except ImportError: pass if os.name=='posix': osType = os.getenv('OSTYPE') if osType!='': return osType ## sys.platform == 'linux2' return os.name 
+1
source

Python is basically a glue language - it doesn't do much, but it depends on various libraries such as pygtk, tkinter, etc. or even with your custom C / C ++ modules. do your stuff. Logically, all you need is specific dependencies for your libraries: PyGTK and WebKit, which will be installed on your target machine.

After you installed them on Windows or even the MAC, along with Python, python will happily execute this code, since all it does is glue !!

0
source

All Articles