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


Python Gtk.Container方法代码示例

本文整理汇总了Python中gi.repository.Gtk.Container方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.Container方法的具体用法?Python Gtk.Container怎么用?Python Gtk.Container使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gi.repository.Gtk的用法示例。


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

示例1: build_widget

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def build_widget(self):
        """
        Builds the interface and returns a Gtk.Container type that
        contains the interface. This containter will be inserted into
        a Gtk.ScrolledWindow page.
        """
        self.scrolledwindow = Gtk.ScrolledWindow(hadjustment=None,
                                                    vadjustment=None)
        self.scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC,
                                       Gtk.PolicyType.AUTOMATIC)
        self.scrolledwindow.add_events(Gdk.EventMask.SCROLL_MASK)
        self.scrolledwindow.connect("scroll-event", self.cb_bg_scroll_event)
        event_box = Gtk.EventBox()
        # Required for drag-scroll events and popup menu
        event_box.add_events(Gdk.EventMask.BUTTON_PRESS_MASK
                             | Gdk.EventMask.BUTTON_RELEASE_MASK
                             | Gdk.EventMask.BUTTON1_MOTION_MASK)
        # Signal begin drag-scroll
        event_box.connect("button-press-event", self.cb_bg_button_press)
        # Signal end drag-scroll and popup menu
        event_box.connect("button-release-event", self.cb_bg_button_release)
        #Signal for controll motion-notify when left mouse button pressed
        event_box.connect("motion-notify-event", self.cb_bg_motion_notify_event)
        self.scrolledwindow.add(event_box)

        self.table = Gtk.Grid()
        # force LTR layout of the tree, even though the text might be RTL!
        # this way the horizontal scroll preferences will be correct always
        if self.table.get_direction() == Gtk.TextDirection.RTL:
            self.table.set_direction(Gtk.TextDirection.LTR)
            self.table.set_halign(Gtk.Align.END)
        event_box.add(self.table)
        event_box.get_parent().set_shadow_type(Gtk.ShadowType.NONE)
        self.table.set_row_spacing(1)
        self.table.set_column_spacing(0)

        return self.scrolledwindow 
开发者ID:gramps-project,项目名称:addons-source,代码行数:39,代码来源:HtreePedigreeView.py

示例2: build_widget

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def build_widget(self):
        """
        Builds the interface and returns a Gtk.Container type that
        contains the interface. This containter will be inserted into
        a Gtk.Notebook page.
        """
        self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=4)
        #top widget at the top
        self.box.pack_start(self.top_widget(), False, False, 0 )
        #web page under it in a scrolled window
        self.toolkit = TOOLKIT = get_toolkits()
        self.renderer = RendererWebkit()
        self.frames = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=4)
        frame = Gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
        frame.set_shadow_type(Gtk.ShadowType.NONE)
        frame.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        frame.add(self.renderer.get_window())
        self.frames.set_homogeneous(False)
        self.frames.pack_start(frame, True, True, 0)
        self.frames.pack_end(self.filter, False, False, 0)
        self.box.pack_start(self.frames, True, True, 0)
        # this is used to activate the back and forward button
        # from the renderer class.
        self.renderer.fct = lambda: self.set_button_sensitivity
        self.renderer.show_all()
        self.filter.hide()
        #load a welcome html page
        urlhelp = self._create_start_page()
        self.open(urlhelp)
        return self.box 
开发者ID:gramps-project,项目名称:addons-source,代码行数:32,代码来源:htmlview.py

