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


Python canvas.Canvas类代码示例

本文整理汇总了Python中canvas.Canvas的典型用法代码示例。如果您正苦于以下问题:Python Canvas类的具体用法?Python Canvas怎么用?Python Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: __init__

 def __init__(self,parent,dpi=100.0):
     Canvas.__init__(self,parent,dpi)
     self.has_data = False
     self.sqplot = None
     self.cb = None
     self.colormap = customcolormap.make_colormap("mymap", 1.0, 0.001, 10)
     self.cmaplimits = 2.0
开发者ID:cstein,项目名称:fmo-ie-analyzer,代码行数:7,代码来源:fiecanvas.py

示例2: test_unknown_method

 def test_unknown_method(self):
     # EXEC
     canvas = Canvas()
     with self.assertRaisesRegex(
             AttributeError, 
             "(Canvas instance|'Canvas' object) has no attribute 'create_wirple'"):
         canvas.create_wirple(1, 'floop')
开发者ID:donkirkby,项目名称:live-py-plugin,代码行数:7,代码来源:test_canvas.py

示例3: run

 def run(self):
     print 'RUNNING'
     r = lambda: random.randint(0, 255)
     while True:
         Canvas.clear()
         Canvas.draw_rect((0, 0), (200, 200), fill_style='#%02X%02X%02X' % (r(), r(), r()))
         sleep(random.uniform(0.03, 1))
开发者ID:djoeman84,项目名称:tikoApp,代码行数:7,代码来源:app.py

示例4: MainWidget

class MainWidget(QtGui.QScrollArea):
	"""
	La clase MainWidget es una derivada de la clase QScrollArea.
	En este widget se pone, centrado, el lienzo del dibujo (Canvas).
	Además, éste es el widget alrededor del cual se centra la MainWindow.
	"""

	def __init__(self, w, h, image, com, color, Parent=None):

		super(MainWidget,self).__init__()

		self.canvas = Canvas(w, h, image, com, color, self)
		self.setWidget(self.canvas)

	def resizeEvent(self, event):

		super(MainWidget,self).resizeEvent(event)
		self.calcNewCanvasGeometry()

	def paintEvent(self, event):

		super(MainWidget,self).paintEvent(event)
		self.calcNewCanvasGeometry()

	def calcNewCanvasGeometry(self):
		g = self.frameGeometry()
		w = g.width()
		h = g.height()
		self.canvas.move( (w-self.canvas.width*self.canvas.zoom)/2, (h-self.canvas.height*self.canvas.zoom)/2 );
		print self.frameGeometry()
开发者ID:aaronsprisma,项目名称:pixelart,代码行数:30,代码来源:mainwidget.py

示例5: prepareString

 def prepareString(self, str, font):
     """Returns a Canvas object with the rasterized string"""
     tmpCanvas = Canvas(8*len(str), 8)
     offset = 0
     for char in str:
         glyph = font.getChar(char)
         tmpCanvas.fromBytes(glyph, offset)
         offset += font.getCharSize(char) + font.getLetterSpace(char)
     return tmpCanvas
开发者ID:elamperti,项目名称:max7219,代码行数:9,代码来源:maxdraw.py

示例6: __init__

 def __init__(self, varname, player_1='human', player_2='random', id=None, width=300, height=300):
     valid_players = ('human', 'random', 'alphabeta')
     if player_1 not in valid_players or player_2 not in valid_players:
         raise TypeError("Players must be one of {}".format(valid_players))
     Canvas.__init__(self, varname, id, width, height)
     self.ttt = TicTacToe()
     self.state = self.ttt.initial
     self.turn = 0
     self.strokeWidth(5)
     self.players = (player_1, player_2)
     self.draw_board()
     self.font("Ariel 30px")
开发者ID:hooperw,项目名称:aima-python,代码行数:12,代码来源:games.py

示例7: test_bounds

 def test_bounds(self):
     # SETUP
     expected_width = 800
     expected_height = 600
     # EXEC
     canvas = Canvas(expected_width, expected_height)
     width = canvas.cget('width')
     height = canvas.cget('height')
     
     # VERIFY
     self.assertEqual(expected_width, width)
     self.assertEqual(expected_height, height)
开发者ID:donkirkby,项目名称:live-py-plugin,代码行数:12,代码来源:test_canvas.py

