Ejemplo n.º 1
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.cols = 1
        self.rows = 2

        self.history = Scrolllabel(height=Window.size[1] * 0.9,
                                   size_hint_y=None)
        self.add_widget(self.history)

        self.new_message = TextInput(width=Window.size[0] * 0.8,
                                     size_hint_x=None,
                                     multiline=False)
        self.send = Button(text="Send")
        self.send.bind(on_press=self.send_message)

        self.bottom_line = MDGridLayout(cols=2)
        self.bottom_line.add_widget(self.new_message)
        self.bottom_line.add_widget(self.send)

        self.add_widget(self.bottom_line)

        Window.bind(on_key_down=self.on_key_down)

        Clock.schedule_once(self.focus_text_input, 1)
        client.start_listening(self.incoming_message, show_err)
Ejemplo n.º 2
0
    def on_pre_enter(self):
        db.cmd_reset_connection()

        cursor = db.cursor()
        cursor.execute("select orderStatus from orderDetailsTimeTable where ordernum = %s", (selected_orderNum_to_see,))
        orderStatus = cursor.fetchall()[0][0]

        self.ids.comment.text = "Order Status :  " + ("Active" if orderStatus == 1 else "Completed" if orderStatus == 0 else "Food not collected. Cancelled" if orderStatus == -1 else "Cancelled by you.")
        self.ids.deleteOrderBtn.disabled = False if orderStatus == 1 else True

        fetchOrder_statement = "select orderDishTable.dish, orderDishTable.quantity, dish.price from orderDishTable left join dish on dish.dish = orderDishTable.dish where orderDishTable.ordernum in (select ordernum from orderDetailsTimeTable where ordernum = %s);"
        cursor.execute(fetchOrder_statement, (selected_orderNum_to_see,))
        orderDetails = pd.DataFrame(cursor.fetchall()).rename(
            columns={0: 'Dish', 1: 'Quantity', 2: 'Price'}).reset_index(drop=True)
        cursor.close()

        totalPay = 0
        self.ids.previous_order_dish_list.clear_widgets()
        for i in range(len(orderDetails)):
            self.orderDetailsItem = MDGridLayout(cols=4)
            self.orderDetailsItem.add_widget(MDLabel(text=orderDetails.loc[i, 'Dish']))
            self.orderDetailsItem.add_widget(MDLabel(text=str(orderDetails.loc[i, 'Quantity'])))
            self.orderDetailsItem.add_widget(MDLabel(text="\u20B9" + str(orderDetails.loc[i, 'Price'])))
            self.orderDetailsItem.add_widget(MDLabel(
                text="\u20B9" + str(orderDetails.loc[i, 'Quantity'] * orderDetails.loc[i, 'Price'])))
            self.ids.previous_order_dish_list.add_widget(self.orderDetailsItem)
            totalPay += orderDetails.loc[i, 'Quantity'] * orderDetails.loc[i, 'Price']

        self.ids.bill_totalPay.text = "Total:    \u20B9" + str(totalPay)
Ejemplo n.º 3
0
    def __init__(self, scrn_mngr, **kwargs):
        super(MainScreen, self).__init__(**kwargs)
        self.grid = MDGridLayout()
        self.grid.cols = 1
        self.practice_type = None
        self.vs = None
        self.rep_num = 0
        # self.manager.transition.direction = 'right'
        self.scrn_mngr = scrn_mngr
        self.scrn_mngr.transition.direction = 'right'

        self.toolbar = MDToolbar()
        self.set_tool_bar_params()
        self.grid.add_widget(self.toolbar)

        # ''' Create the camera view'''
        self.cam = None
        # self.grid.add_widget(self.cam)

        # self.create_camera()

        # ''' Set the back button'''
        # self.set_back_btn()

        self.add_widget(self.grid)
Ejemplo n.º 4
0
 def __init__(self, **kwargs):
     super(MainLayout, self).__init__(**kwargs)
     self.data_tables = MDDataTable(
         padding=10,
         size_hint=(None, None),
         center_x=1,
         width=600,
         height=680,
         use_pagination=True,
         rows_num=10,
         column_data=[
             ("#", dp(5)),
             ("Name", dp(50)),
             ("Genre", dp(30)),
             ("Country", dp(20)),
         ],
         row_data=[
             [
                 i[0],
                 ("play", [39 / 256, 174 / 256, 96 / 256, 1], i[1]),
                 i[2],
                 i[3]
             ] for i in radio_list()]
     )
     self.radio_play_id = []
     self.record = False
     self.cols = 1
     self.topWindow = MDGridLayout(cols=1, adaptive_height=True)
     self.topWindow.add_widget(self.new_top())
     self.add_widget(self.topWindow)
     self.table()
Ejemplo n.º 5
0
    def add_cards(self, instance):
        close_button = MDFlatButton(text="Close", on_release=self.close_dialog)
        enter_button = MDFlatButton(text="Enter",
                                    on_release=self.add_cardname_to_db)

        self.grid = MDGridLayout(rows=4,
                                 size_hint_y=None,
                                 height=int(Window.height) / 8.9)
        self.front_input = MDTextField(size_hint=(.9, 1))
        self.back_input = MDTextField(size_hint=(.9, 1))

        self.dialog = MDDialog(title="Card Creation",
                               pos_hint={
                                   'center_x': .5,
                                   'center_y': .5
                               },
                               type="custom",
                               content_cls=Content(),
                               size_hint=(.9, 1),
                               buttons=[close_button, enter_button])
        self.grid.add_widget(MDLabel(text="  Front"))
        self.grid.add_widget(self.front_input)
        self.grid.add_widget(MDLabel(text="  Back"))
        self.grid.add_widget(self.back_input)
        self.dialog.add_widget(self.grid)
        self.dialog.open()
Ejemplo n.º 6
0
    def update_game(self):
        if not self.game.is_running:
            self.win()
            return

        self.remove_widget(self.game_grid)
        self.game_grid = MDGridLayout(cols=5, pos_hint={"center": 0.5})
        self.add_widget(self.game_grid)

        for i in range(self.game.get_pos() - 1):
            self.game_grid.add_widget(MDIcon(icon="square-outline"))
        self.game_grid.add_widget(MDIcon(icon="radiobox-marked"))

        if self.game.get_pos() < 5:
            for i in range(5 - self.game.get_pos()):
                self.game_grid.add_widget(MDIcon(icon="square-outline"))

        for row in self.game.show_field():
            for chip in row:
                if chip == 0:
                    self.game_grid.add_widget(MDIcon(icon="moon-new"))
                elif chip == 1:
                    self.game_grid.add_widget(MDIcon(icon="numeric-1-circle"))
                elif chip == 2:
                    self.game_grid.add_widget(MDIcon(icon="numeric-2-circle"))

        self.remove_widget(self.game_controls)
        self.add_widget(self.game_controls)
Ejemplo n.º 7
0
class DownloadedMangaDisplay(ScrollView):
    def __init__(self, master, language, **kwargs):
        super().__init__(**kwargs)
        self.master = master
        self.effect_cls = "ScrollEffect"
        self.bar_width = "10dp"
        self.pos_hint = {"top": .9}
        self.do_scroll_y = True

        self.language_folder = self.master.japanese_manga_dir if language == "Japanese" else self.master.english_manga_dir

        self.manga_folders = [
            resource_path(str(dir))
            for dir in glob(os.path.join(self.language_folder, "*/"))
            if os.path.isdir(dir)
        ]
        self.manga_cover_imgs = [
            resource_path(str(img_path))
            for img_path in glob(os.path.join(self.language_folder, "*/*.jpg"))
            if os.path.isfile(img_path)
        ]
        self.manga_tile_data = list(
            zip(self.manga_folders, self.manga_cover_imgs))

        # This grid acts as a container for the number of manga found and the table with the clickable tiles
        self.outer_gird = MDGridLayout(rows=2,
                                       adaptive_height=True,
                                       padding=("0dp", "20dp", "0dp", "20dp"),
                                       pos_hint={"top": .8})
        self.outer_gird.add_widget(
            MDLabel(text=f"{len(self.manga_folders)} manga were found",
                    halign="center",
                    pos_hint={
                        "center_x": .5,
                        "y": .9
                    }))

        self.grid = MDStackLayout(adaptive_height=True,
                                  orientation="lr-tb",
                                  spacing=("20dp", "20dp"),
                                  padding=("5dp", "30dp", "5dp", "30dp"))

        for i in self.manga_tile_data:
            title, manga_path = os.path.basename(os.path.realpath(
                i[0])), resource_path(i[0])
            print("i: ", i, "title", title, "manga_path: ", manga_path)
            reload_func = lambda title=title, manga_path=manga_path: self.master.create_manga_reader_chapter_selection(
                title, manga_path)
            self.btn = MangaCoverTile(source=i[1],
                                      text=title,
                                      size_hint=(.25, .25),
                                      on_release=partial(
                                          kill_screen,
                                          "Manga Reader Chapter Selection",
                                          reload_func))
            self.grid.add_widget(self.btn)

        self.outer_gird.add_widget(self.grid)
        self.add_widget(self.outer_gird)
Ejemplo n.º 8
0
    def provinces_list(self, *args):
        self.phone_number_screen_manager.current = 'phone_provinces'
        content = self.pickle_list()[4]
        self.delete_container = MDGridLayout(cols=1, adaptive_height=True)
        self.phone_provinces.add_widget(self.delete_container)
        for key, value in content.items():
            item = MDExpansionPanel(
                icon=f'images/provinces/{key}.png',
                content=ProvinceContent(content[key]),
                panel_cls=MDExpansionPanelOneLine(text=key))

            self.delete_container.add_widget(item)
Ejemplo n.º 9
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.layout = MDGridLayout(cols=1, size_hint_y=None)
        self.add_widget(self.layout)

        self.chat_history = MDLabel(size_hint_y=None, markup=True)
        self.scroll_to_point = MDLabel()

        self.layout.add_widget(self.chat_history)
        self.layout.add_widget(self.scroll_to_point)

        self.scroll_to(self.scroll_to_point)
Ejemplo n.º 10
0
    def __init__(self, master, **kwargs):
        super().__init__(**kwargs)
        self.master = master
        self.manga_data = self.master.manga_data
        self.downloader_links_methods = {
            "manganelo": MangaNelo.download_manga,
            "kissmanga": KissManga.download_manga,
            "rawdevart": RawDevArt.download_manga,
            "senmanga": SenManga.download_manga
        }
        self.effect_cls = "ScrollEffect"
        self.bar_width = "10dp"
        self.pos_hint = {"top": .9}

        # This grid acts as a container for the number of manga found and the table with the clickable tiles
        self.outer_gird = MDGridLayout(rows=2,
                                       adaptive_height=True,
                                       padding=("0dp", "20dp", "0dp", "20dp"),
                                       pos_hint={"top": .8})
        self.outer_gird.add_widget(
            MDLabel(text=f"{len(self.manga_data)} manga were found",
                    halign="center",
                    pos_hint={
                        "center_x": .5,
                        "y": .9
                    }))

        # This grid acts a table to store all found manga
        self.grid = MDStackLayout(adaptive_height=True,
                                  orientation="lr-tb",
                                  spacing=("20dp", "20dp"),
                                  padding=("5dp", "30dp", "5dp", "30dp"))

        for title, links_tuple in self.manga_data.items():
            self.btn = MangaCoverTile(source=links_tuple[1],
                                      text=title,
                                      on_release=partial(
                                          self.make_request, title),
                                      size_hint=(.25, .25))
            self.grid.add_widget(self.btn)

        # Checks to see if any manga were found; An empty dict means no manga were found with the inputted text
        if self.manga_data == {}:
            self.grid.add_widget(
                MDLabel(text="No Manga found",
                        halign="center",
                        pos_hint={
                            "center_x": .5,
                            "center_y": .5
                        }))

        self.outer_gird.add_widget(self.grid)
        self.add_widget(self.outer_gird)
