Ejemplo n.º 1
0
 def saveImage(self, dirpath):
     img = FlowBoardPainter.renderImage(self._board, self._solver)
     filename = hex(abs(self._solver.stateHash()))[2:] + '.png'
     writer = QImageWriter(path.join(dirpath, filename))
     writer.setFormat('png')
     if not writer.write(img):
         raise Exception(writer.errorString())
Ejemplo n.º 2
0
 def paintEvent(self, event):
     super(FlowBoardEditor, self).paintEvent(event)
     ptr = FlowBoardPainter(self)
     ptr.drawGrid(self._grid)
     ptr.drawBoardFeatures(self._grid, self._board)
     if self._lastMoveCell:
         cell = self._lastMoveCell
         if self.selectedTool.canApply(self._board, cell):
             self._drawToolPreview(ptr, self.selectedTool, cell)
         else:
             for c in self.selectedTool.conflictCells(self._board, cell):
                 ptr.drawConflict(self._grid.cellRect(c))
Ejemplo n.º 3
0
    def __init__(self):
        super(FlowToolChooser, self).__init__()
        self._group = QButtonGroup()
        self._group.setExclusive(True)
        layout = QGridLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(8, 3, 8, 3)
        layout.setAlignment(Qt.AlignCenter)

        endpointTools = map(FlowToolEndpoint, FlowBoardPainter.endpointKeys())
        endpointToolCount = len(FlowBoardPainter.endpointKeys())
        self._endpointButtons = []
        row = 0
        col = 2
        for tool in endpointTools:
            toolButton = FlowToolButton(tool)
            self._endpointButtons.append(toolButton)
            self._group.addButton(toolButton)
            layout.addWidget(toolButton, row, col)
            col += 1
            if col - 1 > endpointToolCount / 2:
                row += 1
                col = 2

        clearToolButton = FlowToolButton(FlowToolClear())
        clearToolButton.setToolTip("clear")
        self._group.addButton(clearToolButton)
        layout.addWidget(clearToolButton, 0, 0)
        clearToolButton.select()

        self._bridgeToolButton = FlowToolButton(FlowToolBridge())
        self._bridgeToolButton.setToolTip("bridge")
        self._group.addButton(self._bridgeToolButton)
        layout.addWidget(self._bridgeToolButton, 1, 1)

        self._blockToolButton = FlowToolButton(FlowToolBlock())
        self._blockToolButton.setToolTip("blockage")
        self._group.addButton(self._blockToolButton)
        layout.addWidget(self._blockToolButton, 1, 0)

        self.setLayout(layout)
Ejemplo n.º 4
0
 def stepEndpointSelection(self, forward=True):
     if isinstance(self.selected, FlowToolEndpoint):
         keys = FlowBoardPainter.endpointKeys()
         i = keys.index(self.selected.endpointKey)
         i = (i + (1 if forward else -1)) % len(keys)
         self.selectEndpoint(keys[i])
Ejemplo n.º 5
0
 def paintEvent(self, event):
     ptr = FlowBoardPainter(self)
     ptr.fillBackground()
     ptr.end()
     super(FlowToolChooser, self).paintEvent(event)
Ejemplo n.º 6
0
 def paintEvent(self, event):
     ptr = FlowBoardPainter(self)
     ptr.fillBackground()
     if self.checkState() == Qt.Checked:
         ptr.setPen(QPen(QColor(255, 255, 255), 2, Qt.DotLine))
         ptr.drawRect(self.rect().adjusted(1, 1, -1, -1))
     iconrect = self.rect().adjusted(2, 2, -2, -2)
     ptr.drawImage(iconrect.topLeft(), self._tool.getIcon(iconrect.size()))
     ptr.end()
Ejemplo n.º 7
0
 def _makeIcon(self, size):
     img = FlowTool._emptyIcon(size)
     ptr = FlowBoardPainter(img)
     ptr.drawBlock(img.rect())
     ptr.end()
     return img
Ejemplo n.º 8
0
 def _makeIcon(self, size):
     img = FlowTool._emptyIcon(size)
     ptr = FlowBoardPainter(img)
     ptr.drawEndpoint(img.rect(), self.endpointKey, scale=1)
     ptr.end()
     return img
Ejemplo n.º 9
0
 def _emptyIcon(size):
     img = QImage(size, QImage.Format_ARGB32_Premultiplied)
     ptr = FlowBoardPainter(img)
     ptr.fillBackground()
     ptr.end()
     return img
Ejemplo n.º 10
0
 def paintEvent(self, event):
     super(FlowSolverWidget, self).paintEvent(event)
     ptr = FlowBoardPainter(self)
     ptr.fillBackground()
     if self._board:
         if self._solver and self._solver.solved:
             ptr.drawFlowHighlights(self._grid, self._solver)
         ptr.drawGrid(self._grid)
         ptr.drawBoardFeatures(self._grid, self._board)
         if self._solver:
             ptr.drawFlows(self._grid, self._solver)
     ptr.end()