How create a signal with checkbox in QTableWidget Pyqt6 - python-3.x

I begin with python v3.10, I use actually PyQt6 for the design of the windows.
I created a QTableWidget in which I put a checkbox with a picture.
Now I would like to create a signal to execute a function when I click on it.
I tried, connect, stateChanged, ... but nothing works.
I write below my code with a picture :
while self.query.next():
# widget checkbox
checkbox_widget = QWidget()
checkbox_widget.setStyleSheet('background-color: transparent;')
w_checkbox = QtWidgets.QCheckBox
layout_cb = QtWidgets.QHBoxLayout(checkbox_widget)
layout_cb.addWidget(w_checkbox())
layout_cb.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout_cb.setContentsMargins(0, 0, 0, 0)
checkbox_widget.setLayout(layout_cb)
tablerow = self.table_EP.rowCount()
self.table_EP.insertRow(tablerow)
self.table_EP.setItem(tablerow, 0, QtWidgets.QTableWidgetItem((self.query.value('col1'))))
self.table_EP.setItem(tablerow, 1, QtWidgets.QTableWidgetItem((self.query.value('col2'))))
self.table_EP.setItem(tablerow, 2, QtWidgets.QTableWidgetItem((self.query.value('col3'))))
self.table_EP.setItem(tablerow, 3, QtWidgets.QTableWidgetItem((str(self.query.value('col4')))))
self.table_EP.setItem(tablerow, 4, QtWidgets.QTableWidgetItem((str(self.query.value('col5')))))
self.table_EP.setItem(tablerow, 5, QtWidgets.QTableWidgetItem((str(self.query.value('col6')))))
self.table_EP.setItem(tablerow, 6, QtWidgets.QTableWidgetItem((self.query.value('col7'))))
self.table_EP.setItem(tablerow, 7, QtWidgets.QTableWidgetItem((str(self.query.value('col8')))))
self.table_EP.setItem(tablerow, 8, QtWidgets.QTableWidgetItem((str(self.query.value('col9')))))
self.table_EP.setCellWidget(tablerow, 9, w_checkbox())
self.table_EP.setCellWidget(tablerow, 9, checkbox_widget)
w_checkbox.stateChanged.connect(self.clicked_button())
enter image description here
Thank you so much for your help (I'm sorry for my English).

This is some weird code.
Ultimately you need to call .stateChanged.connect(self.clicked_button()) on the instance of QtWidgets.QCheckBox.
You create an instance of the class QtWidgets.QCheckBox with this line: layout_cb.addWidget(w_checkbox()), but you don't assign it to a variable.
You should first assign it to a variable, then refer to it using that variable, like so:
checkbox = QtWidgets.QCheckBox()
layout_cb.addWidget(checkbox)
checkbox.stateChanged.connect(self.clicked_button())
Are you sure you need the brackets after self.clicked_button()? That only makes sense if it returns a function.

Related

What is the inverse of torch.fft.fft() for pytorch1.10?

I am using 1.10.2+cu113.
In pytorch 1.7, the code is
ffted = torch.rfft(input, 1, onesided=False)
iffted = torch.irfft(ffted, 1, onesided=False)
I want to migrate it in new version of pytorch.
Here is my code.
ffted = torch.fft.fft(input)
iffted = torch.fft.ifft(ffted)
But iffted is complex. That is not what I want. I did not found the inverse function of torch.fft.fft.
So what is the correct function I should call?
BTW: input.shape=torch.Size([1, 1, 4000, 10])

Best way to generate a Texture.tres 's data by code available in the editor

I want to have MyTexture.tres to generate the Image, and be able to visualise it both at run time and in the editor.
The goal is to have my own Texture type as a Resource file, that can be used like NoiseTexture, GradientTexture, etc, and to use it in the editor (on a Sprite, as a shader uniform...) and NOT to save any image data in project folder.
tool
extends ImageTexture
export var width := 100
export var height := 100
func _init():
var image := Image.new()
# ...
# Generate the image data array
# ...
create_from_image(image)
Using the tool keyword, it works but the Image data is automatically saved into MyTexture.tres, so it break the best advantage that is to save a lot of space.
I assign a script to the .tres file trying inheriting both ImageTexture and ProxyTexture, but the result is the same once I call create_from_image() it saves it to the file.
[sub_resource type="Image" id=3]
data = {
"data": PoolByteArray( 127, 119, 254, 131, 131, 119, 25, ... ) <-----
"format": "RGBA8",
"height": 512,
"mipmaps": false,
"width": 512
}
May be I will try inheriting ViewportTexture but even if it works it seem wrong, that require accessing the SceneTree to instanciate the Viewport (from a Resource script), may be is there a clean way ?

Polling Socket Select inside Docker on Windows (via Python/Pyramid)

tl;dr - Example code from Pyramid cookie cutter example does not respond to requests generated from outside the hosting Docker container on Windows. Other code that doesn't rely on non-blocking I/O (socket select) seems to work as expected.
References:
https://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/cookiecutters.html
https://github.com/Pylons/pyramid-cookiecutter-starter
I am trying to work through some of the example code for using Pyramid (the Python-based web development framework). I am doing this from inside a Docker container (3.6.9-Buster) on Windows 10. Should be simple, at least for running some sample code, right?
It has, predictably, been a nightmare.
The example code just will not work. Problems with lack of IPv6 support choking the code that presumes/requires it, and so on.
Currently, I have the test server from the cookie-cutter-starter running and binding to the port successfully, but it never responds to requests from outside the container.
As background, I haven't touched web development in over 15 years, and avoid Python as much as possible (which is impossible these days), so I could be missing something obvious.
Now, I definitely have the port forwarding enabled properly. I was able to bring up a different HTTP server in the container (also written in Python) on the same port successfully and communicate with it from outside the container. In the case of the example I am working on, however, I only seem to be able to get it to respond to a connection if I spawn another thread inside the Python process and connect from there.
The embedded cookie cutter server, waitress (I think that's the name, it has a ton of unnecessary redirection and wrappers and superfluous classes, so its hard to be sure what is what), is using non-blocking I/O. Where it calls the socket select during polling is apparently where the problem occurs. The select never returns a connection initiated from the outside.
I haven't found any kind of firewall issues. And, as I said, I am able to communicate with other Python code executed from within the container, so I don't think there is anything wrong with the system configuration in that regard. This seems specific to the socket select and non-blocking I/O, which appears to be the main difference between the server implementations.
#From within env/lib/python-3.6/site-packages/waitress/wasyncore.py:
def poll(timeout=0.0, map=None):
if map is None: # pragma: no cover
map = socket_map
if map:
r = []; w = []; e = []
for fd, obj in list(map.items()): # list() call FBO py3
is_r = obj.readable()
is_w = obj.writable()
if is_r:
r.append(fd)
# accepting sockets should not be writable
if is_w and not obj.accepting:
w.append(fd)
if is_r or is_w:
e.append(fd)
if [] == r == w == e:
time.sleep(timeout)
return
try:
#Attention StackOverflow: Note the print statements here.
print("\n select(r=", r, ", w=", w, ", e=", e, ")\n")
r, w, e = select.select(r, w, e, timeout)
print(" r=", r, " w=", w, " e=", e, " = select(...)\n")
except select.error as err:
if err.args[0] != EINTR:
raise
else:
return
for fd in r:
obj = map.get(fd)
if obj is None: # pragma: no cover
continue
read(obj)
for fd in w:
obj = map.get(fd)
if obj is None: # pragma: no cover
continue
write(obj)
for fd in e:
obj = map.get(fd)
if obj is None: # pragma: no cover
continue
_exception(obj)
Expected (also, results when connecting from another thread within the container):
select(r= [5, 6] , w= [] , e= [5, 6] )
r= [6] w= [] e= [] = select(...)
select(r= [5, 6, 8] , w= [] , e= [5, 6, 8] )
r= [8] w= [] e= [] = select(...)
select(r= [5, 6] , w= [8] , e= [5, 6, 8] )
r= [5] w= [8] e= [] = select(...)
select(r= [5, 6] , w= [] , e= [5, 6] )
r= [] w= [] e= [] = select(...)
Actual:
select(r= [5, 6] , w= [] e= [5, 6] )
r= [] w= [] e= [] = select(...)
Is this a known bug? Is non-blocking I/O not supported by Docker on Windows? Is there some other complicating factor that might cause select to come up empty every time?
My best guess is that somewhere in the path from the Windows kernel through the Docker layer, the flag for the select is getting lost, and it never propagates up to the Python code.
All I can do from here, I think, is to test the socket library in isolation and perhaps test the system calls from C. If I understand correctly, Python is just passing through to the system calls anyway. In any case, that won't necessarily isolate the cause of problem, nor does it seem to offer hope of a solution.
At this point, I am on the verge of just scrapping all projects that would depend on this sort of thing, because they may not be worth the hassle. If canned example code is this much trouble, it perhaps doesn't seem worth using as a platform. Just run away as fast as I can? Is it just going to be one problem after another, until I re-write the whole stack myself? Am I almost to the point where I can start doing what I originally set out to do (programming a web interface)?
EDIT: Thanks for the reply. I may not continue with this, since it's such a hassle. For completeness, I'm adding the suggested information and will leave this open for a day or two, then I may close it. As requested, here's the development.ini section:
[server:main]
use = egg:waitress#main
listen = 0.0.0.0:6543
And here is the command used to start the container:
docker run -t -p 6543:6543 --mount src=".",target=/scratch,type=bind --interactive pyramid_hello_world
Hopefully it is useful to someone.

javascript - how to generate and save empty zip with FileSaver.js

I am trying to to generate and save empty zip with FileSaver.js in Chrome browser.
saveAs(new Blob([], {type: "application/zip"}), "empty.zip");
it asks me to save "empty.zip" on disk.
file is being created fine (0 bytes)
i can drag and drop file in Windows explorer there.
but 7-zip does not open it
what should i pass as Blob content argument instead of empty array [] to get proper zip ?
An empty zip file is not an empty file: it needs an "end of central directory record" listing 0 entry (see 4.3.16 End of central directory record for the reference). Even with that, some tools complain that the zip file is empty. I can't test 7zip right now, it may happens to you.
If you don't want to load a zip library just to generate this empty zip file, you can write the 22 bytes:
var buffer = new Uint8Array([ 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]).buffer;
var blob = new Blob([buffer], {type: "application/zip"});

How to input website using os.execute("input text \"...\"")

os.execute("input text \"tp://www.lua.org/manual/2/2.1/\"");
os.execute("input text \"tp://www.lua.org/manual/2/3.1/\"");
4
5
I want to set a variable called i,
for i =2, 5, 1 do
os.execute("input text \"tp://www.lua.org/manual/2/**i**.1/"");
However, I failed.
You need to parse it inside the string. Like this:
for i = 2, 5, 1 do
os.execute( string.format("input text \"tp://www.lua.org/manual/2/%d.1/\"", i) );
Or even better:
for i = 2, 5, 1 do
os.execute( string.format([[input text "tp://www.lua.org/manual/2/%d.1/"]], i) );
See it at work here on codepad.

Resources