parent
b04ca30f83
commit
608047c241
8 changed files with 1 additions and 223 deletions
@ -1,52 +0,0 @@ |
|||||||
import os |
|
||||||
import subprocess |
|
||||||
from openpilot.common.basedir import BASEDIR |
|
||||||
|
|
||||||
|
|
||||||
class Spinner: |
|
||||||
def __init__(self): |
|
||||||
try: |
|
||||||
self.spinner_proc = subprocess.Popen(["./spinner"], |
|
||||||
stdin=subprocess.PIPE, |
|
||||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui"), |
|
||||||
close_fds=True) |
|
||||||
except OSError: |
|
||||||
self.spinner_proc = None |
|
||||||
|
|
||||||
def __enter__(self): |
|
||||||
return self |
|
||||||
|
|
||||||
def update(self, spinner_text: str): |
|
||||||
if self.spinner_proc is not None: |
|
||||||
self.spinner_proc.stdin.write(spinner_text.encode('utf8') + b"\n") |
|
||||||
try: |
|
||||||
self.spinner_proc.stdin.flush() |
|
||||||
except BrokenPipeError: |
|
||||||
pass |
|
||||||
|
|
||||||
def update_progress(self, cur: float, total: float): |
|
||||||
self.update(str(round(100 * cur / total))) |
|
||||||
|
|
||||||
def close(self): |
|
||||||
if self.spinner_proc is not None: |
|
||||||
self.spinner_proc.kill() |
|
||||||
try: |
|
||||||
self.spinner_proc.communicate(timeout=2.) |
|
||||||
except subprocess.TimeoutExpired: |
|
||||||
print("WARNING: failed to kill spinner") |
|
||||||
self.spinner_proc = None |
|
||||||
|
|
||||||
def __del__(self): |
|
||||||
self.close() |
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback): |
|
||||||
self.close() |
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": |
|
||||||
import time |
|
||||||
with Spinner() as s: |
|
||||||
s.update("Spinner text") |
|
||||||
time.sleep(5.0) |
|
||||||
print("gone") |
|
||||||
time.sleep(5.0) |
|
@ -1,120 +0,0 @@ |
|||||||
#include "selfdrive/ui/qt/spinner.h" |
|
||||||
|
|
||||||
#include <algorithm> |
|
||||||
#include <cstdio> |
|
||||||
#include <iostream> |
|
||||||
#include <string> |
|
||||||
|
|
||||||
#include <QApplication> |
|
||||||
#include <QGridLayout> |
|
||||||
#include <QPainter> |
|
||||||
#include <QString> |
|
||||||
#include <QTransform> |
|
||||||
|
|
||||||
#include "system/hardware/hw.h" |
|
||||||
#include "selfdrive/ui/qt/qt_window.h" |
|
||||||
#include "selfdrive/ui/qt/util.h" |
|
||||||
|
|
||||||
TrackWidget::TrackWidget(QWidget *parent) : QWidget(parent) { |
|
||||||
setAttribute(Qt::WA_OpaquePaintEvent); |
|
||||||
setFixedSize(spinner_size); |
|
||||||
|
|
||||||
// pre-compute all the track imgs. make this a gif instead?
|
|
||||||
QPixmap comma_img = loadPixmap("../assets/img_spinner_comma.png", spinner_size); |
|
||||||
QPixmap track_img = loadPixmap("../assets/img_spinner_track.png", spinner_size); |
|
||||||
|
|
||||||
QTransform transform(1, 0, 0, 1, width() / 2, height() / 2); |
|
||||||
QPixmap pm(spinner_size); |
|
||||||
QPainter p(&pm); |
|
||||||
p.setRenderHint(QPainter::SmoothPixmapTransform); |
|
||||||
for (int i = 0; i < track_imgs.size(); ++i) { |
|
||||||
p.resetTransform(); |
|
||||||
p.fillRect(0, 0, spinner_size.width(), spinner_size.height(), Qt::black); |
|
||||||
p.drawPixmap(0, 0, comma_img); |
|
||||||
p.setTransform(transform.rotate(360 / spinner_fps)); |
|
||||||
p.drawPixmap(-width() / 2, -height() / 2, track_img); |
|
||||||
track_imgs[i] = pm.copy(); |
|
||||||
} |
|
||||||
|
|
||||||
m_anim.setDuration(1000); |
|
||||||
m_anim.setStartValue(0); |
|
||||||
m_anim.setEndValue(int(track_imgs.size() -1)); |
|
||||||
m_anim.setLoopCount(-1); |
|
||||||
m_anim.start(); |
|
||||||
connect(&m_anim, SIGNAL(valueChanged(QVariant)), SLOT(update())); |
|
||||||
} |
|
||||||
|
|
||||||
void TrackWidget::paintEvent(QPaintEvent *event) { |
|
||||||
QPainter painter(this); |
|
||||||
painter.drawPixmap(0, 0, track_imgs[m_anim.currentValue().toInt()]); |
|
||||||
} |
|
||||||
|
|
||||||
// Spinner
|
|
||||||
|
|
||||||
Spinner::Spinner(QWidget *parent) : QWidget(parent) { |
|
||||||
QGridLayout *main_layout = new QGridLayout(this); |
|
||||||
main_layout->setSpacing(0); |
|
||||||
main_layout->setMargin(200); |
|
||||||
|
|
||||||
main_layout->addWidget(new TrackWidget(this), 0, 0, Qt::AlignHCenter | Qt::AlignVCenter); |
|
||||||
|
|
||||||
text = new QLabel(); |
|
||||||
text->setWordWrap(true); |
|
||||||
text->setVisible(false); |
|
||||||
text->setAlignment(Qt::AlignCenter); |
|
||||||
main_layout->addWidget(text, 1, 0, Qt::AlignHCenter); |
|
||||||
|
|
||||||
progress_bar = new QProgressBar(); |
|
||||||
progress_bar->setRange(5, 100); |
|
||||||
progress_bar->setTextVisible(false); |
|
||||||
progress_bar->setVisible(false); |
|
||||||
progress_bar->setFixedHeight(20); |
|
||||||
main_layout->addWidget(progress_bar, 1, 0, Qt::AlignHCenter); |
|
||||||
|
|
||||||
setStyleSheet(R"( |
|
||||||
Spinner { |
|
||||||
background-color: black; |
|
||||||
} |
|
||||||
QLabel { |
|
||||||
color: white; |
|
||||||
font-size: 80px; |
|
||||||
background-color: transparent; |
|
||||||
} |
|
||||||
QProgressBar { |
|
||||||
background-color: #373737; |
|
||||||
width: 1000px; |
|
||||||
border solid white; |
|
||||||
border-radius: 10px; |
|
||||||
} |
|
||||||
QProgressBar::chunk { |
|
||||||
border-radius: 10px; |
|
||||||
background-color: white; |
|
||||||
} |
|
||||||
)"); |
|
||||||
|
|
||||||
notifier = new QSocketNotifier(fileno(stdin), QSocketNotifier::Read); |
|
||||||
QObject::connect(notifier, &QSocketNotifier::activated, this, &Spinner::update); |
|
||||||
} |
|
||||||
|
|
||||||
void Spinner::update(int n) { |
|
||||||
std::string line; |
|
||||||
std::getline(std::cin, line); |
|
||||||
|
|
||||||
if (line.length()) { |
|
||||||
bool number = std::all_of(line.begin(), line.end(), ::isdigit); |
|
||||||
text->setVisible(!number); |
|
||||||
progress_bar->setVisible(number); |
|
||||||
text->setText(QString::fromStdString(line)); |
|
||||||
if (number) { |
|
||||||
progress_bar->setValue(std::stoi(line)); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
int main(int argc, char *argv[]) { |
|
||||||
initApp(argc, argv); |
|
||||||
QApplication a(argc, argv); |
|
||||||
Spinner spinner; |
|
||||||
setMainWindow(&spinner); |
|
||||||
return a.exec(); |
|
||||||
} |
|
@ -1,37 +0,0 @@ |
|||||||
#include <array> |
|
||||||
|
|
||||||
#include <QLabel> |
|
||||||
#include <QPixmap> |
|
||||||
#include <QProgressBar> |
|
||||||
#include <QSocketNotifier> |
|
||||||
#include <QVariantAnimation> |
|
||||||
#include <QWidget> |
|
||||||
|
|
||||||
constexpr int spinner_fps = 30; |
|
||||||
constexpr QSize spinner_size = QSize(360, 360); |
|
||||||
|
|
||||||
class TrackWidget : public QWidget { |
|
||||||
Q_OBJECT |
|
||||||
public: |
|
||||||
TrackWidget(QWidget *parent = nullptr); |
|
||||||
|
|
||||||
private: |
|
||||||
void paintEvent(QPaintEvent *event) override; |
|
||||||
std::array<QPixmap, spinner_fps> track_imgs; |
|
||||||
QVariantAnimation m_anim; |
|
||||||
}; |
|
||||||
|
|
||||||
class Spinner : public QWidget { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit Spinner(QWidget *parent = 0); |
|
||||||
|
|
||||||
private: |
|
||||||
QLabel *text; |
|
||||||
QProgressBar *progress_bar; |
|
||||||
QSocketNotifier *notifier; |
|
||||||
|
|
||||||
public slots: |
|
||||||
void update(int n); |
|
||||||
}; |
|
@ -1,3 +0,0 @@ |
|||||||
version https://git-lfs.github.com/spec/v1 |
|
||||||
oid sha256:81d7073d16e8ddc40d4d81fc88f8fc11c434df241593b455e2787935371383e4 |
|
||||||
size 3821728 |
|
@ -1,7 +0,0 @@ |
|||||||
#!/bin/sh |
|
||||||
|
|
||||||
if [ -f /TICI ] && [ ! -f _spinner ]; then |
|
||||||
cp qt/spinner_larch64 _spinner |
|
||||||
fi |
|
||||||
|
|
||||||
exec ./_spinner "$1" |
|
Loading…
Reference in new issue