当前位置: 首页>>代码示例>>Python>>正文


Python History.addAction方法代码示例

本文整理汇总了Python中history.History.addAction方法的典型用法代码示例。如果您正苦于以下问题:Python History.addAction方法的具体用法?Python History.addAction怎么用?Python History.addAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在history.History的用法示例。


在下文中一共展示了History.addAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import addAction [as 别名]
class Canvas:
    '''Canvas Class'''
    width = int
    height = int
    referenceX = int
    referenceY = int
    windowWidth = int
    windowHeight = int
    

    layers = []
    order = []
    
    name = ""
    filepath = "unnamed.cobra"
    
    def __init__(self, width, height, name, path):
        '''Constructor'''

        #Get size from parent
        self.width = width
        self.height = height

        self.name = name
        self.filepath = path

        self.referenceX = 0
        self.referenceY = 0
        self.windowWidth = 800
        self.windowHeight = 600

        self.curStroke = []
        self.brush = Brush(2,"brush",110)
        self.eraser = Brush(2,"eraser",255)
        self.eraserMode = False
        self.his = History()

        self.pointQueue = deque([])
        self.batch = graphics.Batch()
        self.background = graphics.OrderedGroup(0)
        self.drawingLayer = graphics.OrderedGroup(2)
        self.layer1 = graphics.OrderedGroup(1)
        
        self.canvas = self.batch.add(self.width*self.height,
                                     gl.GL_POINTS, self.background,
                                     ('v2i'), ('c3B'))
        self.swap = self.batch.add(self.width*self.height,
                                     gl.GL_POINTS, self.drawingLayer,
                                     ('v2i'), ('c3B'))
        
        self._buildCanvas(self.canvas)
        self._buildSwap(self.swap)

        self.layers.append(Layer(self.width,self.height,self.batch,self.layer1,0))
        
        self.currentLayer = self.layers[0]
        self.order.append(1)
        
        self.layerAction = Action()
        self.layerAction.layer = self.currentLayer
        self.layerAction.name = self.currentLayer.name
        self.his.addAction(self.layerAction)

    def draw(self):
        '''Updates the canvas, drawing all layers'''
        self.batch.draw()

    def _buildCanvas(self, canvas):
        for x in range(self.width):
            for y in range(self.height):
                '''We have to convert our 2d coordinates into a 1d array index'''
                i = self._2dTo1d(x, y)
                canvas.vertices[i*2:i*2+2] = [x, y]
                canvas.colors[i*3:i*3+3] = [255, 255, 255]
                
    def _buildSwap(self, swap):
        for i in range(self.width*self.height):
            '''We have to convert our 2d coordinates into a 1d array index'''
            swap.vertices[i*2:i*2+2] = [0,0]
            swap.colors[i*3:i*3+3] = [0,0,0]

    def setBrushSize(self, command):
        if(command == 'Increase Brush Size'):
            self._incBrush()
        else:
            self._decBrush()
    def _incBrush(self):
        if(self.brush.size < 10):
            self.brush.size = self.brush.size + 2

    def _decBrush(self):
        if(self.brush.size > 2):
            self.brush.size = self.brush.size - 2

    def setPencil(self):
        self.eraserMode = False

    def setEraser(self):
        self.eraserMode = True

#.........这里部分代码省略.........
开发者ID:ChrisNeveu,项目名称:CobraSketch,代码行数:103,代码来源:canvas.py


注:本文中的history.History.addAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。