PyGobject(七十一)Gtk.Widget之Gtk.Entry

Gtk.Entry

Gtk.Entry文本输入框

继承关系

这里写图片描述
这里写图片描述

Methods

方法修饰词方法名及参数
staticnew ()
staticnew_with_buffer (buffer)
get_activates_default ()
get_alignment ()
get_attributes ()
get_buffer ()
get_completion ()
get_current_icon_drag_source ()
get_cursor_hadjustment ()
get_has_frame ()
get_icon_activatable (icon_pos)
get_icon_area (icon_pos)
get_icon_at_pos (x, y)
get_icon_gicon (icon_pos)
get_icon_name (icon_pos)
get_icon_pixbuf (icon_pos)
get_icon_sensitive (icon_pos)
get_icon_stock (icon_pos)
get_icon_storage_type (icon_pos)
get_icon_tooltip_markup (icon_pos)
get_icon_tooltip_text (icon_pos)
get_inner_border ()
get_input_hints ()
get_input_purpose ()
get_invisible_char ()
get_layout ()
get_layout_offsets ()
get_max_length ()
get_max_width_chars ()
get_overwrite_mode ()
get_placeholder_text ()
get_progress_fraction ()
get_progress_pulse_step ()
get_tabs ()
get_text ()
get_text_area ()
get_text_length ()
get_visibility ()
get_width_chars ()
grab_focus_without_selecting ()
im_context_filter_keypress (event)
layout_index_to_text_index (layout_index)
progress_pulse ()
reset_im_context ()
set_activates_default (setting)
set_alignment (xalign)
set_attributes (attrs)
set_buffer (buffer)
set_completion (completion)
set_cursor_hadjustment (adjustment)
set_has_frame (setting)
set_icon_activatable (icon_pos, activatable)
set_icon_drag_source (icon_pos, target_list, actions)
set_icon_from_gicon (icon_pos, icon)
set_icon_from_icon_name (icon_pos, icon_name)
set_icon_from_pixbuf (icon_pos, pixbuf)
set_icon_from_stock (icon_pos, stock_id)
set_icon_sensitive (icon_pos, sensitive)
set_icon_tooltip_markup (icon_pos, tooltip)
set_icon_tooltip_text (icon_pos, tooltip)
set_inner_border (border)
set_input_hints (hints)
set_input_purpose (purpose)
set_invisible_char (ch)
set_max_length (max)
set_max_width_chars (n_chars)
set_overwrite_mode (overwrite)
set_placeholder_text (text)
set_progress_fraction (fraction)
set_progress_pulse_step (fraction)
set_tabs (tabs)
set_text (text)
set_visibility (visible)
set_width_chars (n_chars)
text_index_to_layout_index (text_index)
unset_invisible_char ()

Virtual Methods

do_activate ()
do_backspace ()
do_copy_clipboard ()
do_cut_clipboard ()
do_delete_from_cursor (type, count)
do_get_frame_size (x, y, width, height)
do_get_text_area_size (x, y, width, height)
do_insert_at_cursor (str)
do_move_cursor (step, count, extend_selection)
do_paste_clipboard ()
do_populate_popup (popup)
do_toggle_overwrite ()

Properties

