Active Topics

 


Reply
Thread Tools
Posts: 3,328 | Thanked: 4,476 times | Joined on May 2011 @ Poland
#1
In C++ w/ Qt we'd use
Code:
int foo() {
#if defined Q_WS_MAEMO5 
/* */
#elif defined Q_WS_HARMATTAN
/* */
...
#endif
}
Can we do something like this in python3? I'd like to show a notification, which I can't do in a platform-agnostic way. (no libnotify on Fremantle)
__________________
If you want to support my work, you can donate by PayPal or Flattr

Projects no longer actively developed: here
 
otsaloma's Avatar
Posts: 141 | Thanked: 1,530 times | Joined on May 2011 @ Finland
#2
Maybe something in platform? Sailfish below, I don't know what others return.

Code:
$ python3
Python 3.4.3 (default, May 12 2016, 02:20:34) 
[GCC 4.8.3 20140106 (Mer 4.8.3-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'Linux-3.4.108.20160401.1-armv7l-with-glibc2.4'
>>> platform.uname()
uname_result(system='Linux', node='Sailfish', release='3.4.108.20160401.1', version='#1 SMP PREEMPT Thu May 12 02:21:45 UTC 2016', machine='armv7l', processor='armv7l')
Checking for the existance of a particular file or directory with os.path.isfile/isdir should be quite simple too if you know what to check -- e.g. /usr/lib/qt5/qml/Sailfish.

And in case you're calling executables like notify-send, you can check if they're available with shutil.which.
 
Posts: 3,328 | Thanked: 4,476 times | Joined on May 2011 @ Poland
#3
Originally Posted by otsaloma View Post
Maybe something in platform? Sailfish below, I don't know what others return.

Code:
$ python3
Python 3.4.3 (default, May 12 2016, 02:20:34) 
[GCC 4.8.3 20140106 (Mer 4.8.3-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'Linux-3.4.108.20160401.1-armv7l-with-glibc2.4'
>>> platform.uname()
uname_result(system='Linux', node='Sailfish', release='3.4.108.20160401.1', version='#1 SMP PREEMPT Thu May 12 02:21:45 UTC 2016', machine='armv7l', processor='armv7l')
Checking for the existance of a particular file or directory with os.path.isfile/isdir should be quite simple too if you know what to check -- e.g. /usr/lib/qt5/qml/Sailfish.

And in case you're calling executables like notify-send, you can check if they're available with shutil.which.
node returns the contents of /etc/hostname (uname -n), so it's not reliable.

That's what I thought about, but it's the last resort. I didn't find anything useful in the platform module.

Basically, I use the Python example from here [1] to show the notification on desktop. Since libnotify is unavailable, I guess I'll use a dbus call on Fremantle.
__________________
If you want to support my work, you can donate by PayPal or Flattr

Projects no longer actively developed: here
 
Reply


 
Forum Jump


All times are GMT. The time now is 12:57.