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 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()
def _execute_seek(self, controller, pattern): duration = pattern.duration total_duration = pattern.total_duration lm = self.laser_manager sm = lm.stage_manager ld = sm.lumen_detector ld.mask_kind = pattern.mask_kind ld.custom_mask = pattern.custom_mask_radius osdp = sm.canvas.show_desired_position sm.canvas.show_desired_position = False st = time.time() self.debug('Pre seek delay {}'.format(pattern.pre_seek_delay)) time.sleep(pattern.pre_seek_delay) self.debug('starting seek') self.debug('total duration {}'.format(total_duration)) self.debug('dwell duration {}'.format(duration)) if pattern.kind == 'DragonFlyPeakPattern': try: self._dragonfly_peak(st, pattern, lm, controller) except BaseException as e: self.critical('Dragonfly exception. {}'.format(e)) else: self._hill_climber(st, controller, pattern) sm.canvas.show_desired_position = osdp from pyface.gui import GUI GUI.invoke_later(self._info.dispose)
def _wait_for_data(self): next_poll = self._handle_data() socks = dict(self._poller.poll(timeout=self.poll_timeout)) if self._handshake_socket in socks and \ socks[self._handshake_socket] == zmq.POLLIN: self._handle_connection() GUI.invoke_after(next_poll, self._wait_for_data)
def test_tabular_editor_multi_selection(self): gui = GUI() view = get_view(multi_select=True) with store_exceptions_on_all_threads(), \ self.report_and_editor(view) as (report, editor): gui.process_events() people = report.people self.assertEqual(report.selected_rows, []) self.assertEqual(report.multi_selected, []) set_selected_multiple(editor, [0, 1]) gui.process_events() self.assertEqual(report.selected_rows, [0, 1]) self.assertEqual(report.multi_selected, people[:2]) set_selected_multiple(editor, [2]) gui.process_events() self.assertEqual(report.selected_rows, [2]) self.assertEqual(report.multi_selected, [people[2]]) clear_selection(editor) gui.process_events() self.assertEqual(report.selected_rows, []) self.assertEqual(report.multi_selected, [])
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()
def execute(self): url = 'http://' + self._host + self._url % self._tile_args try: r = requests.get(url) if r.status_code == 200: GUI.invoke_later(self.handler, self._tile_args, r.content) except requests.exceptions.RequestException as ex: print("Exception in request '{}': {}".format(self, ex))
def progress(self, value): """ Set the progress of the operation (0 <= value <= 1). """ if self.dispatch == 'ui': from pyface.gui import GUI GUI.set_trait_later(self.promise, '_progress', value) else: with self.promise._lock: self.promise._progress = value
def do_callback(dispatch, callback, *args): """Invoke the callback with a suitable dispatch. """ if dispatch == 'ui': from pyface.gui import GUI GUI.invoke_later(callback, *args) else: callback(*args)
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()
def setup_gui(self, model, view): gui = GUI() ui = model.edit_traits(view=view) self.addCleanup(ui.dispose) gui.process_events() editor = ui.get_editors("value")[0] return gui, editor
def setUpClass(cls): app = QtGui.QApplication.instance() or QtGui.QApplication([]) person_view = View(body_html=body_html) fred = Person(name='Fred', age=42) person_view.show(model=fred) GUI.process_events() cls.person_view = person_view cls.fred = fred cls.app = app
def _calculation_done(self, future): """ Function which will return the result of the computation to the main thread Parameters ---------- future Object containing the result of the calculation """ GUI.invoke_later(self._computation_done, future.result())
def error(self, value): """ Complete the deferred with failure and specified result. """ if self.dispatch == 'ui': from pyface.gui import GUI promise = self.promise GUI.set_trait_later(promise, '_error', value) GUI.set_trait_later(promise, '_status', 'error') else: with self.promise._lock: self.promise._error = value self.promise._status = 'error'
def _play_func(self): ''' Called while play button is selected :return: ''' if self._play_thread: if self._last_clicked_direction is not None: self._last_clicked_direction() else: self.move_forward() GUI.invoke_after(1000, self._play_func)
def _play_button_changed(self, play_pressed): ''' Triggered when play button is selected :param play_pressed: :return: ''' if play_pressed: if not self._play_thread: self._play_thread = True GUI.invoke_after(1, self._play_func) else: self._play_thread = False
def setUp(self): self.gui = GUI() self.parent = self._create_parent() 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 progress_callback(self, datasets, current_iteration, total_iterations): """ Function called in the secondary thread. It will transfer the progress status of the calculation to the main thread Parameters ---------- progress The progress of the calculation (Integer in the range [0, 100]) """ progress = current_iteration/total_iterations*100 GUI.invoke_later(self._append_frame_and_continue, datasets) GUI.invoke_later(self.progress_dialog.update, progress)
def start(self): self._zmq_context = zmq.Context() self._poller = zmq.Poller() self._handshake_socket = self._zmq_context.socket(zmq.REP) self._handshake_socket.bind(self.handshake_string) self._data_socket = self._zmq_context.socket(zmq.SUB) self._data_socket.setsockopt(zmq.SUBSCRIBE, '') self._data_socket.connect(self.data_string) self._poller.register(self._handshake_socket, zmq.POLLIN) self._poller.register(self._data_socket, zmq.POLLIN) GUI.invoke_after(self.poll_period, self._wait_for_data)
def setup_gui(self, model, view): gui = GUI() ui = model.edit_traits(view=view) self.addCleanup(ui.dispose) gui.process_events() editor = ui.get_editors("value")[0] line_edit = editor.control # FIXME issue enthought/traitsui#851 if is_current_backend_wx(): import wx self.addCleanup(line_edit.Unbind, wx.EVT_KILL_FOCUS) return gui, editor, line_edit
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)
def test_selection_listener_disconnected(self): """ Check that selection listeners get correctly disconnected """ from pyface.api import GUI from pyface.qt.QtGui import QApplication, QItemSelectionModel from pyface.ui.qt4.util.event_loop_helper import EventLoopHelper from pyface.ui.qt4.util.testing import event_loop obj = ListStrEditorWithSelectedIndex(values=["value1", "value2"]) with store_exceptions_on_all_threads(): qt_app = QApplication.instance() if qt_app is None: qt_app = QApplication([]) helper = EventLoopHelper(gui=GUI(), qt_app=qt_app) # open the UI and run until the dialog is closed with create_ui(obj, dict(view=single_select_item_view)) as ui: with helper.delete_widget(ui.control): press_ok_button(ui) # now run again and change the selection with create_ui(obj, dict(view=single_select_item_view)) as ui, \ event_loop(): editor = ui.get_editors("values")[0] list_view = editor.list_view mi = editor.model.index(1) list_view.selectionModel().select( mi, QItemSelectionModel.ClearAndSelect ) obj.selected = "value2"
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
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")
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")
def start(self): """ Start the application, setting up things that are required Subclasses should open at least one ApplicationWindow or subclass in their start method, and should call the superclass start() method before doing any work themselves. """ from pyface.gui import GUI ok = super(GUIApplication, self).start() if ok: # create the GUI so that the splash screen comes up first thing if self.gui is Undefined: self.gui = GUI(splash_screen=self.splash_screen) # create the initial windows to show self._create_windows() return ok
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
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 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'), ]
def test_table_editor_select_cells(self): 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(), \ create_ui(object_list, dict(view=select_cells_view)) as ui: 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() self.assertEqual(selected, [ (object_list.values[5], "value"), (object_list.values[6], "other value"), (object_list.values[8], "value"), ])
def _execute_seek(self, controller, pattern): duration = pattern.duration total_duration = pattern.total_duration lm = self.laser_manager sm = lm.stage_manager ld = sm.lumen_detector ld.mask_kind = pattern.mask_kind ld.custom_mask = pattern.custom_mask_radius osdp = sm.canvas.show_desired_position sm.canvas.show_desired_position = False st = time.time() self.debug('Pre seek delay {}'.format(pattern.pre_seek_delay)) time.sleep(pattern.pre_seek_delay) self.debug('starting seek') self.debug('total duration {}'.format(total_duration)) self.debug('dwell duration {}'.format(duration)) if pattern.kind == 'DragonFlyPeakPattern': try: self._dragonfly_peak(st, pattern, lm, controller) except BaseException as e: self.critical('Dragonfly exception. {}'.format(e)) self.debug_exception() else: self._hill_climber(st, controller, pattern) sm.canvas.show_desired_position = osdp from pyface.gui import GUI GUI.invoke_later(self._info.dispose)
def test_table_editor(self): gui = GUI() object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) with store_exceptions_on_all_threads(), \ create_ui(object_list, dict(view=simple_view)) as ui: gui.process_events() press_ok_button(ui) gui.process_events()
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()
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 test_tabular_editor_single_selection(self): gui = GUI() with store_exceptions_on_all_threads(), \ self.report_and_editor(get_view()) as (report, editor): gui.process_events() people = report.people self.assertEqual(report.selected_row, -1) self.assertIsNone(report.selected) set_selected_single(editor, 1) gui.process_events() self.assertEqual(report.selected_row, 1) self.assertEqual(report.selected, people[1]) set_selected_single(editor, 2) gui.process_events() self.assertEqual(report.selected_row, 2) self.assertEqual(report.selected, people[2])
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
def test_filtered_table_editor(self): gui = GUI() object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) with store_exceptions_on_all_threads(), \ create_ui(object_list, dict(view=filtered_view)) as ui: gui.process_events() filter = ui.get_editors("values")[0].filter press_ok_button(ui) gui.process_events() self.assertIsNotNone(filter)
def done(self, value): """ Complete the deferred with success and specified result. and set the progress to 1.0 """ if self.dispatch == 'ui': from pyface.gui import GUI promise = self.promise GUI.set_trait_later(promise, '_result', value) GUI.set_trait_later(promise, '_progress', 1.0) GUI.set_trait_later(promise, '_status', 'done') else: with self.promise._lock: self.promise._result = value self.promise._progress = 1.0 self.promise._status = 'done'
def test_list_str_editor_item_count(self): gui = GUI() model = ListStrModel() # Without auto_add with store_exceptions_on_all_threads(), \ create_ui(model, dict(view=get_view())) as ui: gui.process_events() editor = ui.get_editors("value")[0] self.assertEqual(editor.item_count, 3) # With auto_add with store_exceptions_on_all_threads(), \ create_ui(model, dict(view=get_view(auto_add=True))) as ui: gui.process_events() editor = ui.get_editors("value")[0] self.assertEqual(editor.item_count, 3)
def test_table_editor_select_row_index(self): gui = GUI() object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) object_list.selected_index = 5 with store_exceptions_on_all_threads(), \ create_ui(object_list, dict(view=select_row_index_view)) as ui: 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_row_index press_ok_button(ui) gui.process_events() self.assertEqual(selected, 5)
def test_table_editor_select_cell_indices(): gui = GUI() object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) object_list.selected_cell_indices = [(5, 0), (6, 1), (8, 0)] with store_exceptions_on_all_threads(): ui = object_list.edit_traits(view=select_cell_indices_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_cell_indices press_ok_button(ui) gui.process_events() assert selected == [(5, 0), (6, 1), (8, 0)]
def setUp(self): self.gui = GUI() self.dialog = ProgressDialog()
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() 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') editor = control._ui.get_editors('value')[1] with self.assertTraitChanges(action, 'value', count=1): if toolkit.toolkit in {'qt', 'qt4'}: editor.control.setCurrentIndex(2) editor.control.activated.emit(2) elif toolkit.toolkit == 'wx': event = wx.CommandEvent(wx.EVT_CHOICE.typeId, editor.control.GetId()) event.SetString('c') wx.PostEvent(editor.control.GetEventHandler(), event) else: self.skipTest("Unknown toolkit") self.gui.process_events() self.assertEqual(action.value, 'c')
def handle_response(self): if self.response.status == 200: GUI.invoke_later(self.handler, self._tile_args, self.response.body) self.close()
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()
def setUp(self): self.gui = GUI() self.parent = Window() self.parent._create() self.addCleanup(self._destroy_parent)
def execute_js(self, js): GUI.process_events() result = self.bridge.widget.execute_js(js) GUI.process_events() return result
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)