NameTypeFlagsShort Description
activates-defaultboolr/w/enWhether to activate the default widget (such as the default button in a dialog) when Enter is pressed
attributesPango.AttrListr/w/enA list of style attributes to apply to the text of the label
bufferGtk.EntryBufferr/w/c/enText buffer object which actually stores entry text
caps-lock-warningboolr/w/enWhether password entries will show a warning when Caps Lock is on
completionGtk.EntryCompletionr/w/enThe auxiliary completion object
cursor-positionintrThe current position of the insertion cursor in chars
editableboolr/w/enWhether the entry contents can be edited
has-frameboolr/w/enFalse removes outside bevel from entry
im-modulestrr/w/enWhich IM module should be used
inner-borderGtk.Borderd/r/w/enBorder between text and frame. Overrides the inner-border style property deprecated
input-hintsGtk.InputHintsr/w/enHints for the text field behaviour
input-purposeGtk.InputPurposer/w/enPurpose of the text field
invisible-charintr/w/enThe character to use when masking entry contents (in “password mode”)
invisible-char-setboolr/wWhether the invisible character has been set
max-lengthintr/w/enMaximum number of characters for this entry. Zero if no maximum
max-width-charsintr/w/enThe desired maximum width of the entry, in characters
overwrite-modeboolr/w/enWhether new text overwrites existing text
placeholder-textstrr/w/enShow text in the entry when it’s empty and unfocused
populate-allboolr/w/enWhether to emit ::populate-popup for touch popups
primary-icon-activatableboolr/w/enWhether the primary icon is activatable
primary-icon-giconGio.Iconr/w/enGio.Icon for primary icon
primary-icon-namestrr/w/enIcon name for primary icon
primary-icon-pixbufGdkPixbuf.Pixbufr/w/enPrimary pixbuf for the entry
primary-icon-sensitiveboolr/w/enWhether the primary icon is sensitive
primary-icon-stockstrd/r/w/enStock ID for primary icon deprecated
primary-icon-storage-typeGtk.ImageTyperThe representation being used for primary icon
primary-icon-tooltip-markupstrr/w/enThe contents of the tooltip on the primary icon
primary-icon-tooltip-textstrr/w/enThe contents of the tooltip on the primary icon
progress-fractionfloatr/w/enThe current fraction of the task that’s been completed
progress-pulse-stepfloatr/w/enThe fraction of total entry width to move the progress bouncing block for each call to Gtk.Entry.progress_pulse()
scroll-offsetintr/enNumber of pixels of the entry scrolled off the screen to the left
secondary-icon-activatableboolr/w/enWhether the secondary icon is activatable
secondary-icon-giconGio.Iconr/w/enGio.Icon for secondary icon
secondary-icon-namestrr/w/enIcon name for secondary icon
secondary-icon-pixbufGdkPixbuf.Pixbufr/w/enSecondary pixbuf for the entry
secondary-icon-sensitiveboolr/w/enWhether the secondary icon is sensitive
secondary-icon-stockstrd/r/w/enStock ID for secondary icon deprecated
secondary-icon-storage-typeGtk.ImageTyperThe representation being used for secondary icon
secondary-icon-tooltip-markupstrr/w/enThe contents of the tooltip on the secondary icon
secondary-icon-tooltip-textstrr/w/enThe contents of the tooltip on the secondary icon
selection-boundintrThe position of the opposite end of the selection from the cursor in chars
shadow-typeGtk.ShadowTyped/r/w/enWhich kind of shadow to draw around the entry when has-frame is set deprecated
tabsPango.TabArrayr/w/enA list of tabstop locations to apply to the text of the entry
textstrr/w/enThe contents of the entry
text-lengthintrLength of the text currently in the entry
truncate-multilineboolr/w/enWhether to truncate multiline pastes to one line.
visibilityboolr/w/enFalse displays the “invisible str” instead of the actual text (password mode)
width-charsintr/w/enNumber of characters to leave space for in the entry
xalignfloatr/w/enThe horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts.

Signals

NameShort Description
activateThe ::activate signal is emitted when the user hits the Enter key.
backspaceThe ::backspace signal is a keybinding signal which gets emitted when the user asks for it.
copy-clipboardThe ::copy-clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard.
cut-clipboardThe ::cut-clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard.
delete-from-cursorThe ::delete-from-cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion.
icon-pressThe ::icon-press signal is emitted when an activatable icon is clicked.
icon-releaseThe ::icon-release signal is emitted on the button release from a mouse click over an activatable icon.
insert-at-cursorThe ::insert-at-cursor signal is a keybinding signal which gets emitted when the user initiates the insertion of a fixed string at the cursor.
move-cursorThe ::move-cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement.
paste-clipboardThe ::paste-clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view.
populate-popupThe ::populate-popup signal gets emitted before showing the context menu of the entry.
preedit-changedIf an input method is used, the typed text will not immediately be committed to the buffer.
toggle-overwriteThe ::toggle-overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the entry.

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/6/14
# section 112
TITLE = "Entry"
DESCRIPTION = """
The Gtk.Entry widget is a single line text entry widget.
"""
import gi

gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject


class EntryWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Entry Demo")
        self.set_size_request(200, 100)

        self.timeout_id = None

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
        self.add(vbox)

        self.entry = Gtk.Entry()
        self.entry.set_text("Hello World")
        vbox.pack_start(self.entry, True, True, 0)

        hbox = Gtk.Box(spacing=6)
        vbox.pack_start(hbox, True, True, 0)

        self.check_editable = Gtk.CheckButton("Editable")
        self.check_editable.connect("toggled", self.on_editable_toggled)
        self.check_editable.set_active(True)
        hbox.pack_start(self.check_editable, True, True, 0)

        self.check_visible = Gtk.CheckButton("Visible")
        self.check_visible.connect("toggled", self.on_visible_toggled)
        self.check_visible.set_active(True)
        hbox.pack_start(self.check_visible, True, True, 0)

        self.pulse = Gtk.CheckButton("Pulse")
        self.pulse.connect("toggled", self.on_pulse_toggled)
        self.pulse.set_active(False)
        hbox.pack_start(self.pulse, True, True, 0)

        self.icon = Gtk.CheckButton("Icon")
        self.icon.connect("toggled", self.on_icon_toggled)
        self.icon.set_active(False)
        hbox.pack_start(self.icon, True, True, 0)

    def on_editable_toggled(self, button):
        value = button.get_active()
        self.entry.set_editable(value)

    def on_visible_toggled(self, button):
        value = button.get_active()
        self.entry.set_visibility(value)

    def on_pulse_toggled(self, button):
        if button.get_active():
            self.entry.set_progress_pulse_step(0.2)
            # Call self.do_pulse every 100 ms
            self.timeout_id = GObject.timeout_add(100, self.do_pulse, None)
        else:
            # Don't call self.do_pulse anymore
            GObject.source_remove(self.timeout_id)
            self.timeout_id = None
            self.entry.set_progress_pulse_step(0)

    def do_pulse(self, user_data):
        self.entry.progress_pulse()
        return True

    def on_icon_toggled(self, button):
        if button.get_active():
            icon_name = "system-search-symbolic"
        else:
            icon_name = None
        self.entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY,
                                           icon_name)


