Beispiel #1
0
 def set_step_buttons(self):
     button_image = games.load_image("images/button.png")
     self.forward_button = games.Sprite(image = button_image, x = 680,
                                        y = 300, is_collideable = False)
     self.backward_button = games.Sprite(image = button_image, x = 530,
                                         y = 300)
     self.forward_text = MT.MyText('Forward', 20, color.black, 680, 300)
     self.backward_text = MT.MyText('Backward', 20, color.black, 530, 300)
     games.screen.add(self.forward_button)
     games.screen.add(self.backward_button)
     games.screen.add(self.forward_text)
     games.screen.add(self.backward_text)
Beispiel #2
0
 def prepare_operations(self, return_state):
     self.reset_text('')
     self.clear_buttons()
     button_image = games.load_image("images/button.png")
     hovered_image = games.load_image("images/hovered-button.png")
     self.set_back_button(button_image, hovered_image, return_state)
     left_start = 270 - 60 * int((self.left_size - 1) / 2)
     right_start = 270 - 60 * int((self.right_size - 1) / 2)
     for i in range(self.left_size):
         self.text_list.append(MT.MyText(str(i), 30, color.black, 30,
                                         left_start + 60 * i))
     for i in range(self.right_size):
         self.text_list.append(MT.MyText(str(i), 30, color.black, 430,
                                         right_start + 60 * i))
     self.render_buttons()
Beispiel #3
0
 def reset_text(self, new_text):
     if (self.main_text_sprite):
         self.main_text_sprite.set_value(new_text)
     else:
         self.main_text_sprite = MT.MyText(new_text, 30, color.black, 600,
                                           30)
         games.screen.add(self.main_text_sprite)
Beispiel #4
0
    def __init__(self, disp, title="Empire output", width=None):
        empParse.baseDisp.__init__(self, disp)

        # Create root window
        self.Root = Tkinter.Toplevel(class_="Output")
        self.Root.title(title)
        self.Root.iconname(title)

        title = string.lower(string.split(title, None, 1)[0])
        # Create text box and scrollbar
        scrollY = Tkinter.Scrollbar(self.Root, name="scrollY")
        scrollY.pack(side='right', fill='y')
        self.Text = MyText.MyText(self.Root,
                                  name=title,
                                  setgrid=1,
                                  yscrollcommand=scrollY.set)
        self.Text.setEditable(0)
        self.Text.pack(side='left', expand=1, fill='both')
        scrollY['command'] = self.Text.yview

        # Forward key events to main window.
        viewer.transferKeys(self.Root)

        # Allow configurable width
        if width is not None:
            self.Text['width'] = width

        self.Text.bind('<Button-3>', viewer.DoLocateSector)
        self.Root.protocol('WM_DELETE_WINDOW', self.goAway)
Beispiel #5
0
 def random_operations_query(self):
     if (self.state == 3):
         self.set_random_edges()
     self.state = 6
     self.reset_text('Choose Procedure For')
     self.has_generated_matching = False
     self.clear_buttons()
     self.remove_option_buttons()
     self.remove_step_text()
     self.unselect_all()
     self.unselect_all_edges()
     # add additional line of prompt text
     self.text_list.append(MT.MyText('Maximal Matching (MM).', 30,
                                     color.black, 600, 60))
     button_image = games.load_image("images/button.png")
     hovered_image = games.load_image("images/hovered-button.png")
     long_button_image = games.load_image("images/long-button.png")
     hovered_long_image = games.load_image("images/hovered-long-button.png")
     self.button_list.append(NB.NavigationButton(self, long_button_image,
                                                 hovered_long_image, 600,
                                                 150, 2, 8))
     self.text_list.append(MT.MyText('Find MM Manually', 20, color.black,
                                     600, 150))
     self.button_list.append(NB.NavigationButton(self, long_button_image,
                                                 hovered_long_image, 600,
                                                 240, 1, 12))
     self.text_list.append(MT.MyText('Automatically Find MM', 20,
                                     color.black, 600, 240))
     self.button_list.append(NB.NavigationButton(self, long_button_image,
                                                 hovered_long_image, 600,
                                                 330, 3, 13))
     self.text_list.append(MT.MyText('Watch Algorithm To Find MM', 20,
                                     color.black, 600, 330))
     self.button_list.append(NB.NavigationButton(self, long_button_image,
                                                 hovered_long_image, 600,
                                                 420, 4, 14))
     self.text_list.append(MT.MyText('Watch Algorithm To Find MM With Steps',
                                     20, color.black, 600, 420))
     self.set_back_button(button_image, hovered_image, 3)
     self.render_buttons()
     if (self.has_congratulation):
         self.remove_congratulation()
     self.matching_list = []
Beispiel #6
0
 def set_edge_choice_query(self, data):
     self.state = 3
     self.reset_text('How do you want to choose edges?')
     self.clear_buttons()
     button_image = games.load_image("images/button.png")
     hovered_image = games.load_image("images/hovered-button.png")
     self.button_list.append(NB.NavigationButton(self, button_image,
                                                 hovered_image, 600, 150, 5,
                                                 4))
     self.text_list.append(MT.MyText('Manually', 20, color.black, 600, 150))
     self.button_list.append(NB.NavigationButton(self, button_image,
                                                 hovered_image, 600, 240, 6,
                                                 6))
     self.text_list.append(MT.MyText('Randomly', 20, color.black, 600, 240))
     self.set_back_button(button_image, hovered_image, 2)
     self.render_buttons()
     if not (data == -1):
         self.set_branch_bipartite(data, 'right')
     # unselect any selected vertices
     self.unselect_all()
Beispiel #7
0
 def set_number_buttons(self, image, hovered_image, to_state):
     for i in range(5):
         for j in range(2):
             self.button_list.append(NB.NavigationButton(self, image,
                                                         hovered_image,
                                                         550 + 150 * j,
                                                         90 + 55 * i,
                                                         2*i + j + 1,
                                                         to_state))
             self.text_list.append(MT.MyText(str(2*i + j + 1), 20,
                                             color.black, 550 + 150 * j,
                                             90 + 55 * i))
Beispiel #8
0
 def set_manual_edge_choice_query(self):
     if (self.state == 3):
         self.delete_all_edges()
         self.reset_branches_data(self.left_size, self.right_size)
     self.state = 4
     self.has_generated_matching = False
     self.reset_text('Make your edge choices on the graph.')
     if (self.state == 4):
         self.main_text_sprite.set_x(620)
     self.clear_buttons()
     button_image = games.load_image("images/button.png")
     hovered_image = games.load_image("images/hovered-button.png")
     self.button_list.append(NB.NavigationButton(self, button_image,
                                                 hovered_image, 600, 150, 7,
                                                 5))
     self.text_list.append(MT.MyText('Done', 20, color.black, 600, 150))
     self.set_back_button(button_image, hovered_image, 3)
     self.render_buttons()
