本文整理汇总了Python中matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo.connect方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTK3Cairo.connect方法的具体用法?Python FigureCanvasGTK3Cairo.connect怎么用?Python FigureCanvasGTK3Cairo.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo
的用法示例。
在下文中一共展示了FigureCanvasGTK3Cairo.connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CanvasItem
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import connect [as 别名]
class CanvasItem(object):
"""Canvas Item
Has figure, canvas
"""
def __init__(self, main_controller):
""" Initializes figure. Sets a default alpha. Initializes
configuration dictionary. Initializes context menu. Connects
button release event on canvas.
"""
self.main_controller = main_controller
self.figure = Figure()
self.figure.patch.set_alpha(0.0)
self.canvas = FigureCanvas(self.figure)
self.customize_window = None
self.config = OrderedDict()
self._context_menu = gtk.Menu()
self._build_context_menu()
self.canvas.connect("button_release_event", self.on_button_release,
self.canvas)
def _build_context_menu(self):
""" Context menu has menu items for exporting to PDF
and customizing plot.
"""
export_pdf_item = gtk.MenuItem("Export to PDF...")
export_pdf_item.connect("activate", self.on_export_pdf, self.canvas)
customize_item = gtk.MenuItem("Customize...")
customize_item.connect("activate", self.show_customize)
self._context_menu.append(export_pdf_item)
self._context_menu.append(customize_item)
self._context_menu.show_all()
def init_default_config(self):
""" Empty abstract default config.
"""
pass
def get_options_dict(self):
""" Return configuration dictionary.
"""
return self.config
def get_config_values(self):
""" Gets values of all items in configuration dictionary.
Returns values as keys in new dictionary.
"""
return {key: configuration.value for key, configuration in
self.config.iteritems()}
def set_config_values(self, config):
""" Sets current configuration values to ones from
configuration dictionary in parameter.
"""
if (config):
for key, val in config.items():
self.config[key].value = val
def apply_config(self, revert_data=None, get_function=None):
""" For each configuration, if revert data exists,
revert configuration. If no revert data is provided,
set configuration value to result from get function.
If no get function is specified, use current value from
configuration.
Calls the function within the configuration with the
revert/get function/current value.
Calls queue_draw to update after applying configuration.
"""
for option_name in self.get_options_dict():
if (self.config[option_name].configurable):
if (self.config[option_name].function):
function = self.config[option_name].function
if (revert_data):
new_val = revert_data[option_name]
elif (get_function):
new_val = get_function(option_name)
else:
new_val = self.config[option_name].value
self.config[option_name].value = new_val
function(new_val)
self.canvas.queue_draw()
@property
def title(self):
""" Abstract title getter.
"""
raise NotImplementedError
def on_export_pdf(self, widget, canvas):
""" Calls controller's export pdf function with plot title.
"""
self.main_controller.on_export_pdf(None, canvas, self.title)
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import connect [as 别名]
class App:
def __init__(self):
self.xsize, self.ysize = 600, 600
self.xmin, self.xmax = -1.5, 1.5
self.ymin, self.ymax = -1.5, 1.5
self.x, self.y = (-0.4, 0.6)
self.n = 2
self.zmax = 4.0
self.niter = 256
self.dpi = 100
self.cmap = 'Set3'
self.digits = 12
self.entries = {}
# create app interface
self.setup_interface()
self.display_image()
def setup_interface(self):
# create main window
self.main_window = Gtk.Window(title="Julia Fractals")
self.main_window.set_border_width(10)
self.main_window.connect("delete-event", Gtk.main_quit)
# setup header bar
self.setup_header_bar()
box = Gtk.Box(orientation='horizontal', spacing=10)
self.main_window.add(box)
sep = Gtk.Separator(orientation='vertical')
box.add(sep)
# setup left panel -- container with image parameters
self.left_box = Gtk.Box(orientation='vertical', spacing=10)
self.setup_left_box()
box.add(self.left_box)
sep = Gtk.Separator(orientation='vertical')
box.add(sep)
# setup right panel -- container with image parameters
self.right_box = Gtk.Box(orientation='vertical', spacing=10)
self.setup_right_box()
box.add(self.right_box)
for name, entry in self.entries.items():
# copy current values to the defaults
setattr(self, name + "_default", getattr(self, name))
self.set_entry_value(entry)
sep = Gtk.Separator(orientation='vertical')
box.add(sep)
# setup image panel -- container with image output
self.image_box = Gtk.Box(orientation='vertical')
self.setup_image_box()
box.add(self.image_box)
def setup_header_bar(self):
'''
'''
self.hb = Gtk.HeaderBar()
self.hb.set_show_close_button(True)
self.hb.props.title = "Julia Fractal"
self.main_window.set_titlebar(self.hb)
self.button_save = Gtk.Button(label='Save')
self.button_save.connect("clicked", self.on_button_save_clicked)
self.hb.pack_end(self.button_save)
def setup_left_box(self):
# box for
box = Gtk.Box(orientation='vertical', spacing=6)
self.left_box.pack_start(box, False, False, 0)
sep = Gtk.Separator(orientation='horizontal')
box.add(sep)
self.namecombo = Gtk.ComboBoxText()
self.namecombo.connect("changed", self.on_namecombo_changed)
#.........这里部分代码省略.........