示例8: __init__

 def __init__(self, parent):
     Canvas.__init__(self, parent)
     self.pen_cadre_1 = Pen((0,0,250), 2)
     self.pen_cadre_2 = Pen(width=3)
     self.pen_aiguille_1 = Pen(width=6)
     self.pen_aiguille_2 = Pen(width=5)
     self.pen_aiguille_3 = Pen(width=2, color=(255,0,0))
     
     self.bind(size=self.on_size)
     #self._draw_cadre()
     self.aiguille_draw_op = CombineDrawOperation(self, [])
     self.scheduler = Thread(target=self.schedule)
     self.scheduler.start()
开发者ID:typerlc,项目名称:ankice-deps,代码行数:13,代码来源:clock.py

示例9: Window

class Window(object):
    def __init__(self, width: int, height: int, pixels: ndarray):
        self.pixels = pixels
        self.width = width
        self.height = height

        self.canvas = Canvas(width, height, pixels)

        # setup key handlers
        key_esc = 27
        self.handlers = {
            key_esc: self.exit
        }

        # self.v1 = Vertex(Vector(0, 0), Color.cyan())
        # self.v2 = Vertex(Vector(300, 100), Color.red())
        # self.v3 = Vertex(Vector(200, 300), Color.green())

        model_path = "illidan.model"
        texture_path = "illidan.texture"

        self.mesh = Mesh(model_path, texture_path)

    def clear(self):
        self.canvas.clear()
        pass

    def update(self, dt):
        pass

    def draw(self):
        # self.canvas.draw_triangle(self.v1, self.v2, self.v3)
        self.canvas.draw_mesh(self.mesh)

    def mouse_event(self, button, state, x, y):
        print('mouse event', button, state, x, y)
        # 0, left button
        # 2, right button
        # 0, state press
        # 1, state release

    def exit(self):
        sys.exit(0)

    def cmd404(self):
        pass

    def key_event(self, key, key_is_down):
        print('key event', key, key_is_down)
        cmd = self.handlers.get(key, self.cmd404)
        cmd()
开发者ID:happlebao,项目名称:rendererpy,代码行数:51,代码来源:window.py

示例10: main

def main():
    global screen
    pygame.init()
    pygame.mixer.quit()
    pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=128)
    can = Canvas()
    for c in can.channels:
        can.channels[c].set_volume(0.1)
    screen = pygame.display.set_mode((640, 200))
    
    while True:
        screen.fill((0, 0, 0))
        can.update(screen)
        pygame.display.update()
        clock.tick(30)
开发者ID:PROGRAM-IX,项目名称:bursts,代码行数:15,代码来源:bursts.py

示例11: MainWindow

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self._create_actions()
        self._create_toolbar()
        self._canvas = Canvas()
        self._canvas.scale(16, 16)
        self.setCentralWidget(self._canvas)

    def _create_actions(self):
        self._delete_action = QAction("Delete", None)
        self._delete_action.setShortcuts(QKeySequence.Delete)
        self._delete_action.triggered.connect(self._delete)

        self._select_action = QAction("Select", None)
        self._select_action.setCheckable(True)
        self._select_action.triggered.connect(self._use_select_tool)

        self._pen_action = QAction("Pen", None)
        self._pen_action.setCheckable(True)
        self._pen_action.setChecked(True)
        self._pen_action.triggered.connect(self._use_pen_tool)

        self._new_shape_action = QAction("New Shape", None)
        self._new_shape_action.triggered.connect(self._new_shape)

        self._tool_group = QActionGroup(None)
        self._tool_group.addAction(self._select_action)
        self._tool_group.addAction(self._pen_action)

    def _create_toolbar(self):
        toolbar = self.addToolBar("Tools")
        toolbar.addAction(self._delete_action)
        toolbar.addAction(self._select_action)
        toolbar.addAction(self._pen_action)
        toolbar.addAction(self._new_shape_action)

    def _use_select_tool(self):
        self._canvas.use_tool(SelectTool)

    def _use_pen_tool(self):
        self._canvas.use_tool(PenTool)

    def _new_shape(self):
        self._canvas.new_shape()

    def _delete(self):
        self._canvas.delete_selection()
开发者ID:lilliemarck,项目名称:linjal-py,代码行数:48,代码来源:linjal.py

示例12: Filler

