default_gui.py 3.25 KB
Newer Older
Karol Actun's avatar
Karol Actun committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from pprint import pprint

from PyQt5.QtGui import QPalette, QColor
from PyQt5.QtWidgets import QVBoxLayout, QPushButton, QFormLayout, QLineEdit, QHBoxLayout, QRadioButton, \
    QLabel, QCheckBox, QWidget, QTabWidget, QSlider, QSizePolicy, QStyle, QStyleFactory
from PyQt5.QtCore import Qt


def define_gui(visualization, world):

    tabbar = QTabWidget()
    tabbar.setMinimumWidth(800)
    tabbar.addTab(sim_tab(visualization), "Simulation")
    tabbar.addTab(vis_tab(visualization), "Visualization")
    set_color(tabbar, QColor(0, 0, 0, 100))

    return tabbar


def sim_tab(visualization):
    tab = QWidget()
    layout = QVBoxLayout()

    #rounds per second slider
    hbox = QHBoxLayout()
    desc = QLabel("rounds per second (%d) : " % visualization.rounds_per_second)
    hbox.addWidget(desc)
    rps_slider = QSlider(Qt.Horizontal)
    rps_slider.setTickInterval(10)
    rps_slider.setTickPosition(2)
    rps_slider.setMaximum(60)
    rps_slider.setMinimum(1)
    rps_slider.setSliderPosition(visualization.rounds_per_second)

    def set_rps():
        visualization.rounds_per_second = rps_slider.value()
        desc.setText("rounds per second (%d): " % rps_slider.value())
    rps_slider.valueChanged.connect(set_rps)

    hbox.addWidget(rps_slider)
    layout.addLayout(hbox)

    #start stop button
    start_stop_button = QPushButton("start")

    def start_stop_sim():
        visualization.running = not visualization.running
        if visualization.running:
            start_stop_button.setText("stop")
        else:
            start_stop_button.setText("start")

    start_stop_button.clicked.connect(start_stop_sim)
    layout.addWidget(start_stop_button)


    tab.setLayout(layout)

    return tab


def vis_tab(visualization):
    tab = QWidget()
    main_layout = QVBoxLayout()

    # fov slider
    fov_layout = QHBoxLayout()
    fov_desc = QLabel("field of view (%d): " % visualization.controller.fov)
    fov_layout.addWidget(fov_desc)
    fov_slider = QSlider(Qt.Horizontal)
    fov_slider.setMinimum(1)
    fov_slider.setMaximum(120)
    fov_slider.setTickInterval(10)
    fov_slider.setTickPosition(2)
    fov_slider.setSliderPosition(50)

    def set_fov():
        visualization.controller.fov = fov_slider.value()
        fov_desc.setText("field of view (%d): " % visualization.controller.fov)
        visualization.controller.update_window()

    fov_slider.valueChanged.connect(set_fov)
    fov_layout.addWidget(fov_slider)

    main_layout.addLayout(fov_layout)

    # projection radio buttons
    projection_layout = QHBoxLayout()
    projection_layout.addWidget(QLabel("projection: "))
    projection_layout.addWidget(QRadioButton("orthografic"))
    persproj = QRadioButton("perspective")

    def change():
        if visualization.controller.projection_type == 'orth':
            visualization.controller.projection_type = 'pers'
        else:
            visualization.controller.projection_type = 'orth'
    persproj.setChecked(True)
    persproj.toggled.connect(change)
    projection_layout.addWidget(persproj)
    main_layout.addLayout(projection_layout)


    tab.setLayout(main_layout)
    return tab

def set_color(widget, color):
    widget.setAutoFillBackground(True)
    p = widget.palette()
    p.setColor(widget.backgroundRole(),color)
    widget.setPalette(p)