default_gui.py 16.5 KB
Newer Older
Karol Actun's avatar
Karol Actun committed
1
2
3
from PyQt5.QtGui import QColor, QIntValidator
from PyQt5.QtWidgets import (QVBoxLayout, QPushButton, QColorDialog, QRadioButton, QLabel, QTabWidget,
                             QSlider, QHBoxLayout, QCheckBox, QTabBar, QTextEdit, QLineEdit, QStyle)
Karol Actun's avatar
Karol Actun committed
4
from PyQt5.QtCore import Qt
Karol Actun's avatar
Karol Actun committed
5
6
7
from OpenGL.GL import glGetFloatv, GL_LINE_WIDTH_RANGE
from lib.vis3d import Visualization
from lib.visualization.utils import eprint
Karol Actun's avatar
Karol Actun committed
8
9


Karol Actun's avatar
Karol Actun committed
10
11
12
13
14
15
16
17
18
19
20
21
22
def create_slider(tick_interval: int, tick_position: int, max_position: int, min_position: int,
                  slider_position: int, callback, orientation=Qt.Horizontal):
    """
    helper function for creating a slider
    """
    slider = QSlider(orientation)
    slider.setTickInterval(tick_interval)
    slider.setTickPosition(tick_position)
    slider.setMaximum(max_position)
    slider.setMinimum(min_position)
    slider.setSliderPosition(slider_position)
    slider.valueChanged.connect(callback)
    return slider
Karol Actun's avatar
Karol Actun committed
23
24


Karol Actun's avatar
Karol Actun committed
25
def create_gui(world, vis: Visualization):
Karol Actun's avatar
Karol Actun committed
26
27

    tabbar = QTabWidget()
Karol Actun's avatar
Karol Actun committed
28
29
30
    tabbar.setMinimumWidth(200)
    tabbar.addTab(sim_tab(vis, world), "Simulation")
    tabbar.addTab(vis_tab(vis), "Visualization")
31
32
    tabbar.addTab(grid_tab(vis), "Grid")
    tabbar.addTab(matter_tab(vis), "Matter")
Karol Actun's avatar
Karol Actun committed
33
34
35
36

    return tabbar


Karol Actun's avatar
Karol Actun committed
37
38
39
40
41
42
43
def key_handler(key, world, vis):
    if key == Qt.Key_Space:
        vis.start_stop()


def sim_tab(vis, world):
    tab = QTabBar()
Karol Actun's avatar
Karol Actun committed
44
    layout = QVBoxLayout()
Karol Actun's avatar
Karol Actun committed
45
46
    layout.addLayout(get_rps_slider(vis))

Karol Actun's avatar
Karol Actun committed
47
    # start stop button
Karol Actun's avatar
Karol Actun committed
48
    start_stop_button = QPushButton("start/stop Simulation")
Karol Actun's avatar
Karol Actun committed
49

Karol Actun's avatar
Karol Actun committed
50
    def start_stop_sim():
Karol Actun's avatar
Karol Actun committed
51
        vis.start_stop()
Karol Actun's avatar
Karol Actun committed
52
    start_stop_button.clicked.connect(start_stop_sim)
Karol Actun's avatar
Karol Actun committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

    # screenshots button
    screenshot_button = QPushButton("take Screenshot")

    def take_screenshot():
        vis.take_screenshot()
    screenshot_button.clicked.connect(take_screenshot)

    # reset button
    reset_button = QPushButton("reset Simulation")

    def reset_sim():
        world.reset()
    reset_button.clicked.connect(reset_sim)

    layout.addWidget(screenshot_button, alignment=Qt.AlignBaseline)
    layout.addWidget(reset_button, alignment=Qt.AlignBaseline)
    layout.addStretch(0)
    layout.addWidget(start_stop_button, alignment=Qt.AlignBaseline)
Karol Actun's avatar
Karol Actun committed
72
73
74
75
    tab.setLayout(layout)

    return tab

Karol Actun's avatar
Karol Actun committed
76
77

def get_rps_slider(vis):
Karol Actun's avatar
Karol Actun committed
78
    hbox = QVBoxLayout()
Karol Actun's avatar
Karol Actun committed
79
80
81
82
83
84
85
86
    desc = QLabel("rounds per second (%d) : " % vis.get_rounds_per_second())
    hbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_rps(value):
        vis.set_rounds_per_second(value)
        desc.setText("rounds per second (%d) : " % vis.get_rounds_per_second())

    hbox.addWidget(create_slider(10, 2, 60, 1, vis.get_rounds_per_second(), set_rps), alignment=Qt.AlignBaseline)
