def start_monitors(self, measurement): """Start the monitors attached to a measurement. Called in the main thread. """ workbench = self.plugin.workbench if not self.monitors_window: with enaml.imports(): from .workspace.monitors_window import MonitorsWindow self.monitors_window = MonitorsWindow() else: self.monitors_window.send_to_front() self.monitors_window.measurement = measurement dock_area = self.monitors_window.dock_area anchor = '' for dock_item in dock_area.dock_items(): if dock_item.name not in measurement.monitors: dock_item.destroy() elif not anchor: anchor = dock_item.name # We show the window now because otherwise the layout ops are not # properly executed. if self.plugin.auto_show_monitors: self.monitors_window.show() ops = [] for monitor in measurement.monitors.values(): decl = monitor.declaration dock_item = dock_area.find(decl.id) if dock_item is None: try: dock_item = decl.create_item(workbench, dock_area) except Exception: msg = 'Failed to create widget for monitor %s :\n %s' logger.error(msg, decl.id, format_exc()) continue if dock_item is not None: if dock_item.float_default: ops.append(FloatItem(item=decl.id)) else: ops.append(InsertTab(item=decl.id, target=anchor)) self.engine.observe('progress', monitor.process_news) if dock_item: dock_item.monitor = monitor monitor.start() if ops: dock_area.update_layout(ops)
def start_monitors(self, measure): workbench = self.plugin.workbench if not self.monitors_window: ui_plugin = workbench.get_plugin('enaml.workbench.ui') with enaml.imports(): from .workspace.monitors_window import MonitorsWindow self.monitors_window = MonitorsWindow(ui_plugin.window) self.monitors_window.measure = measure dock_area = self.monitors_window.dock_area anchor = '' for dock_item in dock_area.dock_items(): if dock_item.name not in measure.monitors: dock_item.destroy() elif not anchor: anchor = dock_item.name # We show the window now because otherwise the layout ops are not # properly executed. if self.plugin.auto_show_monitors: self.monitors_window.show() ops = [] for monitor in measure.monitors.values(): decl = monitor.declaration dock_item = dock_area.find(decl.id) if dock_item is None: try: dock_item = decl.create_item(workbench, dock_area) except Exception: logger.error('Failed to create widget for monitor %s', decl.id) logger.debug(format_exc()) continue if dock_item is not None: if dock_item.float_default: ops.append(FloatItem(item=decl.id)) else: ops.append(InsertTab(item=decl.id, target=anchor)) self.engine.observe('progress', monitor.process_news) if dock_item: dock_item.monitor = monitor monitor.start() if ops: dock_area.update_layout(ops)
def show_debug_console(self): """ Show an IPython console for debugging. """ from enaml.layout.api import FloatItem, RemoveItem from enaml.widgets.api import Window, Container, DockItem, IPythonConsole dock_area = self.dock_area name = 'ipython_console' item = DockItem(dock_area, name=name, title='Console') console_container = Container(item, padding=0) console = IPythonConsole(console_container, initial_ns={ 'main_controller': self, 'windows': Window.windows, }) console.observe('exit_requested', lambda change: \ dock_area.update_layout(RemoveItem(item=name))) dock_area.update_layout(FloatItem(item=name))
def test_dock_area_interactions(enaml_qtbot, enaml_sleep): """Test interations with the dock area. """ # Since timers are used the sleep must be greater than the default enaml_sleep = max(300, enaml_sleep) from enaml.qt.QtCore import Qt, QPoint from enaml.qt.QtWidgets import QWidget from enaml.layout.api import FloatItem, InsertTab dir_path = os.path.abspath(os.path.split(os.path.dirname(__file__))[0]) example_path = os.path.join(dir_path, 'examples', 'widgets', 'dock_area.enaml') with open(example_path) as f: source = f.read() win = compile_source(source, 'Main')() win.show() wait_for_window_displayed(enaml_qtbot, win) enaml_qtbot.wait(enaml_sleep) _children = win.children[0].children btn_save, btn_restore, btn_add, cmb_styles, cbx_evts, dock = _children # Enable dock events enaml_qtbot.mouseClick(cbx_evts.proxy.widget, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) with pytest.warns(DockLayoutWarning): # Change styles cmb_styles.proxy.widget.setFocus() enaml_qtbot.keyClick(cmb_styles.proxy.widget, Qt.Key_Up) # Save layout enaml_qtbot.mouseClick(btn_save.proxy.widget, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) # Toggle closable di = dock.find('item_2') di.closable = False enaml_qtbot.wait(enaml_sleep) di.closable = True # Check alert di.alert('info') # Maximize it tb = di.proxy.widget.titleBarWidget() enaml_qtbot.mouseClick(tb._max_button, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) # Minimize it enaml_qtbot.mouseClick(tb._restore_button, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) # Pin it enaml_qtbot.mouseClick(tb._pin_button, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) # TODO: Open and close it using clicks dock_area = dock.proxy.widget for c in dock_area.dockBarContainers(): dock_bar = c[0] dock_area.extendFromDockBar(dock_bar) enaml_qtbot.wait(enaml_sleep) dock_area.retractToDockBar(dock_bar) enaml_qtbot.wait(enaml_sleep) # Unpin enaml_qtbot.mouseClick(tb._pin_button, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) # Note the location of the dock item title title = tb._title_label ref = win.proxy.widget # Maximize and minimize it by double clicking pos = title.mapTo(tb, title.pos()) enaml_qtbot.mouseDClick(tb, Qt.LeftButton, pos=pos) enaml_qtbot.wait(enaml_sleep) enaml_qtbot.mouseDClick(tb, Qt.LeftButton, pos=pos) enaml_qtbot.wait(enaml_sleep) # Float it op = FloatItem(item=di.name) dock.update_layout(op) enaml_qtbot.wait(enaml_sleep) # Link it enaml_qtbot.mouseClick(tb._link_button, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) # Unlink it enaml_qtbot.mouseClick(tb._link_button, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) # Restore it op = InsertTab(item=di.name, target='item_1') dock.update_layout(op) enaml_qtbot.wait(enaml_sleep) # TODO: Drag it around # Add items enaml_qtbot.mouseClick(btn_add.proxy.widget, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) # Close all added items for i in range(10, 15): di = dock.find('item_%i' % i) if di: enaml_qtbot.mouseClick( di.proxy.widget.titleBarWidget()._close_button, Qt.LeftButton) # Restore layout enaml_qtbot.mouseClick(btn_restore.proxy.widget, Qt.LeftButton) enaml_qtbot.wait(enaml_sleep) enaml_qtbot.wait(enaml_sleep)