From 83cf434426fea35a74d445c9cb71d8de2c2a9d50 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Thu, 17 Sep 2015 15:54:21 -1000 Subject: [PATCH] Put ShapeWidget in a neat GroupBox with the shape's name in the caption. --- src/mcedit2/editortools/brush/shapes.py | 22 ++++++ src/mcedit2/ui/editortools/brush.ui | 100 +++++++----------------- src/mcedit2/widgets/shapewidget.py | 11 ++- 3 files changed, 60 insertions(+), 73 deletions(-) diff --git a/src/mcedit2/editortools/brush/shapes.py b/src/mcedit2/editortools/brush/shapes.py index bf95d64..e4230e4 100644 --- a/src/mcedit2/editortools/brush/shapes.py +++ b/src/mcedit2/editortools/brush/shapes.py @@ -93,6 +93,10 @@ class Round(BrushShape): ID = "Round" icon = "shapes/round.png" + def __init__(self): + super(Round, self).__init__() + self.displayName = self.tr("Round") + def shapeFunc(self, blockPositions, shape): # For spheres: x^2 + y^2 + z^2 <= r^2 # For ovoids: x^2/rx^2 + y^2/ry^2 + z^2/rz^2 <= 1 @@ -125,6 +129,7 @@ class Square(BrushShape): def __init__(self): super(Square, self).__init__() + self.displayName = self.tr("Square") self.optionsWidget = QtGui.QWidget() self.hollowCheckbox = QtGui.QCheckBox() @@ -148,6 +153,10 @@ class Diamond(BrushShape): ID = "Diamond" icon = "shapes/diamond.png" + def __init__(self): + super(Diamond, self).__init__() + self.displayName = self.tr("Diamond") + def shapeFunc(self, blockPositions, selectionSize): # This is an octahedron. @@ -174,6 +183,10 @@ class Cylinder(BrushShape): ID = "Cylinder" icon = "shapes/cylinder.png" + def __init__(self): + super(Cylinder, self).__init__() + self.displayName = self.tr("Cylinder") + def shapeFunc(self, blockPositions, selectionSize): # axis = y # @@ -207,6 +220,10 @@ class ChunkShape(BrushShape): ID = "Chunk" icon = "shapes/chunk.png" + def __init__(self): + super(ChunkShape, self).__init__() + self.displayName = self.tr("Chunk") + def createShapedSelection(self, box, dimension): return box.chunkBox(dimension) @@ -215,6 +232,10 @@ class ParabolicDome(BrushShape): ID = "ParabolicDome" icon = "shapes/parabolic_dome.png" + def __init__(self): + super(ParabolicDome, self).__init__() + self.displayName = self.tr("Parabolic Dome") + def shapeFunc(self, blockPositions, selectionSize): # In 2D: @@ -261,5 +282,6 @@ class ParabolicDome(BrushShape): # xxx what is responsible for "owning" the instances of BrushShape?? # Currently the ShapeWidget seems to own them. + def getShapes(): return Square(), Round(), Diamond(), Cylinder(), ParabolicDome() diff --git a/src/mcedit2/ui/editortools/brush.ui b/src/mcedit2/ui/editortools/brush.ui index 995e7cd..b656800 100644 --- a/src/mcedit2/ui/editortools/brush.ui +++ b/src/mcedit2/ui/editortools/brush.ui @@ -6,7 +6,7 @@ 0 0 - 469 + 517 711 @@ -15,8 +15,8 @@ - - + + @@ -26,7 +26,7 @@ - + @@ -36,28 +36,21 @@ - - - - Shape: - - - - + Length: - + Hover: - + @@ -67,81 +60,28 @@ - + Mode: - + Height: - + Width: - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - true - - - - - 0 - 0 - 447 - 69 - - - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 40 - 40 - - - - - - - - - + @@ -151,7 +91,7 @@ - + @@ -161,6 +101,22 @@ + + + + + 0 + 0 + + + + + 40 + 40 + + + + diff --git a/src/mcedit2/widgets/shapewidget.py b/src/mcedit2/widgets/shapewidget.py index 7e07512..e2f3e25 100644 --- a/src/mcedit2/widgets/shapewidget.py +++ b/src/mcedit2/widgets/shapewidget.py @@ -21,6 +21,8 @@ class ShapeWidget(QtGui.QWidget): addShapes = kwargs.pop('addShapes', None) super(ShapeWidget, self).__init__(*args, **kwargs) buttons = self.buttons = [] + self.groupBox = QtGui.QGroupBox("Shape:") + flowLayout = flowlayout.FlowLayout() actionGroup = QtGui.QActionGroup(self) actionGroup.setExclusive(True) @@ -29,6 +31,7 @@ class ShapeWidget(QtGui.QWidget): shapes = list(getShapes()) if addShapes: shapes.extend(addShapes) + for shape in shapes: if shape.icon is not None: filename = os.path.join(iconBase, shape.icon) @@ -61,7 +64,8 @@ class ShapeWidget(QtGui.QWidget): self.optionsHolder = QtGui.QStackedWidget() layout = Column(flowLayout, (self.optionsHolder, 1)) - self.setLayout(layout) + self.groupBox.setLayout(layout) + self.setLayout(Column(self.groupBox, margin=0)) currentID = BrushShapeSetting.value(shapes[0].ID) shapesByID = {shape.ID: shape for shape in shapes} @@ -77,7 +81,12 @@ class ShapeWidget(QtGui.QWidget): shapeChanged = QtCore.Signal(object) shapeOptionsChanged = QtCore.Signal() + def groupBoxTitle(self, shape): + return self.tr("Shape: ") + shape.displayName + def shapeDidChange(self, newShape): + self.groupBox.setTitle(self.groupBoxTitle(newShape)) + while self.optionsHolder.count(): self.optionsHolder.removeWidget(self.optionsHolder.widget(0))