예제 #1
0
    def _init_components(self):
        self._panes = PanedWindow(self, orient='horizontal', sashrelief="raised")
        self._panes.pack(expand=True, fill='both')

        self._left_pane = Frame(self._panes, padx=10, pady=5)
        self._right_pane = PanedWindow(self._panes)
        self._panes.add(self._left_pane, sticky='n')
        self._panes.add(self._right_pane)

        self._group_select = GroupSelect(self._left_pane)
        self._group_select.pack(expand=True, fill='x')

        # spacer
        Frame(self._left_pane, height=10).pack()

        graph_controls = LabelFrame(self._left_pane, text="Graph options", padx=10, pady=5)
        graph_controls.columnconfigure(1, weight=1)
        graph_controls.pack(expand=True, fill='x')

        self._show_graph_checkbutton = CheckBox(graph_controls, text='Show graph')
        self._show_graph_checkbutton.select()
        self._show_graph_checkbutton.grid(row=0, columnspan=2, sticky='w')

        Label(graph_controls, text='Algorithm').grid(row=1, sticky='w')
        self._graph_type = OptionList(graph_controls, values=MainWindow.GRAPH_TYPES.keys())
        self._graph_type.config(width=15)
        self._graph_type.grid(row=1, column=1, sticky='we')

        # spacer
        Frame(self._left_pane, height=10).pack()

        self._go_button = Button(self._left_pane, text='Go', command=self._go)
        self._go_button.pack()
