def test_ActionButton_adds_shell_command(widget, get_renderer): ab = widgets.ActionButton(0, 0, 0, 0, 'dummy') widget.add_child(ab) ab.add_shell_command('ls') renderer = get_renderer(widget) renderer.assemble() action_nodes = renderer.get_node().findall('./widget/actions/action') assert action_nodes[0].get('type') == 'EXECUTE_CMD' assert action_nodes[0].find('./command').text == 'ls' assert action_nodes[0].find('./command_directory').text == '$(opi.dir)'
def test_ActionButton_adds_exit_action(widget, get_renderer): ab = widgets.ActionButton(0, 0, 0, 0, 'dummy') ab.add_exit() widget.add_child(ab) renderer = get_renderer(widget) renderer.assemble() action_nodes = renderer.get_node().findall('./widget/actions/action') assert len(action_nodes) == 1 assert action_nodes[0].get('type') == 'EXECUTE_JAVASCRIPT' assert action_nodes[0].find('./embedded').text == 'true'
def test_ActionButton_open_opi_macros_raise_ValueError_if_macros_not_strings(widget, get_renderer, macros, raise_expected): ab = widgets.ActionButton(0, 0, 0, 0, 'dummy') ab.add_open_opi('file/path', mode=42, macros=macros) widget.add_child(ab) renderer = get_renderer(widget) if raise_expected: with pytest.raises(ValueError): renderer.assemble() else: renderer.assemble()
def test_ActionButton_adds_open_opi_action(widget, get_renderer): ab = widgets.ActionButton(0, 0, 0, 0, 'dummy') widget.add_child(ab) ab.add_open_opi('file/path', mode=42) renderer = get_renderer(widget) renderer.assemble() action_nodes = renderer.get_node().findall('./widget/actions/action') assert len(action_nodes) == 1 assert action_nodes[0].get('type') == 'OPEN_DISPLAY' assert action_nodes[0].find('./path').text == 'file/path' assert action_nodes[0].find('./mode').text == '42'
def test_ActionButton_adds_write_pv(widget, get_renderer): ab = widgets.ActionButton(0, 0, 0, 0, 'dummy') widget.add_child(ab) ab.add_write_pv('hello', 'bye') renderer = get_renderer(widget) renderer.assemble() action_nodes = renderer.get_node().findall('./widget/actions/action') assert len(action_nodes) == 1 assert action_nodes[0].get('type') == 'WRITE_PV' assert action_nodes[0].find('./pv_name').text == 'hello' assert action_nodes[0].find('./value').text == 'bye'
def test_ActionButton_adds_open_opi_action_with_macros(widget, get_renderer, macros, parent_macros): ab = widgets.ActionButton(0, 0, 0, 0, 'dummy') ab.add_open_opi('file/path', mode=42, macros=macros, parent_macros=parent_macros) widget.add_child(ab) renderer = get_renderer(widget) renderer.assemble() macros_node = renderer.get_node().findall('./widget/actions/action/macros')[0] parent_macros_expected = 'true' if parent_macros else 'false' assert macros_node.find('include_parent_macros').text == parent_macros_expected if macros: for m in macros: assert macros_node.find(m).text == macros[m]
def test_adding_action_n_times_results_in_n_actions(widget, get_renderer, n): ab = widgets.ActionButton(0, 0, 0, 0, 'dummy') command = actions.ExecuteCommand('ls', 'list directory') widget.add_child(ab) # Add the action n times. Note that adding the same action twice does # result in more than one action being included in the opi. for i in range(n): ab.add_action(command) renderer = get_renderer(widget) renderer.assemble() action_nodes = renderer.get_node().findall('./widget/actions/action') assert len(action_nodes) == n for i in range(n): assert action_nodes[i].find('./command').text == 'ls' assert action_nodes[i].find('./command_directory').text == '$(opi.dir)'
example_dir = os.path.dirname(os.path.realpath(__file__)) colors.parse_css_color_file(os.path.join(example_dir, 'color.def')) fonts.parse_css_font_file(os.path.join(example_dir, 'font.def')) # Create the root widget d = widgets.Display(100, 100) # Add a rectangle. w = widgets.Rectangle(0, 0, 10, 10) w.set_fg_color(colors.YELLOW_LED_OFF) d.add_child(w) # Add a grouping container. group = widgets.GroupingContainer(30, 30, 90, 90) # Add two action buttons to the grouping container. ab = widgets.ActionButton(30, 30, 30, 30, 'hello') ab.add_write_pv('hello', 'bye') group.add_child(ab) ab2 = widgets.ActionButton(60, 60, 60, 60, 'ls') ab2.add_shell_command('ls') group.add_child(ab2) # Add a rule to the grouping container. group.rules = [] group.rules.append( rules.GreaterThanRule('visible', 'SR-CS-FILL-01:COUNTDOWN', 300)) d.add_child(group) # Add a label with fonts and colour from the config files l = widgets.Label(100, 100, 200, 20, "test_label") l.set_font(fonts.FINE_PRINT)