def main():
    win = EntryWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()


if __name__ == "__main__":
    main()

二.EntryBuffer

这里写图片描述
代码:

#!/usr/bin/env python3
# section 113
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2010 Red Hat, Inc., John (J5) Palmieri <johnp@redhat.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

TITLE = "Entry Buffer"
DESCRIPTION = """
Gtk.EntryBuffer provides the text content in a Gtk.Entry.
"""


from gi.repository import Gtk


class EntryBufferApp:
    def __init__(self):
        self.window = Gtk.Dialog(title='Gtk.EntryBuffer')
        self.window.add_buttons(Gtk.STOCK_CLOSE, Gtk.ResponseType.NONE)
        self.window.connect('response', self.destroy)
        self.window.connect('destroy', lambda x: Gtk.main_quit())
        self.window.set_resizable(False)

        vbox = Gtk.VBox(homogeneous=False, spacing=0)
        self.window.get_content_area().pack_start(vbox, True, True, 0)
        vbox.set_border_width(5)

        label = Gtk.Label()
        label.set_markup('Entries share a buffer. Typing in one is reflected in the other.')
        vbox.pack_start(label, False, False, 0)

        # create a buffer
        buffer = Gtk.EntryBuffer()

        #create our first entry
        entry = Gtk.Entry(buffer=buffer)
        vbox.pack_start(entry, False, False, 0)

        # create the second entry
        entry = Gtk.Entry(buffer=buffer)
        entry.set_visibility(False)
        vbox.pack_start(entry, False, False, 0)

        self.window.show_all()

    def destroy(self, *args):
        self.window.destroy()
        Gtk.main_quit()


def main():
    EntryBufferApp()
    Gtk.main()

if __name__ == '__main__':
    main()

三.EntryCompletion

这里写图片描述
代码:

#!/usr/bin/env python3
# section 114
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2010 Red Hat, Inc., John (J5) Palmieri <johnp@redhat.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

TITLE = "Entry Completion"
DESCRIPTION = """
Gtk.EntryCompletion provides a mechanism for adding support for
completion in Gtk.Entry.
"""

from gi.repository import Gtk


class EntryCompletionApp:
    def __init__(self):
        self.window = Gtk.Dialog(title='Gtk.EntryCompletion')
        self.window.add_buttons(Gtk.STOCK_CLOSE, Gtk.ResponseType.NONE)
        self.window.connect('response', self.destroy)
        self.window.connect('destroy', lambda x: Gtk.main_quit())
        self.window.set_resizable(False)

        vbox = Gtk.VBox(homogeneous=False, spacing=0)
        self.window.get_content_area().pack_start(vbox, True, True, 0)
        vbox.set_border_width(5)

        label = Gtk.Label()
        label.set_markup('Completion demo, try writing <b>total</b> or <b>gnome</b> for example.')
        vbox.pack_start(label, False, False, 0)

        # create our entry
        entry = Gtk.Entry()
        vbox.pack_start(entry, False, False, 0)

        # create the completion object
        completion = Gtk.EntryCompletion()

        # assign the completion to the entry
        entry.set_completion(completion)

        # create tree model and use it as the completion model
        completion_model = self.create_completion_model()
        completion.set_model(completion_model)

        completion.set_text_column(0)

        self.window.show_all()

    @staticmethod
    def create_completion_model():
        store = Gtk.ListStore(str)

        store.append(['GNOME'])
        store.append(['total'])
        store.append(['totally'])

        return store

    def destroy(self, *args):
        self.window.destroy()
        Gtk.main_quit()


def main():
    EntryCompletionApp()
    Gtk.main()


if __name__ == '__main__':
    main()





代码下载地址:http://download.youkuaiyun.com/detail/a87b01c14/9594728

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值