PyQt demo app (#21625)
* build python helpers lib
* call setMainWindow from python
* put in helper lib
* linter
* move to scripts
old-commit-hash: 25e4e94691
commatwo_master
parent
0afe7d74bc
commit
0d035f6898
5 changed files with 64 additions and 17 deletions
@ -0,0 +1,14 @@ |
|||||||
|
#!/usr/bin/env python3 |
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QApplication, QLabel # pylint: disable=no-name-in-module, import-error |
||||||
|
from selfdrive.ui.qt.python_helpers import set_main_window |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
app = QApplication([]) |
||||||
|
label = QLabel('Hello World!') |
||||||
|
|
||||||
|
# Set full screen and rotate |
||||||
|
set_main_window(label) |
||||||
|
|
||||||
|
app.exec_() |
@ -0,0 +1,21 @@ |
|||||||
|
|
||||||
|
import os |
||||||
|
from cffi import FFI |
||||||
|
|
||||||
|
import sip # pylint: disable=import-error |
||||||
|
|
||||||
|
from common.ffi_wrapper import suffix |
||||||
|
from common.basedir import BASEDIR |
||||||
|
|
||||||
|
|
||||||
|
def get_ffi(): |
||||||
|
lib = os.path.join(BASEDIR, "selfdrive", "ui", "qt", "libpython_helpers" + suffix()) |
||||||
|
|
||||||
|
ffi = FFI() |
||||||
|
ffi.cdef("void set_main_window(void *w);") |
||||||
|
return ffi, ffi.dlopen(lib) |
||||||
|
|
||||||
|
|
||||||
|
def set_main_window(widget): |
||||||
|
ffi, lib = get_ffi() |
||||||
|
lib.set_main_window(ffi.cast('void*', sip.unwrapinstance(widget))) |
@ -0,0 +1,25 @@ |
|||||||
|
#include "selfdrive/ui/qt/qt_window.h" |
||||||
|
|
||||||
|
void setMainWindow(QWidget *w) { |
||||||
|
const bool wide = (QGuiApplication::primaryScreen()->size().width() >= WIDE_WIDTH) ^ |
||||||
|
(getenv("INVERT_WIDTH") != NULL); |
||||||
|
const float scale = util::getenv("SCALE", 1.0f); |
||||||
|
|
||||||
|
w->setFixedSize(QSize(wide ? WIDE_WIDTH : 1920, 1080) * scale); |
||||||
|
w->show(); |
||||||
|
|
||||||
|
#ifdef QCOM2 |
||||||
|
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); |
||||||
|
wl_surface *s = reinterpret_cast<wl_surface*>(native->nativeResourceForWindow("surface", w->windowHandle())); |
||||||
|
wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270); |
||||||
|
wl_surface_commit(s); |
||||||
|
w->showFullScreen(); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
extern "C" { |
||||||
|
void set_main_window(void *w) { |
||||||
|
setMainWindow((QWidget*)w); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue