I've been working on a 2D game playable in the terminal. I began working on the project in Ubuntu 20.04. I use pynput to tap f11 to get the terminal full-screen and then I use pynput.mouse to get the mouse position so my asset can follow it. Everything worked fine, I had a little controllable ASCII spaceship flying on the screen.
Here is my problem : since I upgraded to Ubuntu 22.04, pynput seems to work only if my mouse is not hovering the terminal, if it is, it does nothing.
This code :
from pynput.mouse import Controller
mouse = Controller()
while True:
print(mouse.position)
works fine while the mouse is outside my terminal window but when I hover the terminal, mouse.position returns always the same value, the last value when my cursor wasn't hovering the window. Same problem with keyboard.tap, the key get pressed only when I'm in another window, like Atom for example.
I use python 3.10.4
EDIT :
I noticed that the problem occurs with the entire gnome interface but works with other apps like Firefox or Atom.
Moreover, I've just tried pyautogui and it behaves the same way as pynput, it doesn't work.
Related
I'm attempting to simulate the native MacOS "Window" menu in PYQT5. I am able to cycle through open windows via my menu and indicate the active window by setting its checked state to True.
I would like to also simulate the MacOS HID icon assigned when a window is minimized like this:
However, the closest I have been able to come is with a QIcon, which isn't quite right (the icon isn't quite right either, but I can live with that).
bring = self.view_menu.addAction('&Bring to Front', self.foo)
bring.setIcon(QtGui.QIcon("diamond.png"))
Is it possible to have the QIcon displayed in the left menu column (aligned with the checkmark) or otherwise display a diamond for an action item like MacOS? I didn't see any parms for the QIcon class that appeared to do this.
I built a game with ncurses because of pdcurses' resizing problems i switched to cygwin.
Compiled the game with cygwin and it worked almost perfectly.
Some acs_variables (i.e. ACS_DIAMOND) are seen as a question mark.
When i ran the game the cursor appears at the beginning of the snake (made a traditional snake game with c++) and also appears at the pause menu;
For example: >_ New Game .
2,5. There is also a frame in the window i've set it like this;
box(window, char(219), 0);
-> top and bottom sides are displayed as straight line just as expected; However left and right sides, instead of char(219) there was blue and red lines, side by side.
I first made the game with visual studio and worked just normal except the resizing problem.
I've tried to change Character set to UTF-8 in the Text submenu of the cygwin, it didn't work.
In my code, i already set curs_set(0) function so cursor shouldn't have appeared in the game.
I am new to cygwin, looked over the internet but couldn't find a solution.
So any help will be appreciated!
Thanks in advance.
while True:
x=pyautogui.position()
print(x+pyautogui.pixel(x[0],x[1]))
and program is picking up color that is actually upper left of my cursor...
I am using python 3.6, windows 10, on 125% magnification. is this one of the reason?
Usually picking color with the mouse gives NOT the color of the mouse pointer on the screen but the color of the screen 'below' the cursor.
On my box (Linux Mint) the code:
import pyautogui
while True:
posXY = pyautogui.position()
print(posXY, pyautogui.pixel(posXY[0], posXY[1]) )
if posXY[0] == 0:
break
delivers what it should - the color 'below' the mouse pointer.
Notice the 'break' in the endless loop. This allows you to stop the loop by moving the mouse to the left edge of the screen :)
I have the same setup as yours (but Python 3.7) and faced the very same issue.
Why it occurred? Every now and then I connect and disconnect the external monitor from my laptop. This causes certain scaling issues every time. So, I tried restarting my computer with the external monitor connected and did not disconnect it until I ran this script. It worked like a charm. BTW, I also tried just restarting the Windows Explorer, but this did not resolve the issue.
tldr; Restart your PC and do not modify the display configuration since the restart
I have an issue with the fullscreen state of my QMainWindow (I use QT 5.3.1).
It works perfectly well with Windows and Debian on a PC, but when I try it on a tablet PC (C22 Tablet PC, Ekoore) with Ubuntu 14.04, the behavior is different.
As you can see on the below screenshot, the task bar and the window border are hidden, but it seams that the window is not resized to take all the screen...
http://postimg.org/image/ouyb1fvz5/
I confirmed that by printing debug in the resizeEvent method. Nothing happen when I call showFullscreen().
What is wrong here ? Have you any ideas ? I cannot find anything about that problem.
Thanks in advance. Cedric
I fixed my problem. My window was too big and a part was out of the screen before the call to showFullscreen().
It seams that the resize does not work in this case.
After resizing my window in Qt Creator, the fullscreen now works fine. I do not have a better answer about why it does not work on ubuntu when the window is too big.
I have a full screen application based on Qt. Full screen applications should always be on top because otherwise part of the window will be obstructed. I want the frameless full screen window to have child windows (special dialogs, ..). These child windows should be shown on top of the full screen window. Not much sense in showing them below.
A short, self contained example is:
from PySide import QtGui, QtCore
app = QtGui.QApplication([])
window = QtGui.QWidget(f=QtCore.Qt.WindowStaysOnTopHint)
child_window = QtGui.QWidget(window, f=QtCore.Qt.Window)
child_window.resize(400, 300)
layout = QtGui.QVBoxLayout(window)
exit = QtGui.QPushButton('Exit')
exit.clicked.connect(app.exit)
layout.addWidget(exit)
create = QtGui.QPushButton('Create child window')
create.clicked.connect(child_window.show)
layout.addWidget(create)
layout.addStretch()
window.showFullScreen()
app.exec_()
It's written in Python and tested on Python 3.X + PySide 1.2.2 (Qt 4.8) + Ubuntu 14.04 (Unity desktop) or Windows 7. However transformation to C++ Qt (or PyQt) should be straightforward.
The observation is that on Windows everything is as described at the beginning. The Qt.WindowsStaysOnTopHint is not necessary, while on Ubuntu it is.
On Ubuntu I see that initially the full screen main window is on top of everything but as soon as a child dialog window is created the usual desktop decorations (top and left bars) are shown above the full screen main window obstructing part of the view! As soon as the child window is closed the full screen window is on top again.
Question is now if there is anything that can be done to have a full screen window which is on top plus child windows on Ubuntu and with Qt?
The different behavior between Windows and Linux is also not satisfying because OS specific code should be avoided if possible.
Later:
Using the overview of available desktop environment on Ubuntu I installed several environments and tested them.
KDE, Lubuntu (Lxde?) and Openbox work as expected (and equally to Windows). The main window stays on top when shown full screen and child windows are displayed above.
However for Gnome-Shell (Gnome 3), Xfce, Unity and Awesome the desktop decoration stays on top of full screen mode windows of children windows are displayed also. Xfce and Unity behave exactly equal, Gnome and Awesome have even some small additional problems.
Did you tried thing which documentation suggests?
Qt::WindowStaysOnTopHint 0x00040000 Informs the window system that the window should stay on top of all other windows. Note that on
some window managers on X11 you also have to pass
Qt::X11BypassWindowManagerHint for this flag to work correctly.
Another thing why you want other window to be a child if it you what to be under a parent?