Ejemplo n.º 11
0
class chatPage(MDGridLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.cols = 1
        self.rows = 2

        self.history = Scrolllabel(height=Window.size[1] * 0.9,
                                   size_hint_y=None)
        self.add_widget(self.history)

        self.new_message = TextInput(width=Window.size[0] * 0.8,
                                     size_hint_x=None,
                                     multiline=False)
        self.send = Button(text="Send")
        self.send.bind(on_press=self.send_message)

        self.bottom_line = MDGridLayout(cols=2)
        self.bottom_line.add_widget(self.new_message)
        self.bottom_line.add_widget(self.send)

        self.add_widget(self.bottom_line)

        Window.bind(on_key_down=self.on_key_down)

        Clock.schedule_once(self.focus_text_input, 1)
        client.start_listening(self.incoming_message, show_err)

    def on_key_down(self, instance, keyboard, keycode, text, modifiers):
        if keycode == 40:
            self.send_message(None)

    def send_message(self, _):

        message = self.new_message.text

        self.new_message.text = ''
        if message:
            self.history.update_chat_history(
                f"[color=E98567]{kivymdMDApp.connect_page.username.text}[/color] [color=ffffff]> {str(message)}[/color]"
            )
            client.send(message)

        Clock.schedule_once(self.focus_text_input, 0.1)

    def focus_text_input(self, _):
        self.new_message.focus = True

    def incoming_message(self, username, message):
        self.history.update_chat_history(
            f"[color=5E97AF]{username}[/color][color=ffffff]> {str(message)}[/color]"
        )
Ejemplo n.º 12
0
    def get_result(self):

        self.count_grid = MDGridLayout(cols=3)
        self.count_label = MDLabel(text=str(self.count),
                                   size_hint_x=None,
                                   width=20)
        self.divider = MDLabel(text="/", size_hint_x=None, width=20)
        self.total_num = MDLabel(text=str(len(self.review_cardname)),
                                 size_hint_x=None,
                                 width=20)

        self.count_grid.add_widget(self.count_label)
        self.count_grid.add_widget(self.divider)
        self.count_grid.add_widget(self.total_num)
        self.box.add_widget(self.count_grid)
        self.box.add_widget(MDLabel())
        self.box.add_widget(MDLabel())
Ejemplo n.º 13
0
class Scrolllabel(ScrollView):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.layout = MDGridLayout(cols=1, size_hint_y=None)
        self.add_widget(self.layout)

        self.chat_history = MDLabel(size_hint_y=None, markup=True)
        self.scroll_to_point = MDLabel()

        self.layout.add_widget(self.chat_history)
        self.layout.add_widget(self.scroll_to_point)

        self.scroll_to(self.scroll_to_point)

    def update_chat_history(self, message, _=None):
        self.chat_history.text += '\n' + str(message)

        self.layout.height = self.chat_history.texture_size[1] + 20
        print(self.chat_history.texture_size[1])
        self.chat_history.height = self.chat_history.texture_size[1]
        self.chat_history.text_size = (self.chat_history.width * 0.98, None)
Ejemplo n.º 14
0
    def __init__(self, form_attrs, **kwargs):
        super(Form, self).__init__(**kwargs)
        self.cols = 1
        self.form = MDGridLayout()
        self.form.cols = 2
        self.form_attrs = form_attrs
        self.text_inputs = {}
        self.search_btn = {}
        for key, value in form_attrs.items():
            if key == 'form_name':
                self.form_name = form_attrs[key]
            elif key in ['product_id', 'provider_id']:
                self.form.add_widget(MDLabel(text=value[0] + ':'))
                self.text_inputs[key] = MDTextField(
                    multiline=False,
                    text='' if 'date' not in key else
                    datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                self.search_btn[key] = MDRectangleFlatButton(text='Buscar ' +
                                                             value[0],
                                                             size_hint_x=None,
                                                             font_size=10)
                self.search_btn[key].bind(on_release=self.search)
                search_lo = MDGridLayout()
                search_lo.cols = 2
                search_lo.add_widget(self.text_inputs[key])
                search_lo.add_widget(self.search_btn[key])
                self.form.add_widget(search_lo)
            else:
                self.form.add_widget(MDLabel(text=value[0] + ':'))
                self.text_inputs[key] = MDTextField(
                    multiline=False,
                    text='' if 'date' not in key else
                    datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                self.form.add_widget(self.text_inputs[key])
        self.add_widget(self.form)

        self.submit = MDRectangleFlatButton(text='Crear',
                                            font_size=40,
                                            pos_hint={
                                                'center_x': 0.5,
                                                'center_y': 0.1
                                            },
                                            size_hint_x=None)
        self.submit.bind(on_release=self.submit_form)
        self.add_widget(self.submit)
Ejemplo n.º 15
0
 def show_popup(title, message):
     """ Function to display popup messages. """
     layout = MDGridLayout(cols=1, padding=10, spacing=10)
     popup_label = MDLabel(text=message, font_size=20, bold=True, pos_hint={"center_x": .5, "center_y": .5},
                           theme_text_color="Custom", text_color=[1, 1, 1, 1], halign="center")
     popup_button = MDRaisedButton(text="OK", size_hint=(1, None), height=50, bold=True, font_size=20,
                                   pos_hint={"center_x": .5, "center_y": .5}, md_bg_color=[.06, .47, .47, 1])
     layout.add_widget(popup_label)
     layout.add_widget(popup_button)
     popup = Popup(title=title, content=layout, size_hint=(None, None), size=(350, 350), auto_dismiss=False)
     popup.open()
     popup_button.bind(on_press=popup.dismiss)
Ejemplo n.º 16
0
 def create_numeric_control(self, app, text=''):
     grid = MDGridLayout(spacing=3, padding=3, cols=3)
     decrease_number_btn = MDFloatingActionButton(
         icon="minus",
         md_bg_color=app.theme_cls.primary_color,
         on_release=self.numeric_decrement)
     self.parameter_label = LabelButton(
         text=text,
         font_size=40,
         halign='center',
         theme_text_color="Custom",
         text_color=(1, .2, 1, 1),
         on_release=self.commit_parameter_value)
     increase_number_btn = MDFloatingActionButton(
         icon="plus",
         md_bg_color=app.theme_cls.primary_color,
         on_release=self.numeric_increment)
     self.popup_container.clear_widgets()
     grid.add_widget(decrease_number_btn)
     grid.add_widget(self.parameter_label)
     grid.add_widget(increase_number_btn)
     self.popup_container.add_widget(grid)
Ejemplo n.º 17
0
    def create_switch_control(self, text, app):
        self.switch_state = True if text == 'ON' else False
        grid = MDGridLayout(spacing=3, padding=3, cols=3)
        self.switch = MySwitch(width=dp(64), active=self.switch_state)
        self.switch.bind(on_press=self.switch_callback)

        self.parameter_label = LabelButton(
            text=text,
            font_size=40,
            halign='center',
            theme_text_color="Custom",
            text_color=(1, 0, 0, 1) if not self.switch.active else
            (0, 1, 0, 1),
            on_release=self.commit_parameter_value)
        commit_btn = MDRoundFlatIconButton(
            text="Commit",
            md_bg_color=app.theme_cls.primary_color,
            on_release=self.commit_parameter_value)
        self.popup_container.clear_widgets()
        grid.add_widget(self.parameter_label)
        grid.add_widget(self.switch)
        grid.add_widget(commit_btn)
        self.popup_container.add_widget(grid)
Ejemplo n.º 18
0
    def __init__(self, audio_player, config_handler):
        """
        Creates an AlarmDismissPopup
        """
        self.popup_layout = MDGridLayout(cols=1, padding=10)

        self.dismiss_button = MDRaisedButton(text="Dismiss")
        self.dismiss_button.bind(on_press=self.dismiss)

        dialog_text = "[color=000000]Dismiss Alarm[/color]"
        if config_handler.get_setting(CONFIG_ENABLE_DARK_MODE_KEY):
            "[color=ffffff]Dismiss Alarm[/color]"

        self.alarm_popup = MDDialog(
            title=dialog_text,
            size_hint=(0.75, 0.75),
            buttons=[self.dismiss_button],
        )
        self.alarm_popup.on_touch_up(self.dismiss)
        self.is_open = False

        self.audio_player = audio_player
Ejemplo n.º 19
0
 def on_enter(self):
     db.cmd_reset_connection()
     self.hotel_obj = HotelScreen()
     self.orders_frequency_table = None
     self.cursor = db.cursor()
     self.ids.bill_hotelName.text = str(self.hotel_obj.hotel_ordering_currently).upper()
     self.orders_frequency_table = {i: self.hotel_obj.student_ordering_list.count(i) for i in self.hotel_obj.student_ordering_list}
     self.ids.toBill_ScrollView.clear_widgets()
     for i in self.orders_frequency_table:
         grid_for_bill_card = MDGridLayout(cols=2, adaptive_height = True)
         billDishName_details = TwoLineListItem(text = str(i), secondary_text = "QTY - " + str(self.orders_frequency_table[i]))
         billDishPrice_details = MDLabel(text = str(int(self.hotel_obj.dish_available_in_currentSelectedHotel.query('Dish == @i')['Price']) * self.orders_frequency_table[i]), halign = 'center')
         grid_for_bill_card.add_widget(billDishName_details)
         grid_for_bill_card.add_widget(billDishPrice_details)
         self.ids.toBill_ScrollView.add_widget(grid_for_bill_card)
     self.ids.billTotalAmountToPay_id.text = "\u20B9 " + str(self.hotel_obj.totalAmount_Order)
     self.cursor.close()
Ejemplo n.º 20
0
    def __init__(self, return_back):
        super(GameWidget, self).__init__()
        self.orientation = "vertical"
        self.return_back = return_back
        self.ids.return_button.on_press = return_back

        self.game = Game()
        self.game_grid = GameField(cols=5)

        for i in range(20):
            self.game_grid.add_widget(MDIcon(icon="moon-new"))

        self.game_controls = ControlsBox()
        self.game_controls.add_widget(
            MDIconButton(icon="arrow-collapse-left",
                         on_press=lambda _: self.move(True)))
        self.game_controls.add_widget(
            MDIconButton(icon="arrow-down-bold", on_press=self.drop_cell))
        self.game_controls.add_widget(
            MDIconButton(icon="arrow-collapse-right",
                         on_press=lambda _: self.move(False)))
        self.add_widget(self.game_grid)
        self.add_widget(self.game_controls)
        self.update_game()
Ejemplo n.º 21
0
    def create_top_card_layout(self, num_of_exc, num_of_exc_total, exc):
        help_layout = MDGridLayout(rows=1, cols=2)
        excnum = str(num_of_exc + 1) + " of " + str(num_of_exc_total)
        exc_num = MDLabel(text=excnum,
                          font_style="Caption",
                          theme_text_color="Secondary",
                          pos_hint={
                              "center_y": 0.85,
                              "center_x": 0.2
                          })
        deleteBox = MDCheckbox(pos_hint={
            "center_y": 0.85,
            "center_x": 0.9275
        },
                               on_release=self.active_card_check_box)
        self.ex_reference_by_checkBox[deleteBox] = exc
        help_layout.add_widget(exc_num)
        help_layout.add_widget(deleteBox)

        return help_layout, deleteBox
Ejemplo n.º 22
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.orientation = 'vertical'

        # Main screen layout
        screen_layout = MDGridLayout()
        screen_layout.cols = 2
        screen_layout.md_bg_color = [0, 1, 1, 1]

        # AC region
        self.timer = 0

        # AC Card
        new_layout = MDFloatLayout()
        self.ac_card1 = AcCard((0.75, 0.75))
        self.ac_card1.on_press = self.ac_touch_down
        self.ac_card1.on_release = self.ac_touch_up
        new_layout.add_widget(self.ac_card1)
        screen_layout.add_widget(new_layout)

        self.content = AcPopup()
        self.content.ac_card.on_release = partial(self.ac_touch_up, popup=True)

        self.ac_popup = Popup(title='AC settings', size_hint=(.75, .75))
        self.ac_popup.content = self.content
        self.ac_popup.background_color = [i / 255
                                          for i in [137, 205, 211]] + [1]

        #--------------------------------------------------------------#

        # Light setup
        new_layout = MDFloatLayout()
        self.light_card = MDCard(
            orientation='horizontal',
            padding='10dp',
            pos_hint={
                'center_x': 0.5,
                'center_y': 0.5
            },
            size_hint=(0.75, 0.75),
        )
        self.light_card.md_bg_color = app.dark_color
        light_image = Image(
            source='static/light1.png',
            size_hint=(1, 1),
        )
        self.light_card.on_press = self.light_change
        self.light_card.add_widget(light_image)
        new_layout.add_widget(self.light_card)
        screen_layout.add_widget(new_layout)

        screen_layout.add_widget(Button(text='TODO'))
        screen_layout.add_widget(Button(text='TODO'))
        screen_layout.add_widget(Button(text='TODO'))
        screen_layout.add_widget(Button(text='TODO'))
        screen_layout.add_widget(Button(text='TODO'))
        screen_layout.add_widget(Button(text='TODO'))
        self.add_widget(screen_layout)
Ejemplo n.º 23
0
    def create_card(self, session, num_of_session, total_session_num,
                    session_workout_name, session_date):
        new_card_layout = MDFloatLayout()  # for centering

        excCard = MDCard(
            spacing=5,
            radius=[80],
            orientation="vertical",
            size_hint=(0.87, 0.97),
            padding=[
                25, 16, 15, 25
            ],  # [padding_left, padding_top,padding_right, padding_bottom].
            pos_hint={
                "center_y": 0.5,
                "center_x": 0.5
            },
            background="resources/card_back.png",
            elevation=1)

        # help_layout = self.create_top_card_layout(num_of_exc, num_of_exc_total, exc)
        # excCard.add_widget(help_layout)

        excnum = str(num_of_session + 1) + " of " + str(total_session_num)

        exc_num = MDLabel(text="    " + excnum,
                          font_style="Caption",
                          theme_text_color="Secondary",
                          pos_hint={
                              "center_y": 0.85,
                              "center_x": 0.17
                          })
        # help_layout.add_widget(exc_num)
        # excCard.add_widget(help_layout)
        name_layout_y_size = 1.5
        if len(session_workout_name) > 9:
            name_layout_y_size = 3
        name_layout = MDGridLayout(rows=1,
                                   cols=3,
                                   size_hint_y=name_layout_y_size)
        workout = session_workout_name
        workout_name = MDLabel(text=workout,
                               font_style="H5",
                               theme_text_color="Custom",
                               text_color=self.app.text_color,
                               size_hint_x=1.5)
        workout_date = MDLabel(text=str(session_date),
                               font_style="Caption",
                               theme_text_color="Custom",
                               text_color=self.app.text_color)
        name_layout.add_widget(workout_name)
        name_layout.add_widget(workout_date)
        name_layout.add_widget(exc_num)

        excCard.add_widget(name_layout)
        seperate = MDSeparator(height="1dp", color=self.app.text_color)
        excCard.add_widget(seperate)

        # session = ["3   X   8", "3   X   8", "3   X   8", "3   X   8"]

        for num_of_set, set in enumerate(session):
            set_label, set_number, reps_label = self.create_set_label(
                set, num_of_set)

            exc_layout = MDGridLayout(rows=1, cols=2)
            units_layout = MDGridLayout(rows=1, cols=2, size_hint_y=1.5)
            exc_layout.add_widget(set_label)
            exc_layout.add_widget(set_number)
            units_layout.add_widget(MDLabel(text="", size_hint_x=0.9))
            units_layout.add_widget(reps_label)

            excCard.add_widget(exc_layout)
            excCard.add_widget(units_layout)

        new_card_layout.add_widget(excCard)
        return new_card_layout
    def pressed(self, instance):
        print(self.spinner.text)
        #print(self.spinner.text)
        top3_rank = final_combiner.final_rank([
            int(self.left.two.input1.text),
            int(self.left.two.input3.text),
            int(self.left.two.input5.text)
        ])
        if not self.acard:
            self.rank1 = ThreeLineIconListItem(
                text=top3_rank[0][0],
                secondary_text='人口特性:' + str(top3_rank[0][1]),
                tertiary_text='新資所得:' + str(top3_rank[0][2]),
                text_color=[1, 1, 1, 1])
            self.rank1.add_widget(IconLeftWidget(icon='numeric-1-box'))
            self.rank1.bg_color = [0, 0, 0, 0]
            self.rank1.children[1].children[2].font_name = 'msjhbd.ttc'
            self.rank1.children[1].children[1].font_name = 'msjhbd.ttc'
            self.rank1.children[1].children[0].font_name = 'msjhbd.ttc'
            self.rank1.children[1].children[2].font_size = '18'

            more_rank1 = MDLabel(text='人口消長:' + str(top3_rank[0][3]))
            more_rank1.font_name = 'msjhbd.ttc'
            more_rank1.font_style = 'Body1'
            more_rank1.font_size = 16
            more_rank1.color = [0, 0, 0, 0.7]
            self.rank1.children[1].add_widget(more_rank1)
            self.rank1.children[1].size_hint = [1, None]
            self.rank1.children[1].children[3].pos = [56, 280]

            self.rank1.children[0].children[0].children[0].color = [1, 1, 1, 1]
            self.rank1.children[0].children[0].children[0].pos_hint = {
                'left': 0.1
            }
            self.rank1.children[0].padding = [-10, 0, 0, 0]
            self.rank1.children[1].children[3].theme_text_color = 'Custom'
            self.rank1.children[1].children[3].text_color = [1, 1, 1, 1]
            self.rank1.children[1].children[2].theme_text_color = 'Custom'
            self.rank1.children[1].children[2].text_color = [1, 1, 1, 1]
            self.rank1.children[1].children[1].theme_text_color = 'Custom'
            self.rank1.children[1].children[1].text_color = [1, 1, 1, 1]
            self.rank1.children[1].children[0].theme_text_color = 'Custom'
            self.rank1.children[1].children[0].text_color = [1, 1, 1, 1]
            # 從另一個預先寫好、計算各里指標分數的模組final_combiner引進final_rank函數,取得前三名的區域及其各項指標分數後用top3_rank變數紀錄起來
            # 接著改寫、擴充kivy套件內的工具(ThreeLineIconListItem),做成資訊卡,同時使其擁有按鈕的特性讓使用者做點選

            self.rank2 = ThreeLineIconListItem(
                text=top3_rank[1][0],
                secondary_text='人口特性:' + str(top3_rank[1][1]),
                tertiary_text='新資所得:' + str(top3_rank[1][2]))
            self.rank2.add_widget(IconLeftWidget(icon='numeric-2-box'))
            self.rank2.bg_color = [0, 0, 0, 0]

            self.rank2.children[1].children[2].font_size = '18'
            self.rank2.children[1].children[2].font_name = 'msjhbd.ttc'
            self.rank2.children[1].children[1].font_name = 'msjhbd.ttc'
            self.rank2.children[1].children[0].font_name = 'msjhbd.ttc'

            more_rank2 = MDLabel(text='人口消長:' + str(top3_rank[1][3]))
            more_rank2.font_name = 'msjhbd.ttc'
            more_rank2.font_style = 'Body1'
            more_rank2.font_size = 16
            more_rank2.color = [0, 0, 0, 0.54]
            self.rank2.children[1].add_widget(more_rank2)
            self.rank2.children[1].size_hint = [1, None]

            self.rank2.children[0].children[0].children[0].color = [1, 1, 1, 1]
            self.rank2.children[0].children[0].children[0].pos_hint = {
                'left': 0.1
            }
            self.rank2.children[0].padding = [-10, 0, 0, 0]
            self.rank2.children[1].children[3].theme_text_color = 'Custom'
            self.rank2.children[1].children[3].text_color = [1, 1, 1, 1]
            self.rank2.children[1].children[2].theme_text_color = 'Custom'
            self.rank2.children[1].children[2].text_color = [1, 1, 1, 1]
            self.rank2.children[1].children[1].theme_text_color = 'Custom'
            self.rank2.children[1].children[1].text_color = [1, 1, 1, 1]
            self.rank2.children[1].children[0].theme_text_color = 'Custom'
            self.rank2.children[1].children[0].text_color = [1, 1, 1, 1]

            self.rank3 = ThreeLineIconListItem(
                text=top3_rank[2][0],
                secondary_text='人口特性:' + str(top3_rank[2][1]),
                tertiary_text='新資所得:' + str(top3_rank[2][2]))
            self.rank3.add_widget(IconLeftWidget(icon='numeric-3-box'))
            self.rank3.bg_color = [0, 0, 0, 0]

            self.rank3.children[1].children[2].font_size = '18'
            self.rank3.children[1].children[2].font_name = 'msjhbd.ttc'
            self.rank3.children[1].children[1].font_name = 'msjhbd.ttc'
            self.rank3.children[1].children[0].font_name = 'msjhbd.ttc'

            more_rank3 = MDLabel(text='人口消長:' + str(top3_rank[2][3]))
            more_rank3.font_name = 'msjhbd.ttc'
            more_rank3.font_style = 'Body1'
            more_rank3.font_size = 16
            more_rank3.color = [0, 0, 0, 0.54]
            self.rank3.children[1].add_widget(more_rank3)
            self.rank3.children[1].size_hint = [1, None]

            self.rank3.children[0].children[0].children[0].color = [1, 1, 1, 1]
            self.rank3.children[0].children[0].children[0].pos_hint = {
                'left': 0.1
            }
            self.rank3.children[0].padding = [-10, 0, 0, 0]
            self.rank3.children[1].children[3].theme_text_color = 'Custom'
            self.rank3.children[1].children[3].text_color = [1, 1, 1, 1]
            self.rank3.children[1].children[2].theme_text_color = 'Custom'
            self.rank3.children[1].children[2].text_color = [1, 1, 1, 1]
            self.rank3.children[1].children[1].theme_text_color = 'Custom'
            self.rank3.children[1].children[1].text_color = [1, 1, 1, 1]
            self.rank3.children[1].children[0].theme_text_color = 'Custom'
            self.rank3.children[1].children[0].text_color = [1, 1, 1, 1]

            self.rank1.size = [352, 100]
            self.rank2.size = [352, 100]
            self.rank3.size = [352, 100]

            self.click += 1

            self.rank1.children[1].padding = [56, 16, 24, 7]
            self.rank2.children[1].padding = [56, 4, 24, 7]
            self.rank3.children[1].padding = [56, 4, 24, 7]

            self.rank1.children[1].children[0].adaptive_height = True
            self.rank1.children[1].pos = [0, 180]
            self.rank2.children[1].children[1].adaptive_height = True
            self.rank2.children[1].pos = [0, 130]
            self.rank3.children[1].children[1].adaptive_height = True

            self.add_widget(
                MDGridLayout(cols=1,
                             size_hint=[0.285, 1],
                             md_bg_color=[0.39, 0.4, 0.72, 1]))
            self.children[0].add_widget(self.rank1)
            self.children[0].add_widget(self.rank2)
            self.children[0].add_widget(self.rank3)

            self.rank1.bind(on_release=self.add_renk1_marker)
            self.rank2.bind(on_release=self.add_renk2_marker)
            self.rank3.bind(on_release=self.add_renk3_marker)
Ejemplo n.º 25
0
    def create_exc_card(self, exc, num_of_exc, num_of_exc_total):

        card_layout = MDFloatLayout()  # for centering
        excCard = MDCard(
            spacing=2,
            radius=[80],
            orientation="vertical",
            size_hint=(0.95, 0.8),
            padding=[
                20, 0, 0, 20
            ],  # [padding_left, padding_top,padding_right, padding_bottom].
            pos_hint={
                "center_y": 0.5,
                "center_x": 0.5
            },
            background="resources/card_back.png")

        help_layout = MDGridLayout(rows=1, cols=2, size_hint_y=0.4)
        excnum = str(num_of_exc + 1) + " of " + str(num_of_exc_total)
        exc_num = MDLabel(
            text=excnum,
            font_style="Caption",
            theme_text_color="Secondary",
        )
        del_Button = MDIconButton(
            icon="trash-can-outline",
            theme_text_color="Custom",
            text_color=self.app.text_color,
            on_release=self.show_del_exercise_dialog,
        )

        self.del_button_id_by_exc[exc] = del_Button
        self.exc_by_del_button[del_Button] = exc

        help_layout.add_widget(exc_num)
        help_layout.add_widget(del_Button)
        excCard.add_widget(help_layout)

        name_layout = MDGridLayout(rows=1, cols=2, padding=[
            0, 10, 0, 25
        ])  # [padding_left, padding_top,padding_right, padding_bottom])
        exc_name = MDLabel(text=exc,
                           font_style="H5",
                           theme_text_color="Custom",
                           text_color=self.app.text_color)

        # consider hiding option
        sButton = MDIconButton(
            icon="history",
            theme_text_color="Custom",
            text_color=self.app.theme_cls.primary_color,
            on_release=self.show_exc_history,
        )

        self.stats_button_id_by_exc[exc] = sButton
        self.exc_by_stats_button[sButton] = exc

        name_layout.add_widget(exc_name)
        name_layout.add_widget(sButton)

        excCard.add_widget(name_layout)
        card_layout.add_widget(excCard)
        return card_layout
Ejemplo n.º 26
0
class Library(Screen):
    def __init__(self, **kwargs):
        super(Library, self).__init__(**kwargs)
        self.deckname = None
        self.skeleton_frame()

    def skeleton_frame(self):
        #Displays all decks on the app
        self.box = MDBoxLayout(orientation="vertical")
        self.scrollview = ScrollView()
        self.list = MDList()
        self.scrollview.add_widget(self.list)

        #calls the activate_for_loop method
        self.display_deck()

        # Buttons on the bottom of the screen
        # Buttons are places on bottom of screen
        self.box.add_widget(
            MDLabel(size_hint=(0.2, 0.15)))  # Push down the list of buttons
        self.box.add_widget(self.scrollview)

        self.bottom_bar = MDToolbar()
        self.delete_deck_button = MDIconButton(icon="trash-can-outline",
                                               pos_hint={
                                                   'center_x': .5,
                                                   'center_y': .5
                                               })
        self.delete_deck_button.bind(on_press=self.delete_deck)
        self.build_deck_button = MDIconButton(icon="plus-thick",
                                              pos_hint={
                                                  'center_x': 0.5,
                                                  'center_y': 0.5
                                              })
        self.build_deck_button.bind(on_press=self.build_new_deck)

        #add method to make a new deck
        self.bottom_bar.add_widget(self.delete_deck_button)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.build_deck_button)
        self.bottom_bar.add_widget(MDLabel())
        self.box.add_widget(self.bottom_bar)
        self.add_widget(self.box)

    def skeleton_frame2(self, instance):
        # method must be used to make the on_press method work
        self.scrollview.remove_widget(self.list)
        self.box.remove_widget(self.bottom_bar)
        self.list = MDList()
        self.scrollview.add_widget(self.list)

        #Displays all decks on the app
        self.box = MDBoxLayout(orientation="vertical")
        self.scrollview = ScrollView()
        self.list = MDList()
        self.scrollview.add_widget(self.list)

        #calls the activate_for_loop method
        self.display_deck()

        # Buttons on the bottom of the screen
        # Buttons are places on bottom of screen
        self.box.add_widget(
            MDLabel(size_hint=(0.2, 0.15)))  # Push down the list of buttons
        self.box.add_widget(self.scrollview)

        self.bottom_bar = MDToolbar()
        self.delete_deck_button = MDIconButton(icon="trash-can-outline",
                                               pos_hint={
                                                   'center_x': .5,
                                                   'center_y': .5
                                               })
        self.delete_deck_button.bind(on_press=self.delete_deck)
        self.build_deck_button = MDIconButton(icon="plus-thick",
                                              pos_hint={
                                                  'center_x': 0.5,
                                                  'center_y': 0.5
                                              })
        self.build_deck_button.bind(on_press=self.build_new_deck)

        #add method to make a new deck
        self.bottom_bar.add_widget(self.delete_deck_button)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.build_deck_button)
        self.bottom_bar.add_widget(MDLabel())
        self.box.add_widget(self.bottom_bar)
        self.add_widget(self.box)

# Creates a section that will list out the decks

    def display_deck(self):
        conn = sqlite3.connect("flashcard_app.db")
        cur = conn.cursor()
        cur.execute("""
        SELECT DeckName 
        FROM Decks
        """)
        names = cur.fetchall()
        for name in names:
            # the nested for loop will remove (),' from the string
            name = str(name)
            for char in name:
                if char == "(" or char == ")" or char == "," or char == "'":
                    name = name.replace(char, "")
            self.items = OneLineListItem(text=name)
            self.items.bind(on_press=self.display_cards)
            self.list.add_widget(self.items)
        conn.commit()
        conn.close()

# working code to switch screens with python code

    def display_cards(self, instance):
        self.scrollview.remove_widget(self.list)
        self.box.remove_widget(self.bottom_bar)
        self.list = MDList()
        self.scrollview.add_widget(self.list)
        self.deckname = instance.text
        print(self.deckname)
        conn = sqlite3.connect("flashcard_app.db")
        cur = conn.cursor()
        cur.execute(
            """
                SELECT CardName 
                FROM Cards
                WHERE DeckName = ?
                """, (instance.text, ))
        names = cur.fetchall()
        for name in names:
            # the nested for loop will remove (),' from the string
            name = str(name)
            for char in name:
                if char == "(" or char == ")" or char == "," or char == "'":
                    name = name.replace(char, "")
            self.items = OneLineListItem(text=name)
            self.items.bind(on_press=self.display_name_def)
            self.list.add_widget(self.items)
        conn.commit()
        conn.close()
        self.get_bottom_bar()

    def display_cards2(self):
        self.scrollview.remove_widget(self.list)
        self.box.remove_widget(self.bottom_bar)
        self.list = MDList()
        self.scrollview.add_widget(self.list)
        conn = sqlite3.connect("flashcard_app.db")
        cur = conn.cursor()
        cur.execute(
            """
                SELECT CardName 
                FROM Cards
                WHERE DeckName = ?
                """, (self.deckname, ))
        names = cur.fetchall()
        for name in names:
            # the nested for loop will remove (),' from the string
            name = str(name)
            for char in name:
                if char == "(" or char == ")" or char == "," or char == "'":
                    name = name.replace(char, "")
            self.items = OneLineListItem(text=name)
            self.items.bind(on_press=self.display_name_def)
            self.list.add_widget(self.items)
        conn.commit()
        conn.close()
        self.get_bottom_bar()

#displays the bottom nav bar when display_cards is called

    def get_bottom_bar(self):
        self.bottom_bar = MDToolbar()
        self.add_card_button = MDIconButton(icon="plus-thick",
                                            pos_hint={
                                                'center_x': 0.5,
                                                'center_y': 0.5
                                            })
        self.trash_button = MDIconButton(icon="trash-can-outline",
                                         pos_hint={
                                             'center_x': 0.5,
                                             'center_y': 0.5
                                         })

        self.back_button = MDIconButton(icon="arrow-left-bold",
                                        pos_hint={
                                            'center_x': 0.5,
                                            'center_y': 0.5
                                        })

        self.trash_button.bind(on_press=self.delete_card)
        self.back_button.bind(on_press=self.skeleton_frame2)
        self.add_card_button.bind(on_press=self.add_cards)
        #self.build_deck_button.bind(on_press=self.to_build_card)

        # jargon of code to space out the buttons on bottom nav bar
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.back_button)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.add_card_button)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.trash_button)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(MDLabel())

        self.box.add_widget(self.bottom_bar)

    def add_cards(self, instance):
        close_button = MDFlatButton(text="Close", on_release=self.close_dialog)
        enter_button = MDFlatButton(text="Enter",
                                    on_release=self.add_cardname_to_db)

        self.grid = MDGridLayout(rows=4,
                                 size_hint_y=None,
                                 height=int(Window.height) / 8.9)
        self.front_input = MDTextField(size_hint=(.9, 1))
        self.back_input = MDTextField(size_hint=(.9, 1))

        self.dialog = MDDialog(title="Card Creation",
                               pos_hint={
                                   'center_x': .5,
                                   'center_y': .5
                               },
                               type="custom",
                               content_cls=Content(),
                               size_hint=(.9, 1),
                               buttons=[close_button, enter_button])
        self.grid.add_widget(MDLabel(text="  Front"))
        self.grid.add_widget(self.front_input)
        self.grid.add_widget(MDLabel(text="  Back"))
        self.grid.add_widget(self.back_input)
        self.dialog.add_widget(self.grid)
        self.dialog.open()

    def add_cardname_to_db(self, instance):
        front_input = self.front_input.text
        back_input = self.back_input.text

        print(self.deckname)
        print(front_input)
        print(back_input)

        con = sqlite3.connect("flashcard_app.db")
        cur = con.cursor()
        cur.execute(
            """
        INSERT INTO Cards (CardName, Definition, DeckName)
        VALUES(?, ?, ?)
        """, (front_input, back_input, self.deckname))
        names = cur.fetchall()
        for name in names:
            # the nested for loop will remove (),' from the string
            name = str(name)
            for char in name:
                if char == "(" or char == ")" or char == "," or char == "'":
                    name = name.replace(char, "")
            self.items = OneLineListItem(text=name)
            #self.items.bind(on_press=self.display_name_def)
            self.list.add_widget(self.items)
        con.commit()
        con.close()
        self.display_cards2()

    # displays the front and back of a single card
    def display_name_def(self, instance):
        self.predicate = True
        self.scrollview.remove_widget(self.list)
        self.box.remove_widget(self.bottom_bar)
        print(instance.text)
        con = sqlite3.connect("flashcard_app.db")
        cur = con.cursor()
        cur.execute(
            """
        SELECT CardName, Definition
        FROM Cards
        WHERE CardName = ?
        """, (instance.text, ))
        row = cur.fetchall()
        for cardname, definition in row:
            self.front = cardname
            self.back = definition
            print(self.front, self.back)
        con.commit()
        con.close()

        # will display the front-side of selected card
        self.click_action()