Karol Actun's avatar
Karol Actun committed
87
    return hbox
Karol Actun's avatar
Karol Actun committed
88
89


Karol Actun's avatar
Karol Actun committed
90
91
def vis_tab(vis: Visualization):
    tab = QTabBar()
Karol Actun's avatar
Karol Actun committed
92
    layout = QVBoxLayout()
Karol Actun's avatar
Karol Actun committed
93
94
95
96
97
98
    layout.addLayout(get_projection_switch(vis))
    layout.addLayout(get_fov_slider(vis))
    layout.addLayout(get_render_distance_slider(vis))
    layout.addLayout(get_drag_sens_slider(vis))
    layout.addLayout(get_zoom_sens_slider(vis))
    layout.addLayout(get_rota_sens_slider(vis))
99
100
101
102
103
104
105
106
107
108
109
    reset_position_button = QPushButton("reset position")
    reset_position_button.clicked.connect(vis.reset_camera_position)
    layout.addWidget(reset_position_button, alignment=Qt.AlignBaseline)
    layout.addStretch(0)
    tab.setLayout(layout)
    return tab


def grid_tab(vis: Visualization):
    tab = QTabBar()
    layout = QVBoxLayout()
Karol Actun's avatar
Karol Actun committed
110
111
112
113
114
115
    layout.addLayout(get_grid_width_slider(vis))
    layout.addLayout(get_grid_lines_scale_slider(vis))
    layout.addLayout(get_grid_locations_scale_slider(vis))
    layout.addLayout(get_show_checkboxes(vis))
    layout.addLayout(recalculate_grid(vis))
    layout.addLayout(get_color_picker(vis))
Karol Actun's avatar
Karol Actun committed
116
    layout.addStretch(0)
117
118
    tab.setLayout(layout)
    return tab
Karol Actun's avatar
Karol Actun committed
119
120


121
122
123
124
125
126
127
def matter_tab(vis):
    tab = QTabBar()
    layout = QVBoxLayout()
    layout.addLayout(get_particle_scaler(vis))
    layout.addLayout(get_marker_scaler(vis))
    layout.addLayout(get_tile_scaler(vis))
    layout.addStretch(0)
Karol Actun's avatar
Karol Actun committed
128
129
    tab.setLayout(layout)
    return tab
Karol Actun's avatar
Karol Actun committed
130
131


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def get_particle_scaler(vis):
    def x_scaler_change(value):
        current_scaling = vis.get_particle_scaling()
        print(current_scaling)
        new_scaling = (value/10.0, current_scaling[1], current_scaling[2])
        print(new_scaling)
        vis.set_particle_scaling(new_scaling)

    def y_scaler_change(value):
        current_scaling = vis.get_particle_scaling()
        new_scaling = (current_scaling[0], value/10.0, current_scaling[2])
        vis.set_particle_scaling(new_scaling)

    def z_scaler_change(value):
        current_scaling = vis.get_particle_scaling()
        new_scaling = (current_scaling[0], current_scaling[1], value/10.0)
        vis.set_particle_scaling(new_scaling)

    x_desc = QLabel("x scale:")
    y_desc = QLabel("y scale:")
    z_desc = QLabel("z scale:")
    x_scaler = create_slider(2, 2, 20, 1, 10, x_scaler_change)
    y_scaler = create_slider(2, 2, 20, 1, 10, y_scaler_change)
    z_scaler = create_slider(2, 2, 20, 1, 10, z_scaler_change)

    hbox1 = QHBoxLayout()
    hbox1.addWidget(x_desc, alignment=Qt.AlignBaseline)
    hbox1.addWidget(x_scaler, alignment=Qt.AlignBaseline)

    hbox2 = QHBoxLayout()
    hbox2.addWidget(y_desc, alignment=Qt.AlignBaseline)
    hbox2.addWidget(y_scaler, alignment=Qt.AlignBaseline)

    hbox3 = QHBoxLayout()
    hbox3.addWidget(z_desc, alignment=Qt.AlignBaseline)
    hbox3.addWidget(z_scaler, alignment=Qt.AlignBaseline)

    vbox = QVBoxLayout()
    vbox.addWidget(QLabel("particle scaling:"), alignment=Qt.AlignBaseline)
    vbox.addLayout(hbox1)
    vbox.addLayout(hbox2)
    vbox.addLayout(hbox3)

    return vbox