class Filler(object):
    def __init__(self, bits, starting_pixel_count):
        self.colorset = Colorset(bits)

        # This is technically only correct for an even number of bits, but
        # it rounds down for an odd number of bits, and there are simply some colors
        # that we never use.  Shrug.

        height = width = int(math.sqrt(self.colorset.size()))
        self.canvas = Canvas(width, height)

        self.starting_pixel_count = starting_pixel_count
        self.add_starting_pixels()
        self.start_time = time.time()
        self.last_save_time = time.time()

        self.time_color = 0.0
        self.time_point = 0.0

    def add_starting_pixels(self):
        # Grab some random starting colors just by making a randomly-sorted
        # list of all the colors and taking the first few.
        # Not the most efficient, but doesn't really matter.
        colors = [x for x in self.colorset.iterate()]
        random.shuffle(colors)
        height = width = self.canvas.height
        self.starting_pixel_list = []
        for i in xrange(self.starting_pixel_count):
            starting_color = self.colorset.get_nearest(colors[i])
            x = random.randint(0, width-1)
            y = random.randint(0, height-1)
            self.starting_pixel_list.append((x, y))
            self.canvas.set(x, y, starting_color)

    def write_image(self, i):
        bits = self.colorset.bits
        name = '/tmp/colors-%s.%d.%d.%d.png' % (self.__class__.__name__,
                                                bits,
                                                self.starting_pixel_count,
                                                i)
        avg_rate = i / (time.time() - self.start_time)
        print (name,
               time.time() - self.last_save_time,
               int(avg_rate),
               int(self.time_color),
               int(self.time_point))
        self.canvas.save(name)
        self.last_save_time = time.time()
开发者ID:mkjones,项目名称:allrgb,代码行数:48,代码来源:filler.py

示例13: Window

class Window(object):
    def __init__(self, pixels, width, height):
        self.pixels = pixels
        self.width = width
        self.height = height

        self.canvas = Canvas(width, height, pixels)

        # setup key handlers
        key_esc = 27
        self.handlers = {
            key_esc: self.exit
        }
		
		
        self.v1 = Vertex(Vector(0, 0), Color.cyan())
        self.v2 = Vertex(Vector(300, 100), Color.red())
        self.v3 = Vertex(Vector(200, 300), Color.white())
        self.v4 = Vertex(Vector(300, 0), Color.green())

    def clear(self):
        self.canvas.clear()
        pass

    def update(self, dt):
        pass

    def draw(self):
		self.canvas.draw_triangle(self.v1, self.v2, self.v4)
		self.canvas.draw_triangle(self.v1, self.v2, self.v3)

    def mouse_event(self, button, state, x, y):
        print('mouse event', button, state, x, y)
        # 0, left button
        # 2, right button
        # 0, state press
        # 1, state release

    def exit(self):
        sys.exit(0)

    def cmd404(self):
        pass

    def key_event(self, key, key_is_down):
        print('key event', key, key_is_down)
        cmd = self.handlers.get(key, self.cmd404)
        cmd()
开发者ID:Rain1996,项目名称:rasterizer.py,代码行数:48,代码来源:window.py

示例14: __init__

 def __init__(self):
     QMainWindow.__init__(self)
     self._create_actions()
     self._create_toolbar()
     self._canvas = Canvas()
     self._canvas.scale(16, 16)
     self.setCentralWidget(self._canvas)
开发者ID:lilliemarck,项目名称:linjal-py,代码行数:7,代码来源:linjal.py

示例15: __init__

    def __init__(self, matrixobject, positioninmatrix, weatherdefinition, hours_from_now, update_interval, getweatherobject):
        logging.info('Creating new Weather instance')

        self.__Matrix = matrixobject
        self.__MatrixPosition = positioninmatrix
        self.__WeatherDefinition = weatherdefinition
        self.__HoursFromNow = hours_from_now
        self.__UpdateInterval = update_interval

        self.__WeatherCanvas = Canvas(weatherdefinition['Size'])
        self.__ImageChanged = True

        self.__GetWeatherObject = getweatherobject
        self.__WeatherData = []
        self.__WeatherForecast = {}
        self.__CurrentWeatherIcon = ''
        self.__CurrentWeatherWind = -1
        self.__CurrentWeatherRain = -1.0
        self.__CurrentWeatherSnow = -1.0
        self.__CurrentWeatherMaxTemp = 999.0
        self.__CurrentWeatherMinTemp = -999.0
        self.__CurrentWeatherTime = -1
        self.__WeatherReadError = False
        self.__LastUpdateTime = 0
        self.__WindSpeedIcon = -1
        self.__RainSnowIcon = ''
开发者ID:GeekyTim,项目名称:PiClock,代码行数:26,代码来源:weather.py


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