本文整理汇总了Python中pyface.gui.GUI.process_events方法的典型用法代码示例。如果您正苦于以下问题:Python GUI.process_events方法的具体用法?Python GUI.process_events怎么用?Python GUI.process_events使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyface.gui.GUI
的用法示例。
在下文中一共展示了GUI.process_events方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_progress_column
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
def test_progress_column():
from traitsui.extras.progress_column import ProgressColumn
progress_view = View(
Item(
'values',
show_label=False,
editor=TableEditor(
columns=[
ObjectColumn(name='value'),
ProgressColumn(name='other_value'),
],
)
),
buttons=['OK'],
)
gui = GUI()
object_list = ObjectList(
values=[ListItem(value=str(i**2)) for i in range(10)]
)
with store_exceptions_on_all_threads():
ui = object_list.edit_traits(view=progress_view)
gui.process_events()
press_ok_button(ui)
gui.process_events()
示例2: test_table_editor_select_cells
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
def test_table_editor_select_cells():
gui = GUI()
object_list = ObjectListWithSelection(
values=[ListItem(value=str(i**2)) for i in range(10)]
)
object_list.selected_cells = [
(object_list.values[5], 'value'),
(object_list.values[6], 'other value'),
(object_list.values[8], 'value'),
]
with store_exceptions_on_all_threads():
ui = object_list.edit_traits(view=select_cells_view)
editor = ui.get_editors('values')[0]
gui.process_events()
if is_current_backend_qt4():
selected = editor.selected
elif is_current_backend_wx():
selected = editor.selected_cells
press_ok_button(ui)
gui.process_events()
assert selected == [
(object_list.values[5], 'value'),
(object_list.values[6], 'other value'),
(object_list.values[8], 'value'),
]
示例3: test_styles
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
def test_styles(self):
# simple smoke test of buttons
gui = GUI()
button_text_edit = ButtonTextEdit()
with store_exceptions_on_all_threads():
ui = button_text_edit.edit_traits()
self.addCleanup(ui.dispose)
gui.process_events()
示例4: test_table_editor
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
def test_table_editor():
gui = GUI()
object_list = ObjectList(values=[ListItem(value=str(i ** 2)) for i in range(10)])
with store_exceptions_on_all_threads():
ui = object_list.edit_traits(view=simple_view)
gui.process_events()
press_ok_button(ui)
gui.process_events()
示例5: check_button_text_update
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
def check_button_text_update(self, view):
gui = GUI()
button_text_edit = ButtonTextEdit()
with store_exceptions_on_all_threads():
ui = button_text_edit.edit_traits(view=view)
self.addCleanup(ui.dispose)
gui.process_events()
editor, = ui.get_editors("play_button")
button = editor.control
self.assertEqual(get_button_text(button), "I'm a play button")
button_text_edit.play_button_label = "New Label"
self.assertEqual(get_button_text(button), "New Label")
示例6: test_filtered_table_editor
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
def test_filtered_table_editor():
gui = GUI()
object_list = ObjectListWithSelection(
values=[ListItem(value=str(i**2)) for i in range(10)]
)
with store_exceptions_on_all_threads():
ui = object_list.edit_traits(view=filtered_view)
gui.process_events()
filter = ui.get_editors('values')[0].filter
press_ok_button(ui)
gui.process_events()
assert filter is not None
示例7: check_enum_text_update
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
def check_enum_text_update(self, view):
gui = GUI()
enum_edit = EnumModel()
with store_exceptions_on_all_threads():
ui = enum_edit.edit_traits(view=view)
self.addCleanup(ui.dispose)
gui.process_events()
editor = ui.get_editors("value")[0]
combobox = editor.control
self.assertEqual(get_combobox_text(combobox), "one")
enum_edit.value = "two"
gui.process_events()
self.assertEqual(get_combobox_text(combobox), "two")
示例8: test_table_editor_select_column_index
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
def test_table_editor_select_column_index():
gui = GUI()
object_list = ObjectListWithSelection(
values=[ListItem(value=str(i**2)) for i in range(10)]
)
object_list.selected_index = 1
with store_exceptions_on_all_threads():
ui = object_list.edit_traits(view=select_column_index_view)
editor = ui.get_editors('values')[0]
gui.process_events()
if is_current_backend_qt4():
selected = editor.selected_indices
elif is_current_backend_wx():
selected = editor.selected_column_index
press_ok_button(ui)
gui.process_events()
assert selected == 1
示例9: TestDialog
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
class TestDialog(unittest.TestCase):
def setUp(self):
self.gui = GUI()
self.dialog = ProgressDialog()
def test_create(self):
# test that creation and destruction works as expected
self.dialog._create()
self.gui.process_events()
self.assertIsNotNone(self.dialog.control)
self.assertIsNotNone(self.dialog.progress_bar)
self.assertIsNotNone(self.dialog._message_control)
self.assertIsNone(self.dialog._elapsed_control)
self.assertIsNone(self.dialog._estimated_control)
self.assertIsNone(self.dialog._remaining_control)
self.dialog.destroy()
def test_show_time(self):
# test that creation works with show_time
self.dialog.show_time = True
self.dialog._create()
self.gui.process_events()
self.assertIsNotNone(self.dialog._elapsed_control)
self.assertIsNotNone(self.dialog._estimated_control)
self.assertIsNotNone(self.dialog._remaining_control)
self.dialog.destroy()
def test_show_percent(self):
# test that creation works with show_percent
self.dialog.show_percent = True
self.dialog._create()
self.gui.process_events()
self.assertEqual(self.dialog.progress_bar.format(), "%p%")
self.dialog.destroy()
def test_update(self):
self.dialog.min = 0
self.dialog.max = 10
self.dialog.open()
for i in range(11):
result = self.dialog.update(i)
self.gui.process_events()
self.assertEqual(result, (True, False))
if i < 10:
self.assertEqual(self.dialog.progress_bar.value(), i)
self.assertIsNone(self.dialog.control)
def test_update_no_control(self):
# note: inconsistent implementation with Wx
self.dialog.min = 0
self.dialog.max = 10
result = self.dialog.update(1)
self.assertEqual(result, (None, None))
def test_change_message(self):
self.dialog.min = 0
self.dialog.max = 10
self.dialog.open()
for i in range(11):
self.dialog.change_message('Updating {}'.format(i))
result = self.dialog.update(i)
self.gui.process_events()
self.assertEqual(result, (True, False))
self.assertEqual(self.dialog.message, 'Updating {}'.format(i))
self.assertEqual(self.dialog._message_control.text(),
'Updating {}'.format(i))
self.assertIsNone(self.dialog.control)
def test_change_message_trait(self):
self.dialog.min = 0
self.dialog.max = 10
self.dialog.open()
for i in range(11):
self.dialog.message = 'Updating {}'.format(i)
result = self.dialog.update(i)
self.gui.process_events()
self.assertEqual(result, (True, False))
self.assertEqual(self.dialog.message, 'Updating {}'.format(i))
self.assertEqual(self.dialog._message_control.text(),
'Updating {}'.format(i))
self.assertIsNone(self.dialog.control)
def test_update_show_time(self):
self.dialog.min = 0
self.dialog.max = 10
self.dialog.show_time = True
self.dialog.open()
for i in range(11):
result = self.dialog.update(i)
self.gui.process_events()
self.assertEqual(result, (True, False))
self.assertNotEqual(self.dialog._elapsed_control.text(), "")
self.assertNotEqual(self.dialog._estimated_control.text(), "")
self.assertNotEqual(self.dialog._remaining_control.text(), "")
self.assertIsNone(self.dialog.control)
示例10: TestFieldAction
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
class TestFieldAction(unittest.TestCase):
def setUp(self):
self.gui = GUI()
self.parent = Window()
self.parent._create()
self.addCleanup(self._destroy_parent)
def _destroy_parent(self):
self.parent.destroy()
self.parent = None
def test_combo_field_action(self):
# test whether function is called by updating list
# XXX should really use mock
memo = []
def perform(value):
memo.append(value)
action = FieldAction(
name="Dummy",
field_type=ComboField,
field_defaults={
'values': ['a', 'b', 'c'],
'value': 'a',
'tooltip': 'Dummy',
},
on_perform=perform,
)
control = action.create_control(self.parent.control)
try:
self.gui.process_events()
control._field.value = 'b'
self.gui.process_events()
self.assertEqual(memo, ['b'])
finally:
control._field.destroy()
def test_text_field_action(self):
# test whether function is called by updating list
# XXX should really use mock
memo = []
def perform(value):
memo.append(value)
action = FieldAction(
name="Dummy",
field_type=TextField,
field_defaults={
'value': 'a',
'tooltip': 'Dummy',
},
on_perform=perform,
)
control = action.create_control(self.parent.control)
try:
self.gui.process_events()
control._field.value = 'b'
self.gui.process_events()
self.assertEqual(memo, ['b'])
finally:
control._field.destroy()
def test_spin_field_action(self):
# test whether function is called by updating list
# XXX should really use mock
memo = []
def perform(value):
memo.append(value)
action = FieldAction(
name="Dummy",
field_type=SpinField,
field_defaults={
'value': 1,
'bounds': (0, 100),
'tooltip': 'Dummy',
},
on_perform=perform,
)
control = action.create_control(self.parent.control)
try:
self.gui.process_events()
control._field.value = 5
self.gui.process_events()
self.assertEqual(memo, [5])
finally:
control._field.destroy()
示例11: FieldMixin
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
class FieldMixin(UnittestTools):
""" Mixin which provides standard methods for all fields. """
def setUp(self):
self.gui = GUI()
self.parent = Window()
self.parent._create()
self.addCleanup(self._destroy_parent)
self.gui.process_events()
self.widget = self._create_widget()
self.parent.open()
self.gui.process_events()
def _create_widget(self):
raise NotImplementedError()
def _create_widget_control(self):
self.widget._create()
self.addCleanup(self._destroy_widget)
self.widget.show(True)
self.gui.process_events()
def _destroy_parent(self):
self.parent.destroy()
self.gui.process_events()
self.parent = None
def _destroy_widget(self):
self.widget.destroy()
self.gui.process_events()
self.widget = None
# Tests ------------------------------------------------------------------
def test_field_tooltip(self):
self._create_widget_control()
self.widget.tooltip = "New tooltip."
self.gui.process_events()
self.assertEqual(self.widget._get_control_tooltip(), "New tooltip.")
def test_field_menu(self):
self._create_widget_control()
self.widget.menu = MenuManager(Action(name='Test'), name='Test')
self.gui.process_events()
示例12: ScrollBarTest
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
class ScrollBarTest(unittest.TestCase):
def setUp(self):
from pyface.qt.QtGui import QApplication
from pyface.ui.qt4.util.event_loop_helper import EventLoopHelper
qt_app = QApplication.instance()
if qt_app is None:
qt_app = QApplication([])
self.qt_app = qt_app
if NativeScrollBar is None:
raise unittest.SkipTest("Qt4 NativeScrollbar not available.")
self.gui = GUI()
self.event_loop_helper = EventLoopHelper(gui=self.gui, qt_app=qt_app)
self.container = Container(position=[0, 0], bounds=[600, 600])
self.window = Window(None, size=(600, 600), component=self.container)
@contextmanager
def setup_window(self, window):
window.control.show()
window._size = window._get_control_size()
self.gui.process_events()
try:
yield
finally:
self.gui.process_events()
with self.event_loop_helper.delete_widget(window.control, timeout=1.0):
window.control.deleteLater()
@contextmanager
def setup_scrollbar(self, scrollbar, window):
scrollbar._draw_mainlayer(window._gc)
try:
yield
finally:
scrollbar.destroy()
def test_scroll_position_horizontal(self):
bounds = [600.0, 30.0]
position = [0.0, 0.0]
range = [600, 0.0, 375.0, 20.454545454545453]
scrollbar = NativeScrollBar(orientation="horizontal", bounds=bounds, position=position, range=range)
self.container.add(scrollbar)
with self.setup_window(self.window):
with self.setup_scrollbar(scrollbar, self.window):
self.assertEqual(scrollbar._control.value(), 0)
self.assertEqual(scrollbar.scroll_position, 0)
# move the scrollbar
scrollbar._control.setValue(100)
self.assertEqual(scrollbar.scroll_position, 100)
# set the scroll & redraw
scrollbar.scroll_position = 200
scrollbar._draw_mainlayer(self, self.window._gc)
self.assertEqual(scrollbar._control.value(), 200)
def test_scroll_position_vertical(self):
bounds = [30.0, 600.0]
position = [0.0, 0.0]
range = [600, 0.0, 375.0, 20.454545454545453]
scrollbar = NativeScrollBar(orientation="vertical", bounds=bounds, position=position, range=range)
self.container.add(scrollbar)
with self.setup_window(self.window):
with self.setup_scrollbar(scrollbar, self.window):
self.assertEqual(scrollbar._control.value(), 600 - 375)
self.assertEqual(scrollbar.scroll_position, 0)
# move the scrollbar
scrollbar._control.setValue(100)
self.assertEqual(scrollbar.scroll_position, 600 - 375 - 100)
# set the scroll & redraw
scrollbar.scroll_position = 200
scrollbar._draw_mainlayer(self, self.window._gc)
self.assertEqual(scrollbar._control.value(), 600 - 375 - 200)
def test_minumum_horizontal(self):
bounds = [600.0, 30.0]
position = [0.0, 0.0]
range = [700, 100.0, 375.0, 20.454545454545453]
scrollbar = NativeScrollBar(orientation="horizontal", bounds=bounds, position=position, range=range)
self.container.add(scrollbar)
with self.setup_window(self.window):
with self.setup_scrollbar(scrollbar, self.window):
self.assertEqual(scrollbar._control.value(), 100)
self.assertEqual(scrollbar.scroll_position, 100)
# move the scrollbar
scrollbar._control.setValue(200)
self.assertEqual(scrollbar.scroll_position, 200)
# set the scroll & redraw
scrollbar.scroll_position = 300
scrollbar._draw_mainlayer(self, self.window._gc)
self.assertEqual(scrollbar._control.value(), 300)
def test_minimum_vertical(self):
bounds = [30.0, 600.0]
position = [0.0, 0.0]
#.........这里部分代码省略.........
示例13: ScrollBarTest
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
class ScrollBarTest(unittest.TestCase):
def setUp(self):
if NativeScrollBar is None:
raise unittest.SkipTest("Qt4 NativeScrollbar not available.")
self.gui = GUI()
self.container = Container(position=[0, 0], bounds=[600, 600])
self.window = Window(None, size=(600, 600), component=self.container)
@contextmanager
def setup_window(self, window):
window.control.show()
window._size = window._get_control_size()
self.gui.process_events()
try:
yield
finally:
window.control.destroy()
@contextmanager
def setup_scrollbar(self, scrollbar, window):
scrollbar._draw_mainlayer(window._gc)
try:
yield
finally:
scrollbar.destroy()
def test_scroll_position_horizontal(self):
bounds = [600.0, 30.0]
position = [0.0, 0.0]
range = [600, 0.0, 375.0, 20.454545454545453]
scrollbar = NativeScrollBar(
orientation='horizontal',
bounds=bounds,
position=position,
range=range,
)
self.container.add(scrollbar)
with self.setup_window(self.window):
with self.setup_scrollbar(scrollbar, self.window):
self.assertEqual(scrollbar._control.value(), 0)
self.assertEqual(scrollbar.scroll_position, 0)
# move the scrollbar
scrollbar._control.setValue(100)
self.assertEqual(scrollbar.scroll_position, 100)
# set the scroll & redraw
scrollbar.scroll_position = 200
scrollbar._draw_mainlayer(self, self.window._gc)
self.assertEqual(scrollbar._control.value(), 200)
def test_scroll_position_vertical(self):
bounds = [30.0, 600.0]
position = [0.0, 0.0]
range = [600, 0.0, 375.0, 20.454545454545453]
scrollbar = NativeScrollBar(
orientation='vertical',
bounds=bounds,
position=position,
range=range,
)
self.container.add(scrollbar)
with self.setup_window(self.window):
with self.setup_scrollbar(scrollbar, self.window):
self.assertEqual(scrollbar._control.value(), 600-375)
self.assertEqual(scrollbar.scroll_position, 0)
# move the scrollbar
scrollbar._control.setValue(100)
self.assertEqual(scrollbar.scroll_position, 600-375-100)
# set the scroll & redraw
scrollbar.scroll_position = 200
scrollbar._draw_mainlayer(self, self.window._gc)
self.assertEqual(scrollbar._control.value(), 600-375-200)
def test_minumum_horizontal(self):
bounds = [600.0, 30.0]
position = [0.0, 0.0]
range = [700, 100.0, 375.0, 20.454545454545453]
scrollbar = NativeScrollBar(
orientation='horizontal',
bounds=bounds,
position=position,
range=range,
)
self.container.add(scrollbar)
with self.setup_window(self.window):
with self.setup_scrollbar(scrollbar, self.window):
self.assertEqual(scrollbar._control.value(), 100)
self.assertEqual(scrollbar.scroll_position, 100)
# move the scrollbar
scrollbar._control.setValue(200)
self.assertEqual(scrollbar.scroll_position, 200)
# set the scroll & redraw
scrollbar.scroll_position = 300
scrollbar._draw_mainlayer(self, self.window._gc)
#.........这里部分代码省略.........
示例14: TestTraitsUIWidgetAction
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
class TestTraitsUIWidgetAction(unittest.TestCase, UnittestTools):
def setUp(self):
self.gui = GUI()
self.parent = Window()
self.parent._create()
self.parent.open()
self.addCleanup(self._destroy_parent)
self.gui.process_events()
def _destroy_parent(self):
self.parent.destroy()
self.gui.process_events()
self.parent = None
def create_model(self):
from traitsui.api import View, Item
class SimpleEnum(HasTraits):
value = Enum('a', 'b', 'c')
view = View(Item('value'))
return SimpleEnum()
def test_traitsui_widget_action(self):
from traitsui.api import View, Item
class SimpleEnumAction(TraitsUIWidgetAction):
value = Enum('a', 'b', 'c')
view = View(Item('value'))
action = SimpleEnumAction(name="Simple")
control = action.create_control(self.parent.control)
self.gui.process_events()
editor = control._ui.get_editors('value')[0]
with self.assertTraitChanges(action, 'value', count=1):
if toolkit.toolkit in {'qt', 'qt4'}:
editor.control.setCurrentIndex(1)
editor.control.activated.emit(1)
elif toolkit.toolkit == 'wx':
import wx
event = wx.CommandEvent(wx.EVT_CHOICE.typeId,
editor.control.GetId())
event.SetString('b')
wx.PostEvent(editor.control.GetEventHandler(), event)
else:
self.skipTest("Unknown toolkit")
self.gui.process_events()
self.assertEqual(action.value, 'b')
def test_traitsui_widget_action_model(self):
from traitsui.api import View, Item
class SimpleEnumAction(TraitsUIWidgetAction):
view = View(Item('value'))
model = self.create_model()
action = SimpleEnumAction(name="Simple", model=model)
control = action.create_control(self.parent.control)
self.gui.process_events()
editor = control._ui.get_editors('value')[0]
with self.assertTraitChanges(model, 'value', count=1):
if toolkit.toolkit in {'qt', 'qt4'}:
editor.control.setCurrentIndex(1)
editor.control.activated.emit(1)
elif toolkit.toolkit == 'wx':
import wx
event = wx.CommandEvent(wx.EVT_CHOICE.typeId,
editor.control.GetId())
event.SetString('b')
wx.PostEvent(editor.control.GetEventHandler(), event)
else:
self.skipTest("Unknown toolkit")
self.gui.process_events()
self.assertEqual(model.value, 'b')
def test_traitsui_widget_action_model_view(self):
from traitsui.api import HGroup, View, Item
class ComplexEnumAction(TraitsUIWidgetAction):
value = Enum('a', 'b', 'c')
view = View(
HGroup(
Item('value'),
Item('action.value'),
)
)
model = self.create_model()
action = ComplexEnumAction(name="Simple", model=model)
control = action.create_control(self.parent.control)
self.gui.process_events()
#.........这里部分代码省略.........
示例15: DockPaneToggleGroupTestCase
# 需要导入模块: from pyface.gui import GUI [as 别名]
# 或者: from pyface.gui.GUI import process_events [as 别名]
class DockPaneToggleGroupTestCase(unittest.TestCase):
@unittest.skipIf(USING_WX, "TaskWindowBackend is not implemented in WX")
def setUp(self):
self.gui = GUI()
# Set up the bogus task with its window.
self.task = BogusTask()
self.window = window = TaskWindow()
window.add_task(self.task)
self.task_state = window._get_state(self.task)
# Fish the dock pane toggle group from the menu bar manager.
dock_pane_toggle_group = []
def find_doc_pane_toggle(item):
if item.id == 'tests.bogus_task.DockPaneToggleGroup':
dock_pane_toggle_group.append(item)
self.task_state.menu_bar_manager.walk(find_doc_pane_toggle)
self.dock_pane_toggle_group = dock_pane_toggle_group[0]
def tearDown(self):
del self.task
del self.task_state
del self.dock_pane_toggle_group
if self.window.control is not None:
self.window.destroy()
self.gui.process_events()
del self.window
del self.gui
def get_dock_pane_toggle_action_names(self):
names = [
action_item.action.name
for action_item in self.dock_pane_toggle_group.items
]
return names
#### Tests ################################################################
def test_group_content_at_startup(self):
# Check that there are 2 dock panes in the group at the beginning.
self.assertEqual(2, len(self.dock_pane_toggle_group.items))
# Names are sorted by the group.
names = self.get_dock_pane_toggle_action_names()
expected_names = ['Dock Pane 1', 'Dock Pane 2']
self.assertEqual(list(sorted(expected_names)), list(sorted(names)))
def test_react_to_dock_pane_added(self):
# Add a dock pane to the task.
self.task_state.dock_panes.append(
DockPane(id='tests.bogus_task.dock_pane_0', name='Dock Pane 0')
)
# Check that there are 3 dock panes in the group.
self.assertEqual(3, len(self.dock_pane_toggle_group.items))
# Names are sorted by the group.
names = self.get_dock_pane_toggle_action_names()
expected_names = ['Dock Pane 0', 'Dock Pane 1', 'Dock Pane 2']
self.assertEqual(list(sorted(expected_names)), list(sorted(names)))
def test_react_to_dock_pane_removed(self):
# Remove a dock pane from the task.
self.task_state.dock_panes.remove(self.task.dock_panes[0])
# Check that there is only 1 dock pane left in the group.
self.assertEqual(1, len(self.dock_pane_toggle_group.items))
names = self.get_dock_pane_toggle_action_names()
expected_names = ['Dock Pane 1']
self.assertEqual(list(sorted(expected_names)), list(sorted(names)))