# the screen will act as a button to display the front or back after clicking the screen

    def click_action(self):
        if self.predicate == True:
            self.button = Button(text=self.front,
                                 color=(1, 0, 1, 1),
                                 background_color=(0, 0, 0, 0),
                                 font_size='20sp',
                                 on_release=self.click_action2)
            self.predicate = False
        else:
            self.button = Button(text=self.back,
                                 color=(1, 0, 1, 1),
                                 background_color=(0, 0, 0, 0),
                                 font_size='20sp',
                                 on_release=self.click_action2)
            self.predicate = True

        self.scrollview.add_widget(self.button)
        self.bottom_bar_name_def()

    def click_action2(self, instance):
        self.box.remove_widget(self.scrollview)
        self.remove_widget(self.bottom_bar)
        self.scrollview = ScrollView()
        if self.predicate == True:
            self.button = Button(text=self.front,
                                 color=(1, 0, 1, 1),
                                 background_color=(0, 0, 0, 0),
                                 font_size='20sp',
                                 on_release=self.click_action2)
            self.predicate = False
        else:
            self.button = Button(text=self.back,
                                 color=(1, 0, 1, 1),
                                 background_color=(0, 0, 0, 0),
                                 font_size='20sp',
                                 on_release=self.click_action2)
            self.predicate = True

        self.scrollview.add_widget(self.button)
        self.box.add_widget(self.scrollview)
        self.bottom_bar_name_def()