示例3: build_widget

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def build_widget(self):
        """
        Builds the interface and returns a Gtk.Container type that
        contains the interface. This containter will be inserted into
        a Gtk.ScrolledWindow page.
        """
        self.scrolledwindow = Gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
        self.scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC,
                                       Gtk.PolicyType.AUTOMATIC)
        self.scrolledwindow.add_events(Gdk.EventMask.SCROLL_MASK)
        self.scrolledwindow.connect("scroll-event", self.bg_scroll_event)

        self.gtklayout = Gtk.Layout()
        # Required for drag-scroll events and popup menu
        self.gtklayout.add_events(Gdk.EventMask.BUTTON_PRESS_MASK
                             | Gdk.EventMask.BUTTON_RELEASE_MASK
                             | Gdk.EventMask.BUTTON1_MOTION_MASK)

        self.gtklayout.connect("draw", self.gtklayout_draw)
        self.gtklayout.connect("button-press-event", self.bg_button_press_cb)
        self.gtklayout.connect("button-release-event", self.bg_button_release_cb)
        self.gtklayout.connect("motion-notify-event", self.bg_motion_notify_event_cb)

        self.scrolledwindow.add(self.gtklayout)

        return self.scrolledwindow 
开发者ID:gramps-project,项目名称:addons-source,代码行数:28,代码来源:TimelinePedigreeView.py

示例4: _show_panel

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def _show_panel(self, panel_name):
        """
        Helper function to switch between panels.

        @param panel_name: the name of the wanted panel. Choose between
                        "configuration" or "add"
        """
        if panel_name == "configuration":
            panel_to_remove = self.add_panel
            panel_to_add = self.config_panel
            side_is_enabled = True
        elif panel_name == "add":
            panel_to_remove = self.config_panel
            panel_to_add = self.add_panel
            side_is_enabled = False
        else:
            log.error("panel name unknown")
            return
        # Central pane
        # NOTE: self.central_pane is the Gtk.Container in which we load panels
        if panel_to_remove in self.central_pane:
            self.central_pane.remove(panel_to_remove)
        if panel_to_add not in self.central_pane:
            self.central_pane.add(panel_to_add)
        self.central_pane.show_all()
        # Side treeview
        # disabled if we're adding a new backend
        try:
            # when this is called upon initialization of this class, the
            # backends_tv object has not been created yet.
            self.add_button.set_sensitive(side_is_enabled)
            self.remove_button.set_sensitive(side_is_enabled)
            self.backends_tv.set_sensitive(side_is_enabled)
        except AttributeError:
            pass

########################################
# WIDGETS AND SIGNALS ##################
######################################## 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:41,代码来源:__init__.py

示例5: set_button_children_size_request

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def set_button_children_size_request(widget):
    try:
        if not isinstance(widget, Gtk.Container):
            return
        for child in widget.get_children():
            if isinstance(child, Gtk.Button):
                child.set_size_request(constants.BUTTON_MIN_WIDTH, -1)
            else:
                set_button_children_size_request(child)
    except AttributeError:
        return 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:13,代码来源:label.py

示例6: ellipsize_labels_recursively

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def ellipsize_labels_recursively(widget, ellipsize=Pango.EllipsizeMode.END, width_chars=1):
    if isinstance(widget, Gtk.Label):
        widget.set_ellipsize(ellipsize)
        widget.set_width_chars(width_chars)
    elif isinstance(widget, Gtk.Container):
        for child_widget in widget.get_children():
            ellipsize_labels_recursively(child_widget, ellipsize, width_chars) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:9,代码来源:label.py

示例7: display_connect_dialog

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def display_connect_dialog(self, message, quit_button=True):
		"""
		Displays 'Be patient, i'm trying to connect here' dialog, or updates
		it's message if said dialog is already displayed.
		"""
		if self.connect_dialog == None:
			log.debug("Creating connect_dialog")
			self.connect_dialog = Gtk.MessageDialog(
				self["window"],
				Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
				Gtk.MessageType.INFO, 0, "-")
			if quit_button:
				self.connect_dialog.add_button("gtk-quit", RESPONSE_QUIT)
			# There is only one response available on this dialog
			self.connect_dialog.connect("response", self.cb_connect_dialog_response, None)
			if self.is_visible():
				self.connect_dialog.show_all()
		def set_label(d, message):
			"""
			Small, recursive helper function to set label somehwere
			deep in dialog
			"""
			for c in d.get_children():
				if isinstance(c, Gtk.Container):
					if set_label(c, message):
						return True
				elif isinstance(c, Gtk.Label):
					c.set_markup(message)
					return True
			return False
		log.verbose("Setting connect_dialog label %s" % message[0:15])
		set_label(self.connect_dialog.get_content_area(), message) 