Beispiel #9
0
    def __init__(self):
        title = "Empire Correspondence"
        # Create root window
        self.Root = Tkinter.Toplevel(name="telegram")
        self.Root.withdraw()
        self.Root.title(title)
        self.Root.iconname(title)

        # Forward key events to main window.
        viewer.transferKeys(self.Root)

        # TCL variables
        self.type = Tkinter.StringVar()
        self.type.set('telegrams')

        # Create options bar
        oframe = Tkinter.Frame(self.Root, name="oframe")
        oframe.pack(side='bottom', fill='x', expand=1)
        orframe = Tkinter.Frame(oframe, name="orframe")
        orframe.pack(side='left', fill='y', expand=1)
        self.AnnoB = Tkinter.Radiobutton(orframe,
                                         name="anno",
                                         text="Announcements",
                                         anchor='w',
                                         variable=self.type,
                                         value='announcements',
                                         command=self.redraw)
        self.AnnoB.pack(fill='both', expand=1)
        self.TeleB = Tkinter.Radiobutton(orframe,
                                         name="tele",
                                         text="Telegrams",
                                         anchor='w',
                                         variable=self.type,
                                         value='telegrams',
                                         command=self.redraw)
        self.TeleB.pack(fill='both', expand=1)
        self.SendB = Tkinter.Button(oframe,
                                    name="send",
                                    text="Send",
                                    command=self.DoSend)
        self.SendB.pack(side='left', fill='y', expand=1)
        self.AbortB = Tkinter.Button(oframe,
                                     name="abort",
                                     text="Abort",
                                     command=self.DoAbort,
                                     state='disabled')
        self.AbortB.pack(side='left', fill='y', expand=1)
        self.ReplyB = Tkinter.Button(oframe,
                                     name="reply",
                                     text="Reply",
                                     command=self.DoReply)
        self.ReplyB.pack(side='left', fill='y', expand=1)
        self.RemoveB = Tkinter.Button(oframe,
                                      name="delete",
                                      text="Delete",
                                      command=self.DoRemove)
        self.RemoveB.pack(side='left', fill='y', expand=1)

        # Create search box
        self.SearchMsg = Tkinter.StringVar()
        self.StringRE = Tkinter.StringVar()
        self.TypeRE = Tkinter.IntVar()
        self.TypeRE.set(0)
        sframe = Tkinter.Frame(self.Root, name="sframe")
        sframe.pack(side='top', fill='both', expand=1)
        srframe = Tkinter.Frame(sframe, name="srframe")
        srframe.pack(side='right')
        hsearch = Tkinter.Radiobutton(srframe,
                                      name="headerSearch",
                                      text="Header Search",
                                      anchor='w',
                                      variable=self.TypeRE,
                                      value=0)
        hsearch.pack(fill='both', expand=1)
        viewer.Balloon.bind(hsearch,
                            "Search only the first\n" + "line of text")
        fsearch = Tkinter.Radiobutton(srframe,
                                      name="fullSearch",
                                      text="Full Search",
                                      anchor='w',
                                      variable=self.TypeRE,
                                      value=1)
        fsearch.pack(fill='both', expand=1)
        viewer.Balloon.bind(fsearch, "Search the entire message")
        listall = Tkinter.Button(sframe,
                                 name="listAll",
                                 command=self.DoListAll,
                                 text="List All")
        listall.pack(side='right')
        viewer.Balloon.bind(listall, "Undo a previous search")
        search = Tkinter.Button(sframe,
                                name="search",
                                command=self.DoSearch,
                                text="Search")
        search.pack(side='right')
        viewer.Balloon.bind(search, "Search for string")
        Tkinter.Label(sframe,
                      name="slabel",
                      textvariable=self.SearchMsg,
                      anchor='sw').pack(side='top', fill='x', expand=1)
        searchRE = Tkinter.Entry(sframe,
                                 name="regexp",
                                 textvariable=self.StringRE)
        searchRE.pack(side='top', fill='x', expand=1)
        viewer.Balloon.bind(searchRE, "Click to enter a search string")

        # Create list box
        lframe = Tkinter.Frame(self.Root, name="lframe")
        lframe.pack(side='top', fill='both', expand=1)
        scrollY = Tkinter.Scrollbar(lframe, name="scrollY")
        scrollY.pack(side='right', fill='y')
        self.List = Tk_List.MyListbox(lframe,
                                      name="list",
                                      height=8,
                                      selectmode='extended',
                                      command=self.SetMsg,
                                      yscrollcommand=scrollY.set)
        self.List.pack(side='left', fill='both', expand=1)
        scrollY['command'] = self.List.yview

        # Create text box and scrollbar
        scrollY = Tkinter.Scrollbar(self.Root, name="scrollY")
        scrollY.pack(side='right', anchor='e', fill='y')
        self.Text = MyText.MyText(self.Root,
                                  name="text",
                                  yscrollcommand=scrollY.set)
        self.Text.setEditable(0)
        self.Text.pack(side='left', anchor='w', expand=1, fill='both')
        scrollY['command'] = self.Text.yview
        self.Text.bind('<Button-3>', viewer.DoLocateSector)

        # Draw
        self.DoListAll()

        # Create a special country input box
        self.CInput = Pmw.ComboBoxDialog(viewer.Root,
                                         title="Country Selection",
                                         buttons=("OK", "Cancel"),
                                         defaultbutton="OK",
                                         combobox_labelpos='n',
                                         label_text="Select Country:")
        self.CInput.withdraw()

        # Register automatic updating
        viewer.updateList.append(self)
        self.Root.protocol('WM_DELETE_WINDOW', self.handleDelete)
    def __init__(self, responder, steps):
        self.responder = responder
        self.steps = steps
        self.left_size = responder.left_size
        self.right_size = responder.right_size
        self.left_neighbors = responder.left_neighbors
        image = games.load_image('images/phantom-pizza.bmp')
        super(AlgorithmDisplay, self).__init__(image=image,
                                               x=0,
                                               y=0,
                                               is_collideable=False)
        self.is_counting = False
        self.ticker = 0
        self.ticker_adder = 1
        self.button_click = False
        self.backward_ticker = 0  # time to delay for re-push of backward button
        self.forward_ticker = 0  # time to delay for re-push of forward button
        self.forward_hover = False  # whether forward button is hovered
        self.backward_hover = False  # whether backward button is hovered
        self.button_ticker = 0
        self.forward_click = True  # whether forward button can be clicked
        self.backward_click = True  # whether backward button can be clicked
        self.has_highlighted_edge = False  # whether an edge is being examined
        self.highlighted_edge = None  # currently examined edge
        self.matching = []
        self.title_text = MT.MyText(
            new_value='First find a matching greedily.',
            new_size=30,
            new_color=color.black,
            new_x=630,
            new_y=50)
        games.screen.add(self.title_text)
        self.statement_text_A = MT.MyText(new_value='',
                                          new_size=30,
                                          new_color=color.black,
                                          new_x=600,
                                          new_y=150)
        self.statement_text_B = MT.MyText(new_value='',
                                          new_size=30,
                                          new_color=color.black,
                                          new_x=600,
                                          new_y=180)
        self.statement_text_C = MT.MyText(new_value='',
                                          new_size=30,
                                          new_color=color.black,
                                          new_x=600,
                                          new_y=210)
        games.screen.add(self.statement_text_A)
        games.screen.add(self.statement_text_B)
        games.screen.add(self.statement_text_C)

        # state of algorithm: 1, 2, 3, or 4 (see meanings below)
        self.state = 1
        self.U = []  # list of left int vertices that are unmatched
        self.W = []  # list of right int vertices that are unmatched
        self.S = []  # list of reachable int vertices in left branch
        self.left_unmatched = []  # list of unmatched left vertex objects
        self.right_unmatched = []  # list of unmatched right vertex objects
        self.reachables = []  # list of reachable left vertex objects
        self.queue = [
        ]  # queue of vertex numbers to attempt to increase S from
        self.paths = []  # numerical lists of paths to vertices in S from U
        self.found_addition = 0
        self.left_index = 0
        self.right_index = 0
        self.edge_list = []  # list of edges to be highlighted
        self.flip = 0  # how to restore edge colors, 0 the same, 1 flipped

        # frame attributes for steps display
        self.frames = []  # list of FrameRecord objects
        self.tt = 'First find a matching greedily.'
        self.sA = ''
        self.sB = ''
        self.sC = ''
        self.re = []
        self.ge = []
        self.be = []
        self.bv = []
        self.yv = []
        self.pv = []
        self.lbv = [i for i in range(self.left_size)]
        self.rbv = [i for i in range(self.right_size)]

        for i in range(self.left_size):
            for j in self.left_neighbors[i]:
                self.be.append((i, j))
        self.add_frame()
        self.frame_index = 0
        if (self.steps):
            self.generate_steps()
Beispiel #11
0
 def set_pause_button(self):
     button_image = games.load_image("images/button.png")
     self.pause_button = games.Sprite(image = button_image, x = 600, y = 300)
     self.pause_text = MT.MyText('Pause', 20, color.black, 600, 300)
     games.screen.add(self.pause_button)
     games.screen.add(self.pause_text)
Beispiel #12
0
 def set_back_button(self, button_image, hovered_image, to_state):
     self.button_list.append(NB.NavigationButton(self, button_image,
                                                 hovered_image, 600, 510, -1,
                                                 to_state))
     self.text_list.append(MT.MyText('Go Back', 20, color.black, 600, 510))
Beispiel #13
0
 def set_congratulation(self):
     self.congratulation = MT.MyText('You found a maximum matching!', 30,
                                     color.black, 630, 150)
     games.screen.add(self.congratulation)
     self.has_congratulation = True