Closed davidhoness closed 8 years ago
It's possible with some caveats. It's impossible to (reliably) tell if X is running (even if it's not running on the Pi, who's to say the display isn't forwarded to a machine with a perfectly capable X server which the user wants to use instead), so I'll have to pass on that bit.
At the moment the behaviour of the sense_emu
library is as follows:
sense_emu_gui
is currently running, the emulated registers exist and everything workssense_emu_gui
has never been run (since the last reboot) then the emulated registers don't exist; attempting to construct an instance of SenseHat acts just like the real library does when no Sense HAT is present (i.e. when you try and access the sensors you'll get errors about initializing the IMU etc.)sense_emu_gui
isn't currently running, but has been run since the last reboot, the emulated registers still exist and everything works but the various sensors don't change value (obviously, because there's nothing driving them)Case 2 and possibly case 3 are the two in which you wish sense_emu_gui
to launch implicitly when sense_emu
is imported (or perhaps when SenseHat
is constructed?).
Unfortunately there's an issue with fixing case 3: sense_play
. The recording playback facility of the GUI only works well on high end platforms (there isn't much I can do about this; it involves manipulating almost every GUI element numerous times a second while driving changes through every emulated register and still keeping the display up to date). This is the reason I quickly threw together sense_play
: to provide a (admittedly non-graphical, command line only) playback facility for those on low end platforms (Pi 1 etc.) so they could still test their scripts with recorded experiments (albeit without an emulated display or joystick).
However, this assumes that users are able to start their script then fire up sense_play
on the command line to replay a recording. sense_emu_gui
need not (and should not) be running while sense_play
is operating (otherwise there'll be two applications attempting to drive the emulated registers).
I'll have a think about the various possibilities here tomorrow and see if I can come up with a good compromise.
Okay right, I would like the auto run behaviour for case two and three correct. If it could happen, asyc?, in the sense_emu
SenseHat
constructor that would be ideal, for case one if the gui is already running is there a way to make it jump to the top of the window stack and take focus? That's a nice to have.
Then I think the optimal way forward is to make sense_play
refuse to run if sense_emu_gui
is already running.
for case one if the gui is already running is there a way to make it jump to the top of the window stack and take focus? That's a nice to have
Should already happen - GtkApplication
defaults to singleton mode (run it again and the existing instance is focused instead).
I'll get the rest done today and build a new package for you to have a play with.
Can a check be performed when the user runs their script to see if the sense_emu_gui is running and, if not, launch it? This is only appropriate if X is running too.