예제 #2
0
    def _init_components(self):
        # group type selection (alternating, classical, sporadic, exceptional)
        group_type_frame = LabelFrame(self, text="Group type", padx=10, pady=5)
        group_type_frame.pack(expand=True, fill='x')

        # group type radio buttons (Alternating, Classical etc.)
        self._group_type = StringVar()
        self._type_radio_buttons = dict()
        for group_type in ("Alternating", "Classical", "Exceptional", "Sporadic"):
            radiobutton = Radiobutton(group_type_frame, variable=self._group_type, value=group_type, text=group_type)
            radiobutton.pack(anchor='nw')
            self._type_radio_buttons[group_type] = radiobutton

        # set group type selection handler
        self._group_type.trace("w", lambda n, i, m: self._group_type_selection())

        # spacer
        Frame(self, height=10).pack()

        # parameters for each group (degree for alternating, field and dimension for classical etc.)
        # notice that we do not pack LabelFrame contents. We do that in _group_type_selection method instead.
        group_params_frame = LabelFrame(self, text="Parameters", padx=10, pady=5)
        group_params_frame.pack(expand=True, fill='x')

        # alternating
        self._alt_params = Frame(group_params_frame)
        self._alt_params.columnconfigure(1, weight=1)
        Label(self._alt_params, text="Degree").grid(sticky='w')
        self._alt_degree = NumberBox(self._alt_params, constraints=Constraints(min=5))
        self._alt_degree.grid(row=0, column=1, sticky='we')

        # classical
        self._clas_params = Frame(group_params_frame)
        self._clas_params.columnconfigure(1, weight=1)

        Label(self._clas_params, text="Type").grid(row=0, sticky='w')
        self._clas_type = OptionList(self._clas_params, values=ClassicalGroup.types())
        self._clas_type.variable.trace("w", lambda n, i, m: self._classical_group_type_selection())
        self._clas_type.grid(row=0, column=1, sticky='we')

        Label(self._clas_params, text="Dimension").grid(row=1, sticky='w')
        self._clas_dim = NumberBox(self._clas_params)
        self._clas_dim.grid(row=1, column=1, sticky='we')

        Label(self._clas_params, text="Field order").grid(row=2, sticky='w')
        self._clas_field = NumberBox(self._clas_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._clas_field.grid(row=2, column=1, sticky='we')

        self._classical_group_type_selection()

        # exceptional
        self._ex_params = Frame(group_params_frame)
        self._ex_params.columnconfigure(1, weight=1)

        Label(self._ex_params, text="Type").grid(row=0, sticky='w')
        self._ex_type = OptionList(self._ex_params, values=ExceptionalGroup.types())
        self._ex_type.setvar(value=ExceptionalGroup.types()[0])
        self._ex_type.variable.trace("w", lambda n, i, m: self._exceptional_group_type_selection())
        self._ex_type.grid(row=0, column=1, sticky='we')

        Label(self._ex_params, text="Field order").grid(row=1, sticky='w')
        self._ex_field = NumberBox(self._ex_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._ex_field.grid(row=1, column=1, sticky='we')
        self._exceptional_group_type_selection()

        # sporadic
        self._spor_params = Frame(group_params_frame)
        self._spor_params.columnconfigure(1, weight=1)

        Label(self._spor_params, text="Group").grid(row=0, sticky='w')
        self._sporadic_group = OptionList(self._spor_params, values=SporadicGroup.all_groups())
        self._sporadic_group.grid(row=0, column=1, sticky='we')
예제 #3
0
class GroupSelect(Frame):
    """This is a widget with ability to choose specific group for further
    actions.
    """

    def __init__(self, parent=None, default_type="Classical", **kw):
        Frame.__init__(self, parent, **kw)
        self._parent = parent
        self._init_components()
        self._type_radio_buttons[default_type].select()

    def _init_components(self):
        # group type selection (alternating, classical, sporadic, exceptional)
        group_type_frame = LabelFrame(self, text="Group type", padx=10, pady=5)
        group_type_frame.pack(expand=True, fill='x')

        # group type radio buttons (Alternating, Classical etc.)
        self._group_type = StringVar()
        self._type_radio_buttons = dict()
        for group_type in ("Alternating", "Classical", "Exceptional", "Sporadic"):
            radiobutton = Radiobutton(group_type_frame, variable=self._group_type, value=group_type, text=group_type)
            radiobutton.pack(anchor='nw')
            self._type_radio_buttons[group_type] = radiobutton

        # set group type selection handler
        self._group_type.trace("w", lambda n, i, m: self._group_type_selection())

        # spacer
        Frame(self, height=10).pack()

        # parameters for each group (degree for alternating, field and dimension for classical etc.)
        # notice that we do not pack LabelFrame contents. We do that in _group_type_selection method instead.
        group_params_frame = LabelFrame(self, text="Parameters", padx=10, pady=5)
        group_params_frame.pack(expand=True, fill='x')

        # alternating
        self._alt_params = Frame(group_params_frame)
        self._alt_params.columnconfigure(1, weight=1)
        Label(self._alt_params, text="Degree").grid(sticky='w')
        self._alt_degree = NumberBox(self._alt_params, constraints=Constraints(min=5))
        self._alt_degree.grid(row=0, column=1, sticky='we')

        # classical
        self._clas_params = Frame(group_params_frame)
        self._clas_params.columnconfigure(1, weight=1)

        Label(self._clas_params, text="Type").grid(row=0, sticky='w')
        self._clas_type = OptionList(self._clas_params, values=ClassicalGroup.types())
        self._clas_type.variable.trace("w", lambda n, i, m: self._classical_group_type_selection())
        self._clas_type.grid(row=0, column=1, sticky='we')

        Label(self._clas_params, text="Dimension").grid(row=1, sticky='w')
        self._clas_dim = NumberBox(self._clas_params)
        self._clas_dim.grid(row=1, column=1, sticky='we')

        Label(self._clas_params, text="Field order").grid(row=2, sticky='w')
        self._clas_field = NumberBox(self._clas_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._clas_field.grid(row=2, column=1, sticky='we')

        self._classical_group_type_selection()

        # exceptional
        self._ex_params = Frame(group_params_frame)
        self._ex_params.columnconfigure(1, weight=1)

        Label(self._ex_params, text="Type").grid(row=0, sticky='w')
        self._ex_type = OptionList(self._ex_params, values=ExceptionalGroup.types())
        self._ex_type.setvar(value=ExceptionalGroup.types()[0])
        self._ex_type.variable.trace("w", lambda n, i, m: self._exceptional_group_type_selection())
        self._ex_type.grid(row=0, column=1, sticky='we')

        Label(self._ex_params, text="Field order").grid(row=1, sticky='w')
        self._ex_field = NumberBox(self._ex_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._ex_field.grid(row=1, column=1, sticky='we')
        self._exceptional_group_type_selection()

        # sporadic
        self._spor_params = Frame(group_params_frame)
        self._spor_params.columnconfigure(1, weight=1)

        Label(self._spor_params, text="Group").grid(row=0, sticky='w')
        self._sporadic_group = OptionList(self._spor_params, values=SporadicGroup.all_groups())
        self._sporadic_group.grid(row=0, column=1, sticky='we')

    @property
    def selected_group(self):
        """Returns currently selected group
        """
        if self._group_type.get() == "Alternating":
            self._alt_degree.refresh_input()
            return AlternatingGroup(self._alt_degree.get_number())
        if self._group_type.get() == "Classical":
            self._clas_dim.refresh_input()
            self._clas_field.refresh_input()
            return ClassicalGroup(self._clas_type.variable.get(),
                                  self._clas_dim.get_number(), self._clas_field.get_number())
        if self._group_type.get() == "Sporadic":
            return SporadicGroup(self._sporadic_group.variable.get())
        if self._group_type.get() == "Exceptional":
            self._ex_field.refresh_input()
            return ExceptionalGroup(self._ex_type.variable.get(), self._ex_field.get_number())

    def _group_type_selection(self):
        """Process the change of selected group type
        """

        def set_visible(widget, visible):
            if visible:
                widget.pack(expand=True, fill='both')
            else:
                widget.forget()

        group_type = self._group_type.get()
        set_visible(self._alt_params, group_type == "Alternating")
        set_visible(self._clas_params, group_type == "Classical")
        set_visible(self._spor_params, group_type == "Sporadic")
        set_visible(self._ex_params, group_type == "Exceptional")

    def _classical_group_type_selection(self):
        name = self._clas_type.variable.get()
        self._clas_dim.set_constraints(ClassicalGroup.dim_constraints(name))
        self._clas_field.set_constraints(ClassicalGroup.field_constraints(name))

    def _exceptional_group_type_selection(self):
        name = self._ex_type.variable.get()
        self._ex_field.set_constraints(ExceptionalGroup.field_constraints(name))
예제 #4
0
    def _init_components(self):
        # group type selection (alternating, classical, sporadic, exceptional)
        group_type_frame = LabelFrame(self, text="Group type")
        group_type_frame.pack(expand=True, fill="x", padx=10, pady=5)

        # group type radio buttons (Alternating, Classical etc.)
        self._group_type = StringVar()
        self._type_radio_buttons = dict()
        for type in ("Alternating", "Classical", "Exceptional", "Sporadic"):
            self._type_radio_buttons[type] = Radiobutton(
                group_type_frame, variable=self._group_type, value=type, text=type
            )
            self._type_radio_buttons[type].pack(anchor="nw", padx=10)

        # set group type selection handler
        self._group_type.trace("w", lambda n, i, m: self._group_type_selection())

        # parameters for each group (degree for alternating, field and
        # dimension for classical etc.
        group_params_frame = LabelFrame(self, text="Parameters")
        group_params_frame.pack(expand=True, fill="x", padx=10, pady=5)

        # alternating
        self._alt_params = Frame(group_params_frame)
        self._alt_params.columnconfigure(1, weight=1)
        Label(self._alt_params, text="Degree").grid(sticky="w")
        self._alt_degree = NumberBox(self._alt_params, constraints=Constraints(min=5))
        self._alt_degree.grid(row=0, column=1, sticky="we")

        # classical
        self._clas_params = Frame(group_params_frame)
        self._clas_params.columnconfigure(1, weight=1)
        Label(self._clas_params, text="Type").grid(row=0, sticky="w")
        self._clas_type = OptionList(self._clas_params, values=ClassicalGroup.types())

        self._clas_type.variable.trace("w", lambda n, i, m: self._classical_group_type_selection())

        self._clas_type.grid(row=0, column=1, sticky="we")

        Label(self._clas_params, text="Dimension").grid(row=1, sticky="w")
        self._clas_dim = NumberBox(self._clas_params)
        self._clas_dim.grid(row=1, column=1, sticky="we")
        Label(self._clas_params, text="Field order").grid(row=2, sticky="w")
        self._clas_field = NumberBox(self._clas_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._clas_field.grid(row=2, column=1, sticky="we")

        self._classical_group_type_selection()

        # exceptional
        self._ex_params = Frame(group_params_frame)
        self._ex_params.columnconfigure(1, weight=1)
        Label(self._ex_params, text="Type").grid(row=0, sticky="w")
        self._ex_type = OptionList(self._ex_params, values=ExceptionalGroup.types())
        self._ex_type.setvar(value=ExceptionalGroup.types()[0])
        self._ex_type.grid(row=0, column=1, sticky="we")
        Label(self._ex_params, text="Field order").grid(row=1, sticky="w")
        self._ex_field = NumberBox(self._ex_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._ex_field.grid(row=1, column=1, sticky="we")

        # sporadic
        self._spor_params = Frame(group_params_frame)
        self._spor_params.columnconfigure(1, weight=1)
        Label(self._spor_params, text="Group").grid(row=0, sticky="w")
        self._sporadic_group = OptionList(self._spor_params, values=SporadicGroup.all_groups())
        self._sporadic_group.grid(row=0, column=1, sticky="we")

        # pack params frames
        for child_frame in group_params_frame.winfo_children():
            child_frame.pack(expand=True, fill="x", padx=10)
예제 #5
0
class GroupSelect(Frame):
    """This is a widget with ability to choose specific group for further
    actions.
    """

    def __init__(self, parent=None, default_type="Classical", **kw):
        Frame.__init__(self, parent, **kw)
        self._parent = parent
        self._init_components()
        self._type_radio_buttons[default_type].select()

    def _init_components(self):
        # group type selection (alternating, classical, sporadic, exceptional)
        group_type_frame = LabelFrame(self, text="Group type")
        group_type_frame.pack(expand=True, fill="x", padx=10, pady=5)

        # group type radio buttons (Alternating, Classical etc.)
        self._group_type = StringVar()
        self._type_radio_buttons = dict()
        for type in ("Alternating", "Classical", "Exceptional", "Sporadic"):
            self._type_radio_buttons[type] = Radiobutton(
                group_type_frame, variable=self._group_type, value=type, text=type
            )
            self._type_radio_buttons[type].pack(anchor="nw", padx=10)

        # set group type selection handler
        self._group_type.trace("w", lambda n, i, m: self._group_type_selection())

        # parameters for each group (degree for alternating, field and
        # dimension for classical etc.
        group_params_frame = LabelFrame(self, text="Parameters")
        group_params_frame.pack(expand=True, fill="x", padx=10, pady=5)

        # alternating
        self._alt_params = Frame(group_params_frame)
        self._alt_params.columnconfigure(1, weight=1)
        Label(self._alt_params, text="Degree").grid(sticky="w")
        self._alt_degree = NumberBox(self._alt_params, constraints=Constraints(min=5))
        self._alt_degree.grid(row=0, column=1, sticky="we")

        # classical
        self._clas_params = Frame(group_params_frame)
        self._clas_params.columnconfigure(1, weight=1)
        Label(self._clas_params, text="Type").grid(row=0, sticky="w")
        self._clas_type = OptionList(self._clas_params, values=ClassicalGroup.types())

        self._clas_type.variable.trace("w", lambda n, i, m: self._classical_group_type_selection())

        self._clas_type.grid(row=0, column=1, sticky="we")

        Label(self._clas_params, text="Dimension").grid(row=1, sticky="w")
        self._clas_dim = NumberBox(self._clas_params)
        self._clas_dim.grid(row=1, column=1, sticky="we")
        Label(self._clas_params, text="Field order").grid(row=2, sticky="w")
        self._clas_field = NumberBox(self._clas_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._clas_field.grid(row=2, column=1, sticky="we")

        self._classical_group_type_selection()

        # exceptional
        self._ex_params = Frame(group_params_frame)
        self._ex_params.columnconfigure(1, weight=1)
        Label(self._ex_params, text="Type").grid(row=0, sticky="w")
        self._ex_type = OptionList(self._ex_params, values=ExceptionalGroup.types())
        self._ex_type.setvar(value=ExceptionalGroup.types()[0])
        self._ex_type.grid(row=0, column=1, sticky="we")
        Label(self._ex_params, text="Field order").grid(row=1, sticky="w")
        self._ex_field = NumberBox(self._ex_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._ex_field.grid(row=1, column=1, sticky="we")

        # sporadic
        self._spor_params = Frame(group_params_frame)
        self._spor_params.columnconfigure(1, weight=1)
        Label(self._spor_params, text="Group").grid(row=0, sticky="w")
        self._sporadic_group = OptionList(self._spor_params, values=SporadicGroup.all_groups())
        self._sporadic_group.grid(row=0, column=1, sticky="we")

        # pack params frames
        for child_frame in group_params_frame.winfo_children():
            child_frame.pack(expand=True, fill="x", padx=10)

    @property
    def selected_group(self):
        """Returns currently selected group
        """
        if self._group_type.get() == "Alternating":
            self._alt_degree.refresh_input()
            return AlternatingGroup(int(self._alt_degree.get()))
        if self._group_type.get() == "Classical":
            self._clas_dim.refresh_input()
            self._clas_field.refresh_input()
            return ClassicalGroup(
                self._clas_type.variable.get(), int(self._clas_dim.get()), int(self._clas_field.get())
            )
        if self._group_type.get() == "Sporadic":
            return SporadicGroup(self._sporadic_group.variable.get())
        if self._group_type.get() == "Exceptional":
            self._ex_field.refresh_input()
            return ExceptionalGroup(self._ex_type.variable.get(), int(self._ex_field.get()))

    def _group_type_selection(self):
        """Process the change of selected group type
        """

        def set_visible(widget, visible):
            if visible:
                widget.pack(expand=True, fill="both", padx=10, anchor="nw")
            else:
                widget.forget()

        type = self._group_type.get()
        set_visible(self._alt_params, type == "Alternating")
        set_visible(self._clas_params, type == "Classical")
        set_visible(self._spor_params, type == "Sporadic")
        set_visible(self._ex_params, type == "Exceptional")

    def _classical_group_type_selection(self):
        name = self._clas_type.variable.get()
        self._clas_dim.set_constraints(ClassicalGroup.dim_constraints(name))
        self._clas_field.set_constraints(ClassicalGroup.field_constraints(name))
예제 #6
0
class MainWindow(Frame):
    GRAPH_TYPES = OrderedDict([("Prime Graph", graphs.PrimeGraph),
                               ("Fast Graph", graphs.FastGraph)])

    def __init__(self, **kw):
        Frame.__init__(self, **kw)
        self.winfo_toplevel().minsize(width=600, height=400)
        width = min(self.winfo_screenwidth(), 1280)
        height = min(self.winfo_screenheight(), 720)
        self.winfo_toplevel().geometry("{}x{}".format(width, height))
        self.pack(expand=True, fill='both')
        self._init_variables()
        self._init_components()
        self._init_menu()

    def _init_components(self):
        self._panes = PanedWindow(self,
                                  orient='horizontal',
                                  sashrelief="raised")
        self._panes.pack(expand=True, fill='both')

        self._left_pane = Frame(self._panes, padx=10, pady=5)
        self._right_pane = PanedWindow(self._panes)
        self._panes.add(self._left_pane, sticky='n')
        self._panes.add(self._right_pane)

        self._group_select = GroupSelect(self._left_pane)
        self._group_select.pack(expand=True, fill='x')

        # spacer
        Frame(self._left_pane, height=10).pack()

        graph_controls = LabelFrame(self._left_pane,
                                    text="Graph options",
                                    padx=10,
                                    pady=5)
        graph_controls.columnconfigure(1, weight=1)
        graph_controls.pack(expand=True, fill='x')

        self._show_graph_checkbutton = CheckBox(graph_controls,
                                                text='Show graph')
        self._show_graph_checkbutton.select()
        self._show_graph_checkbutton.grid(row=0, columnspan=2, sticky='w')

        Label(graph_controls, text='Algorithm').grid(row=1, sticky='w')
        self._graph_type = OptionList(graph_controls,
                                      values=tuple(
                                          MainWindow.GRAPH_TYPES.keys()))
        self._graph_type.config(width=15)
        self._graph_type.grid(row=1, column=1, sticky='we')

        # spacer
        Frame(self._left_pane, height=10).pack()

        self._go_button = Button(self._left_pane, text='Go', command=self._go)
        self._go_button.pack()

    def _init_variables(self):
        # init default properties
        self.setvar("graphframeview", "onlyone")
        self.setvar("vertexlabelposition", "auto")

    def _init_menu(self):
        toplevel = self.winfo_toplevel()
        self._menu = Menu(toplevel)
        toplevel['menu'] = self._menu

        view = Menu(self._menu, tearoff=0)
        self._menu.add_cascade(label="View", menu=view)

        graph_view = Menu(view, tearoff=0)
        view.add_cascade(label="View graphs", menu=graph_view)

        graph_view.add_radiobutton(variable="graphframeview",
                                   label="Only one",
                                   value="onlyone")
        #        graph_view.add_radiobutton(label="In a row", value="row",
        #            variable=graph_view_var)
        graph_view.add_radiobutton(variable="graphframeview",
                                   label="In separate window",
                                   value="window")

    def _go(self):
        view = self.getvar("graphframeview")

        if view == "onlyone":
            for child in self._right_pane.winfo_children():
                child.destroy()
                #if view in ("onlyone", "row"):
            container = FrameWithCloseButton(self._right_pane)
            self._right_pane.add(container, minsize=600)
        else:
            container = Toplevel()

        graph_class = MainWindow.GRAPH_TYPES[self._graph_type.variable.get()]

        facade = Facade(container,
                        self._group_select.selected_group,
                        show_graph=self._show_graph_checkbutton.is_selected(),
                        graph_class=graph_class)

        facade.pack(expand=True, fill='both')
예제 #7
0
    def _init_components(self):
        # group type selection (alternating, classical, sporadic, exceptional)
        group_type_frame = LabelFrame(self, text="Group type", padx=10, pady=5)
        group_type_frame.pack(expand=True, fill='x')

        # group type radio buttons (Alternating, Classical etc.)
        self._group_type = StringVar()
        self._type_radio_buttons = dict()
        for group_type in ("Alternating", "Classical", "Exceptional", "Sporadic"):
            radiobutton = Radiobutton(group_type_frame, variable=self._group_type, value=group_type, text=group_type)
            radiobutton.pack(anchor='nw')
            self._type_radio_buttons[group_type] = radiobutton

        # set group type selection handler
        self._group_type.trace("w", lambda n, i, m: self._group_type_selection())

        # spacer
        Frame(self, height=10).pack()

        # parameters for each group (degree for alternating, field and dimension for classical etc.)
        # notice that we do not pack LabelFrame contents. We do that in _group_type_selection method instead.
        group_params_frame = LabelFrame(self, text="Parameters", padx=10, pady=5)
        group_params_frame.pack(expand=True, fill='x')

        # alternating
        self._alt_params = Frame(group_params_frame)
        self._alt_params.columnconfigure(1, weight=1)
        Label(self._alt_params, text="Degree").grid(sticky='w')
        self._alt_degree = NumberBox(self._alt_params, constraints=Constraints(min=5))
        self._alt_degree.grid(row=0, column=1, sticky='we')

        # classical
        self._clas_params = Frame(group_params_frame)
        self._clas_params.columnconfigure(1, weight=1)

        Label(self._clas_params, text="Type").grid(row=0, sticky='w')
        self._clas_type = OptionList(self._clas_params, values=ClassicalGroup.types())
        self._clas_type.variable.trace("w", lambda n, i, m: self._classical_group_type_selection())
        self._clas_type.grid(row=0, column=1, sticky='we')

        Label(self._clas_params, text="Dimension").grid(row=1, sticky='w')
        self._clas_dim = NumberBox(self._clas_params)
        self._clas_dim.grid(row=1, column=1, sticky='we')

        Label(self._clas_params, text="Field order").grid(row=2, sticky='w')
        self._clas_field = NumberBox(self._clas_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._clas_field.grid(row=2, column=1, sticky='we')

        self._classical_group_type_selection()

        # exceptional
        self._ex_params = Frame(group_params_frame)
        self._ex_params.columnconfigure(1, weight=1)

        Label(self._ex_params, text="Type").grid(row=0, sticky='w')
        self._ex_type = OptionList(self._ex_params, values=ExceptionalGroup.types())
        self._ex_type.setvar(value=ExceptionalGroup.types()[0])
        self._ex_type.grid(row=0, column=1, sticky='we')

        Label(self._ex_params, text="Field order").grid(row=1, sticky='w')
        self._ex_field = NumberBox(self._ex_params, constraints=Constraints(primality=numeric.PRIME_POWER))
        self._ex_field.grid(row=1, column=1, sticky='we')

        # sporadic
        self._spor_params = Frame(group_params_frame)
        self._spor_params.columnconfigure(1, weight=1)

        Label(self._spor_params, text="Group").grid(row=0, sticky='w')
        self._sporadic_group = OptionList(self._spor_params, values=SporadicGroup.all_groups())
        self._sporadic_group.grid(row=0, column=1, sticky='we')
예제 #8
0
class MainWindow(Frame):
    GRAPH_TYPES = OrderedDict([
        ("Prime Graph", graphs.PrimeGraph),
        ("Fast Graph", graphs.FastGraph)
    ])

    def __init__(self, **kw):
        Frame.__init__(self, **kw)
        self.winfo_toplevel().minsize(width=600, height=400)
        width = min(self.winfo_screenwidth(), 1280)
        height = min(self.winfo_screenheight(), 720)
        self.winfo_toplevel().geometry("{}x{}".format(width, height))
        self.pack(expand=True, fill='both')
        self._init_variables()
        self._init_components()
        self._init_menu()

    def _init_components(self):
        self._panes = PanedWindow(self, orient='horizontal', sashrelief="raised")
        self._panes.pack(expand=True, fill='both')

        self._left_pane = Frame(self._panes, padx=10, pady=5)
        self._right_pane = PanedWindow(self._panes)
        self._panes.add(self._left_pane, sticky='n')
        self._panes.add(self._right_pane)

        self._group_select = GroupSelect(self._left_pane)
        self._group_select.pack(expand=True, fill='x')

        # spacer
        Frame(self._left_pane, height=10).pack()

        graph_controls = LabelFrame(self._left_pane, text="Graph options", padx=10, pady=5)
        graph_controls.columnconfigure(1, weight=1)
        graph_controls.pack(expand=True, fill='x')

        self._show_graph_checkbutton = CheckBox(graph_controls, text='Show graph')
        self._show_graph_checkbutton.select()
        self._show_graph_checkbutton.grid(row=0, columnspan=2, sticky='w')

        Label(graph_controls, text='Algorithm').grid(row=1, sticky='w')
        self._graph_type = OptionList(graph_controls, values=MainWindow.GRAPH_TYPES.keys())
        self._graph_type.config(width=15)
        self._graph_type.grid(row=1, column=1, sticky='we')

        # spacer
        Frame(self._left_pane, height=10).pack()

        self._go_button = Button(self._left_pane, text='Go', command=self._go)
        self._go_button.pack()

    def _init_variables(self):
        # init default properties
        self.setvar("graphframeview", "onlyone")
        self.setvar("vertexlabelposition", "auto")

    def _init_menu(self):
        toplevel = self.winfo_toplevel()
        self._menu = Menu(toplevel)
        toplevel['menu'] = self._menu

        view = Menu(self._menu, tearoff=0)
        self._menu.add_cascade(label="View", menu=view)

        graph_view = Menu(view, tearoff=0)
        view.add_cascade(label="View graphs", menu=graph_view)

        graph_view.add_radiobutton(variable="graphframeview", label="Only one", value="onlyone")
        #        graph_view.add_radiobutton(label="In a row", value="row",
        #            variable=graph_view_var)
        graph_view.add_radiobutton(variable="graphframeview", label="In separate window", value="window")

    def _go(self):
        view = self.getvar("graphframeview")

        if view == "onlyone":
            for child in self._right_pane.winfo_children():
                child.destroy()
                #if view in ("onlyone", "row"):
            container = FrameWithCloseButton(self._right_pane)
            self._right_pane.add(container, minsize=600)
        else:
            container = Toplevel()

        graph_class = MainWindow.GRAPH_TYPES[self._graph_type.variable.get()]

        facade = Facade(container, self._group_select.selected_group,
                        show_graph=self._show_graph_checkbutton.is_selected(),
                        graph_class=graph_class)

        facade.pack(expand=True, fill='both')