开发者ID:kozec,项目名称:syncthing-gtk,代码行数:34,代码来源:app.py

示例8: __init__

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def __init__(self, app, title, icon):
		# Variables
		self.app = app
		self.child = None
		self.header = None
		self.str_title = None
		self.str_status = None
		self.header_inverted = False
		self.values = {}
		self.icons = {}
		self.value_widgets = {}
		self.hilight = False
		self.hilight_factor = 0.0
		self.timer_enabled = False
		self.icon = icon
		self.color = (1, 0, 1, 1)		# rgba
		self.background = (1, 1, 1, 1)	# rgba
		self.dark_color  = None			# Overrides background if set
		self.text_color = (0, 0, 0, 1)	# rgba (text color)
		self.real_color = self.color	# set color + hilight
		self.border_width = 2
		self.children = [self.header, self.child]
		# Initialization
		Gtk.Container.__init__(self)
		self.init_header()
		self.init_grid()
		# Settings
		self.set_title(title)
		self.set_status(_("Disconnected")) 
开发者ID:kozec,项目名称:syncthing-gtk,代码行数:31,代码来源:infobox.py

示例9: find_widget

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def find_widget(self, compare_fn, parent=None):
		"""
		Recursively searches for widget, returning first one
		for which compare_fn(widget) returns True
		"""
		if parent is None : parent = self
		for w in parent.get_children():
			if compare_fn(w): return w
			if isinstance(w, Gtk.Container):
				r = self.find_widget(compare_fn, w)
				if not r is None: return r
		return None 
开发者ID:kozec,项目名称:syncthing-gtk,代码行数:14,代码来源:wizard.py

示例10: find_widget_by_id

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def find_widget_by_id(self, id, parent=None):
		""" Recursively searches for widget with specified ID """
		if parent == None:
			if id in self: return self[id] # Do things fast if possible
			parent = self["editor"]
		for c in parent.get_children():
			if hasattr(c, "get_id"):
				if c.get_id() == id:
					return c
			if isinstance(c, Gtk.Container):
				r = self.find_widget_by_id(id, c)
				if not r is None:
					return r
		return None 
开发者ID:kozec,项目名称:syncthing-gtk,代码行数:16,代码来源:editordialog.py

示例11: override_css_style

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def override_css_style(self, colorscheme, theme_plugin):
        new_theme_plugin_name = colorscheme["THEME_STYLE"]
        if new_theme_plugin_name == self.theme_plugin_name:
            return
        if self.theme_plugin_name:
            for child in self.get_children():
                self.remove(child)
                child.destroy()
            self.init_widgets()
        self.theme_plugin_name = new_theme_plugin_name
        base_theme_css_provider = self.get_theme_css_provider(theme_plugin)

        def apply_css(widget):
            widget_style_context = widget.get_style_context()
            Gtk.StyleContext.add_provider(
                widget_style_context,
                self.css_providers.reset_style,
                Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
            )
            Gtk.StyleContext.add_provider(
                widget_style_context,
                base_theme_css_provider,
                Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
            )
            if isinstance(widget, Gtk.Container):
                widget.forall(apply_css)
        apply_css(self)

        Gtk.StyleContext.add_provider(
            self.gtk_preview.headerbar.get_style_context(),
            self.css_providers.headerbar_border,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )

        self.show_all() 
开发者ID:themix-project,项目名称:oomox,代码行数:37,代码来源:preview.py

示例12: __recursive_translate_widgets

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def __recursive_translate_widgets(a_widget):
        """ Calls gettext on all strings we can find in widgets, and recursively on its children.

        Args:
            a_widget (:class:`~GObject.Object`): an object built by the builder, usually a widget
        """
        Builder.__translate_widget_strings(a_widget)

        if issubclass(type(a_widget), Gtk.Container):
            # NB: Parent-loop in widgets would cause infinite loop here, but that's absurd (right?)
            # NB2: maybe forall instead of foreach if we miss some strings?
            a_widget.foreach(Builder.__recursive_translate_widgets)

        if issubclass(type(a_widget), Gtk.MenuItem) and a_widget.get_submenu() is not None:
            Builder.__recursive_translate_widgets(a_widget.get_submenu()) 
