Exemplo n.º 1
0
    def __init__(self, parent=None):
        ''' (QWidget) -> NoneType
        '''
        QMainWindow.__init__(self, parent)

        self.scene = GxSceneBlocks()
        self.scene.setSceneRect(0, 0, 800, 800)
        self.gx_example_path = GxExamplePaths(self.scene)

        self.initUI()
Exemplo n.º 2
0
    def __init__(self, parent=None):
        """ (QWidget) -> NoneType
        """
        QMainWindow.__init__(self, parent)

        self.scene = GxSceneBlocks()
        self.scene.setSceneRect(0, 0, 800, 800)
        self.gx_example_path = GxExamplePaths(self.scene)

        self.initUI()
Exemplo n.º 3
0
class ExampleMainWindow(QMainWindow):
    POSITIONS = ('top', 'bottom', 'left', 'right')
    DIMENSIONS = ('w', 'h')
    CORNER_PLACES = ('tl', 'tr', 'bl', 'br')

    def __init__(self, parent=None):
        ''' (QWidget) -> NoneType
        '''
        QMainWindow.__init__(self, parent)

        self.scene = GxSceneBlocks()
        self.scene.setSceneRect(0, 0, 800, 800)
        self.gx_example_path = GxExamplePaths(self.scene)

        self.initUI()

    def initUI(self):
        ''' () -> NoneType
        '''

        # --- corner settings ----------------------------------------------

        self.wg_area_corners = QWidget(self)

        self.wg_gbx_bl_corner = self.setupCornerGroupBox(' Bottom-Left ',
            'bl', 'tl', 'br', self.wg_area_corners)

        self.wg_gbx_br_corner = self.setupCornerGroupBox(' Bottom-Right ',
            'br', 'tr', 'bl', self.wg_area_corners)

        self.wg_gbx_tl_corner = self.setupCornerGroupBox(' Top-Left ',
            'tl', 'bl', 'tr', self.wg_area_corners)

        self.wg_gbx_tr_corner = self.setupCornerGroupBox(' Top-Right ',
            'tr', 'br', 'tl', self.wg_area_corners)

        vl = QVBoxLayout()
        vl.addWidget(self.wg_gbx_bl_corner)
        vl.addWidget(self.wg_gbx_br_corner)
        vl.addWidget(self.wg_gbx_tl_corner)
        vl.addWidget(self.wg_gbx_tr_corner)
        self.wg_area_corners.setLayout(vl)

        # ---- notch settings ----------------------------------------------

        self.wg_area_notch = QWidget(self)

        self.wg_gbx_top_notch = self.setupNotchGroupBox(' Top ',
            'top', 'bottom', None, self.wg_area_notch)

        self.wg_gbx_bottom_notch = self.setupNotchGroupBox(' Bottom ',
            'bottom', 'top', None, self.wg_area_notch)

        self.wg_gbx_left_notch = self.setupNotchGroupBox(' Left ',
            'left', None, 'right', self.wg_area_notch)

        self.wg_gbx_right_notch = self.setupNotchGroupBox(' Right ',
            'right', None, 'left', self.wg_area_notch)

        vl = QVBoxLayout()
        vl.addWidget(self.wg_gbx_top_notch)
        vl.addWidget(self.wg_gbx_bottom_notch)
        vl.addWidget(self.wg_gbx_left_notch)
        vl.addWidget(self.wg_gbx_right_notch)
        self.wg_area_notch.setLayout(vl)

        # --------------------------------------------------------------

        self.wg_area_win = QWidget(self)

        self.wg_view = GxView(self.scene, parent=self)

        self.wg_tab_command = QTabWidget(self)
        self.wg_tab_command.addTab(self.wg_area_corners, 'Corners')
        self.wg_tab_command.addTab(self.wg_area_notch, 'Notch')
        self.wg_tab_command.setFixedWidth(200)

        hl = QHBoxLayout()
        hl.addWidget(self.wg_view)
        hl.addWidget(self.wg_tab_command, 200)
        self.wg_area_win.setLayout(hl)

        self.setGeometry(200, 50, 1000, 550)
        self.setCentralWidget(self.wg_area_win)

    def setupNotchGroupBox(self, title, notch, follow_w, follow_h, parent):
        ''' (str, str in self.POSITIONS, QWidget) -> QGroupBox
        '''
        groupbox = QGroupBox(title, parent)

        combobox_shape = QComboBox(parent)
        combobox_shape.addItems(['trig', 'arc'])
        combobox_shape.setCurrentIndex(combobox_shape.findText(
            self.gx_example_path.notch_data[notch]['shape']))
        self.connect(combobox_shape, SIGNAL('currentIndexChanged(int)'),
            lambda: self.gx_example_path.setNotchData(notch, 'shape',
                    combobox_shape.currentText()))

        slider_base = QSlider(parent)
        slider_base.setOrientation(Qt.Horizontal)
        slider_base.setRange(0, 100)
        slider_base.setSingleStep(1)
        slider_base.setValue(
            self.gx_example_path.notch_data[notch]['base_fc'] * 100)
        self.connect(slider_base, SIGNAL('valueChanged(int)'),
            lambda: self.gx_example_path.setNotchData(notch, 'base_fc',
                    slider_base.value()/100))

        combobox_facing = QComboBox(parent)
        combobox_facing.addItems(['up', 'down'] if notch in ('top', 'bottom')
                                                else ['left', 'right'])
        combobox_facing.setCurrentIndex(combobox_facing.findText(
            self.gx_example_path.notch_data[notch]['facing']))
        self.connect(combobox_facing, SIGNAL('currentIndexChanged(int)'),
            lambda: self.gx_example_path.setNotchData(notch, 'facing',
                    combobox_facing.currentText()))

        slider_width = QSlider()
        slider_width.setOrientation(Qt.Horizontal)
        if notch in ('top', 'bottom'):
            slider_width.setRange(0, 300)
        else:
            slider_width.setRange(0, 100)
        slider_width.setSingleStep(1)
        slider_width.setValue(
            int(self.gx_example_path.notch_data[notch]['size'].width()))
        self.connect(slider_width, SIGNAL('valueChanged(int)'),
            lambda: self.setNotchSize('w', notch, follow_w,
                    slider_width))

        slider_height = QSlider()
        slider_height.setOrientation(Qt.Horizontal)
        if notch in ('top', 'bottom'):
            slider_height.setRange(0, 100)
        else:
            slider_height.setRange(0, 300)
        slider_height.setSingleStep(1)
        slider_height.setValue(
            int(self.gx_example_path.notch_data[notch]['size'].height()))
        self.connect(slider_height, SIGNAL('valueChanged(int)'),
            lambda: self.setNotchSize('h', notch, follow_h,
                    slider_height))

        setattr(self, 'wg_slider_%s_notch_size_w' % notch, slider_width)
        setattr(self, 'wg_slider_%s_notch_size_h' % notch, slider_height)

        gl = QGridLayout()
        gl.addWidget(QLabel('shape', parent), 0, 0)
        gl.addWidget(combobox_shape, 0, 1)
        gl.addWidget(QLabel('base', parent), 1, 0)
        gl.addWidget(slider_base, 1, 1)
        gl.addWidget(QLabel('facing', parent), 2, 0)
        gl.addWidget(combobox_facing, 2, 1)
        gl.addWidget(QLabel('width', parent), 3, 0)
        gl.addWidget(slider_width, 3, 1)
        gl.addWidget(QLabel('height', parent), 4, 0)
        gl.addWidget(slider_height, 4, 1)
        groupbox.setLayout(gl)

        return groupbox

    def setNotchSize(self, dimension, notch, follow_notch, slider):
        ''' (str in self.DIMENSIONS, str in self.DIRECTIONS,
             float) -> NoneType
        '''
        value = slider.value()

        if dimension == 'w':
            new_size = QSizeF(value, self.gx_example_path.\
                              notch_data[notch]['size'].height())
        else:
            new_size = QSizeF(
                self.gx_example_path.notch_data[notch]['size'].width(), value)

        self.gx_example_path.notch_data[notch]['size'] = new_size

        if follow_notch is not None:
            if dimension == 'w':
                new_follow_size = QSizeF(value, self.gx_example_path.\
                                  notch_data[follow_notch]['size'].height())
            else:
                new_follow_size = QSizeF(self.gx_example_path.notch_data \
                                         [follow_notch]['size'].width(), value)

            self.gx_example_path.notch_data[follow_notch]['size'] = \
                new_follow_size
            getattr(self, 'wg_slider_%s_notch_size_%s' % \
                (follow_notch, dimension)).setValue(value)

        self.gx_example_path.updateMetrics()

    def setupCornerGroupBox(self, title, corner, follow_w, follow_h, parent):
        ''' (str, str in self.CORNER_PLACES, QWidget) -> QGroupBox
        '''
        corner = corner.lower()
        follow_w, follow_h = follow_w.lower(), follow_h.lower()

        groupbox = QGroupBox(title, parent)

        combobox = QComboBox(parent)
        combobox.addItems(['trig', 'arc', 'rect'])
        combobox.setCurrentIndex(1)
        self.connect(combobox, SIGNAL('currentIndexChanged(int)'),
            lambda: self.setCornerShape(combobox, corner))

        slider_width = self.setupCornerSlider('w', corner, follow_w, parent)
        slider_height = self.setupCornerSlider('h', corner, follow_h, parent)

        setattr(self, 'wg_cbx_%s_corner_shape' % corner, combobox)
        setattr(self, 'wg_slider_%s_corner_size_w' % corner, slider_width)
        setattr(self, 'wg_slider_%s_corner_size_h' % corner, slider_height)

        gl = QGridLayout()
        gl.addWidget(QLabel('shape', parent), 0, 0)
        gl.addWidget(combobox, 0, 1)
        gl.addWidget(QLabel('width', parent), 1, 0)
        gl.addWidget(slider_width, 1, 1)
        gl.addWidget(QLabel('height', parent), 2, 0)
        gl.addWidget(slider_height, 2, 1)
        groupbox.setLayout(gl)

        return groupbox

    def setupCornerSlider(self, dimension, corner, follow_corner, parent):
        ''' (str in self.DIMENSIONS, str in self.CORNER_PLACES,
             str in self.CORNER_PLACES, QWidget) -> QSlider
        '''
        slider = QSlider(parent)
        slider.setOrientation(Qt.Horizontal)
        slider.setRange(0, 100)
        slider.setSingleStep(1)
        slider.setValue(50)
        self.connect(slider, SIGNAL('valueChanged(int)'),
            lambda: self.setCornerSize(slider, dimension[:], corner,
                                       follow_corner))
        return slider

    def setCornerShape(self, cbx, corner):
        ''' (QComboBox, str in self.CORNER_PLACES) -> NoneType
        '''
        self.gx_example_path.corner_shape[corner] = cbx.currentText()
        self.gx_example_path.updateMetrics()

    def setCornerSize(self, slider, dimension, corner, follow_corner):
        ''' (QSlider, str in self.DIMENSIONS, str in self.CORNER_PLACES,
             str in self.CORNER_PLACES) -> NoneType
        '''

        value = slider.value()
        if dimension == 'w':
            self.gx_example_path.corner_size[corner].setWidth(value)
            self.gx_example_path.corner_size[follow_corner].setWidth(value)
        else:
            self.gx_example_path.corner_size[corner].setHeight(value)
            self.gx_example_path.corner_size[follow_corner].setHeight(value)
        getattr(self, 'wg_slider_%s_corner_size_%s' % \
                (follow_corner, dimension)).setValue(value)
        self.gx_example_path.updateMetrics()
