Qt text window (#2489)
* qt text window * auto size * real text * this is cleaner * fix android build * exit on pc * tici fixes old-commit-hash: 68ba1649b91984c106491cf1894c3f44f21a34df
This commit is contained in:
@@ -6,17 +6,16 @@ from common.basedir import BASEDIR
|
||||
|
||||
|
||||
class TextWindow:
|
||||
def __init__(self, s, noop=False):
|
||||
def __init__(self, text):
|
||||
# text window is only implemented for android currently
|
||||
self.text_proc = None
|
||||
if not noop:
|
||||
try:
|
||||
self.text_proc = subprocess.Popen(["./text", s],
|
||||
stdin=subprocess.PIPE,
|
||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "text"),
|
||||
close_fds=True)
|
||||
except OSError:
|
||||
self.text_proc = None
|
||||
try:
|
||||
self.text_proc = subprocess.Popen(["./text", text],
|
||||
stdin=subprocess.PIPE,
|
||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui"),
|
||||
close_fds=True)
|
||||
except OSError:
|
||||
self.text_proc = None
|
||||
|
||||
def get_status(self):
|
||||
if self.text_proc is not None:
|
||||
|
||||
@@ -348,9 +348,9 @@ selfdrive/ui/spinner/Makefile
|
||||
selfdrive/ui/spinner/spinner
|
||||
selfdrive/ui/spinner/spinner.c
|
||||
|
||||
selfdrive/ui/text/Makefile
|
||||
selfdrive/ui/text/text
|
||||
selfdrive/ui/text/text.c
|
||||
selfdrive/ui/android/text/Makefile
|
||||
selfdrive/ui/android/text/text
|
||||
selfdrive/ui/android/text/text.c
|
||||
|
||||
selfdrive/ui/qt/*.cc
|
||||
selfdrive/ui/qt/*.hpp
|
||||
|
||||
@@ -140,7 +140,7 @@ if not prebuilt:
|
||||
# Show TextWindow
|
||||
no_ui = __name__ != "__main__" or not ANDROID
|
||||
error_s = "\n \n".join(["\n".join(textwrap.wrap(e, 65)) for e in errors])
|
||||
with TextWindow("openpilot failed to build\n \n" + error_s, noop=no_ui) as t:
|
||||
with TextWindow("openpilot failed to build\n \n" + error_s) as t:
|
||||
t.wait_for_exit()
|
||||
|
||||
exit(1)
|
||||
|
||||
1
selfdrive/ui/.gitignore
vendored
1
selfdrive/ui/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
moc_*
|
||||
qt/text
|
||||
|
||||
@@ -71,3 +71,6 @@ else:
|
||||
|
||||
qt_src = ["qt/ui.cc", "qt/window.cc", "qt/qt_sound.cc", "qt/offroad/settings.cc", "qt/offroad/onboarding.cc"] + src
|
||||
qt_env.Program("_ui", qt_src, LIBS=qt_libs + libs)
|
||||
|
||||
# text window
|
||||
qt_env.Program("qt/text", ["qt/text.cc"], LIBS=qt_libs + libs)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
CC = clang
|
||||
CXX = clang++
|
||||
|
||||
PHONELIBS = ../../../phonelibs
|
||||
PHONELIBS = ../../../../phonelibs
|
||||
COMMON = ../../../common
|
||||
|
||||
WARN_FLAGS = -Werror=implicit-function-declaration \
|
||||
-Werror=incompatible-pointer-types \
|
||||
@@ -19,9 +20,9 @@ OPENGL_LIBS = -lGLESv3
|
||||
FRAMEBUFFER_LIBS = -lutils -lgui -lEGL
|
||||
|
||||
OBJS = text.o \
|
||||
../../common/framebuffer.o \
|
||||
../../common/util.o \
|
||||
../../../selfdrive/common/touch.o \
|
||||
$(COMMON)/framebuffer.o \
|
||||
$(COMMON)/util.o \
|
||||
$(COMMON)/touch.o \
|
||||
$(PHONELIBS)/nanovg/nanovg.o \
|
||||
opensans_regular.o \
|
||||
|
||||
@@ -39,7 +40,7 @@ text: $(OBJS)
|
||||
$(OPENGL_LIBS) \
|
||||
-lm -llog
|
||||
|
||||
opensans_regular.o: ../../assets/fonts/opensans_regular.ttf
|
||||
opensans_regular.o: ../../../assets/fonts/opensans_regular.ttf
|
||||
@echo "[ bin2o ] $@"
|
||||
cd '$(dir $<)' && ld -r -b binary '$(notdir $<)' -o '$(abspath $@)'
|
||||
|
||||
@@ -47,7 +48,7 @@ opensans_regular.o: ../../assets/fonts/opensans_regular.ttf
|
||||
mkdir -p $(@D)
|
||||
@echo "[ CC ] $@"
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) \
|
||||
-I../.. \
|
||||
-I../../.. \
|
||||
-I$(PHONELIBS)/android_frameworks_native/include \
|
||||
-I$(PHONELIBS)/android_system_core/include \
|
||||
-I$(PHONELIBS)/android_hardware_libhardware/include \
|
||||
@@ -58,8 +59,8 @@ opensans_regular.o: ../../assets/fonts/opensans_regular.ttf
|
||||
mkdir -p $(@D)
|
||||
@echo "[ CXX ] $@"
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) \
|
||||
-I../../selfdrive \
|
||||
-I../../ \
|
||||
-I../../../selfdrive \
|
||||
-I../../../ \
|
||||
-I$(PHONELIBS)/android_frameworks_native/include \
|
||||
-I$(PHONELIBS)/android_system_core/include \
|
||||
-I$(PHONELIBS)/android_hardware_libhardware/include \
|
||||
90
selfdrive/ui/qt/text.cc
Normal file
90
selfdrive/ui/qt/text.cc
Normal file
@@ -0,0 +1,90 @@
|
||||
#include <cstdlib>
|
||||
|
||||
#include <QString>
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
#ifdef QCOM2
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
#include <QPlatformSurfaceEvent>
|
||||
#include <wayland-client-protocol.h>
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
QWidget *window = new QWidget();
|
||||
|
||||
// TODO: get size from QScreen, doesn't work on tici
|
||||
#ifdef QCOM2
|
||||
int w = 2160, h = 1080;
|
||||
#else
|
||||
int w = 1920, h = 1080;
|
||||
#endif
|
||||
window->setFixedSize(w, h);
|
||||
|
||||
QVBoxLayout *main_layout = new QVBoxLayout();
|
||||
|
||||
QString text = "";
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (i > 1) {
|
||||
text.append(" ");
|
||||
}
|
||||
text.append(argv[i]);
|
||||
}
|
||||
|
||||
QLabel *label = new QLabel(text);
|
||||
label->setAlignment(Qt::AlignTop);
|
||||
main_layout->addWidget(label);
|
||||
|
||||
QPushButton *btn = new QPushButton();
|
||||
#ifdef __aarch64__
|
||||
btn->setText("Reboot");
|
||||
QObject::connect(btn, &QPushButton::released, [=]() {
|
||||
std::system("sudo reboot");
|
||||
});
|
||||
#else
|
||||
btn->setText("Exit");
|
||||
QObject::connect(btn, SIGNAL(released()), &a, SLOT(quit()));
|
||||
#endif
|
||||
main_layout->addWidget(btn);
|
||||
|
||||
window->setLayout(main_layout);
|
||||
window->setStyleSheet(R"(
|
||||
QWidget {
|
||||
margin: 60px;
|
||||
background-color: black;
|
||||
}
|
||||
QLabel {
|
||||
color: white;
|
||||
font-size: 60px;
|
||||
}
|
||||
QPushButton {
|
||||
color: white;
|
||||
font-size: 50px;
|
||||
padding: 60px;
|
||||
margin-left: 1500px;
|
||||
border-color: white;
|
||||
border-width: 2px;
|
||||
border-style: solid;
|
||||
border-radius: 20px;
|
||||
}
|
||||
)");
|
||||
|
||||
window->show();
|
||||
|
||||
|
||||
#ifdef QCOM2
|
||||
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
|
||||
wl_surface *s = reinterpret_cast<wl_surface*>(native->nativeResourceForWindow("surface", window->windowHandle()));
|
||||
wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270);
|
||||
wl_surface_commit(s);
|
||||
window->showFullScreen();
|
||||
#endif
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
8
selfdrive/ui/text
Executable file
8
selfdrive/ui/text
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -f /EON ]; then
|
||||
export LD_LIBRARY_PATH="/system/lib64:$LD_LIBRARY_PATH"
|
||||
exec ./android/text/text "$1"
|
||||
else
|
||||
exec ./qt/text "$1"
|
||||
fi
|
||||
Reference in New Issue
Block a user