# displays bottom bar that will return user to displaying the list of decks

    def bottom_bar_name_def(self):
        self.bottom_bar = MDToolbar()
        #self.box = MDBoxLayout(orientation="horizontal")
        self.back_button = MDFlatButton(text="Return to Decks",
                                        pos_hint={
                                            'center_x': 0.5,
                                            'center_y': 0.5
                                        })
        self.back_button.bind(on_press=self.back_display_cards)
        #self.box.add_widget(self.back_button)
        #self.box.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.back_button)
        self.add_widget(self.bottom_bar)

    def back_display_cards(self, instance):
        self.box.remove_widget(self.scrollview)
        self.remove_widget(self.bottom_bar)
        self.skeleton_frame()

# method to build a new deck using a dialog box

    def build_new_deck(self, instance):
        close_button = MDFlatButton(text="Close", on_release=self.close_dialog)

        # *** This button will put name into db, then refresh the page
        enter_button = MDFlatButton(text="Enter",
                                    on_release=self.add_name_to_db)
        self.input = MDTextField(pos_hint={
            'center_x': 0.5,
            'center_y': 0.5
        },
                                 size_hint=(.9, 1))
        self.dialog = MDDialog(title="Enter Deck Name",
                               size_hint=(0.7, 1),
                               buttons=[close_button, enter_button])
        self.dialog.add_widget(self.input)
        self.dialog.open()

# method to close the dialog box

    def close_dialog(self, instance):
        self.dialog.dismiss()


#method that inserts the deck name into db

    def add_name_to_db(self, instance):
        input = self.input.text

        # this will have an if else statement if an error was typed in
        #self.error = MDDialog()
        #self.error.open()
        conn = sqlite3.connect("flashcard_app.db")
        cur = conn.cursor()
        cur.execute(
            """
                INSERT INTO Decks (deckname)
                VALUES(?)""", (input, ))
        conn.commit()
        conn.close()
        self.remove_widget(self.box)
        self.skeleton_frame()
        print("boo")

    def delete_deck(self, instance):
        close_button = MDFlatButton(text="Close", on_release=self.close_dialog)
        delete_dialog_button = MDFlatButton(text="Delete",
                                            on_release=self.delete_deck_input)
        self.dialog = MDDialog(title="Delete Deck",
                               size_hint=(0.7, 1),
                               buttons=[close_button, delete_dialog_button])
        self.input = MDTextField()
        self.dialog.add_widget(self.input)
        self.dialog.open()

    def delete_deck_input(self, instance):
        input = self.input.text

        con = sqlite3.connect("flashcard_app.db")
        cur = con.cursor()
        cur.execute(
            """
        DELETE FROM Decks
        WHERE DeckName = ?;
        """, (input, ))

        cur.execute(
            """
        DELETE FROM Cards
        WHERE DeckName = ?;
        """, (input, ))
        con.commit()
        con.close()
        self.remove_widget(self.box)
        self.skeleton_frame()

    def delete_card(self, instance):
        close_button = MDFlatButton(text="Close", on_release=self.close_dialog)
        delete_dialog_button = MDFlatButton(text="Delete",
                                            on_release=self.delete_card_input)
        self.dialog = MDDialog(title="Delete Card",
                               size_hint=(0.7, 1),
                               buttons=[close_button, delete_dialog_button])
        self.input = MDTextField()
        self.dialog.add_widget(self.input)
        self.dialog.open()

    def delete_card_input(self, instance):
        input = self.input.text

        con = sqlite3.connect("flashcard_app.db")
        cur = con.cursor()
        cur.execute(
            """
        DELETE FROM Cards
        WHERE CardName = ?
        """, (input, ))
        con.commit()
        con.close()
        self.display_cards2()
Ejemplo n.º 27
0
class Review(Screen):
    def __init__(self, **kwargs):
        super(Review, self).__init__(**kwargs)
        self.predicate = True
        self.skeleton_frame()

    def skeleton_frame(self):
        # Displays all decks on the app
        self.box = MDBoxLayout(orientation="vertical")
        self.scrollview = ScrollView()
        self.list = MDList()
        self.scrollview.add_widget(self.list)

        # calls the activate_for_loop method
        self.display_deck()

        # Buttons on the bottom of the screen
        # Buttons are places on bottom of screen
        self.box.add_widget(
            MDLabel(size_hint=(0.2, 0.15)))  # Push down the list of buttons
        self.box.add_widget(self.scrollview)

        self.bottom_bar = MDToolbar()
        self.box.add_widget(self.bottom_bar)
        self.add_widget(self.box)

    def skeleton_frame2(self, instance):
        # Displays all decks on the app
        #self.box.remove_widget(self.complete_label)
        self.box.remove_widget(self.count_grid)
        self.box = MDBoxLayout(orientation="vertical")
        self.scrollview = ScrollView()
        self.list = MDList()
        self.scrollview.add_widget(self.list)

        # calls the activate_for_loop method
        self.display_deck()

        # Buttons on the bottom of the screen
        # Buttons are places on bottom of screen
        self.box.add_widget(
            MDLabel(size_hint=(0.2, 0.15)))  # Push down the list of buttons
        self.box.add_widget(self.scrollview)

        self.bottom_bar = MDToolbar()
        self.box.add_widget(self.bottom_bar)
        self.add_widget(self.box)

    def display_deck(self):
        conn = sqlite3.connect("flashcard_app.db")
        cur = conn.cursor()
        cur.execute("""
        SELECT DeckName 
        FROM Decks
        """)
        names = cur.fetchall()
        for name in names:
            # the nested for loop will remove (),' from the string
            name = str(name)
            for char in name:
                if char == "(" or char == ")" or char == "," or char == "'":
                    name = name.replace(char, "")
            self.items = OneLineListItem(text=name)
            self.items.bind(on_press=self.review_deck)
            self.list.add_widget(self.items)
        conn.commit()
        conn.close()


# screen will display the review section

    def review_deck(self, instance):
        self.num = 0
        self.count = 0
        self.review_cardname = ["This deck is empty"]
        self.review_definition = ["This deck is empty"]
        self.scrollview.remove_widget(self.list)
        self.box.remove_widget(self.bottom_bar)
        con = sqlite3.connect("flashcard_app.db")
        cur = con.cursor()
        cur.execute(
            """
        SELECT CardName, Definition
        FROM Cards
        WHERE DeckName = ?
        """, (instance.text, ))
        row = cur.fetchall()
        for cardname, definition in row:
            self.review_cardname.append(cardname)
            self.review_definition.append(definition)
            self.front = cardname
            self.back = definition
            print(self.front, self.back)
        print(self.review_cardname)
        if len(self.review_cardname) != 1 and len(self.review_definition) != 1:
            self.review_cardname.remove("This deck is empty")
            self.review_definition.remove("This deck is empty")

        con.commit()
        con.close()
        self.click_action()

    def click_action(self):
        if self.predicate == True:
            self.button = Button(text=self.review_cardname[self.num],
                                 color=(1, 0, 1, 1),
                                 background_color=(0, 0, 0, 0),
                                 font_size='20sp',
                                 on_release=self.click_action2)
            self.predicate = False
        else:
            self.button = Button(text=self.review_definition[self.num],
                                 color=(1, 0, 1, 1),
                                 background_color=(0, 0, 0, 0),
                                 font_size='20sp',
                                 on_release=self.click_action2)
            self.predicate = True

        self.scrollview.add_widget(self.button)
        self.bottom_bar_name_def()

    def click_action2(self, instance):
        self.box.remove_widget(self.scrollview)
        self.remove_widget(self.bottom_bar)
        self.scrollview = ScrollView()
        if self.predicate == True:
            self.button = Button(text=self.review_cardname[self.num],
                                 color=(1, 0, 1, 1),
                                 background_color=(0, 0, 0, 0),
                                 font_size='20sp',
                                 on_release=self.click_action2)
            self.predicate = False
        else:
            self.button = Button(text=self.review_definition[self.num],
                                 color=(1, 0, 1, 1),
                                 background_color=(0, 0, 0, 0),
                                 font_size='20sp',
                                 on_release=self.click_action2)
            self.predicate = True

        self.scrollview.add_widget(self.button)
        self.box.add_widget(self.scrollview)
        self.bottom_bar_name_def()

    def bottom_bar_name_def(self):
        self.bottom_bar = MDToolbar()
        self.pass_button = MDIconButton(icon="check-bold",
                                        pos_hint={
                                            'center_x': 0.5,
                                            'center_y': 0.5
                                        },
                                        on_release=self.next_card_pass)
        self.fail_button = MDIconButton(icon="close-box-outline",
                                        pos_hint={
                                            'center_x': 0.5,
                                            'center_y': 0.5
                                        },
                                        on_release=self.next_card_fail)
        self.tag_button = MDIconButton(icon="star-circle",
                                       pos_hint={
                                           'center_x': 0.5,
                                           'center_y': 0.5
                                       })
        #self.back_button.bind(on_press=self.back_display_cards)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.fail_button)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.tag_button)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(self.pass_button)
        self.bottom_bar.add_widget(MDLabel())
        self.bottom_bar.add_widget(MDLabel())
        self.add_widget(self.bottom_bar)

    def bottom_bar_complete(self):
        self.bottom_bar = MDToolbar()
        self.return_review = MDFlatButton(text="Return to Decks",
                                          pos_hint={
                                              'center_x': .5,
                                              'center_y': .5
                                          },
                                          on_release=self.skeleton_frame2)
        self.bottom_bar.add_widget(self.return_review)
        self.add_widget(self.bottom_bar)

    def back_display_cards(self, instance):
        self.box.remove_widget(self.scrollview)
        self.remove_widget(self.bottom_bar)
        self.skeleton_frame()

    def next_card_pass(self, instance):
        self.count += 1
        self.num += 1
        self.predicate = True
        if self.num == len(self.review_cardname):
            self.box.remove_widget(self.scrollview)
            self.remove_widget(self.bottom_bar)
            self.get_result()
            #self.complete_label = MDLabel(text="Complete")
            #self.box.add_widget(self.complete_label)
            self.bottom_bar_complete()

        else:
            self.click_action2(instance)

    def next_card_fail(self, instance):
        self.num += 1
        self.predicate = True
        if self.num == len(self.review_cardname):
            self.box.remove_widget(self.scrollview)
            self.remove_widget(self.bottom_bar)
            self.get_result()
            #self.complete_label = MDLabel(text="Complete")
            #self.box.add_widget(self.complete_label)
            self.bottom_bar_complete()

        else:
            self.click_action2(instance)

    def get_result(self):

        self.count_grid = MDGridLayout(cols=3)
        self.count_label = MDLabel(text=str(self.count),
                                   size_hint_x=None,
                                   width=20)
        self.divider = MDLabel(text="/", size_hint_x=None, width=20)
        self.total_num = MDLabel(text=str(len(self.review_cardname)),
                                 size_hint_x=None,
                                 width=20)

        self.count_grid.add_widget(self.count_label)
        self.count_grid.add_widget(self.divider)
        self.count_grid.add_widget(self.total_num)
        self.box.add_widget(self.count_grid)
        self.box.add_widget(MDLabel())
        self.box.add_widget(MDLabel())