Exemplo n.º 4
0
class ExampleMainWindow(QMainWindow):
    POSITIONS = ("top", "bottom", "left", "right")
    DIMENSIONS = ("w", "h")
    CORNER_PLACES = ("tl", "tr", "bl", "br")

    def __init__(self, parent=None):
        """ (QWidget) -> NoneType
        """
        QMainWindow.__init__(self, parent)

        self.scene = GxSceneBlocks()
        self.scene.setSceneRect(0, 0, 800, 800)
        self.gx_example_path = GxExamplePaths(self.scene)

        self.initUI()

    def initUI(self):
        """ () -> NoneType
        """

        # --- corner settings ----------------------------------------------

        self.wg_area_corners = QWidget(self)

        self.wg_gbx_bl_corner = self.setupCornerGroupBox(" Bottom-Left ", "bl", "tl", "br", self.wg_area_corners)

        self.wg_gbx_br_corner = self.setupCornerGroupBox(" Bottom-Right ", "br", "tr", "bl", self.wg_area_corners)

        self.wg_gbx_tl_corner = self.setupCornerGroupBox(" Top-Left ", "tl", "bl", "tr", self.wg_area_corners)

        self.wg_gbx_tr_corner = self.setupCornerGroupBox(" Top-Right ", "tr", "br", "tl", self.wg_area_corners)

        vl = QVBoxLayout()
        vl.addWidget(self.wg_gbx_bl_corner)
        vl.addWidget(self.wg_gbx_br_corner)
        vl.addWidget(self.wg_gbx_tl_corner)
        vl.addWidget(self.wg_gbx_tr_corner)
        self.wg_area_corners.setLayout(vl)

        # ---- notch settings ----------------------------------------------

        self.wg_area_notch = QWidget(self)

        self.wg_gbx_top_notch = self.setupNotchGroupBox(" Top ", "top", "bottom", None, self.wg_area_notch)

        self.wg_gbx_bottom_notch = self.setupNotchGroupBox(" Bottom ", "bottom", "top", None, self.wg_area_notch)

        self.wg_gbx_left_notch = self.setupNotchGroupBox(" Left ", "left", None, "right", self.wg_area_notch)

        self.wg_gbx_right_notch = self.setupNotchGroupBox(" Right ", "right", None, "left", self.wg_area_notch)

        vl = QVBoxLayout()
        vl.addWidget(self.wg_gbx_top_notch)
        vl.addWidget(self.wg_gbx_bottom_notch)
        vl.addWidget(self.wg_gbx_left_notch)
        vl.addWidget(self.wg_gbx_right_notch)
        self.wg_area_notch.setLayout(vl)

        # --------------------------------------------------------------

        self.wg_area_win = QWidget(self)

        self.wg_view = GxView(self.scene, parent=self)

        self.wg_tab_command = QTabWidget(self)
        self.wg_tab_command.addTab(self.wg_area_corners, "Corners")
        self.wg_tab_command.addTab(self.wg_area_notch, "Notch")
        self.wg_tab_command.setFixedWidth(200)

        hl = QHBoxLayout()
        hl.addWidget(self.wg_view)
        hl.addWidget(self.wg_tab_command, 200)
        self.wg_area_win.setLayout(hl)

        self.setGeometry(200, 50, 1000, 550)
        self.setCentralWidget(self.wg_area_win)

    def setupNotchGroupBox(self, title, notch, follow_w, follow_h, parent):
        """ (str, str in self.POSITIONS, QWidget) -> QGroupBox
        """
        groupbox = QGroupBox(title, parent)

        combobox_shape = QComboBox(parent)
        combobox_shape.addItems(["trig", "arc"])
        combobox_shape.setCurrentIndex(combobox_shape.findText(self.gx_example_path.notch_data[notch]["shape"]))
        self.connect(
            combobox_shape,
            SIGNAL("currentIndexChanged(int)"),
            lambda: self.gx_example_path.setNotchData(notch, "shape", combobox_shape.currentText()),
        )

        slider_base = QSlider(parent)
        slider_base.setOrientation(Qt.Horizontal)
        slider_base.setRange(0, 100)
        slider_base.setSingleStep(1)
        slider_base.setValue(self.gx_example_path.notch_data[notch]["base_fc"] * 100)
        self.connect(
            slider_base,
            SIGNAL("valueChanged(int)"),
            lambda: self.gx_example_path.setNotchData(notch, "base_fc", slider_base.value() / 100),
        )

        combobox_facing = QComboBox(parent)
        combobox_facing.addItems(["up", "down"] if notch in ("top", "bottom") else ["left", "right"])
        combobox_facing.setCurrentIndex(combobox_facing.findText(self.gx_example_path.notch_data[notch]["facing"]))
        self.connect(
            combobox_facing,
            SIGNAL("currentIndexChanged(int)"),
            lambda: self.gx_example_path.setNotchData(notch, "facing", combobox_facing.currentText()),
        )

        slider_width = QSlider()
        slider_width.setOrientation(Qt.Horizontal)
        if notch in ("top", "bottom"):
            slider_width.setRange(0, 300)
        else:
            slider_width.setRange(0, 100)
        slider_width.setSingleStep(1)
        slider_width.setValue(int(self.gx_example_path.notch_data[notch]["size"].width()))
        self.connect(
            slider_width, SIGNAL("valueChanged(int)"), lambda: self.setNotchSize("w", notch, follow_w, slider_width)
        )

        slider_height = QSlider()
        slider_height.setOrientation(Qt.Horizontal)
        if notch in ("top", "bottom"):
            slider_height.setRange(0, 100)
        else:
            slider_height.setRange(0, 300)
        slider_height.setSingleStep(1)
        slider_height.setValue(int(self.gx_example_path.notch_data[notch]["size"].height()))
        self.connect(
            slider_height, SIGNAL("valueChanged(int)"), lambda: self.setNotchSize("h", notch, follow_h, slider_height)
        )

        setattr(self, "wg_slider_%s_notch_size_w" % notch, slider_width)
        setattr(self, "wg_slider_%s_notch_size_h" % notch, slider_height)

        gl = QGridLayout()
        gl.addWidget(QLabel("shape", parent), 0, 0)
        gl.addWidget(combobox_shape, 0, 1)
        gl.addWidget(QLabel("base", parent), 1, 0)
        gl.addWidget(slider_base, 1, 1)
        gl.addWidget(QLabel("facing", parent), 2, 0)
        gl.addWidget(combobox_facing, 2, 1)
        gl.addWidget(QLabel("width", parent), 3, 0)
        gl.addWidget(slider_width, 3, 1)
        gl.addWidget(QLabel("height", parent), 4, 0)
        gl.addWidget(slider_height, 4, 1)
        groupbox.setLayout(gl)

        return groupbox

    def setNotchSize(self, dimension, notch, follow_notch, slider):
        """ (str in self.DIMENSIONS, str in self.DIRECTIONS,
             float) -> NoneType
        """
        value = slider.value()

        if dimension == "w":
            new_size = QSizeF(value, self.gx_example_path.notch_data[notch]["size"].height())
        else:
            new_size = QSizeF(self.gx_example_path.notch_data[notch]["size"].width(), value)

        self.gx_example_path.notch_data[notch]["size"] = new_size

        if follow_notch is not None:
            if dimension == "w":
                new_follow_size = QSizeF(value, self.gx_example_path.notch_data[follow_notch]["size"].height())
            else:
                new_follow_size = QSizeF(self.gx_example_path.notch_data[follow_notch]["size"].width(), value)

            self.gx_example_path.notch_data[follow_notch]["size"] = new_follow_size
            getattr(self, "wg_slider_%s_notch_size_%s" % (follow_notch, dimension)).setValue(value)

        self.gx_example_path.updateMetrics()

    def setupCornerGroupBox(self, title, corner, follow_w, follow_h, parent):
        """ (str, str in self.CORNER_PLACES, QWidget) -> QGroupBox
        """
        corner = corner.lower()
        follow_w, follow_h = follow_w.lower(), follow_h.lower()

        groupbox = QGroupBox(title, parent)

        combobox = QComboBox(parent)
        combobox.addItems(["trig", "arc", "rect"])
        combobox.setCurrentIndex(1)
        self.connect(combobox, SIGNAL("currentIndexChanged(int)"), lambda: self.setCornerShape(combobox, corner))

        slider_width = self.setupCornerSlider("w", corner, follow_w, parent)
        slider_height = self.setupCornerSlider("h", corner, follow_h, parent)

        setattr(self, "wg_cbx_%s_corner_shape" % corner, combobox)
        setattr(self, "wg_slider_%s_corner_size_w" % corner, slider_width)
        setattr(self, "wg_slider_%s_corner_size_h" % corner, slider_height)

        gl = QGridLayout()
        gl.addWidget(QLabel("shape", parent), 0, 0)
        gl.addWidget(combobox, 0, 1)
        gl.addWidget(QLabel("width", parent), 1, 0)
        gl.addWidget(slider_width, 1, 1)
        gl.addWidget(QLabel("height", parent), 2, 0)
        gl.addWidget(slider_height, 2, 1)
        groupbox.setLayout(gl)

        return groupbox

    def setupCornerSlider(self, dimension, corner, follow_corner, parent):
        """ (str in self.DIMENSIONS, str in self.CORNER_PLACES,
             str in self.CORNER_PLACES, QWidget) -> QSlider
        """
        slider = QSlider(parent)
        slider.setOrientation(Qt.Horizontal)
        slider.setRange(0, 100)
        slider.setSingleStep(1)
        slider.setValue(50)
        self.connect(
            slider, SIGNAL("valueChanged(int)"), lambda: self.setCornerSize(slider, dimension[:], corner, follow_corner)
        )
        return slider

    def setCornerShape(self, cbx, corner):
        """ (QComboBox, str in self.CORNER_PLACES) -> NoneType
        """
        self.gx_example_path.corner_shape[corner] = cbx.currentText()
        self.gx_example_path.updateMetrics()

    def setCornerSize(self, slider, dimension, corner, follow_corner):
        """ (QSlider, str in self.DIMENSIONS, str in self.CORNER_PLACES,
             str in self.CORNER_PLACES) -> NoneType
        """

        value = slider.value()
        if dimension == "w":
            self.gx_example_path.corner_size[corner].setWidth(value)
            self.gx_example_path.corner_size[follow_corner].setWidth(value)
        else:
            self.gx_example_path.corner_size[corner].setHeight(value)
            self.gx_example_path.corner_size[follow_corner].setHeight(value)
        getattr(self, "wg_slider_%s_corner_size_%s" % (follow_corner, dimension)).setValue(value)
        self.gx_example_path.updateMetrics()