File size: 2,191 Bytes
389d072
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from PyQt5.QtWidgets import QVBoxLayout, qApp, QLabel, QDoubleSpinBox, QScrollArea

#######
# GUI #
#######


def stepsFigure(workspace):
    """GUI layout for step-by-step solution

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout

    Returns:
        stepslayout {QtWidgets.QVBoxLayout} -- step-by-step solution layout
    """
    workspace.stepsfigure = Figure()
    workspace.stepscanvas = FigureCanvas(workspace.stepsfigure)
    workspace.stepsfigure.clear()
    workspace.scroll = QScrollArea()
    workspace.scroll.setWidget(workspace.stepscanvas)
    stepslayout = QVBoxLayout()
    stepslayout.addWidget(workspace.scroll)
    return stepslayout


def showSteps(workspace):
    """Renders step-by-step solution in matplotlib figure

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout
    """
    workspace.stepsfigure.suptitle(workspace.output, y=0.98,
                                   horizontalalignment='center',
                                   verticalalignment='top', size=qApp.font().pointSize()*workspace.stepsFontSize)
    workspace.stepscanvas.draw()
    hbar = workspace.scroll.horizontalScrollBar()
    hbar.setValue((hbar.minimum()+hbar.maximum())/2)


###############
# preferences #
###############


def stepsPref(workspace):

    workspace.sizeChangeText = QLabel("Steps font size: " + str(round(workspace.stepsFontSize, 1)) + "x")
    workspace.sizeChangeBox = QDoubleSpinBox()
    workspace.sizeChangeBox.setFixedSize(200, 30)
    workspace.sizeChangeBox.setRange(0.1, 10)
    workspace.sizeChangeBox.setValue(1)
    workspace.sizeChangeBox.setSingleStep(0.1)
    workspace.sizeChangeBox.setSuffix('x')
    workspace.sizeChangeBox.valueChanged.connect(lambda: sizeChange(workspace))
    return workspace.sizeChangeText, workspace.sizeChangeBox


def sizeChange(workspace):
    workspace.stepsFontSize = workspace.sizeChangeBox.value()
    workspace.sizeChangeText.setText("Steps font size: " + str(round(workspace.stepsFontSize, 1)) + "x")
    if workspace.resultOut is True:
        showSteps(workspace)