def expand_query_search(self):

        # Get expanded query
        query_str = self.ids['search_query_input'].text
        query_expanded = expand_query(query_str, self.model_selected)
        query = self.vsm_models[self.corpus_selected].to_vector(
            query_str) if self.model_selected == 'vsm' else query_str

        # Buttons for options
        yes_btn = Button(text='Expanded',
                         on_press=partial(self.search, query_expanded,
                                          query_str))
        no_btn = Button(text='Original',
                        on_press=partial(self.search, query, query_str))

        # Popup
        box_layout = BoxLayout(orientation='horizontal')
        box_layout.add_widget(yes_btn)
        box_layout.add_widget(no_btn)
        query_expansion_popup = Popup()
        query_expansion_popup.add_widget(box_layout)
        query_expansion_popup.title = str(query_expanded)
        query_expansion_popup.title_align = "center"
        query_expansion_popup.size_hint = None, None
        query_expansion_popup.size = 800, 400
        query_expansion_popup.open()

        return
Example #2
0
    def Network_PlayerInit(self, data):
        self.player_id = data['id']
        connection.Send({"action": "loby_list"})

        def confirm(name, p):
            connection.Send({"action": "nickname", "nickname": name})
            self.nickname = name
            p.dismiss()

        p = Popup(auto_dismiss=False)
        p.size_hint = (None, None)
        p.size = (420 / density_ratio, 180 / density_ratio)
        p.title = "Choose a nickname"
        box = BoxLayout(size_hint_y=None, height=60 / density_ratio)
        nickname_input = TextInput(multiline=False)
        confirm_btn = ThemedButton(text="Confirm", on_press=lambda btn: confirm(nickname_input.text, p),
                             size_hint_x=None, width=120 / density_ratio)
        box.add_widget(nickname_input)
        box.add_widget(confirm_btn)
        p.add_widget(box)
        p.open()
    def show_search_result_popup(self, instance) -> None:
        """
        Open a popup for clicked on search result to show entire search result body
        """

        docID = instance.text.split("-")[0].strip()
        if self.corpus_selected == "reuters":
            docID = int(docID)

        doc = get_corpus_texts(self.corpus_selected, [docID]).iloc[0]
        title = doc["title"]
        body = doc["body"]

        # Popup
        search_result_popup = Popup()
        search_result_popup.title = f"{docID} - {title}"
        search_result_popup.title_align = "center"
        search_result_popup.size_hint = None, None
        search_result_popup.size = 1400, 800

        label = Label(text=textwrap.fill(body, 170))

        # label_scroll = ScrollableLabel()
        # label_scroll.text = body
        # label_scroll.size_hint_y = None
        # label_scroll.height = 500
        # label_scroll.text_size = 200, None
        # search_result_popup = Popup(
        #     title=f"{docID} - {title}",
        #     content=label_scroll,
        #     size_hint=(None, None),
        #     size=(600, 600)
        # )
        search_result_popup.add_widget(label)
        search_result_popup.open()

        return
Example #4
0
def GameOver():
    '''
    This function is called when the clock ran out and the game ends.
    The user is Propmted for their name, and it's entered in the high score file
    and list if it is among the top 5 scores. The top five scores are displayed.
    Highscores are written to a file named high_scores.txt, if there doesn't
    exist one one is created.
    '''

    try: # check that data is initialized
        GameOver.input_text
    except AttributeError: # initialize data
        GameOver.input_text = None
        GameOver.score_list = []
    
    # update board status and animations
    _Board._highlighted.clear()
    Clock.unschedule(_Board.game_timer.tile_drop)
    _Board.game_timer.cover_timer = -1
    _Board.tile_cover.pos = -5000, -5000
    _Board.manager.transition = RiseInTransition(duration=.5)
    _Board.manager.current = 'menu'
    
    # create the popup prompt for user name
    box = BoxLayout()
    text_in = TextInput(multiline = False, font_size = 40)
    box.add_widget(text_in)

    popup = Popup(title='Enter Your Name')
    popup.content = box
    popup.auto_dismiss = False
    popup.size_hint = (None, None)
    popup.size=(550, 120)

    # go to last screen when user presses 'enter'
    text_in.on_text_validate = LastScreen
    
    GameOver.input_text = text_in
    GameOver.input_text.popup = popup
    
    
    # Read in highscore file of 5 highest scores must end with newline
    try:
        file = open('high_scores.txt', 'r')
        for line in file:
            line = line.strip().split(",")
            line[1] = ' '.join(line[1].split())
            try:
                GameOver.score_list.append((line[0],line[1])) 
            except:
                # if blank line do nothing
                continue
        file.close()
    except:
        # Do nothing if no file or empty line
        pass

    # THIS SHOULDN'T HAPPEN, but if the highscore file ended up
    # with more than 5 things in it, we will rewrite the new one to have 5
    # by removing lowest scores
    while(len(GameOver.score_list)>5):
        GameOver.score_list.pop(0)

    # IF LIST LESS THAN 5 RECORDS LONG THEN FILL IT WITH EMPTIES
    while(len(GameOver.score_list)<5):
        GameOver.score_list = [(0, 'No Record Yet')] + GameOver.score_list
    
    popup.open()