ChatCrawlersearch across public Telegram Open the app
Q

Qt for Python (PySide/Shiboken)

19 October 2023
2023-10-19×
19 October 2023
I
Hello! Does anyone know if it's possible to keep the last frame at the end of a video when using QMediaPlayer? The current behavior is to display a black screen right after EndOfMedia has been reached, which is very unpleasant for my application purposes :/ I know some "hacks" that make use of the positionChanged signal, but I wonder if there is a clean solution to this?
T
Markus BauerWhat is the pythonic way to create a notify signal for a Property when I use the @Property decorator?
I’d say declare the signal with in the class definition with propertyNameChanged = Signal(parameter_type) and explicitly emit it in the property setter, if the new value differs from the old. That's plain and obvious when reading the code, and IDEs do find the signal usage. Now, there's a clash between Qt's name convention for change signals (using camelCase, like valueChanged), and Python, using snake_case, for example value_changed. PEP8 and related style guildes aren't set in stone, so I’d say, take the choice with the highest consistency
M
That's what I am doing now: runFilter_changed = Signal(name="runFilterChanged") @Property(bool, notify=runFilter_changed) and than I have @runFilter.setter def runFilter(self, val): print( val ) self._runFilter = val self.runFilter_changed.emit() But this doesn't feel pythonic I tried with @Property(bool, notify=Signal(name="runFilterChanged")) but so I can't emit it anymore
T
Markus BauerThat's what I am doing now: runFilter_changed = Signal(name="runFilterChanged") @Property(bool, notify=runFilter_changed) and than I have @runFilter.setter def runFilter(self, val): print( val ) self._runFilter = val self.runFilter_changed.emit() But thi
Ссылка
click to show
Notify signals typically carry the new value, like https://doc.qt.io/qt-6/qlineedit.html#textChanged, so I’d include that. Otherwise the receiver has to go lengths retrieving the new value, if they want to do something with it. Also, you probably shouldn't mix both styles and produce camelCase_snake_case. That's neither Qt's naming scheme nor Pythonic according to PEP8 style. Either have run_filter and run_filter_changed, or runFilter and runFilterChanged. And yeah, the last doesn't assign it to a Python variable, so it gets garbage collected immediately, and may cause RuntimeErrors later.
So more like this? runFilterChanged = Signal(bool, name="runFilterChanged") @Property(bool, notify=runFilterChanged) def runFilter(self): return self._runFilter @runFilter.setter def runFilter(self, val): self._runFilter = val self.runFilterChanged.emit(val)
Are you sure it will be garbage collected? As you assign it to the notify, it should stick I did not find it in the sources tbh
M
And yes you could improve by an if self._runFilter != val
T
Markus BauerAre you sure it will be garbage collected? As you assign it to the notify, it should stick I did not find it in the sources tbh
I'm relatively sure that doing only @Property(bool, notify=Signal(name="runFilterChanged")) will cause the Signal() instance (the PyObject wrapping the underlying C++ object) to get GC'ed, but I'm not 100% on that. If you pass something to a Qt function, it will not keep a reference to the PyObject, but only the wrapped object. If there's no reference to the wrapper in Python code, the GC will eat it.
Calendar: October 2023
MoTuWeThFrSaSu1239456578398102611171221314115167171218151916202122231624125226127428293031
Archive by month
Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog