本文整理汇总了Python中canvas.Canvas.show方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.show方法的具体用法?Python Canvas.show怎么用?Python Canvas.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.show方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Meter
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import show [as 别名]
class Meter(object):
canvas = None;
widgets = None;
height = None;
width = None;
def __init__(self, width, height):
self.canvas = Canvas();
handler = MeterEventHandler(self);
self.canvas.setup("below", handler);
self.canvas.set_size(width, height);
self.width = width;
self.height = height;
self.widgets = [];
def add_widget(self, widget, x, y, x_alignment = -1, y_alignment = -1):
self.widgets.append((widget, x, y, x_alignment, y_alignment));
def refresh_func(self):
self.canvas.redraw();
return self.canvas.get_mapped();
def show(self):
self.canvas.show();
GLib.timeout_add(200, self.refresh_func);
def hide(self):
self.canvas.hide();
def get_window(self):
return self.canvas.get_window();
示例2: Meter
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import show [as 别名]
class Meter(object):
canvas = None;
handler = None;
width = None;
height = None;
hour_radius = None;
min_radius = None;
sec_radius = None;
padding = 5;
fill_color = None;
opacity = None;
def __init__(self, width, height):
self.canvas = Canvas();
handler = MeterEventHandler(self);
self.canvas.setup("below", handler);
self.canvas.set_size(width, height);
self.width = width;
self.height = height;
self.hour_radius = 4;
self.min_radius = 8;
self.sec_radius = 6;
self.padding = 5;
# self.fill_color = (0.3, 0.7, 0.1);
self.fill_color = (1.0, 1.0, 1.0);
self.opacity = 0.5;
def refresh_thread(self):
self.canvas.redraw();
return self.canvas.get_mapped();
def show(self):
self.canvas.show();
GLib.timeout_add(200, self.refresh_thread);
def hide(self):
self.canvas.hide();
def get_window(self):
return self.canvas.get_window();
示例3: __init__
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import show [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
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import show [as 别名]
class PositionTracker3:
"""
Main GUI for the Position Tracker
"""
def __init__(self):
self.gladefile = os.path.join(__location__, "pt3.glade")
self.builder = Gtk.Builder()
self.builder.add_from_file(self.gladefile)
#Create & Link canvas
self.canvas_box = self.builder.get_object("canvasBox")
self.canvas = Canvas()
self.watcher = VarWatcher(self.canvas)
self.canvas.show()
self.canvas_box.pack_start(self.canvas, True, True, 0)
# Automatically connect signals to functions defined above
# as specified in the glade file
self.builder.connect_signals(self)
# Get the main window
self.window = self.builder.get_object("ptWindow")
self.window.show()
self.window.connect("key-press-event", self.key_press)
#Ctrl+C handling
def handler(signum, frame):
self.log.warning("INTERRUPT: exiting gracefully")
self.window_destroy()
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGINT, handler)
#Fire up the main window
self.log.info("Launching GUI. Welcome to PT3! Press %s for help" % conf.key_binds["help"])
Gtk.main()
def window_destroy(self, data=None):
# Close this application
self.watcher.kill()
self.logger.critical("Program shutdown!")
self.canvas.kill()
Gtk.main_quit()
def help_menu(self):
dialog = HelpDialog()
response = dialog.run()
dialog.destroy()
def key_press(self,window,event):
key = Gdk.keyval_name(event.keyval)
if event.state == Gdk.ModifierType.CONTROL_MASK:
key = "ctrl " + key
if event.state == Gdk.ModifierType.SHIFT_MASK:
key = "shift " + key
key = string.lower(key)
if key == "ctrl w":
self.window_destroy()
if key == conf.key_binds["bindings toggle"]:
conf.bindings_on = not conf.bindings_on
self.log.info("Key Bindings " + ("on" if conf.bindings_on else "off"))
if not conf.bindings_on:
return
if key == conf.key_binds['quit']:
self.window_destroy()
elif key == conf.key_binds["help"]:
self.help_menu()
elif key == conf.key_binds["zoom in"]:
self.canvas.zoom(conf.ZOOM_FACTOR)
elif key == conf.key_binds["zoom out"]:
self.canvas.zoom(1./conf.ZOOM_FACTOR)
elif key == conf.key_binds["follow sub"]:
self.canvas.follow_sub(True)
elif key == conf.key_binds["follow position only"]:
self.canvas.follow_sub(False)
elif key == conf.key_binds["reset path"]:
self.canvas.reset_path()
elif key == conf.key_binds["pan up"]:
self.canvas.pan(0, conf.PAN_DIST)
elif key == conf.key_binds["pan up large"]:
self.canvas.pan(0, conf.PAN_DIST_LARGE)
elif key == conf.key_binds["pan down"]:
self.canvas.pan(0, -conf.PAN_DIST)
elif key == conf.key_binds["pan down large"]:
self.canvas.pan(0, -conf.PAN_DIST_LARGE)
elif key == conf.key_binds["pan right"]:
self.canvas.pan(-conf.PAN_DIST, 0)
elif key == conf.key_binds["pan right large"]:
self.canvas.pan(-conf.PAN_DIST_LARGE, 0)
elif key == conf.key_binds["pan left"]:
self.canvas.pan(conf.PAN_DIST, 0)
elif key == conf.key_binds["pan left large"]:
self.canvas.pan(conf.PAN_DIST_LARGE, 0)
elif key == conf.key_binds["center view"]:
#.........这里部分代码省略.........