开发者ID:Cimbali,项目名称:pympress,代码行数:17,代码来源:builder.py

示例13: react_to_event

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def react_to_event(view, widget, event):
    """Checks whether the widget is supposed to react to passed event

    The function is intended for callback methods registering to shortcut actions. As several widgets can register to
    the same shortcut, only the one having the focus should react to it.

    :param gtkmvc3.View view: The view in which the widget is registered
    :param Gtk.Widget widget: The widget that subscribed to the shortcut action, should be the top widget of the view
    :param event: The event that caused the callback
    :return: Whether the widget is supposed to react to the event or not
    :rtype: bool
    """
    # See
    # http://pyGtk.org/pygtk2reference/class-gtkwidget.html#method-gtkwidget--is-focus and
    # http://pyGtk.org/pygtk2reference/class-gtkwidget.html#method-gtkwidget--has-focus
    # for detailed information about the difference between is_focus() and has_focus()
    if not view:  # view needs to be initialized
        return False
    # widget parameter must be set and a Gtk.Widget
    if not isinstance(widget, Gtk.Widget):
        return False
    # Either the widget itself or one of its children must be the focus widget within their toplevel
    child_is_focus = False if not isinstance(widget, Gtk.Container) else bool(widget.get_focus_child())
    if not child_is_focus and not widget.is_focus():
        return False

    def has_focus(widget):
        """Checks whether `widget` or one of its children ``has_focus()`` is ``True``

        :param Gtk.Widget widget: The widget to be checked
        :return: If any (child) widget has the global input focus
        """
        if widget.has_focus():
            return True
        if not isinstance(widget, Gtk.Container):
            return False
        return any(has_focus(child) for child in widget.get_children())
    # Either, for any of widget or its children, has_focus must be True, in this case the widget has the global focus.
    if has_focus(widget):
        return True
    # Or the callback was not triggered by a shortcut, but e.g. a mouse click or a call from a test.
    # If the callback was triggered by a shortcut action, the event has at least a length of two and the second
    # element is a Gdk.ModifierType
    if len(event) < 2 or (len(event) >= 2 and not isinstance(event[1], Gdk.ModifierType)):
        return True
    return False 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:48,代码来源:label.py

示例14: find

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Container [as 别名]
def find(node, search_id, search_type, button_label=None):
        """
        find various GTK Widgets
        :param node: node is the starting container to find from
        :param search_id: search_id is the GtkWidget type string or
        GtkWidget name
        :param search_type: search_type is the type of search
                            "by_name" to search by the type of GtkWidget
                            e.g. GtkButton
                            "by_id" to search by the GtkWidget (glade name)
                            e.g. box_1
        :param button_label: button_label to find specific buttons where we
        cannot use by_id
        :return:N/A
        """

        # Couldn't find better way to find widgets than loop through them
        # print("by_name %s by_id %s" % (node.get_name(),
        # Gtk.Buildable.get_name(node)))

        def extract_label(button):
            label = button.get_label()
            if label:
                return label

            child = button.get_child()
            if child and child.get_name() == "GtkLabel":
                return child.get_text()

            return None

        if isinstance(node, Gtk.Buildable):
            if search_type == 'by_id':
                if Gtk.Buildable.get_name(node) == search_id:
                    if button_label is None or (
                            'Button' in node.get_name() and extract_label(
                            node) == button_label):
                        return node
            elif search_type == 'by_name':
                if node.get_name() == search_id:
                    if button_label is None or (
                            'Button' in node.get_name() and extract_label(
                            node) == button_label):
                        return node

        if isinstance(node, Gtk.Container):
            for child in node.get_children():
                ret = AltToolbarPlugin.find(child, search_id, search_type,
                                            button_label)
                if ret:
                    return ret

        return None 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:55,代码来源:alternative-toolbar.py


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