def get_tile_scaler(vis):
    def x_scaler_change(value):
        current_scaling = vis.get_tile_scaling()
        print(current_scaling)
        new_scaling = (value/10.0, current_scaling[1], current_scaling[2])
        print(new_scaling)
        vis.set_tile_scaling(new_scaling)

    def y_scaler_change(value):
        current_scaling = vis.get_tile_scaling()
        new_scaling = (current_scaling[0], value/10.0, current_scaling[2])
        vis.set_tile_scaling(new_scaling)

    def z_scaler_change(value):
        current_scaling = vis.get_tile_scaling()
        new_scaling = (current_scaling[0], current_scaling[1], value/10.0)
        vis.set_tile_scaling(new_scaling)

    x_desc = QLabel("x scale:")
    y_desc = QLabel("y scale:")
    z_desc = QLabel("z scale:")
    x_scaler = create_slider(2, 2, 20, 1, 10, x_scaler_change)
    y_scaler = create_slider(2, 2, 20, 1, 10, y_scaler_change)
    z_scaler = create_slider(2, 2, 20, 1, 10, z_scaler_change)

    hbox1 = QHBoxLayout()
    hbox1.addWidget(x_desc, alignment=Qt.AlignBaseline)
    hbox1.addWidget(x_scaler, alignment=Qt.AlignBaseline)

    hbox2 = QHBoxLayout()
    hbox2.addWidget(y_desc, alignment=Qt.AlignBaseline)
    hbox2.addWidget(y_scaler, alignment=Qt.AlignBaseline)

    hbox3 = QHBoxLayout()
    hbox3.addWidget(z_desc, alignment=Qt.AlignBaseline)
    hbox3.addWidget(z_scaler, alignment=Qt.AlignBaseline)

    vbox = QVBoxLayout()
    vbox.addWidget(QLabel("tile scaling:"), alignment=Qt.AlignBaseline)
    vbox.addLayout(hbox1)
    vbox.addLayout(hbox2)
    vbox.addLayout(hbox3)

    return vbox


def get_marker_scaler(vis):
    def x_scaler_change(value):
        current_scaling = vis.get_marker_scaling()
        print(current_scaling)
        new_scaling = (value/10.0, current_scaling[1], current_scaling[2])
        print(new_scaling)
        vis.set_marker_scaling(new_scaling)

    def y_scaler_change(value):
        current_scaling = vis.get_marker_scaling()
        new_scaling = (current_scaling[0], value/10.0, current_scaling[2])
        vis.set_marker_scaling(new_scaling)

    def z_scaler_change(value):
        current_scaling = vis.get_marker_scaling()
        new_scaling = (current_scaling[0], current_scaling[1], value/10.0)
        vis.set_marker_scaling(new_scaling)

    x_desc = QLabel("x scale:")
    y_desc = QLabel("y scale:")
    z_desc = QLabel("z scale:")
    x_scaler = create_slider(2, 2, 20, 1, 10, x_scaler_change)
    y_scaler = create_slider(2, 2, 20, 1, 10, y_scaler_change)
    z_scaler = create_slider(2, 2, 20, 1, 10, z_scaler_change)

    hbox1 = QHBoxLayout()
    hbox1.addWidget(x_desc, alignment=Qt.AlignBaseline)
    hbox1.addWidget(x_scaler, alignment=Qt.AlignBaseline)

    hbox2 = QHBoxLayout()
    hbox2.addWidget(y_desc, alignment=Qt.AlignBaseline)
    hbox2.addWidget(y_scaler, alignment=Qt.AlignBaseline)

    hbox3 = QHBoxLayout()
    hbox3.addWidget(z_desc, alignment=Qt.AlignBaseline)
    hbox3.addWidget(z_scaler, alignment=Qt.AlignBaseline)

    vbox = QVBoxLayout()
    vbox.addWidget(QLabel("marker scaling:"), alignment=Qt.AlignBaseline)
    vbox.addLayout(hbox1)
    vbox.addLayout(hbox2)
    vbox.addLayout(hbox3)

    return vbox

Karol Actun's avatar
Karol Actun committed
269
def get_fov_slider(vis: Visualization):
Karol Actun's avatar
Karol Actun committed
270
    hbox = QVBoxLayout()
