Qt5: drawing on X11 root screen (and changing the WId of an existing QWidget - qt5

Is it still possible in Qt5 to draw on the X11 root window and if so, how? As far as I understand this worked in Qt4 by changing the WId of an existing (just created) QWidget:
class Foo : public QWidget;
Foo:Foo(WId id)
        : QWidget()
{
    if (id) {
        create( id, false, true );
    }
}
Apparently this is no longer possible despite what looks like only minor changes to the underlying code.
The sanctioned replacement approach of using
QWidget::fromWindowContainer(QWindow::fromWinId(QX11Info::appScreen()))
does not work for me: I get 2 more or less standard windows plus error messages:
QXcbConnection: XCB error: 8 (BadMatch), sequence: 850, resource id: 37748756, major code: 7 (ReparentWindow), minor code: 0
QXcbConnection: XCB error: 8 (BadMatch), sequence: 962, resource id: 37748760, major code: 7 (ReparentWindow), minor code: 0
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
I'm not calling paintEngine myself, and am also not doing any painting outside of my QWidget::paintEvent() override.
I see similar questions have been asked but remained unanswered, I hope this one has more success.

appScreen returns a screen number, not a window ID. It returns 0 for the first screen/monitor, and that happens to the be default to tell QWidget() to create a new window. You need the QX11Info::appRootWindow() function.

Related

How to close a QInputDialog with after a defined amount of time

I'm currently working on an application that run in the background and sometime create an input dialog for the user to answer. If the user doesn't interact, I'd like to close the dialog after 30 seconds. I made a QThread that act like a timer and the "finished" signal should close the dialog. I unfortunately cannot find a way to close it.
At this point I'm pretty much lost. I completely new to QThread and a beginner in PyQt5
Here is a simplified version of the code (we are inside a class running a UI):
def Myfunction(self,q):
# q : [q1,q2,q3]
self.popup = counter_thread()
self.popup.start()
self.dial = QInputDialog
self.popup.finished.connect(self.dial.close)
text, ok = self.dial.getText(self, 'Time to compute !', '%s %s %s = ?'%(q[0], q[2], q[1]))
#[...]
I tried ".close()" and others but i got this error message:
TypeError: close(self): first argument of unbound method must have type 'QWidget'
I did it in a separated function but got the same problem...
You cannot close it because the self.dial you created is just an alias (another reference) to a class, not an instance.
Also, getText() is a static function that internally creates the dialog instance, and you have no access to it.
While it is possible to get that dialog through some tricks (installing an event filter on the QApplication), there's no point in complicating things: instead of using the static function, create a full instance of QInputDialog.
def Myfunction(self,q):
# q : [q1,q2,q3]
self.popup = counter_thread()
self.dial = QInputDialog(self) # <- this is an instance!
self.dial.setInputMode(QInputDialog.TextInput)
self.dial.setWindowTitle('Time to compute !')
self.dial.setLabelText('%s %s %s = ?'%(q[0], q[2], q[1]))
self.popup.finished.connect(self.dial.reject)
self.popup.start()
if self.dial.exec():
text = self.dial.textValue()
Note that I started the thread just before showing the dialog, in the rare case it may return immediately, and also because, for the same reason, the signal should be connected before starting it.

SDL_CreateWindowFrom vs SDL_DestroyWindow X11 error SDL2

I get a window ID from the command line, and create an SDL window with it:
Window window_id = from_cli(); // e.g. 0x34000c8
w = SDL_CreateWindowFrom((void*) (Window) window_id);
When my program finishes I try to clean up:
SDL_DestroyWindow(w);
And that is when I got an X11 error:
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 3 (X_GetWindowAttributes)
Resource id in failed request: 0x34000c8
Serial number of failed request: 255
Current serial number in output stream: 256
Obviously, the caller of my program - which I cannot change - has already destroyed the X window I was using.
How should I handle this situation?
SDL_DestroyWindow() can be omitted if the SDL window was created with SDL_CreateWindowFrom()
go for SDL_SysWMinfo, pick up x11.display, create my own X11 error handler, and filter errors for window_id?
Looking at the SDL2-2.0.9 source code, it seems that SDL already sets an error handler, which calls the previous error handler, which is the default one that terminates the program on error. (src/video/x11/SDL_x11video.c::X11_SafetyNetErrHandler())
Internally SDL will override this error handler temporarily, when doing its own stuff. (src/video/x11/SDL_x11video.c::X11_CheckWindowManager())
Thus, I guess 2) is the correct way to go.
EDIT:
When omitting SDL_DestroyWindow(), SDL_Quit() will fail with the same X error.
I also realized that SDL may not anticipate a failed X call, so ignoring the error may not be a good idea, after all.
EDIT2:
I just realized that SetErrorHandler() does not require a display.
Adding an X error handler that ignores X errors regarding this particular X window seems to work, not sure if it creates new problems unseen.
Is there preferred way to handle this problem?
Version:
SDL2-2.0.9

