PyQt demo app (#21625)
* build python helpers lib * call setMainWindow from python * put in helper lib * linter * move to scripts
This commit is contained in:
parent
1f39d8cee6
commit
25e4e94691
|
@ -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_()
|
|
@ -22,7 +22,7 @@ widgets_src = ["qt/util.cc", "qt/widgets/input.cc", "qt/widgets/drive_stats.cc",
|
|||
"qt/widgets/ssh_keys.cc", "qt/widgets/toggle.cc", "qt/widgets/controls.cc",
|
||||
"qt/widgets/offroad_alerts.cc", "qt/widgets/prime.cc", "qt/widgets/keyboard.cc",
|
||||
"qt/widgets/scrollview.cc", "qt/widgets/cameraview.cc", "#third_party/qrcode/QrCode.cc", "qt/api.cc",
|
||||
"qt/request_repeater.cc"]
|
||||
"qt/request_repeater.cc", "qt/qt_window.cc"]
|
||||
|
||||
if arch != 'aarch64':
|
||||
widgets_src += ["qt/offroad/networking.cc", "qt/offroad/wifiManager.cc"]
|
||||
|
@ -48,6 +48,8 @@ qt_env.Program("_soundd", "soundd.cc", LIBS=base_libs)
|
|||
if GetOption('test'):
|
||||
qt_env.Program("tests/playsound", "tests/playsound.cc", LIBS=base_libs)
|
||||
|
||||
qt_env.SharedLibrary("qt/python_helpers", ["qt/qt_window.cc"], LIBS=qt_libs)
|
||||
|
||||
# spinner and text window
|
||||
qt_env.Program("qt/text", ["qt/text.cc"], LIBS=qt_libs)
|
||||
qt_env.Program("qt/spinner", ["qt/spinner.cc"], LIBS=qt_libs)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -18,19 +18,4 @@ const QString ASSET_PATH = ":/";
|
|||
|
||||
const int WIDE_WIDTH = 2160;
|
||||
|
||||
inline 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
|
||||
}
|
||||
void setMainWindow(QWidget *w);
|
||||
|
|
Loading…
Reference in New Issue