Karol Actun's avatar
Karol Actun committed
271
272
273
274
275
276
277
278
    desc = QLabel("(only for perspective projection)\nfield of view (%d°) : " % vis.get_field_of_view())
    hbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_fov(value):
        vis.set_field_of_view(value)
        desc.setText("(only for perspective projection)\nfield of view (%d°) : " % vis.get_field_of_view())

    hbox.addWidget(create_slider(10, 2, 120, 10, vis.get_field_of_view(), set_fov), alignment=Qt.AlignBaseline)
Karol Actun's avatar
Karol Actun committed
279
    return hbox
Karol Actun's avatar
Karol Actun committed
280
281


Karol Actun's avatar
Karol Actun committed
282
def get_drag_sens_slider(vis):
Karol Actun's avatar
Karol Actun committed
283
284
    hbox = QVBoxLayout()
    desc = QLabel("drag sensitivity:")
Karol Actun's avatar
Karol Actun committed
285
286
287
288
289
290
291
    hbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_ds(value):
        vis.set_drag_sensitivity(5100-value)

    hbox.addWidget(create_slider(500, 2, 5000, 100, 5100-vis.get_drag_sensitivity(), set_ds),
                   alignment=Qt.AlignBaseline)
Karol Actun's avatar
Karol Actun committed
292
293
294
    return hbox


Karol Actun's avatar
Karol Actun committed
295
def get_zoom_sens_slider(vis):
Karol Actun's avatar
Karol Actun committed
296
297
    hbox = QVBoxLayout()
    desc = QLabel("zoom sensitivity:")
Karol Actun's avatar
Karol Actun committed
298
299
300
301
302
303
    hbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_zs(value):
        vis.set_zoom_sensitivity(1001-value)

    hbox.addWidget(create_slider(100, 2, 1000, 1, 1001-vis.get_zoom_sensitivity(), set_zs), alignment=Qt.AlignBaseline)
Karol Actun's avatar
Karol Actun committed
304
305
306
    return hbox


Karol Actun's avatar
Karol Actun committed
307
def get_rota_sens_slider(vis):
Karol Actun's avatar
Karol Actun committed
308
309
    hbox = QVBoxLayout()
    desc = QLabel("(only for 3D)\nrotation sensitivity:")
Karol Actun's avatar
Karol Actun committed
310
311
312
313
314
315
    hbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_rs(value):
        vis.set_rotation_sensitivity(11-value)

    hbox.addWidget(create_slider(1, 2, 10, 1, 11-vis.get_rotation_sensitivity(), set_rs), alignment=Qt.AlignBaseline)
Karol Actun's avatar
Karol Actun committed
316
317
318
    return hbox


Karol Actun's avatar
Karol Actun committed
319
def get_projection_switch(vis):
Karol Actun's avatar
Karol Actun committed
320
321
    vbox = QVBoxLayout()
    desc = QLabel("projection type:")
Karol Actun's avatar
Karol Actun committed
322
    vbox.addWidget(desc, alignment=Qt.AlignBaseline)
Karol Actun's avatar
Karol Actun committed
323
324
325

    o = QRadioButton("orthographic")

Karol Actun's avatar
Karol Actun committed
326
    def orth_toggle():
Karol Actun's avatar
Karol Actun committed
327
        if o.isChecked():
Karol Actun's avatar
Karol Actun committed
328
329
            vis.set_projection_type("ortho")
    o.toggled.connect(orth_toggle)
Karol Actun's avatar
Karol Actun committed
330
331
332

    p = QRadioButton("perspective")

Karol Actun's avatar
Karol Actun committed
333
334
335
336
337
338
    if vis.get_projection_type() == "ortho":
        o.setChecked(True)
    else:
        p.setChecked(True)

    def pers_toggle():
Karol Actun's avatar
Karol Actun committed
339
        if p.isChecked():
Karol Actun's avatar
Karol Actun committed
340
341
342
            vis.set_projection_type("perspective")
    p.toggled.connect(pers_toggle)

Karol Actun's avatar
Karol Actun committed
343
    hbox = QHBoxLayout()
Karol Actun's avatar
Karol Actun committed
344
345
    hbox.addWidget(o, alignment=Qt.AlignBaseline)
    hbox.addWidget(p, alignment=Qt.AlignBaseline)
Karol Actun's avatar
Karol Actun committed
346
347
348
349
    vbox.addLayout(hbox)
    return vbox


Karol Actun's avatar
Karol Actun committed
350
def get_color_picker(vis):
Karol Actun's avatar
Karol Actun committed
351

