本文整理汇总了Python中canvas.Canvas.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.connect方法的具体用法?Python Canvas.connect怎么用?Python Canvas.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import connect [as 别名]
class MainWindow(GladeWindow):
glade_file = os.path.join("gui", "pybotlearn.glade")
def __init__(self):
super(MainWindow, self).__init__()
self.canvas = Canvas()
self.canvas.connect("key-press-event", self.on_key)
self.robot = self.canvas.robot
execution.robot = self.robot
self.canvas_sw.add(self.canvas)
self.console = PythonConsole(execution.namespace)
self.main_paned.pack2(self.console)
self.show_all()
self.canvas.get_hadjustment().connect("value-changed", self.on_scroll)
self.canvas.get_vadjustment().connect("value-changed", self.on_scroll)
def on_up(self, *args):
self.console.eval("move_up()", True)
def on_down(self, *args):
self.console.eval("move_down()", True)
def on_right(self, *args):
self.console.eval("move_right()", True)
def on_left(self, *args):
self.console.eval("move_left()", True)
def on_key(self, sender, event):
if event.keyval == gtk.keysyms.Up:
self.on_up()
return True
elif event.keyval == gtk.keysyms.Down:
self.on_down()
return True
elif event.keyval == gtk.keysyms.Left:
self.on_left()
return True
elif event.keyval == gtk.keysyms.Right:
self.on_right()
return True
def on_say(self, button):
text = self.say_textview.get_buffer()
text = text.get_text(text.get_start_iter(), text.get_end_iter())
self.console.eval("say(%s)" % repr(text), True)
def on_scroll(self, *args):
scroll_x = self.canvas.get_hadjustment()
scroll_y = self.canvas.get_vadjustment()
robot_x = self.robot.get_pixel_x()
robot_y = self.robot.get_pixel_y()
self.hruler.set_range(scroll_x.value, scroll_x.value + scroll_x.page_size, robot_x, self.canvas.width)
self.vruler.set_range(scroll_y.value, scroll_y.value + scroll_y.page_size, robot_y, self.canvas.height)
示例2: _create_canvas
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import connect [as 别名]
def _create_canvas(self, canvas_name):
canvas = Canvas()
canvas.set_size_request(self.DEFAULT_CANVAS_WIDTH, self.DEFAULT_CANVAS_WIDTH)
canvas.connect("button-press-event", self._on_canvas_button_press, canvas_name)
canvas.connect("drawing-stopped", self._on_canvas_drawing_stopped, canvas_name)
canvas.connect("stroke-added", self._on_canvas_stroke_added, canvas_name)
setattr(self, canvas_name, canvas)
frame = gtk.Frame()
frame.add(canvas)
setattr(self, canvas_name + "_frame", frame)
示例3: __init__
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import connect [as 别名]
class Window:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete-event", self.delete_event_cb)
self.window.connect("destroy", self.destroy_cb)
self.window.set_border_width(0)
self.window.set_size_request(800, 600)
self.window.show()
self.canvas = Canvas()
self.canvas.set_background((0,0,0))
self.canvas.set_foreground((0,0,0))
self.canvas.set_flags(gtk.HAS_FOCUS|gtk.CAN_FOCUS)
self.canvas.grab_focus()
self.layer1 = CanvasLayer()
self.layer2 = CanvasLayer()
self.canvas.append(self.layer1)
self.canvas.append(self.layer2)
self.canvas.show()
self.window.add(self.canvas)
for n in xrange(100):
o = CanvasRect(self.layer1, 100, 100, 200, 200, filled=True)
o.scale(random(), random(), random(), random())
o.move(randrange(1000), randrange(1000))
o.connect('button-press-event', self.button_press_event_cb)
o.connect('motion-notify-event', self.motion_notify_event_cb)
o.connect('button-release-event', self.button_release_event_cb)
for n in xrange(100):
g = CanvasGroup(self.layer2, fg=(0,0,1))
o = CanvasLine(g, 0, 0, 100, 100)
print(dir(o))
o = CanvasRect(g, 0, 100, 100, 200, filled=True, fg=(0.5, 0.3,0.4),bg=(1, 0.3,0.4))
o = CanvasOval(g, 0, 200, 100, 300, fg=(0.5, 1,0.3))
o = CanvasArc(g, 0, 300, 100, 400, start=0, extent=180)
o = CanvasText(g, 0, 400, text='Hello')
o = CanvasLine(g, 100, 0, 200, 100)
o = CanvasRect(g, 100, 100, 200, 200, filled=True, outline=True)
o = CanvasOval(g, 100, 200, 200, 300, filled=True)
o = CanvasArc(g, 100, 300, 200, 400, start=90, extent=270, filled=True)
o = CanvasText(g, 100, 400, text='World')
g.scale(random(), random(), random(), random())
g.move(randrange(1000), randrange(1000))
g.connect('button-press-event', self.button_press_event_cb)
g.connect('motion-notify-event', self.motion_notify_event_cb)
g.connect('button-release-event', self.button_release_event_cb)
# o = CanvasImage(self.layer1, 0, 0, filename='image2.jpeg')
# o.connect('button-press-event', self.button_press_event_cb)
# o.connect('motion-notify-event', self.motion_notify_event_cb)
# o.connect('button-release-event', self.button_release_event_cb)
# o = CanvasImage(self.layer1, 100, 100, filename='image1.png')
# o.connect('button-press-event', self.button_press_event_cb)
# o.connect('motion-notify-event', self.motion_notify_event_cb)
# o.connect('button-release-event', self.button_release_event_cb)
# o = CanvasFunc(self.layer1, target=self.canvas_func1, args=(), kw={})
self.canvas_button = None
self.item = None
self.item_prev_x = None
self.item_prev_y = None
self.item_button = None
self.window.connect('key-press-event', self.window_key_press_event_cb)
self.window.connect('key-release-event', self.window_key_release_event_cb)
self.canvas.connect('button-press-event', self.canvas_button_press_event_cb)
self.canvas.connect('motion-notify-event', self.canvas_motion_notify_event_cb)
self.canvas.connect('button-release-event', self.canvas_button_release_event_cb)
self.canvas.connect('scroll-event', self.canvas_scroll_event_cb)
def delete_event_cb(self, widget, event, data=None):
return False
def destroy_cb(self, widget, data=None):
gtk.main_quit()
def main(self):
gtk.main()
def button_press_event_cb(self, widget, item, event):
self.item = item
self.item_prev_x = event.x
self.item_prev_y = event.y
self.item_button = event.button
def motion_notify_event_cb(self, widget, item, event):
if self.item_button == 1:
dx = event.x - self.item_prev_x
dy = event.y - self.item_prev_y
self.item.move(dx, dy)
self.item_prev_x = event.x
self.item_prev_y = event.y
def button_release_event_cb(self, widget, item, signal_id):
self.item_button = None
#.........这里部分代码省略.........