Re: [pygame] How to prevent mouse initialization in Pygame

2017-08-01 Thread Roman Mescheryakov


Hi Theo, thank you very much for the reply! As of blinking text cursor 
problem, I succeeded with finding an answer here 
. In order to get 
rid of blinking text cursor one should issue under the root user the 
following command:

echo 0 > /sys/class/graphics/fbcon/cursor_blink

Note that this change doesn’t survive the reboot, so I added it to my 
application before pygame initialization.

I also managed to solve the “screen going black” problem. It turned out 
that it’s just a some sort of monitor lifetime care or energy saving and it 
isn’t related to pygame or systemd. Here is the solution 

 
that helped me to solve the problem.

So it seems all my troubles with running pygame-based Python application as 
a systemd service are gone now. A huge thank you to everyone who 
participated in this long discussion!


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-28 Thread Roman Mescheryakov


Thank you Theo for this information! I tried these settings in systemd 
service file and here are my results:

   1. 
   
   I had to change TTYPath to /dev/tty2. With /dev/tty1, I had the 
   following problems:
   1. 
  
  My application crashed after displaying first or second test image
  2. 
  
  I started to receive strange errors when connecting to my RPi through 
  SSH under limited user:
  “-bash: /dev/null: Access denied” (about 20 times for one connection) 
  Fortunately the SSH connection was successful even after the errors.
  2. 
   
   When running under limited user, I faced the aforementioned “black 
   screen after 5-10 minutes, framebuffer graphics no longer displayed” and 
   “blinking text cursor” problems. 
   3. 
   
   When running under root, everything works fine.
   
Let me remind you my Linux machine is Raspberry Pi 3 and operating system 
is Raspbian Jessie. There is no keyboard or mouse connected to RPi. I 
connect to it using SSH. I set pygame/SDL to use the “fbcon” framebuffer 
driver via the SDL_VIDEODRIVER environment variable.

My `systemd --version` output is:

systemd 215

+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ 
-SECCOMP -APPARMOR

My pygame package version is: (`aptitude show python-pygame`):

1.9.2~pre~r3348-2~bpo8+rpi1

My libSDL 1.2 version is: (` aptitude show libsdl1.2debian` - on your 
machine package name can be different):

1.2.15-10+rpi1

Theo, please tell:

   1. 
   
   What Linux machine do you run your systemd+pygame application on 
   (hardware platform and operating system)?
   2. 
   
   Did you set pygame/SDL to use specific video driver?
   3. 
   
   What are systemd, pygame and libSDL 1.2 versions on this machine?
   4. 
   
   For how long does usually your application show graphics with pygame? Do 
   you face the “black screen after 5-10 minutes, framebuffer graphics no 
   longer displayed” problem when running your systemd+pygame application 
   under limited user?
   5. 
   
   Do you face the “blinking text cursor” problem when running your 
   systemd+pygame application under limited user?
   

Kind regards, Roman Mescheryakov


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-27 Thread Roman Mescheryakov


In case anybody interested, I faced some troubles running pygame 
application as a systemd service under limited user. Application runs fine 
for 5-10 minutes, but after that the screen becomes black and pygame 
graphics is not displayed. Running as root didn’t fix the problem. The SDL 
version used is version that I compiled myself with disabled keyboard 
support.

My guess is that this is because this call was eliminated after disabling 
keyboard support in SDL:

ioctl(keyboard_fd, VT_LOCKSWITCH, 1); /* Prevent switching the virtual 
terminal */

Maybe some application decides to switch virtual terminal and another 
terminal becomes active and gets control over framebuffer. Though I should 
note that after my screen becomes black pygame continues to execute 
commands I give to it without any errors.

Also I believe that the problem with text cursor blinking was due to this 
call commented out after disabling keyboard support in SDL:

ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS)

As far as I know, one needs root rights to successfully execute these ioctl 
requests.

Taking into account all these facts I came to conclusion that trying to run 
pygame framebuffer graphics as a limited user was a bad idea. I rebuilt SDL 
with my changes reverted and run my test pygame application under systemd 
with root rights. The “black screen after 5-10 minutes” and “blinking text 
cursor” problems were solved.

As to security considerations, I think that code which needs root rights 
could be isolated in a separate executable file which has root as it’s 
owner and has setuid bit enabled. After that main process running under 
limited user could run this helper executable to get the work done.

Kind regards, Roman Mescheryakov


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-24 Thread Roman Mescheryakov


In case somebody interested: running pygame with modified SDL as a systemd 
service succeeded without any surprises. I also hid mouse cursor with help 
of pygame.mouse.set_visible(False) call. 

My next task to solve is hiding blinking text cursor.