Karol Actun's avatar
Karol Actun committed
352
    bg_button = QPushButton("background")
Karol Actun's avatar
Karol Actun committed
353

Karol Actun's avatar
Karol Actun committed
354
355
356
357
358
359
    def bg():
        qcd = QColorDialog()
        qcd.setCurrentColor(QColor.fromRgbF(*vis.get_background_color()))
        qcd.exec()
        if qcd.result() == 1:
            vis.set_background_color((qcd.selectedColor().getRgbF()[:3]))
Karol Actun's avatar
Karol Actun committed
360

Karol Actun's avatar
Karol Actun committed
361
    bg_button.clicked.connect(bg)
Karol Actun's avatar
Karol Actun committed
362

Karol Actun's avatar
Karol Actun committed
363
    lines_button = QPushButton("grid lines")
Karol Actun's avatar
Karol Actun committed
364

Karol Actun's avatar
Karol Actun committed
365
366
367
368
369
370
371
    def lines():
        qcd = QColorDialog()
        qcd.setOption(QColorDialog.ShowAlphaChannel)
        qcd.setCurrentColor(QColor.fromRgbF(*vis.get_grid_line_color()))
        qcd.exec()
        if qcd.result() == 1:
            vis.set_grid_line_color((qcd.selectedColor().getRgbF()))
Karol Actun's avatar
Karol Actun committed
372

Karol Actun's avatar
Karol Actun committed
373
    lines_button.clicked.connect(lines)
Karol Actun's avatar
Karol Actun committed
374

Karol Actun's avatar
Karol Actun committed
375
    locs_button = QPushButton("grid locations")
Karol Actun's avatar
Karol Actun committed
376

Karol Actun's avatar
Karol Actun committed
377
378
379
380
381
382
383
    def locs():
        qcd = QColorDialog()
        qcd.setOption(QColorDialog.ShowAlphaChannel)
        qcd.setCurrentColor(QColor.fromRgbF(*vis.get_grid_location_color()))
        qcd.exec()
        if qcd.result() == 1:
            vis.set_grid_location_color((qcd.selectedColor().getRgbF()))
Karol Actun's avatar
Karol Actun committed
384

Karol Actun's avatar
Karol Actun committed
385
    locs_button.clicked.connect(locs)
Karol Actun's avatar
Karol Actun committed
386

Karol Actun's avatar
Karol Actun committed
387
388
389
390
391
392
393
394
395
    vbox = QVBoxLayout()
    desc = QLabel("change color of:")
    vbox.addWidget(desc, alignment=Qt.AlignBaseline)
    hbox = QHBoxLayout()
    hbox.addWidget(lines_button, alignment=Qt.AlignBaseline)
    hbox.addWidget(locs_button, alignment=Qt.AlignBaseline)
    hbox.addWidget(bg_button, alignment=Qt.AlignBaseline)
    vbox.addLayout(hbox)
    return vbox
Karol Actun's avatar
Karol Actun committed
396
397


Karol Actun's avatar
Karol Actun committed
398
399
400
401
402
403
404
405
def get_grid_width_slider(vis):
    hbox = QVBoxLayout()
    desc = QLabel("grid width (%d):" % vis.get_grid_line_width())
    hbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_gw(value):
        vis.set_grid_line_width(value)
        desc.setText("grid width (%d):" % value)
Karol Actun's avatar
Karol Actun committed
406

Karol Actun's avatar
Karol Actun committed
407
408
409
410
411
412
    hbox.addWidget(create_slider(1, 2, glGetFloatv(GL_LINE_WIDTH_RANGE)[1], 1, vis.get_grid_line_width(), set_gw),
                   alignment=Qt.AlignBaseline)
    return hbox


def get_render_distance_slider(vis):
Karol Actun's avatar
Karol Actun committed
413
    vbox = QVBoxLayout()
Karol Actun's avatar
Karol Actun committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
    desc = QLabel("render distance (%d):" % vis.get_render_distance())
    vbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_mrd(value):
        vis.set_render_distance(value)
        desc.setText("render distance (%d):" % vis.get_render_distance())

    vbox.addWidget(create_slider(10, 2, 5000, 5, vis.get_render_distance(), set_mrd), alignment=Qt.AlignBaseline)
    return vbox


