本文整理汇总了Python中canvas.Canvas.set_config方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.set_config方法的具体用法?Python Canvas.set_config怎么用?Python Canvas.set_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.set_config方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NetEditor
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import set_config [as 别名]
class NetEditor(gtk.VBox):
def __init__(self, app, project):
gtk.VBox.__init__(self)
self.project = project
self.app = app
self.net = None
self.undo_manager = None
self.set_size_request(500,400)
self.canvas = None
self.attribute_widgets = []
self.attribute_item = None
self.mode = "edit"
self.pack_start(self._controls(), False)
paned = gtk.HPaned()
self.pack_start(paned)
self.netlist = NetList(project, self)
vpaned = gtk.VPaned()
vpaned.pack1(self._attribute_box(), True, True)
vpaned.pack2(self.netlist, False, False)
paned.pack1(vpaned, False, False)
self.canvas = Canvas(None)
paned.pack2(self.canvas, True, True)
paned.show_all()
self._setup_no_attribute("Nothing selected")
self.transition_edit_callback = None
self.place_edit_callback = None
self.set_tool("selection")
self.switch_to_net(self.get_net(), False)
self.on_undomanager_changed()
self.project.set_callback("changed", self._project_changed)
def get_net(self):
return self.netlist.selected_object()
def set_mode(self, value):
self.mode = value
self.canvas.config.configure()
self.redraw()
def switch_to_net(self, net, select_in_netlist=True):
self.net = net
if self.canvas: # Bootstrap problem
self.canvas.config.set_net(net, None)
if net is None:
self.undo_manager = None
return
def changed(net, item):
net.project.generator = None
self.redraw()
net.change_item_callback = changed
if select_in_netlist:
self.netlist.select_object(net)
self.undo_manager = net.undo_manager
def set_tool(self, name, set_button=False):
if name == "selection":
self.canvas.set_config(neteditcc.SelectionCanvasConfig(self))
if set_button:
self.button_selection.set_active(True)
elif name == "transition":
self.canvas.set_config(neteditcc.NewTransitionCanvasConfig(self))
elif name == "place":
self.canvas.set_config(neteditcc.NewPlaceCanvasConfig(self))
elif name == "edge":
self.canvas.set_config(neteditcc.NewEdgeCanvasConfig(self))
elif name == "area":
self.canvas.set_config(neteditcc.NewAreaCanvasConfig(self))
else:
raise Exception("Invalid tool")
self.canvas.config.set_net(self.net, self.canvas.viewport)
def add_undo_action(self, action):
self.undo_manager.add_action(action)
self.on_undomanager_changed()
def on_undomanager_changed(self):
if self.undo_manager is None:
self.button_undo.set_sensitive(False)
self.button_redo.set_sensitive(False)
else:
self.button_undo.set_sensitive(self.undo_manager.has_undo())
self.button_redo.set_sensitive(self.undo_manager.has_redo())
def save_as_svg(self, filename):
self.canvas.save_as_svg(filename)
def get_zoom(self):
return self.canvas.get_zoom()
#.........这里部分代码省略.........
示例2: NetView
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import set_config [as 别名]
class NetView(gtk.HPaned):
def __init__(self, app, config=None, other_tabs=None):
gtk.HPaned.__init__(self)
self.app = app
if other_tabs:
notebook = gtk.Notebook()
notebook.append_page(self._perspectives(), gtk.Label("Views"))
for name, widget in other_tabs:
notebook.append_page(widget, gtk.Label(name))
self.perspectives.hide_headers()
self.pack1(notebook)
else:
self.pack1(self._perspectives(), False)
self.config = config
self.canvas = Canvas(self.config, zoom=1)
self.pack2(self.canvas, True)
self.show_all()
def set_config(self, config):
self.config = config
self.canvas.set_config(config)
def redraw(self):
self.canvas.redraw()
def save_as_svg(self, filename):
self.canvas.save_as_svg(filename)
def get_perspective(self):
return self.perspectives.get_selection(0)
def set_runinstance(self, runinstance):
self.runinstance = runinstance
self._refresh_perspectives(runinstance.get_perspectives())
def _refresh_perspectives(self, perspectives):
p = self.get_perspective()
if p is not None:
name = self.get_perspective().name
else:
name = None
selected = False
self.perspectives.clear()
for p in perspectives:
i = self.perspectives.append((p, str(p.name)))
if name == p.name:
self.perspectives.select_iter(i)
selected = True
if not selected:
self.perspectives.select_first()
self._perspectives_changed(None)
def _perspectives(self):
self.perspectives = gtkutils.SimpleList((("_", object), ("Views",str)))
self.perspectives.set_size_request(80,10)
self.perspectives.connect_view("cursor-changed", self._perspectives_changed);
return self.perspectives
def _perspectives_changed(self, w):
perspective = self.get_perspective()
if perspective is not None:
self.config.set_perspective(perspective)
else:
self.config.set_perspective(None)
self.redraw()
def open_tokens_tab(self, place):
text_buffer = gtk.TextBuffer()
t = self.get_perspective().get_removed_tokens(place)
removed_tokens = "\n".join("consumed: " + token for token in map(str, t))
tokens = "\n".join(map(str, self.get_perspective().get_tokens(place)))
new_tokens = "\n".join(map(str, self.get_perspective().get_new_tokens(place)))
if removed_tokens != "" and tokens != "":
removed_tokens = removed_tokens + "\n"
if tokens != "" and new_tokens != "":
tokens = tokens + "\n"
tag_removed = text_buffer.create_tag('removed', font="Italic")
tag_new = text_buffer.create_tag('new', font="Bold")
text_buffer.insert_with_tags(text_buffer.get_end_iter(), removed_tokens, tag_removed)
text_buffer.insert(text_buffer.get_end_iter(), tokens)
text_buffer.insert_with_tags(text_buffer.get_end_iter(), new_tokens, tag_new)
text_area = gtk.TextView()
text_area.set_buffer(text_buffer)
text_area.set_editable(False)
sw = gtk.ScrolledWindow()
sw.add(text_area)
sw.show_all()
label = "Tokens of " + place.get_name()
self.app.window.add_tab(mainwindow.Tab(label, sw))
def open_transition_tab(self, transition):
values = self.get_perspective().get_transition_trace_values(transition)
if values:
text_buffer = gtk.TextBuffer()
#.........这里部分代码省略.........