суббота, 22 июля 2017 г., 19:51:22 UTC+3 пользователь themusi...@gmail.com 
написал:
>
> Hi Roman, do you have any more details about how you were able to solve 
> this? I'm stuck on the same problem.
>
> Thanks.
>

 I have plans to publish modified SDL sources on site like GitHub, but my 
experiments aren't complete yet and also my GitHub experience is very 
scarce, so this is a long road... As a fast help, I could attach here 
modified SDL sources in a .zip file. Let me know if you want to get them.


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-18 Thread Roman Mescheryakov


Good news: I succeeded with commenting out SDL code that deals with 
keyboard, and after that I was able to run pygame framebuffer graphics 
without root rights! But there is a small issue: there is a text cursor 
blanking at the bottom of the screen.

By the way, it turned out that /dev/console rights change mentioned in 
reply to the How do I let an SDL app (not running as root) use the console 

 
StackExchange post is not necessary, at least on Raspbian.

My next steps are to run pygame framebuffer graphics as a daemon. I will 
try using systemd as a daemon supervisor, because this is the default 
choice in Raspbian.

Kind regards, Roman Mescheryakov


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-17 Thread Roman Mescheryakov


понедельник, 17 июля 2017 г., 21:34:54 UTC+3 пользователь Martin Kühne 
написал:

> What's your status about the `tty` group membership? 
>
> cheers! 
> mar77i 
>

The limited user is a member of this group:

pi@masternoinit:~ $ groups

pi adm tty dialout cdrom sudo audio video plugdev games users input netdev 
console gpio i2c spi

 


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-17 Thread Martin Kühne
What's your status about the `tty` group membership?

cheers!
mar77i


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-16 Thread Roman Mescheryakov


четверг, 13 июля 2017 г., 23:22:27 UTC+3 пользователь Martin Kühne написал:
>
> Also Roman, please note that 
> many ioctls return data in pointers that can be passed to them which 
> should be the spot where your results actually differ. 
>
>
I remember that, in particular, VT_OPENQRY accepts pointer to integer to 
store result. In my experiments I printed to stdout value of integer 
pointed to, not the pointer itself.

пятница, 14 июля 2017 г., 19:33:29 UTC+3 пользователь Alec Bennett написал:
>
> Another possibility would be to execute a command that moves the mouse way 
> off screen?
>
>
I think the title of this discussion thread became confusing, because my 
goal is not to just get rid of mouse pointer, but rather get rid of 
necessity to run pygame-based script as root. When I started this thread I 
thought that need for root rights was a consequence of mouse 
initialization. But now with help of kind people here I realized that the 
problem is not mouse but keyboard/console terminal initialization instead.

As the moment I think that more correct title for this discussion thread 
would be “How to run pygame framebuffer graphics without root rights” or 
something similar.

I started thinking about looking into SDL sources already, but I was hoping 
there is an easier way. But after Annette’s reply with direct references to 
relevant points in the code I realized that time has come :) Thank you very 
much Annette for your help!

I succeeded with SDL compilation from libSDL 1.2 sources for Debian 
 using this 
really simple and working instruction . 
Here are first results.

First I commented out FB_OpenKeyboard call in SDL_fbvideo.c, but that lead 
to pygame error without descriptive error message, so I reverted my changes 
and tried removing check for root rights inside FB_OpenKeyboard. This 
revealed necessity to add read permissions to the tty group on the 
/dev/tty2 device. After fixing that, the failing system call now is:

ioctl(5, VT_ACTIVATE, 0x2)  = -1 EPERM (Operation not permitted)

I’ve spent some time investigating this but haven’t find complete solution 
yet.

Taking into account that my ultimate goal is to run pygame without root 
rights as a daemon, I suppose completely eliminating keyboard/console 
terminal initialization is a more promising direction.

Let me know in case you have any advice or suggestion.

 


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-14 Thread Alec Bennett
Another possibility would be to execute a command that moves the mouse way
off screen?

https://unix.stackexchange.com/questions/164262/can-i-simulate-mouse-movements-via-terminal-without-xdotool



On Fri, Jul 14, 2017 at 5:26 AM, Annette Wilson 
wrote:

