示例#1
0
    def delete(self, app, text_color):
        """
        code for deleting from database goes here
        """
        conn = self.connect_database(self.db_file)
        res = self.delete_from_database(self.table_name, conn, self.condition)
        conn.close()

        if res:
            if self.id_ == "fee":
                if self.delete_table(self.db_file,
                                     self.table_name + "_" + self.data["sem"]):
                    self.success = True
                    res_text = "Successfully deleted!"

                    if self.callback is not None:
                        self.callback()

                    ##userlog
                    dnt = strftime("%d-%m-%Y %H:%M:%S")
                    uname = self.data["uname"]
                    activity = activities["delete_fee"].format(
                        self.data["name"], self.data["sem"])
                    create_log(dnt, uname, activity)
                else:
                    res_text = "Error in deletion!"
            else:
                self.success = True
                res_text = "Successfully deleted!"

                if self.callback is not None:
                    self.callback()
        else:
            res_text = "Error in deletion!"

        self.ids.container.clear_widgets()
        layout = GridLayout(cols=1)
        self.ids.container.add_widget(layout)
        layout.add_widget(
            Label(text=res_text, font_size=self.height / 25 + self.width / 25))
        anc_layout = AnchorLayout()
        layout.add_widget(anc_layout)

        raised = MDRaisedButton()
        raised.text = "Ok"
        raised.bind(on_release=self.dismiss)
        raised.md_bg_color = app.theme_cls.accent_color
        raised.text_color = text_color
        raised.elevation_normal = 10
        anc_layout.add_widget(raised)
 def show_confirmation_dialog(self):
     """Shows the confirmation dialog (MDDialog class)"""
     if not self.confirmation_dialog:
         raised_button = MDRaisedButton(
             text='Yes',
             text_color=self.app.theme_cls.primary_color,
             on_release=lambda x: self.go_to_form())
         raised_button.text_color = (1, 1, 1, 1)
         self.confirmation_dialog = MDDialog(
             title="Want more information?",
             text='More details about your performance.',
             size_hint=(0.7, 1),
             buttons=[
                 raised_button,
                 MDFlatButton(text='No, cancel',
                              text_color=self.app.theme_cls.primary_color,
                              on_release=lambda x: self.confirmation_dialog.
                              dismiss())
             ])
     self.confirmation_dialog.open()
 def add_buttons(self, buttons):
     if not buttons:
         button = MDRaisedButton(
             text="OK",
             pos_hint={"center_x": 0.5},
             font_size=self.font_size_button,
             on_release=lambda x: self.dismiss(),
         )
         button.md_bg_color = (self.color_button if self.color_button else
                               self.theme_cls.primary_color)
         button.text_color = (self.text_color_button
                              if self.text_color_button else (0, 0, 0, 1))
         self.content_cls.add_widget(button)
     else:
         box = MDBoxLayout(adaptive_size=True,
                           spacing="12dp",
                           pos_hint={"center_x": 0.5})
         self.content_cls.add_widget(box)
         for button in buttons:
             box.add_widget(button)
    def show_dialog_saves(self, data, full_list):
        """Gives the choice to the user :
        Whether he continues the game, or he checks the data of the game"""
        if not self.save:
            raised_button = MDRaisedButton(
                text='Continue',
                on_release=lambda x: self.continue_game(data, full_list),
            )
            raised_button.text_color = (1, 1, 1, 1)
            self.save = MDDialog(
                title="What's your choice?",
                size_hint=(0.7, 1),
                text='Continue the match or see the statistics.',
                buttons=[
                    raised_button,
                    MDFlatButton(
                        text='Stats',
                        text_color=self.app.theme_cls.primary_color,
                        on_release=lambda x: self.data_choice(data))])

        if not data['match_ended']:
            self.save.open()
        else:
            self.data_choice(data)