def get_show_checkboxes(vis):

    lines_cb = QCheckBox()
    lines_cb.setText("show lines")
    lines_cb.setChecked(vis.get_show_lines())

    def lines_clicked():
        vis.set_show_lines(lines_cb.isChecked())
    lines_cb.clicked.connect(lines_clicked)

    locs_cb = QCheckBox()
    locs_cb.setText("show locations")
    locs_cb.setChecked(vis.get_show_locations())

    def locs_clicked():
        vis.set_show_locations(locs_cb.isChecked())

    locs_cb.clicked.connect(locs_clicked)

    center_cb = QCheckBox()
    center_cb.setText("show center")
    center_cb.setChecked(vis.get_show_center())

    def center_clicked():
        vis.set_show_center(center_cb.isChecked())

    center_cb.clicked.connect(center_clicked)

    focus_cb = QCheckBox()
    focus_cb.setText("show focus")
    focus_cb.setChecked(vis.get_show_focus())

    def focus_clicked():
        vis.set_show_focus(focus_cb.isChecked())

    focus_cb.clicked.connect(focus_clicked)

    rl_cb = QCheckBox()
    rl_cb.setText("rotate light")
    rl_cb.setChecked(vis.light_rotation)

    def rl_clicked():
        vis.light_rotation = rl_cb.isChecked()

    rl_cb.clicked.connect(rl_clicked)

Karol Actun's avatar
Karol Actun committed
471
    hbox1 = QHBoxLayout()
Karol Actun's avatar
Karol Actun committed
472
473
    hbox1.addWidget(lines_cb)
    hbox1.addWidget(locs_cb)
Karol Actun's avatar
Karol Actun committed
474
    hbox2 = QHBoxLayout()
Karol Actun's avatar
Karol Actun committed
475
476
477
478
479
480
    hbox2.addWidget(center_cb)
    hbox2.addWidget(focus_cb)
    hbox3 = QHBoxLayout()
    hbox3.addWidget(rl_cb)

    vbox = QVBoxLayout()
Karol Actun's avatar
Karol Actun committed
481
482
    vbox.addLayout(hbox1)
    vbox.addLayout(hbox2)
Karol Actun's avatar
Karol Actun committed
483
484
485
486
487
488
    vbox.addLayout(hbox3)
    return vbox


def get_grid_lines_scale_slider(vis):
    vbox = QVBoxLayout()
489
    desc = QLabel("grid lines scale (%d%%):" % int(vis.get_grid_line_scaling()[0]*100))
Karol Actun's avatar
Karol Actun committed
490
491
492
493
    vbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_scale(value):
        vis.set_grid_line_scaling([value/50.0, value/50.0, value/50.0])
494
        desc.setText("grid lines scale (%d%%):" % (int(value*2.0)))
Karol Actun's avatar
Karol Actun committed
495
496
497
498
499
500
501
502

    vbox.addWidget(create_slider(10, 2, 50, 10, int(vis.get_grid_line_scaling()[0]*50), set_scale),
                   alignment=Qt.AlignBaseline)
    return vbox


def get_grid_locations_scale_slider(vis):
    vbox = QVBoxLayout()
503
    desc = QLabel("grid locations model scale (%d%%):" % int(vis.get_grid_location_scaling()[0]*500))
Karol Actun's avatar
Karol Actun committed
504
505
506
507
    vbox.addWidget(desc, alignment=Qt.AlignBaseline)

    def set_scale(value):
        vis.set_grid_location_scaling([value/1000.0, value/1000.0, value/1000.0])
508
        desc.setText("grid locations model scale (%d%%):" % (int(value/2.0)))
Karol Actun's avatar
Karol Actun committed
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536

    vbox.addWidget(create_slider(10, 2, 200, 10, int(vis.get_grid_location_scaling()[0]*1000.0), set_scale),
                   alignment=Qt.AlignBaseline)
    return vbox


def recalculate_grid(vis):
    hbox = QHBoxLayout()
    rec_button = QPushButton("update grid with size:")

    size_edit = QLineEdit()
    size_edit.setValidator(QIntValidator())
    size_edit.setText(str(vis._world.grid.size))

    def on_click():
        if size_edit.text().isnumeric():
            vis.recalculate_grid(int(size_edit.text()))
        else:
            eprint("warning: grid size has to be a number")

    rec_button.clicked.connect(on_click)

    hbox.addWidget(rec_button, alignment=Qt.AlignBaseline)
    hbox.addWidget(size_edit, alignment=Qt.AlignBaseline)

    return hbox