> Hi, I'm not able to follow along as I don't have a Pi, but since I see
> attempts to dissect the behaviour of the SDL code via strace, I
> thought it worth pointing out that this source code is available and
> need not be treated as a complete black box. You can download it from
> the SDL site. My links below are to an unofficial copy that somebody
> has uploaded to github, but seems to be match the download version.
>
> FB_OpenKeyboard in SDL_fbevents[1] is called unconditionally during
> Framebuffer video initialization.[2] You can see there that *most* of
> the logic to find a keyboard device is guarded by a check that
> geteuid() == 0. (I.e. that the user is root.) The only fallback for
> when not root is to try to open /dev/tty. If it fails to find a
> keyboard device it can use it aborts. I hope that helps back up what
> has been gleaned from the strace and maybe gives some clues.
>
> [1] - https://github.com/infertux/SDL-1.2.7/blob/master/src/
> video/fbcon/SDL_fbevents.c#L246
> [2] - https://github.com/infertux/SDL-1.2.7/blob/master/src/
> video/fbcon/SDL_fbvideo.c#L531
>
> On 13 July 2017 at 21:22, Martin Kühne  wrote:
> > Sorry everyone for the confusion, as was mentioned, two of my previous
> > emails was sent off-list for whatever reason.
> > I read up on the topic arriving at the SE thread that was linked
> > before [0] and tried to figure out the problem based on the work with
> > strace, which I commended as very through and well-conceived. I also
> > asked Roman to tell me whether group membership in `tty` would help,
> > which own the files in /dev on my system. Also Roman, please note that
> > many ioctls return data in pointers that can be passed to them which
> > should be the spot where your results actually differ.
> >
> > cheers!
> > mar77i
> >
> > [0] https://unix.stackexchange.com/questions/117981/what-are-
> the-responsibilities-of-each-pseudo-terminal-pty-component-software.
>


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-14 Thread Annette Wilson
Hi, I'm not able to follow along as I don't have a Pi, but since I see
attempts to dissect the behaviour of the SDL code via strace, I
thought it worth pointing out that this source code is available and
need not be treated as a complete black box. You can download it from
the SDL site. My links below are to an unofficial copy that somebody
has uploaded to github, but seems to be match the download version.

FB_OpenKeyboard in SDL_fbevents[1] is called unconditionally during
Framebuffer video initialization.[2] You can see there that *most* of
the logic to find a keyboard device is guarded by a check that
geteuid() == 0. (I.e. that the user is root.) The only fallback for
when not root is to try to open /dev/tty. If it fails to find a
keyboard device it can use it aborts. I hope that helps back up what
has been gleaned from the strace and maybe gives some clues.

[1] - 
https://github.com/infertux/SDL-1.2.7/blob/master/src/video/fbcon/SDL_fbevents.c#L246
[2] - 
https://github.com/infertux/SDL-1.2.7/blob/master/src/video/fbcon/SDL_fbvideo.c#L531

On 13 July 2017 at 21:22, Martin Kühne  wrote:
> Sorry everyone for the confusion, as was mentioned, two of my previous
> emails was sent off-list for whatever reason.
> I read up on the topic arriving at the SE thread that was linked
> before [0] and tried to figure out the problem based on the work with
> strace, which I commended as very through and well-conceived. I also
> asked Roman to tell me whether group membership in `tty` would help,
> which own the files in /dev on my system. Also Roman, please note that
> many ioctls return data in pointers that can be passed to them which
> should be the spot where your results actually differ.
>
> cheers!
> mar77i
>
> [0] 
> https://unix.stackexchange.com/questions/117981/what-are-the-responsibilities-of-each-pseudo-terminal-pty-component-software.


Fwd: [pygame] How to prevent mouse initialization in Pygame

2017-07-13 Thread Martin Kühne
Sorry everyone for the confusion, as was mentioned, two of my previous
emails was sent off-list for whatever reason.
I read up on the topic arriving at the SE thread that was linked
before [0] and tried to figure out the problem based on the work with
strace, which I commended as very through and well-conceived. I also
asked Roman to tell me whether group membership in `tty` would help,
which own the files in /dev on my system. Also Roman, please note that
many ioctls return data in pointers that can be passed to them which
should be the spot where your results actually differ.

cheers!
mar77i

[0] 
https://unix.stackexchange.com/questions/117981/what-are-the-responsibilities-of-each-pseudo-terminal-pty-component-software.


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-09 Thread Roman Mescheryakov


First some interesting fact. Earlier I wrote that performed limited user 
permissions setup according to reply in the How do I let an SDL app (not 
running as root) use the console 

 
StackExchange post. Today I discovered that rights change on /dev/console 
doesn’t survive reboot. I changed rights back and immediately, without 
rebooting, tried pygame example again. No visible changes, same “Unable to 
open console terminal” error for the limited user.