class Test(MDGridLayout, MDApp, Widget):
    '''這是螢幕主畫面(不包含一開始進去tutorial,tutorial在650多行那邊的on_start()'''
    '''這邊到300行出頭是一開始進去後會難到的配置,300多行後會是按完Run之後會秀出來的畫面'''

    progress_bar = ObjectProperty()

    def __init__(self, **kwargs):
        super(Test, self).__init__(**kwargs)

        self.click = 0

        # ---以下定義點擊前三名按鈕時的次數---
        self.add1 = 0
        self.add1_shop_list = []
        self.add1_temp_list = []
        self.add1_rent_list = []
        self.add1_bound = []
        self.bound1 = GeoJsonMapLayer()

        self.add2 = 0
        self.add2_shop_list = []
        self.add2_temp_list = []
        self.add2_rent_list = []
        self.add2_bound = []
        self.bound2 = GeoJsonMapLayer()

        self.add3 = 0
        self.add3_shop_list = []
        self.add3_temp_list = []
        self.add3_rent_list = []
        self.add3_bound = []
        self.bound3 = GeoJsonMapLayer()

        # from geopy.geocoders import Nominatim
        # self.geolocator = Nominatim(user_agent="Brian_map")

        # self.wid = Widget()
        self.progress_bar = MDProgressBar()
        self.popup = MDDialog(title='數據加載中,請稍後!',

                              #content = self.progress_bar
                              )
        self.popup.auto_dismiss = False
        self.popup.add_widget(self.progress_bar)
        self.popup.children[1].size_hint = [1, 1]
        self.popup.children[1].children[5].font_size = 40
        self.popup.children[1].children[5].font_name = 'msjhbd.ttc'
        self.popup.size_hint = [0.5, 0.5]
        self.popup.background_color = [0.5, 0.5, 0.5, 0.75]
        self.progress_bar.value = 1
        self.popup.bind(on_open=self.puopen)

        # 主畫面切成左右兩欄
        self.cols = 3

        # 左欄是一個Gridlayout,有四列
        self.left = MDGridLayout(rows=6, size_hint=[0.4, 1], spacing=[0, 3])
        # 創建地圖
        self.map = FarmersMapView()

        # 左欄最上方要來做店租範圍
        self.left.one = MDGridLayout(size=[590, 657],
                                     rows=2,
                                     size_hint=[1, 0.2],
                                     md_bg_color=[0.39, 0.4, 0.72, 1],
                                     padding=[35, -20, 35, -20],
                                     spacing=[0, -30])
        # 把標籤裝進去最上層
        self.left.one.add_widget(
            Label(text='選擇月租範圍',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  size_hint_y=0.18))
        # 新增一層容器準備裝三個東西
        self.left.one.box = BoxLayout(spacing=8, size_hint_y=0.15)
        # 盒子裝進一個下限input、一上限input、一個'-'tag
        self.lower_bound = MDTextFieldRect(x=275,
                                           hint_text="$下限",
                                           font_name='msjhbd.ttc',
                                           pos_hint={'y': 0.45},
                                           size_hint=[1.5, 0.5],
                                           use_bubble=True,
                                           use_handles=True)
        self.upper_bound = MDTextFieldRect(hint_text="$上限",
                                           font_name='msjhbd.ttc',
                                           pos_hint={'y': 0.45},
                                           center_x=275.76,
                                           center_y=508.20,
                                           size_hint=[1.5, 0.5],
                                           use_bubble=True,
                                           use_handles=True)
        self.dash_sign = MDFlatButton(text='-',
                                      font_size=30,
                                      size_hint=[1, 0.49],
                                      pos_hint={'y': 0.45})
        self.dash_sign.md_bg_color = [1, 1, 1, 1]
        self.left.one.box.add_widget(self.lower_bound)
        self.left.one.box.add_widget(self.dash_sign)
        self.left.one.box.add_widget(self.upper_bound)
        # 盒子裝回上層
        self.left.one.add_widget(self.left.one.box)

        # 新增行政區選單
        self.left.six = MDGridLayout(size=[590, 657],
                                     rows=2,
                                     size_hint=[1, 0.25],
                                     md_bg_color=[0.39, 0.4, 0.72, 1],
                                     padding=[35, -5, 35, 5],
                                     spacing=[0, -10])
        self.left.six.add_widget(
            Label(text='行政區選擇',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.1]))
        self.left.six.box = BoxLayout(size_hint_y=0.15, center_y=390)
        from kivy.uix.spinner import Spinner
        district = [
            "中區", "東區", "西區", "南區", "北區", "西屯區", "南屯區", "北屯區", "豐原區", "大里區",
            "太平區", "清水區", "沙鹿區", "大甲區", "東勢區", "梧棲區", "烏日區", "神岡區", "大肚區",
            "大雅區", "后里區", "霧峰區", "潭子區", "龍井區", "外埔區", "和平區", "石岡區", "大安區",
            "新社區"
        ]
        self.spinner = Spinner(
            text='行政區',
            values=[n for n in district],
            size_hint=(None, None),
            size=(95, 44),
            #pos_hint = {'right':0.2},
            font_name='msjhbd.ttc',
            background_color=[1, 0, 0, 1])
        self.spinner.option_cls.font_name = 'msjhbd.ttc'
        self.spinner.option_cls.background_color = [1, 0, 0, 1]
        #self.spinner.values[0].font_name = 'msjhbd.ttc'
        self.spinner.dropdown_cls.max_height = self.spinner.height * 7 + 7 * 4
        #self.spinner.center_x = 160
        #self.left.six.box.add_widget(BoxLayout(size_hint_y=0.5, size_hint_x=0.5, width=100))
        self.left.six.box.add_widget(
            MDGridLayout(md_bg_color=[0.39, 0.4, 0.72, 1],
                         size_hint=[None, 0.5]))
        self.left.six.box.add_widget(self.spinner)
        self.left.six.add_widget(self.left.six.box)
        #self.left.six.box.children[0].center = (160, 522.1339285)
        #self.spinner.pos_hint = {'right':0.9}
        #self.spinner.center_x = 150

        # 這裡是畫面左欄第二格
        self.left.two = MDGridLayout(rows=2,
                                     size_hint=[1, None],
                                     size=[365, 170],
                                     md_bg_color=[0.39, 0.4, 0.72, 1])
        #self.left.two.center_y = 400
        # 把"指標排序"標籤裝進第二格子的上方
        self.left.two.add_widget(
            Label(text='指標排序',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.1]))
        # 左欄第二格下方增加一個grid容器
        self.left.two.grid = MDGridLayout(rows=3,
                                          size_hint=[1, 0.26],
                                          padding=[30, 0, 20, 0])
        self.left.two.grid.size_hint = [1, 0.26]
        self.left.two.add_widget(self.left.two.grid)
        # 準備三個box放入此grid
        self.left.two.box1 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.box2 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.box3 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.grid.add_widget(self.left.two.box1)
        self.left.two.grid.add_widget(self.left.two.box2)
        self.left.two.grid.add_widget(self.left.two.box3)
        # 處理第一個box的標籤(全用按鈕取代)、輸入
        self.left.two.btn1 = MDRaisedButton(text='      人口特性      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn1.md_bg_color = [0.55, 0.63, 0.99, 1]
        self.left.two.input1 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input1.size_hint_x = None
        self.left.two.input1.width = 120
        self.left.two.box1.add_widget(self.left.two.btn1)
        self.left.two.box1.add_widget(self.left.two.input1)

        self.left.two.btn3 = MDRaisedButton(text='      薪資所得      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn3.md_bg_color = [0.68, 0.82, 0.96, 1]
        self.left.two.input3 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input3.size_hint_x = None
        self.left.two.input3.width = 120
        self.left.two.box2.add_widget(self.left.two.btn3)
        self.left.two.box2.add_widget(self.left.two.input3)

        self.left.two.btn5 = MDRaisedButton(text='      人口消長      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn5.md_bg_color = [0.5, 0.87, 0.98, 1]
        self.left.two.input5 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input5.size_hint_x = None
        self.left.two.input5.width = 120
        self.left.two.box3.add_widget(self.left.two.btn5)
        self.left.two.box3.add_widget(self.left.two.input5)

        # 這裡是畫面左欄第三格
        self.left.three = MDGridLayout(rows=2,
                                       md_bg_color=[0.39, 0.4, 0.72, 1],
                                       size_hint=[1, 0.57])
        # 把"指標排序"標籤裝進第二格子的上方
        self.left.three.add_widget(
            Label(text='選擇競爭對手',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.06]))

        # 左欄第三格下方增加一個grid容器
        self.left.three.grid = MDGridLayout(rows=5,
                                            size_hint=[1, 0.26],
                                            spacing=3,
                                            padding=[30, 0, 40, 0])
        self.left.three.add_widget(self.left.three.grid)
        # 準備五個box放入此grid
        self.left.three.box1 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box2 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box3 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box4 = BoxLayout(size_hint=[1, 0.05])
        #self.left.three.box5 = BoxLayout(size_hint=[1, 0.4])
        self.left.three.box6 = BoxLayout()
        self.left.three.grid.add_widget(self.left.three.box1)
        self.left.three.grid.add_widget(self.left.three.box2)
        self.left.three.grid.add_widget(self.left.three.box3)
        self.left.three.grid.add_widget(self.left.three.box4)

        # 處理第一個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn1 = MDRaisedButton(text='       早餐店         ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn1.md_bg_color = [0.55, 0.63, 0.99, 1]
        self.left.three.input1 = MDCheckbox()
        self.left.three.input1.x = 140
        self.left.three.input1.selected_color = (1, 1, 1, 1)
        self.left.three.input1.unselected_color = (1, 1, 1, 1)
        self.left.three.box1.add_widget(self.left.three.btn1)
        self.left.three.box1.add_widget(self.left.three.input1)
        # 處理第二個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn2 = MDRaisedButton(text='便當、自助餐店',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn2.md_bg_color = [0.48, 0.81, 0.78, 1]
        self.left.three.input2 = MDCheckbox()
        self.left.three.input2.x = 140
        self.left.three.input2.selected_color = (1, 1, 1, 1)
        self.left.three.input2.unselected_color = (1, 1, 1, 1)
        self.left.three.box2.add_widget(self.left.three.btn2)
        self.left.three.box2.add_widget(self.left.three.input2)
        # 處理第三個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn3 = MDRaisedButton(text='麵店、小吃店    ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn3.md_bg_color = [0.68, 0.82, 0.96, 1]
        self.left.three.input3 = MDCheckbox()
        self.left.three.input3.x = 140
        self.left.three.input3.selected_color = (1, 1, 1, 1)
        self.left.three.input3.unselected_color = (1, 1, 1, 1)
        self.left.three.box3.add_widget(self.left.three.btn3)
        self.left.three.box3.add_widget(self.left.three.input3)
        # 處理第四個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn4 = MDRaisedButton(text='      餐館餐廳      ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn4.md_bg_color = [0.62, 0.84, 0.51, 1]
        self.left.three.input4 = MDCheckbox()
        self.left.three.input4.x = 140
        #self.left.three.input4.color = [1,1,1,2]
        self.left.three.input4.selected_color = (1, 1, 1, 1)
        self.left.three.input4.unselected_color = (1, 1, 1, 1)
        self.left.three.box4.add_widget(self.left.three.btn4)
        self.left.three.box4.add_widget(self.left.three.input4)

        self.run_button = MDRaisedButton(text='Run')

        # 製作廟宇按鈕
        self.left.four = MDGridLayout(rows=2,
                                      size_hint=[1, None],
                                      size=[365, 90],
                                      md_bg_color=[0.39, 0.4, 0.72, 1])
        self.left.four.add_widget(
            Label(text='廟宇出現與否',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.025]))
        self.left.four.box = BoxLayout(size_hint=[1, 0.025],
                                       padding=[30, -20, 40, 5])
        self.left.four.add_widget(self.left.four.box)
        self.left.four.btn = MDRaisedButton(text='          廟宇          ',
                                            font_name='msjhbd.ttc',
                                            size_hint=[None, 0.8],
                                            font_size='16sp')
        self.left.four.input = MDCheckbox()
        self.left.four.input.selected_color = (1, 1, 1, 1)
        self.left.four.input.unselected_color = (1, 1, 1, 1)
        self.left.four.box.add_widget(self.left.four.btn)
        self.left.four.box.add_widget(self.left.four.input)

        # 把每一層加回去
        self.left.add_widget(self.left.one)
        self.left.add_widget(self.left.six)
        self.left.add_widget(self.left.two)
        self.left.add_widget(self.left.three)
        self.left.add_widget(self.left.four)
        self.add_widget(self.left)
        self.add_widget(self.map)

        # 測試用的按鈕
        #self.run_button = MDRaisedButton(text='Run')
        self.left.five = MDGridLayout(size_hint=[1, 0.1],
                                      md_bg_color=[0.39, 0.4, 0.72, 1])
        self.left.five.add_widget(self.run_button)
        self.run_button.bind(on_release=self.popup.open)
        self.left.add_widget(self.left.five)
        self.run_button.right = 270
        self.run_button.ripple_alpha = 0.7
        self.run_button.radius = [10, 10, 10, 10]
        self.run_button.md_bg_color = [1, 1, 1, 1]
        self.run_button.text_color = [0, 0, 0, 1]
        #self.left.six.box.children[0].right = 150
        #self.left.six.box.right = 390
        #self.left.six.box.children[0].pos_hint = {'right':0.001, 'left':0.9}

        #self.left.four.box.pos_hint = {'top':0.5}

    def add_shop(self, neigh, clist, password):
        shop_list = gd.get_shop_codata(neigh, clist)
        # print(shop_list)
        #self.add1 += 1
        #print(self.add1)
        print('###add_shop_func###')
        if shop_list == ['no data']:
            print('')
        else:
            for shop in shop_list:
                lon = float(shop['coor'][1])
                lat = float(shop['coor'][0])
                marker = MapMarkerPopup(lat=lat, lon=lon, source="競爭對手_標點.png")
                marker.add_widget(
                    Button(text=neigh + '\n' + shop['name'] + '\n' +
                           shop['class'],
                           font_name='msjhbd.ttc',
                           font_size=15,
                           size_hint=[None, None],
                           size=[150, 150]))
                self.map.add_marker(marker)
                if (password == 1):
                    self.add1_shop_list.append(marker)
                elif (password == 2):
                    self.add2_shop_list.append(marker)
                elif (password == 3):
                    self.add3_shop_list.append(marker)
            #print(self.add1)
        # else:
        #     for marker in self.add1_shop_list:
        #         self.map.remove_marker(marker)
        #print('sucess')
    def clear_shop(self, password):

        print('###clear_shop_func###')

        if (password == 1):
            print("clear1!")
            for marker in self.add1_shop_list:
                self.map.remove_marker(marker)
            self.add1_shop_list.clear()
        elif (password == 2):
            print("clear2!")
            for marker in self.add2_shop_list:
                self.map.remove_marker(marker)
            self.add2_shop_list.clear()
        elif (password == 3):
            for marker in self.add3_shop_list:
                self.map.remove_marker(marker)
            self.add3_shop_list.clear()

    def add_temp(self, neigh, boolt, password):
        print('###add_temp_func###')

        temp_list = gd.get_temp_codata(neigh)
        # print(temp_list)
        if boolt == True:
            if temp_list == ['no data']:
                print('')
            else:
                for temp in temp_list:
                    lon = float(temp['coor'][1])
                    lat = float(temp['coor'][0])
                    marker = MapMarkerPopup(lat=lat,
                                            lon=lon,
                                            source="廟_標點.png")
                    marker.add_widget(
                        Button(text=neigh + '\n' + temp['name'],
                               font_name='msjhbd.ttc',
                               font_size=15,
                               size_hint=[None, None],
                               size=[100, 100]))
                    self.map.add_widget(marker)
                    if (password == 1):
                        self.add1_temp_list.append(marker)
                    elif (password == 2):
                        self.add2_temp_list.append(marker)
                        print('hoooooo')
                    elif (password == 3):
                        self.add3_temp_list.append(marker)
        else:
            print("")

    def clear_temp(self, password):
        print('###clear_temp_func###')

        if (password == 1):
            print("clear1!")
            for marker in self.add1_temp_list:
                print(marker)
                self.map.remove_marker(marker)
            self.add1_temp_list.clear()
        elif (password == 2):
            print("clear2!")
            for marker in self.add2_temp_list:
                print(marker)
                self.map.remove_marker(marker)
            self.add2_temp_list.clear()
        elif (password == 3):
            for marker in self.add3_temp_list:
                print(marker)
                self.map.remove_marker(marker)
            self.add3_temp_list.clear()

    def add_rent(self, password, neigh, Min_price=0, Max_price=100000000):
        print('###add_rent_func###')

        # print(Min_price, Max_price)
        rent_list = gd.get_rent_codata(neigh)
        # print(rent_list)
        if rent_list == ['no data']:
            print('')
        else:
            cou = 1
            for rent in rent_list:
                if (int(rent['price']) >= Min_price) & (int(rent['price']) <=
                                                        Max_price):
                    lon = float(rent['coor'][1])
                    lat = float(rent['coor'][0])
                    marker = MapMarkerPopup(lat=lat,
                                            lon=lon,
                                            source="店面_標點.png")
                    rent_button = Button(text=neigh + '\n' + '店面' + str(cou) +
                                         '\n' + rent['size'] + '\n' + '$' +
                                         rent['price'] + '/月',
                                         font_name='msjhbd.ttc',
                                         font_size=15,
                                         size_hint=[None, None],
                                         size=[100, 100])
                    rent_button.bind(
                        on_press=partial(webbrowser.open, rent['web']))
                    marker.add_widget(rent_button)
                    self.map.add_widget(marker)
                    cou += 1
                    if (password == 1):
                        self.add1_rent_list.append(marker)
                    elif (password == 2):
                        self.add2_rent_list.append(marker)
                    elif (password == 3):
                        self.add3_rent_list.append(marker)

    def clear_rent(self, password):
        print('###clear_rent_func###')

        if (password == 1):
            print("clear1!")
            for marker in self.add1_rent_list:
                self.map.remove_marker(marker)
            self.add1_rent_list.clear()
        elif (password == 2):
            print("clear2!")
            for marker in self.add2_rent_list:
                self.map.remove_marker(marker)
            self.add2_rent_list.clear()
        elif (password == 3):
            for marker in self.add3_rent_list:
                self.map.remove_marker(marker)
            self.add3_rent_list.clear()

    # def add_border(self, filename):
    #     import os, sys
    #     import json
    #     with open(os.path.realpath(sys.argv[0]).strip(sys.argv[0])+"data\\"+"鄰里邊界\\"+filename, 'r', encoding = 'utf-8') as f:
    #         data = json.load(f)
    #     for i in data['features'][0]['geometry']['coordinates'][0]:
    #         lon = i[0]
    #         lat = i[1]
    #         marker = MapMarkerPopup(lon=lon, lat=lat, source='邊界.png')
    #         self.map.add_widget(marker)

    def add_boundary(self, password):
        print('###add_boundary_func###')

        print('我要密碼')
        print(password)
        # if(self.add1 == 1 and password == 1):
        #     self.bound1 = GeoJsonMapLayer()
        # elif(self.add2 == 1 and password == 2):
        #     self.bound2 = GeoJsonMapLayer()
        # if(self.add3 == 1 and password == 3):
        #     self.bound3 = GeoJsonMapLayer()
        #self.bound3 = GeoJsonMapLayer()

        # if(password == 1):
        #     print('1號邊界成功')
        #     #print("梧棲區\\" + self.rank1.text + ".json")

        #     self.bound1.source = os.path.realpath(sys.argv[0]).strip(sys.argv[0]) + "梧棲區\\" + self.rank1.text + ".json"
        #     self.add1_bound.append(self.bound1)
        #     self.map.add_layer(self.bound1)
        if (password == 1):

            self.bound1.source = os.path.realpath(sys.argv[0]).strip(
                sys.argv[0]
            ) + "data\\" + "鄰里邊界\\" + self.spinner.text + "\\" + self.rank1.text + ".json"

            self.add1_bound.append(self.bound1)
            self.map.add_layer(self.bound1)
        elif (password == 2):

            self.bound2.source = os.path.realpath(sys.argv[0]).strip(
                sys.argv[0]
            ) + "data\\" + "鄰里邊界\\" + self.spinner.text + "\\" + self.rank2.text + ".json"
            self.add2_bound.append(self.bound2)
            self.map.add_layer(self.bound2)
        elif (password == 3):

            self.bound3.source = os.path.realpath(sys.argv[0]).strip(
                sys.argv[0]
            ) + "data\\" + "鄰里邊界\\" + self.spinner.text + "\\" + self.rank3.text + ".json"

            self.add3_bound.append(self.bound3)
            self.map.add_layer(self.bound3)
        # elif(password == 3):
        #     print(password)

        #     self.bound3.source = os.path.realpath(sys.argv[0]).strip(sys.argv[0]) + "梧棲區\\" + self.rank3.text + ".json"
        #     self.add3_bound.append(self.bound3)
        #     self.map.add_layer(self.bound3)
        # if(password == 1):
        #     self.bound1.source = os.path.realpath(sys.argv[0]).strip(sys.argv[0]) + "梧棲區\\" + self.rank1.text + ".json"
        #     #print(bound1.source)
        #     self.add1_bound.append(self.bound1)
        #     print("我是密碼" + str(password))
        #     print(self.rank1.text)
        # elif(password == 2):
        #     self.bound2.source = os.path.realpath(sys.argv[0]).strip(sys.argv[0]) + "梧棲區\\" + self.rank2.text + ".json"
        #     #print(self.bound2.source)
        #     self.add2_bound.append(self.bound2)
        #     print("我是密碼" + str(password))
        #     print(self.rank2.text)
        # elif(password == 3):
        #     self.bound3.source = os.path.realpath(sys.argv[0]).strip(sys.argv[0]) + "梧棲區\\" + self.rank3.text + ".json"
        #     self.add3_bound.append(self.bound3)
        #     print("我是密碼" + str(password))

        # if(password == 1):
        #     self.map.add_layer(self.bound1)
        # elif(password == 2):
        #     self.map.add_layer(self.bound2)
        # elif(password == 3):
        #     self.map.add_layer(self.bound3)

    def remove_boundary(self, password):
        print('###remove_boundary_func###')

        #target = None
        # if(password == 1):
        #     for a in self.add1_bound:
        #         self.map.remove_layer(a)
        #         self.add1_bound.clear()
        if (password == 1):
            for b in self.add1_bound:
                self.map.remove_layer(b)
                self.add1_bound.clear()
        elif (password == 2):
            for b in self.add2_bound:
                self.map.remove_layer(b)
                self.add2_bound.clear()
        elif (password == 3):
            for b in self.add3_bound:
                self.map.remove_layer(b)
                self.add3_bound.clear()
        # elif(password == 3):
        #     for c in self.add3_bound:
        #         self.map.remove_layer(c)
        #         self.add3_bound.clear()
        #print(target, end=',,')
        #self.map.remove_layer(target[0])
        #target.clear()
        #print(target, end=',,')

    '''pressed定義Run之後處理數據並放到資訊卡上的事件'''

    acard = None

    def pressed(self, instance):
        print(self.spinner.text)
        #print(self.spinner.text)
        top3_rank = final_combiner.final_rank([
            int(self.left.two.input1.text),
            int(self.left.two.input3.text),
            int(self.left.two.input5.text)
        ])
        if not self.acard:
            self.rank1 = ThreeLineIconListItem(
                text=top3_rank[0][0],
                secondary_text='人口特性:' + str(top3_rank[0][1]),
                tertiary_text='新資所得:' + str(top3_rank[0][2]),
                text_color=[1, 1, 1, 1])
            self.rank1.add_widget(IconLeftWidget(icon='numeric-1-box'))
            self.rank1.bg_color = [0, 0, 0, 0]
            self.rank1.children[1].children[2].font_name = 'msjhbd.ttc'
            self.rank1.children[1].children[1].font_name = 'msjhbd.ttc'
            self.rank1.children[1].children[0].font_name = 'msjhbd.ttc'
            self.rank1.children[1].children[2].font_size = '18'

            more_rank1 = MDLabel(text='人口消長:' + str(top3_rank[0][3]))
            more_rank1.font_name = 'msjhbd.ttc'
            more_rank1.font_style = 'Body1'
            more_rank1.font_size = 16
            more_rank1.color = [0, 0, 0, 0.7]
            self.rank1.children[1].add_widget(more_rank1)
            self.rank1.children[1].size_hint = [1, None]
            self.rank1.children[1].children[3].pos = [56, 280]

            self.rank1.children[0].children[0].children[0].color = [1, 1, 1, 1]
            self.rank1.children[0].children[0].children[0].pos_hint = {
                'left': 0.1
            }
            self.rank1.children[0].padding = [-10, 0, 0, 0]
            self.rank1.children[1].children[3].theme_text_color = 'Custom'
            self.rank1.children[1].children[3].text_color = [1, 1, 1, 1]
            self.rank1.children[1].children[2].theme_text_color = 'Custom'
            self.rank1.children[1].children[2].text_color = [1, 1, 1, 1]
            self.rank1.children[1].children[1].theme_text_color = 'Custom'
            self.rank1.children[1].children[1].text_color = [1, 1, 1, 1]
            self.rank1.children[1].children[0].theme_text_color = 'Custom'
            self.rank1.children[1].children[0].text_color = [1, 1, 1, 1]
            # 從另一個預先寫好、計算各里指標分數的模組final_combiner引進final_rank函數,取得前三名的區域及其各項指標分數後用top3_rank變數紀錄起來
            # 接著改寫、擴充kivy套件內的工具(ThreeLineIconListItem),做成資訊卡,同時使其擁有按鈕的特性讓使用者做點選

            self.rank2 = ThreeLineIconListItem(
                text=top3_rank[1][0],
                secondary_text='人口特性:' + str(top3_rank[1][1]),
                tertiary_text='新資所得:' + str(top3_rank[1][2]))
            self.rank2.add_widget(IconLeftWidget(icon='numeric-2-box'))
            self.rank2.bg_color = [0, 0, 0, 0]

            self.rank2.children[1].children[2].font_size = '18'
            self.rank2.children[1].children[2].font_name = 'msjhbd.ttc'
            self.rank2.children[1].children[1].font_name = 'msjhbd.ttc'
            self.rank2.children[1].children[0].font_name = 'msjhbd.ttc'

            more_rank2 = MDLabel(text='人口消長:' + str(top3_rank[1][3]))
            more_rank2.font_name = 'msjhbd.ttc'
            more_rank2.font_style = 'Body1'
            more_rank2.font_size = 16
            more_rank2.color = [0, 0, 0, 0.54]
            self.rank2.children[1].add_widget(more_rank2)
            self.rank2.children[1].size_hint = [1, None]

            self.rank2.children[0].children[0].children[0].color = [1, 1, 1, 1]
            self.rank2.children[0].children[0].children[0].pos_hint = {
                'left': 0.1
            }
            self.rank2.children[0].padding = [-10, 0, 0, 0]
            self.rank2.children[1].children[3].theme_text_color = 'Custom'
            self.rank2.children[1].children[3].text_color = [1, 1, 1, 1]
            self.rank2.children[1].children[2].theme_text_color = 'Custom'
            self.rank2.children[1].children[2].text_color = [1, 1, 1, 1]
            self.rank2.children[1].children[1].theme_text_color = 'Custom'
            self.rank2.children[1].children[1].text_color = [1, 1, 1, 1]
            self.rank2.children[1].children[0].theme_text_color = 'Custom'
            self.rank2.children[1].children[0].text_color = [1, 1, 1, 1]

            self.rank3 = ThreeLineIconListItem(
                text=top3_rank[2][0],
                secondary_text='人口特性:' + str(top3_rank[2][1]),
                tertiary_text='新資所得:' + str(top3_rank[2][2]))
            self.rank3.add_widget(IconLeftWidget(icon='numeric-3-box'))
            self.rank3.bg_color = [0, 0, 0, 0]

            self.rank3.children[1].children[2].font_size = '18'
            self.rank3.children[1].children[2].font_name = 'msjhbd.ttc'
            self.rank3.children[1].children[1].font_name = 'msjhbd.ttc'
            self.rank3.children[1].children[0].font_name = 'msjhbd.ttc'

            more_rank3 = MDLabel(text='人口消長:' + str(top3_rank[2][3]))
            more_rank3.font_name = 'msjhbd.ttc'
            more_rank3.font_style = 'Body1'
            more_rank3.font_size = 16
            more_rank3.color = [0, 0, 0, 0.54]
            self.rank3.children[1].add_widget(more_rank3)
            self.rank3.children[1].size_hint = [1, None]

            self.rank3.children[0].children[0].children[0].color = [1, 1, 1, 1]
            self.rank3.children[0].children[0].children[0].pos_hint = {
                'left': 0.1
            }
            self.rank3.children[0].padding = [-10, 0, 0, 0]
            self.rank3.children[1].children[3].theme_text_color = 'Custom'
            self.rank3.children[1].children[3].text_color = [1, 1, 1, 1]
            self.rank3.children[1].children[2].theme_text_color = 'Custom'
            self.rank3.children[1].children[2].text_color = [1, 1, 1, 1]
            self.rank3.children[1].children[1].theme_text_color = 'Custom'
            self.rank3.children[1].children[1].text_color = [1, 1, 1, 1]
            self.rank3.children[1].children[0].theme_text_color = 'Custom'
            self.rank3.children[1].children[0].text_color = [1, 1, 1, 1]

            self.rank1.size = [352, 100]
            self.rank2.size = [352, 100]
            self.rank3.size = [352, 100]

            self.click += 1

            self.rank1.children[1].padding = [56, 16, 24, 7]
            self.rank2.children[1].padding = [56, 4, 24, 7]
            self.rank3.children[1].padding = [56, 4, 24, 7]

            self.rank1.children[1].children[0].adaptive_height = True
            self.rank1.children[1].pos = [0, 180]
            self.rank2.children[1].children[1].adaptive_height = True
            self.rank2.children[1].pos = [0, 130]
            self.rank3.children[1].children[1].adaptive_height = True

            self.add_widget(
                MDGridLayout(cols=1,
                             size_hint=[0.285, 1],
                             md_bg_color=[0.39, 0.4, 0.72, 1]))
            self.children[0].add_widget(self.rank1)
            self.children[0].add_widget(self.rank2)
            self.children[0].add_widget(self.rank3)

            self.rank1.bind(on_release=self.add_renk1_marker)
            self.rank2.bind(on_release=self.add_renk2_marker)
            self.rank3.bind(on_release=self.add_renk3_marker)

    ''' 當初設計沒有想好架構,導致要再次定義pressed事件(第二次之後的Run),如果是如果是第二次點擊Run之後要重新更新資訊卡的內容'''

    def second_pressed(self, instance):
        for i in range(1, 4):
            self.clear_shop(i)
            self.clear_temp(i)
            self.clear_rent(i)
            self.remove_boundary(i)
        self.add1 = 0
        self.add2 = 0
        self.add3 = 0
        #self.map.children[0].unload()
        top3_rank = final_combiner.final_rank([
            int(self.left.two.input1.text),
            int(self.left.two.input3.text),
            int(self.left.two.input5.text)
        ])
        self.rank1.children[1].children[3].text = top3_rank[0][0]
        self.rank1.children[1].children[2].text = "人口特性:" + str(
            top3_rank[0][1])
        self.rank1.children[1].children[1].text = "新資所得:" + str(
            top3_rank[0][2])
        self.rank1.children[1].children[0].text = "人口消長:" + str(
            top3_rank[0][3])

        self.rank2.children[1].children[3].text = top3_rank[1][0]
        self.rank2.children[1].children[2].text = "人口特性:" + str(
            top3_rank[1][1])
        self.rank2.children[1].children[1].text = "新資所得:" + str(
            top3_rank[1][2])
        self.rank2.children[1].children[0].text = "人口消長:" + str(
            top3_rank[1][3])

        self.rank3.children[1].children[3].text = top3_rank[2][0]
        self.rank3.children[1].children[2].text = "人口特性:" + str(
            top3_rank[2][1])
        self.rank3.children[1].children[1].text = "新資所得:" + str(
            top3_rank[2][2])
        self.rank3.children[1].children[0].text = "人口消長:" + str(
            top3_rank[2][3])
        self.rank1.bind(on_release=self.add_renk1_marker)
        self.rank2.bind(on_release=self.add_renk2_marker)
        self.rank3.bind(on_release=self.add_renk3_marker)

    def add_renk1_marker(self, instance):
        # print(len(self.map.children[2]))
        cla_list = [
            self.left.three.btn1.text.strip(),
            self.left.three.btn2.text.strip(),
            self.left.three.btn3.text.strip(),
            self.left.three.btn4.text.strip()
        ]
        ch_list = [
            self.left.three.input1.active, self.left.three.input2.active,
            self.left.three.input3.active, self.left.three.input4.active
        ]
        #print(cla_list, ch_list)
        act_list = []
        for cont in range(4):
            if ch_list[cont] == True:
                act_list.append(cla_list[cont])
        #print(self.rank1.text)
        self.add1 += 1

        if (self.add1 % 2 == 1):
            self.add_boundary(1)
            self.add_shop(self.rank1.text, act_list, 1)
            self.add_temp(self.rank1.text, self.left.four.input.active, 1)
            self.add_rent(1, self.rank1.text, int(self.lower_bound.text),
                          int(self.upper_bound.text))

            # location = self.geolocator.geocode("梧棲區大庄里")
            # self.map.center_on(location.latitude , location.longitude)
            self.map.center_on(24.2454073, 120.54976945174974)
        elif (self.add1 % 2 == 0):
            self.remove_boundary(1)
            self.clear_shop(1)
            self.clear_temp(1)
            self.clear_rent(1)

        # filename = self.rank1.text + ".json"
        # self.add_border(filename)

        self.map.zoom = 13
        # from geopy.geocoders import Nominatim
        # geolocator = Nominatim(user_agent="Brian_map")

    def add_renk2_marker(self, instance):
        cla_list = [
            self.left.three.btn1.text.strip(),
            self.left.three.btn2.text.strip(),
            self.left.three.btn3.text.strip(),
            self.left.three.btn4.text.strip()
        ]
        ch_list = [
            self.left.three.input1.active, self.left.three.input2.active,
            self.left.three.input3.active, self.left.three.input4.active
        ]

        act_list = []
        for cont in range(4):
            if ch_list[cont] == True:
                act_list.append(cla_list[cont])

        self.add2 += 1

        if (self.add2 % 2 == 1):
            self.add_boundary(2)
            self.add_shop(self.rank2.text, act_list, 2)
            self.add_temp(self.rank2.text, self.left.four.input.active, 2)
            self.add_rent(2, self.rank2.text, int(self.lower_bound.text),
                          int(self.upper_bound.text))

            # location = self.geolocator.geocode("梧棲區大村里")
            # self.map.center_on(location.latitude , location.longitude)
            self.map.center_on(24.2549239, 120.5316259)
        elif (self.add2 % 2 == 0):
            self.remove_boundary(2)
            self.clear_shop(2)
            self.clear_temp(2)
            self.clear_rent(2)

    def add_renk3_marker(self, instance):
        cla_list = [
            self.left.three.btn1.text.strip(),
            self.left.three.btn2.text.strip(),
            self.left.three.btn3.text.strip(),
            self.left.three.btn4.text.strip()
        ]
        ch_list = [
            self.left.three.input1.active, self.left.three.input2.active,
            self.left.three.input3.active, self.left.three.input4.active
        ]

        act_list = []
        for cont in range(4):
            if ch_list[cont] == True:
                act_list.append(cla_list[cont])

        self.add3 += 1

        if (self.add3 % 2 == 1):
            self.add_boundary(3)
            self.add_shop(self.rank3.text, act_list, 3)
            self.add_temp(self.rank3.text, self.left.four.input.active, 3)
            self.add_rent(3, self.rank3.text, int(self.lower_bound.text),
                          int(self.upper_bound.text))

            # location = self.geolocator.geocode("梧棲區大村里")
            # self.map.center_on(location.latitude , location.longitude)
            self.map.center_on(24.2570033, 120.53346300048884)
        elif (self.add3 % 2 == 0):
            self.remove_boundary(3)
            self.clear_shop(3)
            self.clear_temp(3)
            self.clear_rent(3)

    '''進度條跑到滿格時,要讓他reset變1'''

    def progress_reset(self, run):
        self.progress_bar.value = 1

    '''讓進度條要一直往右跑,如果滿了就要關掉進度條畫面'''

    def next(self, dt):
        self.progress_bar.value += 6
        if self.progress_bar.value >= 100:

            Clock.schedule_once(self.popup.dismiss, 0.5)
            if self.click == 0:
                Clock.schedule_once(self.pressed, 0.6)
            else:
                Clock.schedule_once(self.second_pressed, 0.6)
            #else:
            Clock.unschedule(self.new)
            Clock.schedule_once(self.progress_reset, 0.6)

    '''定義進度條跑的速率'''

    def puopen(self, instance):

        self.new = Clock.schedule_interval(self.next, 1 / 20)
    def __init__(self, **kwargs):
        super(Test, self).__init__(**kwargs)

        self.click = 0

        # ---以下定義點擊前三名按鈕時的次數---
        self.add1 = 0
        self.add1_shop_list = []
        self.add1_temp_list = []
        self.add1_rent_list = []
        self.add1_bound = []
        self.bound1 = GeoJsonMapLayer()

        self.add2 = 0
        self.add2_shop_list = []
        self.add2_temp_list = []
        self.add2_rent_list = []
        self.add2_bound = []
        self.bound2 = GeoJsonMapLayer()

        self.add3 = 0
        self.add3_shop_list = []
        self.add3_temp_list = []
        self.add3_rent_list = []
        self.add3_bound = []
        self.bound3 = GeoJsonMapLayer()

        # from geopy.geocoders import Nominatim
        # self.geolocator = Nominatim(user_agent="Brian_map")

        # self.wid = Widget()
        self.progress_bar = MDProgressBar()
        self.popup = MDDialog(title='數據加載中,請稍後!',

                              #content = self.progress_bar
                              )
        self.popup.auto_dismiss = False
        self.popup.add_widget(self.progress_bar)
        self.popup.children[1].size_hint = [1, 1]
        self.popup.children[1].children[5].font_size = 40
        self.popup.children[1].children[5].font_name = 'msjhbd.ttc'
        self.popup.size_hint = [0.5, 0.5]
        self.popup.background_color = [0.5, 0.5, 0.5, 0.75]
        self.progress_bar.value = 1
        self.popup.bind(on_open=self.puopen)

        # 主畫面切成左右兩欄
        self.cols = 3

        # 左欄是一個Gridlayout,有四列
        self.left = MDGridLayout(rows=6, size_hint=[0.4, 1], spacing=[0, 3])
        # 創建地圖
        self.map = FarmersMapView()

        # 左欄最上方要來做店租範圍
        self.left.one = MDGridLayout(size=[590, 657],
                                     rows=2,
                                     size_hint=[1, 0.2],
                                     md_bg_color=[0.39, 0.4, 0.72, 1],
                                     padding=[35, -20, 35, -20],
                                     spacing=[0, -30])
        # 把標籤裝進去最上層
        self.left.one.add_widget(
            Label(text='選擇月租範圍',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  size_hint_y=0.18))
        # 新增一層容器準備裝三個東西
        self.left.one.box = BoxLayout(spacing=8, size_hint_y=0.15)
        # 盒子裝進一個下限input、一上限input、一個'-'tag
        self.lower_bound = MDTextFieldRect(x=275,
                                           hint_text="$下限",
                                           font_name='msjhbd.ttc',
                                           pos_hint={'y': 0.45},
                                           size_hint=[1.5, 0.5],
                                           use_bubble=True,
                                           use_handles=True)
        self.upper_bound = MDTextFieldRect(hint_text="$上限",
                                           font_name='msjhbd.ttc',
                                           pos_hint={'y': 0.45},
                                           center_x=275.76,
                                           center_y=508.20,
                                           size_hint=[1.5, 0.5],
                                           use_bubble=True,
                                           use_handles=True)
        self.dash_sign = MDFlatButton(text='-',
                                      font_size=30,
                                      size_hint=[1, 0.49],
                                      pos_hint={'y': 0.45})
        self.dash_sign.md_bg_color = [1, 1, 1, 1]
        self.left.one.box.add_widget(self.lower_bound)
        self.left.one.box.add_widget(self.dash_sign)
        self.left.one.box.add_widget(self.upper_bound)
        # 盒子裝回上層
        self.left.one.add_widget(self.left.one.box)

        # 新增行政區選單
        self.left.six = MDGridLayout(size=[590, 657],
                                     rows=2,
                                     size_hint=[1, 0.25],
                                     md_bg_color=[0.39, 0.4, 0.72, 1],
                                     padding=[35, -5, 35, 5],
                                     spacing=[0, -10])
        self.left.six.add_widget(
            Label(text='行政區選擇',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.1]))
        self.left.six.box = BoxLayout(size_hint_y=0.15, center_y=390)
        from kivy.uix.spinner import Spinner
        district = [
            "中區", "東區", "西區", "南區", "北區", "西屯區", "南屯區", "北屯區", "豐原區", "大里區",
            "太平區", "清水區", "沙鹿區", "大甲區", "東勢區", "梧棲區", "烏日區", "神岡區", "大肚區",
            "大雅區", "后里區", "霧峰區", "潭子區", "龍井區", "外埔區", "和平區", "石岡區", "大安區",
            "新社區"
        ]
        self.spinner = Spinner(
            text='行政區',
            values=[n for n in district],
            size_hint=(None, None),
            size=(95, 44),
            #pos_hint = {'right':0.2},
            font_name='msjhbd.ttc',
            background_color=[1, 0, 0, 1])
        self.spinner.option_cls.font_name = 'msjhbd.ttc'
        self.spinner.option_cls.background_color = [1, 0, 0, 1]
        #self.spinner.values[0].font_name = 'msjhbd.ttc'
        self.spinner.dropdown_cls.max_height = self.spinner.height * 7 + 7 * 4
        #self.spinner.center_x = 160
        #self.left.six.box.add_widget(BoxLayout(size_hint_y=0.5, size_hint_x=0.5, width=100))
        self.left.six.box.add_widget(
            MDGridLayout(md_bg_color=[0.39, 0.4, 0.72, 1],
                         size_hint=[None, 0.5]))
        self.left.six.box.add_widget(self.spinner)
        self.left.six.add_widget(self.left.six.box)
        #self.left.six.box.children[0].center = (160, 522.1339285)
        #self.spinner.pos_hint = {'right':0.9}
        #self.spinner.center_x = 150

        # 這裡是畫面左欄第二格
        self.left.two = MDGridLayout(rows=2,
                                     size_hint=[1, None],
                                     size=[365, 170],
                                     md_bg_color=[0.39, 0.4, 0.72, 1])
        #self.left.two.center_y = 400
        # 把"指標排序"標籤裝進第二格子的上方
        self.left.two.add_widget(
            Label(text='指標排序',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.1]))
        # 左欄第二格下方增加一個grid容器
        self.left.two.grid = MDGridLayout(rows=3,
                                          size_hint=[1, 0.26],
                                          padding=[30, 0, 20, 0])
        self.left.two.grid.size_hint = [1, 0.26]
        self.left.two.add_widget(self.left.two.grid)
        # 準備三個box放入此grid
        self.left.two.box1 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.box2 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.box3 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.grid.add_widget(self.left.two.box1)
        self.left.two.grid.add_widget(self.left.two.box2)
        self.left.two.grid.add_widget(self.left.two.box3)
        # 處理第一個box的標籤(全用按鈕取代)、輸入
        self.left.two.btn1 = MDRaisedButton(text='      人口特性      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn1.md_bg_color = [0.55, 0.63, 0.99, 1]
        self.left.two.input1 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input1.size_hint_x = None
        self.left.two.input1.width = 120
        self.left.two.box1.add_widget(self.left.two.btn1)
        self.left.two.box1.add_widget(self.left.two.input1)

        self.left.two.btn3 = MDRaisedButton(text='      薪資所得      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn3.md_bg_color = [0.68, 0.82, 0.96, 1]
        self.left.two.input3 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input3.size_hint_x = None
        self.left.two.input3.width = 120
        self.left.two.box2.add_widget(self.left.two.btn3)
        self.left.two.box2.add_widget(self.left.two.input3)

        self.left.two.btn5 = MDRaisedButton(text='      人口消長      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn5.md_bg_color = [0.5, 0.87, 0.98, 1]
        self.left.two.input5 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input5.size_hint_x = None
        self.left.two.input5.width = 120
        self.left.two.box3.add_widget(self.left.two.btn5)
        self.left.two.box3.add_widget(self.left.two.input5)

        # 這裡是畫面左欄第三格
        self.left.three = MDGridLayout(rows=2,
                                       md_bg_color=[0.39, 0.4, 0.72, 1],
                                       size_hint=[1, 0.57])
        # 把"指標排序"標籤裝進第二格子的上方
        self.left.three.add_widget(
            Label(text='選擇競爭對手',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.06]))

        # 左欄第三格下方增加一個grid容器
        self.left.three.grid = MDGridLayout(rows=5,
                                            size_hint=[1, 0.26],
                                            spacing=3,
                                            padding=[30, 0, 40, 0])
        self.left.three.add_widget(self.left.three.grid)
        # 準備五個box放入此grid
        self.left.three.box1 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box2 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box3 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box4 = BoxLayout(size_hint=[1, 0.05])
        #self.left.three.box5 = BoxLayout(size_hint=[1, 0.4])
        self.left.three.box6 = BoxLayout()
        self.left.three.grid.add_widget(self.left.three.box1)
        self.left.three.grid.add_widget(self.left.three.box2)
        self.left.three.grid.add_widget(self.left.three.box3)
        self.left.three.grid.add_widget(self.left.three.box4)

        # 處理第一個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn1 = MDRaisedButton(text='       早餐店         ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn1.md_bg_color = [0.55, 0.63, 0.99, 1]
        self.left.three.input1 = MDCheckbox()
        self.left.three.input1.x = 140
        self.left.three.input1.selected_color = (1, 1, 1, 1)
        self.left.three.input1.unselected_color = (1, 1, 1, 1)
        self.left.three.box1.add_widget(self.left.three.btn1)
        self.left.three.box1.add_widget(self.left.three.input1)
        # 處理第二個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn2 = MDRaisedButton(text='便當、自助餐店',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn2.md_bg_color = [0.48, 0.81, 0.78, 1]
        self.left.three.input2 = MDCheckbox()
        self.left.three.input2.x = 140
        self.left.three.input2.selected_color = (1, 1, 1, 1)
        self.left.three.input2.unselected_color = (1, 1, 1, 1)
        self.left.three.box2.add_widget(self.left.three.btn2)
        self.left.three.box2.add_widget(self.left.three.input2)
        # 處理第三個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn3 = MDRaisedButton(text='麵店、小吃店    ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn3.md_bg_color = [0.68, 0.82, 0.96, 1]
        self.left.three.input3 = MDCheckbox()
        self.left.three.input3.x = 140
        self.left.three.input3.selected_color = (1, 1, 1, 1)
        self.left.three.input3.unselected_color = (1, 1, 1, 1)
        self.left.three.box3.add_widget(self.left.three.btn3)
        self.left.three.box3.add_widget(self.left.three.input3)
        # 處理第四個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn4 = MDRaisedButton(text='      餐館餐廳      ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn4.md_bg_color = [0.62, 0.84, 0.51, 1]
        self.left.three.input4 = MDCheckbox()
        self.left.three.input4.x = 140
        #self.left.three.input4.color = [1,1,1,2]
        self.left.three.input4.selected_color = (1, 1, 1, 1)
        self.left.three.input4.unselected_color = (1, 1, 1, 1)
        self.left.three.box4.add_widget(self.left.three.btn4)
        self.left.three.box4.add_widget(self.left.three.input4)

        self.run_button = MDRaisedButton(text='Run')

        # 製作廟宇按鈕
        self.left.four = MDGridLayout(rows=2,
                                      size_hint=[1, None],
                                      size=[365, 90],
                                      md_bg_color=[0.39, 0.4, 0.72, 1])
        self.left.four.add_widget(
            Label(text='廟宇出現與否',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.025]))
        self.left.four.box = BoxLayout(size_hint=[1, 0.025],
                                       padding=[30, -20, 40, 5])
        self.left.four.add_widget(self.left.four.box)
        self.left.four.btn = MDRaisedButton(text='          廟宇          ',
                                            font_name='msjhbd.ttc',
                                            size_hint=[None, 0.8],
                                            font_size='16sp')
        self.left.four.input = MDCheckbox()
        self.left.four.input.selected_color = (1, 1, 1, 1)
        self.left.four.input.unselected_color = (1, 1, 1, 1)
        self.left.four.box.add_widget(self.left.four.btn)
        self.left.four.box.add_widget(self.left.four.input)

        # 把每一層加回去
        self.left.add_widget(self.left.one)
        self.left.add_widget(self.left.six)
        self.left.add_widget(self.left.two)
        self.left.add_widget(self.left.three)
        self.left.add_widget(self.left.four)
        self.add_widget(self.left)
        self.add_widget(self.map)

        # 測試用的按鈕
        #self.run_button = MDRaisedButton(text='Run')
        self.left.five = MDGridLayout(size_hint=[1, 0.1],
                                      md_bg_color=[0.39, 0.4, 0.72, 1])
        self.left.five.add_widget(self.run_button)
        self.run_button.bind(on_release=self.popup.open)
        self.left.add_widget(self.left.five)
        self.run_button.right = 270
        self.run_button.ripple_alpha = 0.7
        self.run_button.radius = [10, 10, 10, 10]
        self.run_button.md_bg_color = [1, 1, 1, 1]
        self.run_button.text_color = [0, 0, 0, 1]
Ejemplo n.º 30
0
class GameWidget(MDBoxLayout):
    def __init__(self, return_back):
        super(GameWidget, self).__init__()
        self.orientation = "vertical"
        self.return_back = return_back
        self.ids.return_button.on_press = return_back

        self.game = Game()
        self.game_grid = GameField(cols=5)

        for i in range(20):
            self.game_grid.add_widget(MDIcon(icon="moon-new"))

        self.game_controls = ControlsBox()
        self.game_controls.add_widget(
            MDIconButton(icon="arrow-collapse-left",
                         on_press=lambda _: self.move(True)))
        self.game_controls.add_widget(
            MDIconButton(icon="arrow-down-bold", on_press=self.drop_cell))
        self.game_controls.add_widget(
            MDIconButton(icon="arrow-collapse-right",
                         on_press=lambda _: self.move(False)))
        self.add_widget(self.game_grid)
        self.add_widget(self.game_controls)
        self.update_game()

    def drop_cell(self, _):
        try:
            self.game.move("drop")
            self.update_game()
        except IndexError:
            self.ids.error_label.text = "Position occupied!"

    def win(self):
        theme_cls = MDApp.get_running_app().theme_cls
        win_popup = Popup(title=f"User {self.game.current_player} won!")

        content = MDBoxLayout(orientation="vertical",
                              md_bg_color=theme_cls.primary_dark)
        content.add_widget(
            MDLabel(text=f"User {self.game.current_player} won!",
                    theme_text_color='Primary',
                    halign="center"))
        content.add_widget(
            MDRaisedButton(text="Exit",
                           on_press=lambda x: self.game_win_return(win_popup),
                           size_hint=(1, None),
                           md_bg_color=theme_cls.primary_color,
                           font_size="20"))

        win_popup.content = content
        win_popup.open()

    def update_game(self):
        if not self.game.is_running:
            self.win()
            return

        self.remove_widget(self.game_grid)
        self.game_grid = MDGridLayout(cols=5, pos_hint={"center": 0.5})
        self.add_widget(self.game_grid)

        for i in range(self.game.get_pos() - 1):
            self.game_grid.add_widget(MDIcon(icon="square-outline"))
        self.game_grid.add_widget(MDIcon(icon="radiobox-marked"))

        if self.game.get_pos() < 5:
            for i in range(5 - self.game.get_pos()):
                self.game_grid.add_widget(MDIcon(icon="square-outline"))

        for row in self.game.show_field():
            for chip in row:
                if chip == 0:
                    self.game_grid.add_widget(MDIcon(icon="moon-new"))
                elif chip == 1:
                    self.game_grid.add_widget(MDIcon(icon="numeric-1-circle"))
                elif chip == 2:
                    self.game_grid.add_widget(MDIcon(icon="numeric-2-circle"))

        self.remove_widget(self.game_controls)
        self.add_widget(self.game_controls)

    def move(self, is_left):
        if is_left:
            self.game.move("left")
        else:
            self.game.move("right")
        self.update_game()

    def game_win_return(self, popup):
        popup.dismiss()
        self.return_back()