I need help upgrading OroCommerce to 4.1.1

I just upgraded from 3.1.17 to 4.1.1 and I'm finding a problem with my shopping lists.
When I get to /customer/shoppinglist/5064 I see this:
Looking at my log files from production I see:
[2020-06-23 17:42:56] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\UndefinedMethodError: "Attempted to call an undefined method named "getDigitalAsset" of class "Proxies\__CG__\Oro\Bundle\AttachmentBundle\Entity\File"." at /usr/share/nginx/html/oroapp/vendor/oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php line 47 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Attempted to call an undefined method named \"getDigitalAsset\" of class \"Proxies\\__CG__\\Oro\\Bundle\\AttachmentBundle\\Entity\\File\". at /usr/share/nginx/html/oroapp/vendor/oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php:47)"} []
I went to look at the code and I see that in fact there is no method getDigitalAsset in oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php, nor in the proxy... how can this be?
I checked this on my VM (where the problem is not happening) and I see that there's this definition in the proxy class:
/**
* {#inheritDoc}
*/
public function getDigitalAsset()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getDigitalAsset', []);
return parent::getDigitalAsset();
}
But again, I don't see a method called getDigitalAsset in the parent class.
I had some issues when doing the upgrade (I realized my nodejs wasn't upgraded as I thought it was), could that have anything to do with the issue?
Thanks
Edit:
I went through my platform upgrade again and found that there were some problems that prevented it from finishing completely.
This is what I found:
> loading Oro\Bundle\CMSBundle\Migrations\Data\ORM\LoadImageSlider
In LoadImageSlider.php line 117:
Attempted to call an undefined method named "setMainImage" of class "Oro\Bundle\CMSBundle\Entity\ImageSlide".
I commented out the loop inside the load method and re-run the upgrade. Then I got:
> loading Oro\Bundle\CMSBundle\Migrations\Data\ORM\LoadImageSlider
In QueryException.php line 65:
[Semantical Error] line 0, col 117 near 'digitalAsset': Error: Class Oro\Bundle\AttachmentBundle\Entity\File has no association named digitalAsset
In QueryException.php line 43:
SELECT file, digitalAsset, sourceFile FROM Oro\Bundle\AttachmentBundle\Entity\File file INNER JOIN file.digitalAsset digitalAsset INNER JOIN digitalAsset.sourceFile sourceFile WHERE file.parentEntityClass = :parentEntityClass
AND file.parentEntityId = :parentEntityId AND file.parentEntityFieldName =
:parentEntityFieldName
Finally I was able to complete the upgrade by commenting out the whole body of the load method
I had some issues when doing the upgrade (I realized my nodejs wasn't upgraded as I thought it was), could that have anything to do with the issue?
It looks like you have multiple versions of nodejs installed. To make an application use the right one, you can provide the absolute path to the executable with the AssetBundle configuration, like:
# config/config.yml
oro_asset:
nodejs_path: /usr/local/node
npm_path: /usr/local/npm

How to fix problem with 'getColor' getting every car being green?

I'm making a program that makes the cars running in the simulation pass on their colors to other cars, to achieve that I'm using the TraCi function 'getColor'. The problem is that every car that I ask the color returns (255,255,0,255) doesn't matter what the actual color is. However, using 'getColor' inside a condition for the "contamination" makes the program work, maybe out of sheer luck. Please help me understand how to fix it and how it works.
I'm on Ubuntu 18.04.3 LTS, SUMO 0.32.0 and using the traci library. I've tried modifying the program and running the simulation step by step, even running the same line in different code with the same idea in mind.
This is the program in which the "contamination" works although it gets the wrong colors:
def run():
step = 0
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
step += 1
if step > 2:
if distancia("veh1","veh0") < 5:
traci.vehicle.setColor("veh1",(255,0,0,255))
if distancia("veh0","veh2") < 5 :
traci.vehicle.setColor("veh2",(255,0,0,255))
if traci.vehicle.getColor("veh2") == (255,0,0,255):
if distancia("veh1","veh2") < 5 :
traci.vehicle.setColor("veh1",(255,0,0,255))
print(traci.vehicle.getColor("veh1"))
traci.close()
sys.stdout.flush()
I hoped when I selected the red car I would get (255,0,0,255), but I got (255,255,0,0). But it doesn't get any error messages, just shows the worng color.
It seems that the default color for traci is yellow, I'd to set every car to its own color from the python code to start doing what I wanted.

Lua: ProteaAudio API confuse -- How to use it?

Hello everyone.
Sorry for my noob question as I'm just a non-programmer trying to learn to program with Lua.
I'm so attracted with Lua since it's indeed very simple, either in size as well as in syntax.
And I decided to explore further experiment with this Brazilian born language, like playing with sound -- as I did in Python and Ruby.
So I found this ProteaAudio and tried to play the sample scripts came within package I downloaded from here.
The package comes with two sample scripts:
first named example.lua to play the ogg sample file (also comes within the package)
and another to play function generated sound named scale.lua
The first script runs just fine on my Win 7 and Ubuntu 12.04 x86 machine.
But the second script only runs on Windows and got an error when I tried to run it on Ubuntu, generating this message:
../lua52: scale.lua:13: bad argument #1 to 'soundLoop' (number expected, got nil)
stack traceback:
[C]: in function 'soundLoop'
scale.lua:13: in function 'playNote'
scale.lua:29: in main chunk
[C]: in ?
The full original source-code from scale.lua is:
-- function creating a sine wave sample:
function sampleSine(freq, duration, sampleRate)
local data = { }
for i = 1,duration*sampleRate do
data[i] = math.sin( (i*freq/sampleRate)*math.pi*2)
end
return proAudio.sampleFromMemory(data, sampleRate)
end
-- plays a sample shifted by a number of halftones for a definable period of time
function playNote(sample, pitch, duration, volumeL, volumeR, disparity)
local scale = 2^(pitch/12)
local sound = proAudio.soundLoop(sample, volumeL, volumeR, disparity, scale)
proAudio.sleep(duration)
proAudio.soundStop(sound)
end
-- create an audio device using default parameters and exit in case of errors
require("proAudioRt")
if not proAudio.create() then os.exit(1) end
-- generate a sample:
local sample = sampleSine(440, 0.5, 88200)
-- play scale (a major):
local duration = 0.5
for i,note in ipairs({ 0, 2, 4, 5, 7, 9, 11, 12 }) do
playNote(sample, note, duration)
end
-- cleanup
proAudio.destroy()
And since I got confused with this ProteaAudio Lua API, I really can't get why this error comes.
Please help.
This is actually just a guess, but...
To play a "major" scale upwards (8 notes, jumping: full full half, full full full half) the original code does:
local duration = 0.5
for i,note in ipairs({ 0, 2, 4, 5, 7, 9, 11, 12 }) do
playNote(sample, note, duration)
end
where the sample is a handle to a pre-generated sample created by proAudio.sampleFromMemory which is returned by function sampleSine, that passed it a calculated 'table' representing a 440hz sine-wave (concert-pitch frequency for note 'A4', the first above middle 'C').
Thus playing an 'A major scale' by changing (increasing) the 'pich' (frequency) of that sample (in 8 steps=notes). That pitch-calculation is done by function playNote.
Function playNote accepts the following arguments:
sample, pitch, duration, volumeL, volumeR, disparity,
but it currently does not receive the arguments:
volumeL, volumeR, disparity (which will then be nil).
So when function playNote tries to call:
proAudio.soundLoop(sample, volumeL, volumeR, disparity, scale),
then the call will end up like:
proAudio.soundLoop(sample, nil, nil, nil, scale),
where the sample is passed on and scale is the 'playback-pitch' of that sample, as just calculated (according to specified note) by function playNote.
Your error-message states: bad argument #1 to 'soundLoop' (number expected, got nil).
Hmm, that seems consistent with what is happening (assuming that 'bad argument #1' is the second argument, in this case volumeL).
So,
you might want to try specifying some values for volumeL, volumeR, disparity like:
local duration = 0.5
local volumeL = 1.0
local volumeR = 1.0
local disparity = 0.0
for i,note in ipairs({ 0, 2, 4, 5, 7, 9, 11, 12 }) do
playNote(sample, note, duration, volumeL, volumeR, disparity)
end
From the proteaAudio documentation one can read about soundLoop's arguments:
sample - A sample handle returned by a previous load() call
volumeL - (optional) Left volume
volumeR - (optional) Right volume
disparity - (optional) Time difference between left and right channel in seconds.
Use negative values to specify a delay for the left
channel, positive for the right.
pitch - (optional) Pitch factor for playback. 0.5 corresponds to one octave
below, 2.0 to one above the original sample.
If that should do the trick, then the arguments might not be so optional on Ubuntu.
Hope this helps!