本文整理汇总了Python中kiwi.ui.widgets.entry.ProxyEntry.read方法的典型用法代码示例。如果您正苦于以下问题:Python ProxyEntry.read方法的具体用法?Python ProxyEntry.read怎么用?Python ProxyEntry.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kiwi.ui.widgets.entry.ProxyEntry
的用法示例。
在下文中一共展示了ProxyEntry.read方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _testValidDataType
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
def _testValidDataType(self):
entry = ProxyEntry()
entry.set_property("data-type", "date")
# let's make the entry complain!
entry.set_text("string")
self.assertEqual(entry.read(), ValueUnset)
self.assertNotEqual(entry._complaint_checker_id, -1)
# now let's put proper data
entry.set_text(self.date_format)
date = datatypes.date2str(entry.read())
self.assertEqual(date, self.date_format)
self.assertEqual(entry._background_timeout_id, -1)
locale_dictionary = datatypes.locale_dictionary
# now change the data-type and do it again
entry.set_property("data-type", "float")
if locale_dictionary["thousands_sep"] == ',':
# correct value
entry.set_text("23,400,000.2")
self.assertEqual(entry.read(), 23400000.2)
self.assertEqual(entry._background_timeout_id, -1)
# wrong value
entry.set_text("23.400.000,2")
self.assertEqual(entry.read(), ValueUnset)
示例2: testRead
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
def testRead(self):
entry = ProxyEntry()
entry.set_text('1')
entry.set_property("data-type", "int")
self.assertEqual(entry.read(), 1)
entry.set_text('')
self.assertEqual(entry.read(), ValueUnset)
示例3: test_apply
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
def test_apply(self):
entry = ProxyEntry()
entry.data_type = currency
entry.set_text('150')
calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)
# calc.popup will not work here, so call _update_ui directly
calc._update_ui()
calc._entry.set_text('10%')
event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
event.keyval = gtk.keysyms.Return
event.window = gtk.gdk.get_default_root_window()
calc.emit('key-press-event', event)
calc.emit('key-press-event', event)
self.assertEqual(entry.read(), 135)
示例4: testRead
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
def testRead(self):
# int without mask
entry = ProxyEntry()
entry.set_text('1')
entry.set_property("data-type", "int")
self.assertEqual(entry.read(), 1)
entry.set_text('')
# empty int reads as ValueUnset
self.assertEqual(entry.read(), ValueUnset)
# int with mask
entry = ProxyEntry()
entry.set_property("data-type", "int")
entry.set_mask('00')
entry.set_text('12')
self.assertEqual(entry.read(), 12)
entry.set_text('')
# empty int reads as ValueUnset
self.assertEqual(entry.read(), ValueUnset)
# str without mask
entry = ProxyEntry()
entry.set_property("data-type", "str")
entry.set_text('123')
self.assertEqual(entry.read(), '123')
entry.set_text('')
self.assertEqual(entry.read(), '')
# str with mask
entry = ProxyEntry()
entry.set_property("data-type", "str")
entry.set_mask('00-00.00')
entry.set_text('123456')
self.assertEqual(entry.read(), '12-34.56')
entry.set_text('')
self.assertEqual(entry.read(), '')
示例5: DateTimeEditUI
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
class DateTimeEditUI(GladeSlaveDelegate):
def __init__(self, dt = None):
if not dt:
self.dt = datetime.datetime.now()
else:
self.dt = dt
# Set up the user interface
GladeSlaveDelegate.__init__(self, gladefile="mo_datetime_edit", toplevel_name="window_main")
self.entry_date = DateEntry()
self.entry_time = ProxyEntry(data_type=datetime.time)
self.set_datetime(self.dt)
self.entry_date.connect('changed', self.entry_date__changed)
self.entry_time.connect('changed', self.entry_time__changed)
self.hbox.pack_start(self.entry_date, expand=False, fill=False)
self.hbox.pack_start(self.entry_time, expand=False, fill=False)
self.show()
def entry_date__changed(self, *args):
dt = self.entry_date.get_date()
if dt != None:
self.dt = self.dt.replace(dt.year, dt.month, dt.day)
def entry_time__changed(self, *args):
dt = None
try:
dt = self.entry_time.read()
except ValidationError, e:
# Ignore invalid times because the user might still be filling it
# out.
pass
if dt != None:
self.dt = self.dt.replace(self.dt.year, self.dt.month, self.dt.day, dt.hour, dt.minute)
示例6: testDataMode
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
def testDataMode(self):
entry = ProxyEntry()
entry.data_type = str
entry.set_exact_completion()
items = {'xxx': object(),
'yyy': object()}
entry.prefill([(k, v) for k, v in items.items()])
entry.set_text('xxx')
self.assertIs(entry.read(), items['xxx'])
entry.set_text('x')
self.assertIs(entry.read(), None)
entry.set_text('xxxxx')
self.assertIs(entry.read(), None)
entry.set_text('yyy')
self.assertIs(entry.read(), items['yyy'])
entry.set_text('y')
self.assertIs(entry.read(), None)
entry.set_text('yyyyy')
self.assertIs(entry.read(), None)
示例7: TestSearchEntryGadget
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
class TestSearchEntryGadget(GUITest):
def _create_interface(self, run_editor=None):
self.sale = self.create_sale()
self.window = gtk.Window()
self.entry = ProxyEntry()
self.window.add(self.entry)
self.client_gadget = SearchEntryGadget(
self.entry, self.store, model=self.sale, model_property='client',
search_columns=['name'], search_class=ClientSearch,
parent=self.window, run_editor=run_editor)
self.client_gadget.get_model_obj = lambda obj: obj and obj.client
def test_create(self):
window = gtk.Window()
box = gtk.VBox()
window.add(box)
entry = ProxyEntry()
box.pack_start(entry)
self.check_dialog(window, 'search-entry-before-replace')
sale = self.create_sale()
SearchEntryGadget(entry, self.store, model=sale,
model_property='client', search_columns=['name'],
search_class=ClientSearch, parent=window)
self.check_dialog(window, 'search-entry-after-replace')
@mock.patch('stoqlib.gui.widgets.searchentry.run_dialog')
def test_run_search(self, run_dialog):
self._create_interface()
run_dialog.return_value = None
self.click(self.client_gadget.find_button)
run_dialog.assert_called_once_with(
ClientSearch, self.window, self.store, initial_string='',
double_click_confirm=True)
@mock.patch('stoqlib.gui.widgets.searchentry.api.new_store')
@mock.patch('stoqlib.gui.widgets.searchentry.run_person_role_dialog')
def test_run_editor(self, run_dialog, new_store):
new_store.return_value = self.store
self._create_interface()
client = self.create_client(name=u'Fulano de Tal')
run_dialog.return_value = self.store.find(
ClientView, ClientView.id == client.id).one()
with mock.patch.object(self.store, 'commit'):
with mock.patch.object(self.store, 'close'):
self.click(self.client_gadget.edit_button)
run_dialog.assert_called_once_with(
ClientEditor, self.window, self.store, None)
self.assertEquals(self.entry.read(), client)
self.assertEquals(self.entry.get_text(), u'Fulano de Tal')
@mock.patch('stoqlib.gui.widgets.searchentry.api.new_store')
def test_run_editor_override(self, new_store):
new_store.return_value = self.store
run_editor = mock.MagicMock()
run_editor.return_value = None
self.assertEquals(run_editor.call_count, 0)
self._create_interface(run_editor=run_editor)
with mock.patch.object(self.store, 'commit'):
with mock.patch.object(self.store, 'close'):
self.click(self.client_gadget.edit_button)
self.assertEquals(run_editor.call_count, 1)
@mock.patch('stoqlib.gui.widgets.searchentry.api.new_store')
@mock.patch('stoqlib.gui.widgets.searchentry.run_dialog')
def test_entry_activate(self, run_dialog, new_store):
new_store.return_value = self.store
self._create_interface()
fulano = self.create_client(u'Fulano de Tal')
ciclano = self.create_client(u'Cicrano de Tal')
# There should be only one match for Fulano, then the entry should be
# updated with this only match
self.entry.set_text('Fulano')
self.entry.activate()
self.assertEquals(self.entry.get_text(), 'Fulano de Tal')
self.assertEquals(self.entry.read(), fulano)
# Now when we use 'de tal', there are two clients that match. The
# search should be displayed
run_dialog.return_value = self.store.find(
ClientView, ClientView.id == ciclano.id).one()
self.entry.set_text('de tal')
self.entry.activate()
run_dialog.assert_called_once_with(
ClientSearch, self.window, self.store, initial_string='de tal',
double_click_confirm=True)
self.assertEquals(self.entry.get_text(), 'Cicrano de Tal')
self.assertEquals(self.entry.read(), ciclano)
@mock.patch('stoqlib.gui.widgets.searchentry.api.new_store')
#.........这里部分代码省略.........
示例8: DateEntry
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
#.........这里部分代码省略.........
# Callbacks
def _on_entry__changed(self, entry):
try:
date = self.get_date()
except ValidationError:
date = None
self._changed(date)
def _on_entry__activate(self, entry):
self.emit('activate')
def _on_entry__scroll_event(self, entry, event):
if event.direction == Gdk.ScrollDirection.UP:
days = 1
elif event.direction == Gdk.ScrollDirection.DOWN:
days = -1
else:
return
try:
date = self.get_date()
except ValidationError:
date = None
if not date:
newdate = datetime.date.today()
else:
newdate = date + datetime.timedelta(days=days)
self.set_date(newdate)
def _on_button__toggled(self, button):
if self._popping_down:
return
try:
date = self.get_date()
except ValidationError:
date = None
self._popup.popup(date)
def _on_popup__hide(self, popup):
self._popping_down = True
self._button.set_active(False)
self._popping_down = False
def _on_popup__date_selected(self, popup, date):
self.set_date(date)
popup.popdown()
self.entry.grab_focus()
self.entry.set_position(len(self.entry.get_text()))
self._changed(date)
def _changed(self, date):
if self._block_changed:
return
if self._old_date != date:
self.emit('changed')
self._old_date = date
# Public API
def set_date(self, date):
"""Sets the date.
:param date: date to set
:type date: a datetime.date instance or None
"""
if not isinstance(date, datetime.date) and date not in [None, ValueUnset]:
raise TypeError(
"date must be a datetime.date instance or None, not %r" % (
date,))
if date in [None, ValueUnset]:
value = ''
else:
value = date_converter.as_string(date)
# We're block the changed call and doing it manually because
# set_text() triggers a delete-text and then an insert-text,
# both which are emitting an entry::changed signal
self._block_changed = True
self.entry.set_text(value)
self._block_changed = False
self._changed(date)
def get_date(self):
"""Get the selected date
:returns: the date.
:rtype: datetime.date or None
"""
try:
date = self.entry.read()
except ValidationError:
date = None
if date == ValueUnset:
date = None
return date
示例9: DateEntry
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
#.........这里部分代码省略.........
self._popup = _DateEntryPopup(self)
self._popup.connect('date-selected', self._on_popup__date_selected)
self._popup.connect('hide', self._on_popup__hide)
self._popup.set_size_request(-1, 24)
# Virtual methods
def do_grab_focus(self):
self.entry.grab_focus()
# Callbacks
def _on_entry__changed(self, entry):
try:
date = self.get_date()
except ValidationError:
date = None
self._changed(date)
def _on_entry__activate(self, entry):
self.emit('activate')
def _on_entry__scroll_event(self, entry, event):
if event.direction == gdk.SCROLL_UP:
days = 1
elif event.direction == gdk.SCROLL_DOWN:
days = -1
else:
return
try:
date = self.get_date()
except ValidationError:
date = None
if not date:
newdate = datetime.date.today()
else:
newdate = date + datetime.timedelta(days=days)
self.set_date(newdate)
def _on_button__toggled(self, button):
if self._popping_down:
return
try:
date = self.get_date()
except ValidationError:
date = None
self._popup.popup(date)
def _on_popup__hide(self, popup):
self._popping_down = True
self._button.set_active(False)
self._popping_down = False
def _on_popup__date_selected(self, popup, date):
self.set_date(date)
popup.popdown()
self.entry.grab_focus()
self.entry.set_position(len(self.entry.get_text()))
self._changed(date)
def _changed(self, date):
if self._old_date != date:
self.emit('changed')
self._old_date = date
# Public API
def set_date(self, date):
"""Sets the date.
@param date: date to set
@type date: a datetime.date instance or None
"""
if not isinstance(date, datetime.date) and date is not None:
raise TypeError(
"date must be a datetime.date instance or None, not %r" % (
date,))
if date is None:
value = ''
else:
value = date_converter.as_string(date)
self.entry.set_text(value)
def get_date(self):
"""Get the selected date
@returns: the date.
@rtype: datetime.date or None
"""
try:
date = self.entry.read()
except ValidationError:
date = None
if date == ValueUnset:
date = None
return date
示例10: testCorrectlySetsEmptyString
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
def testCorrectlySetsEmptyString(self):
entry = ProxyEntry()
entry.update('')
self.assertEqual(entry.read(), '')
示例11: testModel
# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import read [as 别名]
def testModel(self):
entry = ProxyEntry()
entry.set_text('value')
entry.set_property("data-type", "str")
self.assertEqual(entry.read(), 'value')