Exemplo n.º 1
0
def test_hierarchical_typed_keys(dict_model_3):
    view = mock.Mock()
    cont = hier.Hierarchical(dict_model_3, view)
    view.reset_mock()
    cont.new_selection(0, 1)
    assert view.set_choices.call_args_list == [
        mock.call(1, [2, 3]), mock.call(2, [3, 4])
    ]
    assert view.set_selection.call_args_list == [
        mock.call(1, 2), mock.call(2, 3)
    ]
    assert tuple(dict_model_3.current_selection) == (1, 2, 3)
    assert dict_model_3.current_item == 5

    view.reset_mock()
    cont.new_selection(1, 3)
    assert view.set_choices.call_args_list == [mock.call(2, [2])]
    assert view.set_selection.call_args_list == [mock.call(2, 2)]
    assert tuple(dict_model_3.current_selection) == (1, 3, 2)
    assert dict_model_3.current_item == 8

    view.reset_mock()
    cont.callback = mock.Mock()
    cont.new_selection(0, 2)
    assert view.set_choices.call_args_list == [
        mock.call(1, [1]), mock.call(2, [1])
    ]
    assert view.set_selection.call_args_list == [
        mock.call(1, 1), mock.call(2, 1)
    ]
    assert tuple(dict_model_3.current_selection) == (2, 1, 1)
    assert dict_model_3.current_item == 9
    assert cont.callback.called
Exemplo n.º 2
0
 def __init__(self, parent, result, main_model):
     self._logger = logging.getLogger(__name__)
     self.model = BrowseAnalysisModel(result, main_model)
     self._current_adjust_task = None
     self.view = browse_analysis_view.BrowseAnalysisView(parent, self)
     self._prediction_hierarchy = hierarchical.Hierarchical(
         self.model.prediction_hierarchy, view=self.view.hierarchical_view)
     self._prediction_hierarchy.callback = self._update_plot
     self._update_plot()
Exemplo n.º 3
0
def test_hierarchical_init(dict_model_1):
    view = mock.Mock()
    cont = hier.Hierarchical(dict_model_1, view)
    assert view.set_choices.call_args_list == [
        mock.call(0, [1]),
        mock.call(1, [2]),
        mock.call(2, [3, 4])
    ]
    assert view.set_selection.call_args_list == [
        mock.call(0, 1), mock.call(1, 2),
        mock.call(2, 3)
    ]
    assert dict_model_1.current_selection == (1, 2, 3)
    assert dict_model_1.current_item == 5
Exemplo n.º 4
0
import open_cp.gui.hierarchical as hierarchical

model = hierarchical.DictionaryModel({
    (1, 2, 3): "123",
    (1, 2, 4): "124",
    (1, 3, 1): "131",
    (1, 4, 2): "142",
    (1, 4, 4): "144"
})

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()
hier = hierarchical.Hierarchical(model, parent=root)

for i in range(3):
    ttk.Label(root, text="Choice {}:".format(i + 1)).grid(row=i, column=0)
    hier.view.frames[i].grid(row=i, column=1)

ttk.Label(root, text="Data:").grid(row=100, column=0)
label = ttk.Label(root, )
label.grid(row=100, column=1)


def update():
    label["text"] = model.current_item


hier.callback = update