суббота, 8 июля 2017 г., 6:40:08 UTC+3 пользователь Martin Kühne написал:
>
> > I already changed permissions for the limited user (pi) according to 
> this instruction: How do I let an SDL app (not running as root) use the 
> console, but to no avail :( 
>
> I just wanted to suggest you make sure permissions in /dev are 
> granted, but you appear to have arrived at that conclusion yourself. 
> Of course now you have to figure out which device is being opened 
> unsuccessfully. /dev/console only applies to text i/o and not 
> framebuffer and graphics. /dev/fb0 maybe? Maybe use strace instead? 
>
> cheers! 
> mar77i 
>

I tried running under strace and got 2 log files: one of running under root 
and one for running under limited user (pi). Here is the different part:

ssh terminal, run as root

ssh terminal, run as limited user

Comment

open("/dev/tty0", O_WRONLY) = 5

ioctl(5, VIDIOC_QUERYCAP or VT_OPENQRY, 0x1e5f89c) = 0

close(5)= 0

open("/dev/tty0", O_WRONLY) = 5

ioctl(5, VIDIOC_QUERYCAP or VT_OPENQRY, 0x776e1c) = 0

close(5)= 0

Visible match, but I don’t know whether ioctl output data was the same, 
looking at subsequent system calls I suppose it wasn’t.

Frankly speaking, I don’t understand what does ioctl call with 2 OR’ed 
requests mean…

According to this article  (it’s 
1994!!! But there is no reason not to believe…), ioctl VT_OPENQRY is 
something like “kernel, give me some number of the free terminal I could 
use”

geteuid32() = 0

geteuid32() = 1000

Mismatch: got user ID we are running behind of

open("/dev/vc/2", O_RDWR) = -1 ENOENT (No such file or directory)

Mismatch: there was no try to open "/dev/vc/2" under limited user

open("/dev/tty2", O_RDWR) = 5

Mismatch: there was no try to open "/dev/tty2" under limited user

Looking at this and previous system calls I suppose ioctl VT_OPENQRY 
returned terminal number 2 for the case when pygame was run under root. For 
the limited-user case it’s not clear what was the result of that ioctl.

open("/dev/tty", O_RDWR) = 6

open("/dev/tty", O_RDWR) = 5

Match: opened current terminal device

ioctl(6, TIOCNOTTY) = 0

close(6)= 0


Root version detached itself from the current terminal. As I could find 
using Google, this is what usually daemon processes started from terminal 
do.

ioctl(5, VT_GETSTATE, 0x7ee7da28) = -1 ENOTTY (Inappropriate ioctl for 
device)

According to article mentioned above, ioctl VT_GETSTATE query is something 
like “kernel, give me list of terminals available and their use state”

ioctl(5, KDGKBMODE, 0x7eaf2078) = 0

ioctl(5, KDGKBMODE, 0x7ee7da28) = -1 ENOTTY (Inappropriate ioctl for device)

“Kernel, give me keyboard mode associated with this tty”

Limited-user version run this request on /dev/tty and root-user version run 
on /dev/tty2.

ioctl(5, KDGKBENT, 0x7eaf2078) = 0

close(5)= 0

munmap(0x7434, 3145728) = 0

close(3)= 0

rt_sigaction(SIGINT, NULL, {0x127304, [], SA_RESTORER, 0x76d18180}, 8) = 0

rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0

write(2, "Traceback (most recent call last"..., 35) = 35

Seems previous ioctl result was fatal for limited-user version.

Despite large amount of data from strace, it’s really not clear to me what 
permissions and on what files should I set to allow limited user to run 
pygame from ssh terminal...
 


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-07 Thread Martin Kühne
> I already changed permissions for the limited user (pi) according to this 
> instruction: How do I let an SDL app (not running as root) use the console, 
> but to no avail :(

I just wanted to suggest you make sure permissions in /dev are
granted, but you appear to have arrived at that conclusion yourself.
Of course now you have to figure out which device is being opened
unsuccessfully. /dev/console only applies to text i/o and not
framebuffer and graphics. /dev/fb0 maybe? Maybe use strace instead?

cheers!
mar77i


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-07 Thread Roman Mescheryakov
среда, 5 июля 2017 г., 18:37:31 UTC+3 пользователь Daniel Foerster написал:
>
> Yeah that's not going to work because the attempted imports just fail. If 
> you think having the mouse not initialized might help, change your call to 
> pygame.init() into calls like pygame.display.init().
>

I tried pygame.display.init() already and that didn’t help, mouse pointer 
is still there and root rights are still required for the successful run...

четверг, 6 июля 2017 г., 2:22:41 UTC+3 пользователь Greg Ewing написал:
>
> Probably the framebuffer device is owned by root and only allows 
> access by root. Changing the permissions on /dev/fb might let 
> you avoid the need to run as root. 
>

I already changed permissions for the limited user (pi) according to this 
instruction: How do I let an SDL app (not running as root) use the console 
,
 
but to no avail :(


четверг, 6 июля 2017 г., 3:29:43 UTC+3 пользователь Alec Bennett написал:
>
> Why not just programmatically move the mouse offscreen? 
>
> Or change the mouse cursor to something invisible. Both are easy under wx 
> python, im guessing easy with pygame too. 
>

I know this is possible, there is even dedicated method 
pygame.mouse.set_visible(), but I need to eliminate mouse (or, better, any 
input device) initialization, because I want to run pygame without root 
rights and I believe skipping input devices initialization will let me do 
that.



Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-05 Thread Alec Bennett
Why not just programmatically move the mouse offscreen? 

Or change the mouse cursor to something invisible. Both are easy under wx 
python, im guessing easy with pygame too. 




> On Jul 5, 2017, at 4:22 PM, Greg Ewing  wrote:
> 
> Роман Мещеряков wrote:
>> I instruct pygame to not use X Window server (which, if I understand right, 
>> should set $DISPLAY environment variable), but to use framebuffer.
> 
> Probably the framebuffer device is owned by root and only allows
> access by root. Changing the permissions on /dev/fb might let
> you avoid the need to run as root.
> 
> -- 
> Greg
> 


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-05 Thread Greg Ewing

Роман Мещеряков wrote:


I instruct pygame to not use X Window 
server (which, if I understand right, should set $DISPLAY environment 
variable), but to use framebuffer.


Probably the framebuffer device is owned by root and only allows
access by root. Changing the permissions on /dev/fb might let
you avoid the need to run as root.

--
Greg



Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-05 Thread Daniel Foerster
Yeah that's not going to work because the attempted imports just fail. If
you think having the mouse not initialized might help, change your call to
pygame.init() into calls like pygame.display.init().

On Jul 5, 2017 10:33, "Роман Мещеряков" 
wrote:

>
> среда, 5 июля 2017 г., 3:39:28 UTC+3 пользователь
> mic...@callthecomputerdoctor.com написал:
>>
>> I think I can answer this. When your keyboard and mouse are plugged
>> directly into a Linux box and you're sitting in front of the box using it
>> regularly, the system has already started the X Window server, which is a
>> root-level process, for you.
>>
>> When you log into the Linux box using ssh, you are given a text-only
>> container/shell to play in. The X Window server is attached to a different
>> login instance, not to you. So if you want to have access to the video
>> sub-system from an ssh shell, you need to get root permission.
>>
>> Alternatively, you could set up a VNC daemon server on the Pi to run when
>> your desktop loads, and then from a remote computer, you could log into the
>> Pi and control the desktop. I think that is more what you're looking for.
>>
>
> I’m not sure that X Window server is the cause, because I set up my
> Raspberry Pi to boot to command line. At least I see no desktop GUI after
> booting with keyboard connected, just command line login prompt. There is
> also second reason: I instruct pygame to not use X Window server (which, if
> I understand right, should set $DISPLAY environment variable), but to use
> framebuffer.
>
> But I think you are right in that ssh console and “real” console are
> different in some aspects which are important for pygame initialization.
>
> By the way, I examined __init__.py file of pygame (on my system it’s
> located in /usr/lib/python2.7/dist-packages/pygame/) and found out that
> it imports some modules with self-descriptive names like “key”, “mouse” and
> “joystick”. Moreover, comments and code in this file told me that these
> modules are not mandatory. So I renamed “mouse.so”, “key.so” and
> “joystick.so” in the aforementioned directory. My hope was that this will
> at least help me to get rid of mouse pointer in the top left corner of the
> screen or maybe even will let pygame initialize from ssh console without
> sudo. But, unfortunately, renaming didn’t change anything apart from
> several warnings printed on each pygame import:
>
>
>
> pyscopefb.py:2: RuntimeWarning: import joystick: No module named joystick
>
> (ImportError: No module named joystick)
>
>  import pygame
>
> pyscopefb.py:2: RuntimeWarning: import key: No module named key
>
> (ImportError: No module named key)
>
>  import pygame
>
> pyscopefb.py:2: RuntimeWarning: import mouse: No module named mouse
>
> (ImportError: No module named mouse)
>
>  import pygame
>


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-05 Thread Роман Мещеряков

среда, 5 июля 2017 г., 3:39:28 UTC+3 пользователь 
mic...@callthecomputerdoctor.com написал:
>
> I think I can answer this. When your keyboard and mouse are plugged 
> directly into a Linux box and you're sitting in front of the box using it 
> regularly, the system has already started the X Window server, which is a 
> root-level process, for you. 
>
> When you log into the Linux box using ssh, you are given a text-only 
> container/shell to play in. The X Window server is attached to a different 
> login instance, not to you. So if you want to have access to the video 
> sub-system from an ssh shell, you need to get root permission.
>
> Alternatively, you could set up a VNC daemon server on the Pi to run when 
> your desktop loads, and then from a remote computer, you could log into the 
> Pi and control the desktop. I think that is more what you're looking for.
>

I’m not sure that X Window server is the cause, because I set up my 
Raspberry Pi to boot to command line. At least I see no desktop GUI after 
booting with keyboard connected, just command line login prompt. There is 
also second reason: I instruct pygame to not use X Window server (which, if 
I understand right, should set $DISPLAY environment variable), but to use 
framebuffer. 

But I think you are right in that ssh console and “real” console are 
different in some aspects which are important for pygame initialization. 

By the way, I examined __init__.py file of pygame (on my system it’s 
located in /usr/lib/python2.7/dist-packages/pygame/) and found out that it 
imports some modules with self-descriptive names like “key”, “mouse” and 
“joystick”. Moreover, comments and code in this file told me that these 
modules are not mandatory. So I renamed “mouse.so”, “key.so” and 
“joystick.so” in the aforementioned directory. My hope was that this will 
at least help me to get rid of mouse pointer in the top left corner of the 
screen or maybe even will let pygame initialize from ssh console without 
sudo. But, unfortunately, renaming didn’t change anything apart from 
several warnings printed on each pygame import:

 

pyscopefb.py:2: RuntimeWarning: import joystick: No module named joystick

(ImportError: No module named joystick)

 import pygame

pyscopefb.py:2: RuntimeWarning: import key: No module named key

(ImportError: No module named key)

 import pygame

pyscopefb.py:2: RuntimeWarning: import mouse: No module named mouse

(ImportError: No module named mouse)

 import pygame


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-04 Thread michael
_> I attached keyboard (and mouse) and logged in using this
keyboard. _
_> This was very surprising to me but running my application from
this _

_> real console doesn’t require sudo to use pygame! Why do I need
sudo _

_> when running from SSH console?!_

I think I can answer this. When your keyboard and mouse are plugged
directly into a Linux box and you're sitting in front of the box using
it regularly, the system has already started the X Window server,
which is a root-level process, for you. 

When you log into the Linux box using ssh, you are given a text-only
container/shell to play in. The X Window server is attached to a
different login instance, not to you. So if you want to have access to
the video sub-system from an ssh shell, you need to get root
permission.

Alternatively, you could set up a VNC daemon server on the Pi to run
when your desktop loads, and then from a remote computer, you could
log into the Pi and control the desktop. I think that is more what
you're looking for.

Michael



Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-03 Thread Роман Мещеряков


What I want to do with my Raspberry Pi: my application will run as a 
service and I will interact with it via web interface. There will be 
multimedia projector connected to RPi. Using web interface and pygame-based 
backend of my application I want to output to the projector some test 
patterns like grids, colour fillings etc.


суббота, 1 июля 2017 г., 21:26:53 UTC+3 пользователь Jake b написал:
>
> The best SE to post this would probably be stack overflow. There's quite a 
> few pygame questions.
>
> Do you always require sudo to run, or only if using ssh?
>
>  

I attached keyboard (and mouse) and logged in using this keyboard. This was 
very surprising to me but running my application from this real console 
doesn’t require sudo to use pygame! Why do I need sudo when running from 
SSH console?!

The good point is that using framebuffer on Raspbian without root access is 
possible. Though this point can be not so good after taking into account 
Ian’s words about random user hijacking already running graphical session, 
because this random user could be attacker that managed to get limited user 
access.

There is the second observation. If I run my pygame-using script as a 
service via systemd under limited user, I get the usual “unable to open a 
console terminal” exception (tried with and without mouse and keyboard 
attached). If I run my pygame-using script as a service via systemd under 
root, the service just exits unexpectedly! In /var/log/syslog there is no 
exception or any other useful information about cause of service exiting, 
it seems like some sort of crash. Very mysterious...



Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-01 Thread Jake b
The best SE to post this would probably be stack overflow. There's quite a
few pygame questions.

Do you always require sudo to run, or only if using ssh?

On Jun 30, 2017 1:29 PM, "Роман Мещеряков" 
wrote:

> Hi all,
>
> In my Python application running on Raspberry Pi under Raspbian I use
> Pygame to display some software-generated images via framebuffer. I don’t
> need any input from mouse, keyboard or any other devices, all I need is a
> convenient way of using framebuffer.
>
>
>
> I initialize Pygame in the following way:
>
>
> class FramebufferStaticImage(object):
>
>
>
> black = (0, 0, 0)
>
> white = (255, 255, 255)
>
>
>
> _ENV_VAR_DISPLAY = "DISPLAY"
>
> _instance = None
>
>
>
> def __init__(self, log):
>
> "Ininitializes a new pygame screen using the framebuffer"
>
> # Based on "Python GUI in Linux frame buffer"
>
> # http://www.karoltomala.com/blog/?p=679
>
> if FramebufferStaticImage._instance != None:
>
> raise Exception("No more than 1 instance of
> FramebufferStaticImage is allowed!")
>
> FramebufferStaticImage._instance = self
>
> self._log = log
>
> self._log.info("[fb_static_image] Init: entered")
>
> self._screen = None
>
>
>
> # Try ensure using framebuffer and not X11 display even if it
> exists
>
> if self._ENV_VAR_DISPLAY in os.environ:
>
> del os.environ[self._ENV_VAR_DISPLAY]
>
>
>
> os.putenv('SDL_FBDEV', '/dev/fb0')
>
> os.putenv('SDL_VIDEODRIVER', 'fbcon')
>
> os.environ['SDL_NOMOUSE'] = '1'
>
> os.putenv('SDL_NOMOUSE', '1')
>
> self._log.debug("Current environment is: {env}", env = os.environ)
>
> import pygame
>
> pygame.display.init()
>
>
>
> self._width = pygame.display.Info().current_w
>
> self._height = pygame.display.Info().current_h
>
> self._log.info("[fb_static_image] Framebuffer size: {width} x
> {height}",
>
>width = self._width, height = self._height)
>
> self._screen = pygame.display.set_mode(
>
> (self._width, self._height), pygame.FULLSCREEN)
>
> # Clear the screen to start
>
> self._screen.fill(self.black)
>
> # Initialise font support
>
> pygame.font.init()
>
> # Render the screen
>
> pygame.display.update()
>
> self._log.info("[fb_static_image] Init: leaving")
>
>
>
>
> Problem #1: I have mouse pointer at the top left corner of Pygame-drawn
> images. I want mouse pointer to be hidden.
>
> I know that I can disable mouse pointer using pygame.mouse.set_visible,
> but here comes
>
> Problem #2: I have to run my application with sudo in order for pygame to
> not raise “unable to open a console terminal” exception. But I want to run
> my application without root rights, because this increases my application’s
> security.
>
> There are some posts on forums that recommend setting SDL_NOMOUSE=1
> environment variable before initializing pygame which should skip mouse
> initialization and maybe make it possible to get rid of sudo, but this
> doesn’t work for me: I still need to use sudo and mouse pointer is still
> there.
>
> If this makes any difference, I have no mouse or keyboard attached to the
> Raspberry Pi, I connect to it using SSH.
>
> I use
>
> Pygame version 1.9.2~pre~r3348-2~bpo8+rpi1
>
> libsdl-image1.2 version 1.2.12-5+b1
>
> libsdl1.2debian version 1.2.15-10+rpi1
>
>
>
> Does SDL_NOMOUSE work for anyone using recent Pygame versions?
>
> Is it possible to skip mouse initialization in Pygame?
>
> P.S. This question was originally posted on StackExchange
> ,
> but it seems I chose the wrong section. For this reason or another, I
> haven’t got any straight answer yet, so I write here and hope for the best
> :)
>


Re: [pygame] How to prevent mouse initialization in Pygame

2017-07-01 Thread Ian Mallett
On Fri, Jun 30, 2017 at 12:28 PM, Роман Мещеряков <
roman.mescherya...@gmail.com> wrote:

> In my Python application running on Raspberry Pi under Raspbian I use
> Pygame to display some software-generated images via framebuffer. I don’t
> need any input from mouse, keyboard or any other devices, all I need is a
> convenient way of using framebuffer.
>
>
>
> I initialize Pygame in the following way:
>


> Problem #1: I have mouse pointer at the top left corner of Pygame-drawn
> images. I want mouse pointer to be hidden.
>
> I know that I can disable mouse pointer using pygame.mouse.set_visible,
> but here comes
>
> Problem #2: I have to run my application with sudo in order for pygame to
> not raise “
> ​​
> unable to open a console terminal” exception. But I want to run my
> application without root rights, because this increases my application’s
> security.
>
> There are some posts on forums that recommend setting SDL_NOMOUSE=1
> environment variable before initializing pygame which should skip mouse
> initialization and maybe make it possible to get rid of sudo, but this
> doesn’t work for me: I still need to use sudo and mouse pointer is still
> there.
>
> If this makes any difference, I have no mouse or keyboard attached to the
> Raspberry Pi, I connect to it using SSH.
>
> I use
>
> Pygame version 1.9.2~pre~r3348-2~bpo8+rpi1
>
> libsdl-image1.2 version 1.2.12-5+b1
>
> libsdl1.2debian version 1.2.15-10+rpi1
>
>
>
> Does SDL_NOMOUSE work for anyone using recent Pygame versions?
>
> Is it possible to skip mouse initialization in Pygame?
>
> P.S. This question was originally posted on StackExchange
> ,
> but it seems I chose the wrong section. For this reason or another, I
> haven’t got any straight answer yet, so I write here and hope for the best
> :)
>
​Hi,

It's not exactly clear to me what you're trying to do. It sounds like:

*I want to SSH into a RPI, open a fullscreen window on it, and disable user
input on that window entirely. However, the mouse cursor still shows on
that window, and I can't disable it with `mouse.set_visible(...)` because
that makes my program require root privileges.*

If this is so, your code and attempts are more-or-less what I would have
tried. I don't know enough about Debian to know if that permission error is
insurmountable (I can think of a fairly good reason it should be; you don't
want random users to be able to hijack already running graphical sessions,
although I'd expect opening a fullscreen window would also require root
privileges for the same reason).

If it does turns out to be unworkable, is SSHing into the RPI and uploading
images to an already-running daemon an answer? What exactly are you trying
to do?

Ian​


[pygame] How to prevent mouse initialization in Pygame

2017-06-30 Thread Роман Мещеряков


Hi all, 

In my Python application running on Raspberry Pi under Raspbian I use 
Pygame to display some software-generated images via framebuffer. I don’t 
need any input from mouse, keyboard or any other devices, all I need is a 
convenient way of using framebuffer.

 

I initialize Pygame in the following way:

 
class FramebufferStaticImage(object):



black = (0, 0, 0)

white = (255, 255, 255)

 

_ENV_VAR_DISPLAY = "DISPLAY"

_instance = None



def __init__(self, log):

"Ininitializes a new pygame screen using the framebuffer"

# Based on "Python GUI in Linux frame buffer"

# http://www.karoltomala.com/blog/?p=679

if FramebufferStaticImage._instance != None:

raise Exception("No more than 1 instance of 
FramebufferStaticImage is allowed!")

FramebufferStaticImage._instance = self

self._log = log

self._log.info("[fb_static_image] Init: entered")

self._screen = None

 

# Try ensure using framebuffer and not X11 display even if it exists

if self._ENV_VAR_DISPLAY in os.environ:

del os.environ[self._ENV_VAR_DISPLAY]



os.putenv('SDL_FBDEV', '/dev/fb0')

os.putenv('SDL_VIDEODRIVER', 'fbcon')

os.environ['SDL_NOMOUSE'] = '1'

os.putenv('SDL_NOMOUSE', '1')

self._log.debug("Current environment is: {env}", env = os.environ)

import pygame

pygame.display.init()

 

self._width = pygame.display.Info().current_w

self._height = pygame.display.Info().current_h

self._log.info("[fb_static_image] Framebuffer size: {width} x 
{height}",

   width = self._width, height = self._height)

self._screen = pygame.display.set_mode(

(self._width, self._height), pygame.FULLSCREEN)

# Clear the screen to start

self._screen.fill(self.black)

# Initialise font support

pygame.font.init()

# Render the screen

pygame.display.update()

self._log.info("[fb_static_image] Init: leaving")


 

Problem #1: I have mouse pointer at the top left corner of Pygame-drawn 
images. I want mouse pointer to be hidden.

I know that I can disable mouse pointer using pygame.mouse.set_visible, but 
here comes 

Problem #2: I have to run my application with sudo in order for pygame to 
not raise “unable to open a console terminal” exception. But I want to run 
my application without root rights, because this increases my application’s 
security.

There are some posts on forums that recommend setting SDL_NOMOUSE=1 
environment variable before initializing pygame which should skip mouse 
initialization and maybe make it possible to get rid of sudo, but this 
doesn’t work for me: I still need to use sudo and mouse pointer is still 
there.

If this makes any difference, I have no mouse or keyboard attached to the 
Raspberry Pi, I connect to it using SSH.

I use

Pygame version 1.9.2~pre~r3348-2~bpo8+rpi1

libsdl-image1.2 version 1.2.12-5+b1

libsdl1.2debian version 1.2.15-10+rpi1

 

Does SDL_NOMOUSE work for anyone using recent Pygame versions?

Is it possible to skip mouse initialization in Pygame?

P.S. This question was originally posted on StackExchange 
,
 
but it seems I chose the wrong section. For this reason or another, I 
haven’t got any straight answer yet, so I write here and hope for the best 
:)