Пример #1
0
class LatexWidget(BoxLayout):
    text = StringProperty('')

    def __init__(self, **kwargs):
        self.scatterlayout = ScatterLayout(do_rotation=False,
                                           do_translation_y=False)
        super(LatexWidget, self).__init__(**kwargs)
        self.add_widget(self.scatterlayout)

    @staticmethod
    def latex_image(latex_str):
        fig, ax = pyplot.subplots()
        ax.axis('off')
        ax.text(.5,
                .5,
                latex_str,
                size=20,
                horizontalalignment='center',
                verticalalignment='center',
                bbox={})
        return FigureCanvasKivyAgg(fig)

    def on_text(self, *args):
        if self.scatterlayout.children:
            self.remove_widget(self.scatterlayout.children[0])
        im = LatexWidget.latex_image(self.text)
        self.scatterlayout.add_widget(im)
Пример #2
0
class hitPin(Widget):
    width_shot = NumericProperty()
    height_shot = NumericProperty()
    file_pin = StringProperty()

    def __init__(self, **kwargs):
        super(hitPin, self).__init__(**kwargs)
        #self.animation = Clock.create_trigger(self.animateHit, 0.5)
        
            
        self._shot = ScatterLayout(
            size=(self.width_shot, self.height_shot),
            do_rotate=False, 
            do_scale=False, 
            do_translation=False
            )

        _img_shot = Image(source=self.file_pin, size=(self.width_shot, 
            self.height_shot), allow_stretch=True)


        self._shot.add_widget(_img_shot)   
        self.add_widget(self._shot)
        self.bind(pos=self._update)
        self.bind(size=self._update)
        
    def _update(self, *args):
        self._shot.pos = self.pos
        #self.cur_pos = self._shot.pos
        #self.animation()

    def animateHit(self, dt):
        self._shot.size = (self.width_shot/2, self.height_shot/2)
Пример #3
0
def main_base_menu(build_place):
    scatter = ScatterLayout()
    menu = building.MenuLayout()
    inside_menu = building.InsideMenuLayout()
    main_box = BoxLayout(orientation='horizontal')
    left_box = BoxLayout(orientation='vertical', size_hint_x=.35)
    right_box = BoxLayout(size_hint_x=.65)
    icon_bottom_box = BoxLayout(size_hint=(.9, .8))
    icon_layout = BoxLayout(size_hint_y=.4)  # pos_hint=({'top': 1})

    # Вывод производства ресурсов
    stat_res = res_generation('main_base')

    # Добавление вкладок Здания
    tb = TabbedPanel(do_default_tab=False, tab_width=130)
    base_e = TabbedPanelItem(text='Энергия')
    base_e.content = base_energy()
    base_f = TabbedPanelItem(text='Пища')
    base_f.content = base_food()
    tb.add_widget(base_e)
    tb.add_widget(base_f)

    icon_bottom_box.add_widget(stat_res)
    icon_layout.add_widget(Image(source='data/images/buildings/main-base.png'))
    left_box.add_widget(icon_layout)
    left_box.add_widget(icon_bottom_box)
    right_box.add_widget(tb)
    main_box.add_widget(left_box)
    main_box.add_widget(right_box)
    inside_menu.add_widget(main_box)
    close_b = building.CloseMenuButton(build_place, scatter)
    menu.add_widget(inside_menu)
    menu.add_widget(close_b)
    scatter.add_widget(menu)
    return scatter
Пример #4
0
class ship(Widget):
    unit = NumericProperty(1)
    width_ship = NumericProperty()
    height_ship = NumericProperty()
    file_ship = StringProperty()
    value = NumericProperty()

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

        self._ship = ScatterLayout(size=(self.width_ship, self.height_ship),
                                   do_rotate=False,
                                   do_scale=False,
                                   do_translation=False)

        self._img_ship = Image(source=self.file_ship,
                               size=(self.width_ship, self.height_ship),
                               allow_stretch=True)

        self.add_widget(self._ship)
        self._ship.add_widget(self._img_ship)
        self.bind(pos=self._update)
        self.bind(size=self._update)
        self.bind(value=self._aniSweep)

    def _update(self, *args):
        #self._radar.pos = self.pos
        self._ship.pos = (self.x, self.y)
        self._ship.center = self._ship.center
        self._ship.size = (self.width_ship, self.height_ship)

    def _aniSweep(self, *args):
        self._ship.rotation = -float(self.value) * self.unit
Пример #5
0
 def build(self):  # pylint: disable=no-self-use; # pragma: no cover
     """Called when the app is created."""
     layout = ScatterLayout(translation_touches=2,
                            do_rotation=False,
                            scale_min=0.2,
                            scale_max=1.5)
     layout.add_widget(self._grid_widget)
     return layout
Пример #6
0
    def build(self, testMode=True):
        """
        Initiate objects and views.
        """
        ''' init game objects '''
        self.deck = Deck()
        self.evaluator = Evaluator()

        self.player = []
        self.player.append(Player(0))
        self.player.append(Player(1))
        # board stands for public cards on board
        self.board = Board()

        # In test mode, both player select right-most cards for the turn automatically
        self.testMode = testMode
        ''' create view objects '''
        # Scatter that can be rotated to display players
        scatter_bot = ScatterLayout(do_rotation=False,
                                    do_translation=False,
                                    do_scale=False,
                                    size_hint=(1, 1),
                                    pos_hint={
                                        'x': 0,
                                        'y': 0
                                    },
                                    rotation=0)
        # For player on top, the widget rotates 180 degree
        scatter_top = ScatterLayout(do_rotation=False,
                                    do_translation=False,
                                    do_scale=False,
                                    size_hint=(1, 1),
                                    pos_hint={
                                        'x': 0,
                                        'y': 0
                                    },
                                    rotation=180)

        box = PlayerDeck()
        box2 = PlayerDeck()
        publicArea = PublicArea()
        box.build(self, "player1", 0, self.testMode)
        box2.build(self, "player2", 1, self.testMode)
        publicArea.build()

        scatter_bot.add_widget(box)
        scatter_top.add_widget(box2)

        self.add_widget(scatter_bot)
        self.add_widget(scatter_top)
        self.add_widget(publicArea)

        # register id of view objects
        self.ids[box.id] = box
        self.ids[box2.id] = box2
        self.ids[publicArea.id] = publicArea
Пример #7
0
class MyBigImage(FloatLayout):
    def __init__(self, **kwargs):
        super(MyBigImage, self).__init__(**kwargs)
	self.addImage("oak.jpeg")

    def addImage(self, filename):
	self.layout = ScatterLayout()
        #self.layout.scale = 1.8
        #self.layout.scale_min= 1.5
        #self.layout.scale_max= 4.5
        self.image = Image(source=filename, mipmap=True)
	self.layout.add_widget(self.image)
	self.add_widget(self.layout)
Пример #8
0
class hitBang(Widget):
    width_shot = NumericProperty()
    height_shot = NumericProperty()
    file_pin = StringProperty()

    def __init__(self, **kwargs):
        super(hitBang, self).__init__(**kwargs)
        self.animation = Clock.create_trigger(self.animateHit, 0.25)
        self.cur_pos = (0.0, 0.0)
        self.ani = 0

        self._shot = ScatterLayout(size=(self.width_shot, self.height_shot),
                                   do_rotate=False,
                                   do_scale=False,
                                   do_translation=False)

        _img_shot = Image(source=self.file_pin,
                          size=(self.width_shot, self.height_shot),
                          allow_stretch=True)

        self._shot.add_widget(_img_shot)
        self.add_widget(self._shot)
        self.bind(pos=self._update)
        self.bind(size=self._update)

    def _update(self, *args):
        self._shot.pos = self.pos
        self.cur_pos = self._shot.pos
        self.animation()

    def animateHit(self, dt):
        if self.ani == 1:
            self._shot.size = (self.width_shot / 4, self.height_shot / 4)
            self._shot.pos = (self.cur_pos[0] + self.width_shot / 2.75,
                              self.cur_pos[1] + self.height_shot / 2.75)
        if self.ani == 2:
            self._shot.size = (self.width_shot / 2, self.height_shot / 2)
            self._shot.pos = (self.cur_pos[0] + self.width_shot / 4,
                              self.cur_pos[1] + self.height_shot / 4)
        if self.ani == 3:
            self._shot.size = (self.width_shot, self.height_shot)
            self._shot.pos = (self.cur_pos[0], self.cur_pos[1])
        if self.ani == 4:
            self.ani = 0
        self.ani += 1
        self.animation()
Пример #9
0
def prod_menu(build_place):
    scatter = ScatterLayout()
    menu = MenuLayout()
    inside_menu = InsideMenuLayout()
    main_box = BoxLayout(orientation='horizontal')
    left_box = BoxLayout(orientation='vertical', size_hint_x=.35)
    right_box = BoxLayout(size_hint_x=.65)
    icon_bottom_box = BoxLayout(size_hint=(.9, .8))
    icon_layout = BoxLayout(size_hint_y=.4)  # pos_hint=({'top': 1})
    statistic_grid = GridLayout(cols=1,
                                size_hint_y=None,
                                pos_hint=({
                                    'top': .9
                                }),
                                spacing=10,
                                padding=5)
    for r in config.resources:
        res = config.resources[r]
        stat_box = BoxLayout(orientation='horizontal',
                             height=40,
                             size_hint_y=None)
        stat_box.add_widget(Image(source=res[2], size_hint_x=.2))
        stat_box.add_widget(Label(text=f'{res[0]}', size_hint_x=.8))
        statistic_grid.add_widget(stat_box)
    tb = TabbedPanel(do_default_tab=False, tab_width=130)
    ti = TabbedPanelItem(text='Улучшения')
    ti.content = prod_upgrade_content()
    tb.add_widget(ti)
    tb.add_widget(TabbedPanelItem(text='Автоматизация'))
    tb.add_widget(TabbedPanelItem(text='Статистика'))
    icon_bottom_box.add_widget(statistic_grid)
    icon_layout.add_widget(Image(source='data/images/buildings/buildings.zip'))
    left_box.add_widget(icon_layout)
    left_box.add_widget(icon_bottom_box)
    right_box.add_widget(tb)
    main_box.add_widget(left_box)
    main_box.add_widget(right_box)
    inside_menu.add_widget(main_box)
    close_b = CloseMenuButton(build_place, scatter)
    menu.add_widget(inside_menu)
    menu.add_widget(close_b)
    scatter.add_widget(menu)
    return scatter
Пример #10
0
class radar(Widget):
    unit = NumericProperty(1)
    width_radar = NumericProperty()
    height_radar = NumericProperty()
    value = NumericProperty()

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

        self._radar = ScatterLayout(size=(self.width_radar, self.height_radar),
                                    do_rotate=False,
                                    do_scale=False,
                                    do_translation=False)

        _img_radar = Image(source='radar_1.png',
                           size=(self.width_radar, self.height_radar),
                           allow_stretch=True)

        self._sweeperGauge = ScatterLayout(size=(self.width_radar,
                                                 self.height_radar),
                                           do_rotate=False,
                                           do_scale=False,
                                           do_translation=False)

        self._img_sweeper = Image(source='Sweeper.png',
                                  size=(self.width_radar, self.height_radar),
                                  allow_stretch=True)

        self._radar.add_widget(_img_radar)
        self.add_widget(self._radar)
        self.add_widget(self._sweeperGauge)
        self._sweeperGauge.add_widget(self._img_sweeper)
        self.bind(pos=self._update)
        self.bind(size=self._update)
        self.bind(value=self._aniSweep)

    def _update(self, *args):
        self._radar.pos = self.pos
        self._sweeperGauge.pos = (self.x, self.y)
        self._sweeperGauge.center = self._radar.center

    def _aniSweep(self, *args):
        self._sweeperGauge.rotation = -float(self.value) * self.unit
Пример #11
0
 def gen_set(self):
     scatter = ScatterLayout()
     menu = building.MenuLayout()
     inside_menu = building.InsideMenuLayout()
     main_box = BoxLayout(orientation='horizontal')
     left_box = BoxLayout(orientation='vertical', size_hint_x=.35)
     right_box = BoxLayout(size_hint_x=.65)
     icon_bottom_box = BoxLayout(size_hint=(.9, .8))
     icon_layout = BoxLayout(size_hint_y=.4)  # pos_hint=({'top': 1})
     left_box.add_widget(icon_layout)
     left_box.add_widget(icon_bottom_box)
     main_box.add_widget(left_box)
     main_box.add_widget(right_box)
     inside_menu.add_widget(main_box)
     close_b = building.CloseMenuButton(self, scatter)
     menu.add_widget(inside_menu)
     menu.add_widget(close_b)
     scatter.add_widget(menu)
     return scatter
Пример #12
0
 def open_terminal(self):
     scatter_terminal = ScatterLayout(size_hint=(.4, .5))
     terminal_lay = TerminalRelativeLayout()
     scroll_terminal = TerminalScrollView(size_hint=(.97, .87), pos_hint=({'center_x': .5, 'top': .9}))
     terminal_top = RelativeLayout(size_hint=(.97, .1), pos_hint=({'center_x': .5, 'top': 1}))
     terminal_top.add_widget(TerminalIcon(pos_hint=({'x': .005, 'top': 1}), size_hint_x=.04))
     terminal_top.add_widget(TerminalTitleLabel(text=r'C:\JARVIS\Terminal [Version 7.1.2336]',
                                                pos_hint=({'x': .05, 'top': 1}), size_hint_x=.992))
     terminal_top.add_widget(
         TerminalClose(parent_lay=self.layout, close_lay=scatter_terminal, pos_hint=({'right': .99, 'top': 1}),
                       size_hint_x=.04))
     terminal_main = TerminalGridLayout(cols=1, size_hint_y=None, padding=3, spacing=5)
     terminal_main.bind(minimum_height=terminal_main.setter('height'))
     terminal_main.add_widget(
         TerminalLabel(text='JARVIS Terminal (c) Corporation JARVIS, 2044. All rights reserved'))
     terminal_main.add_widget(TerminalTextInput(grid=terminal_main))
     terminal_lay.add_widget(terminal_top)
     scroll_terminal.add_widget(terminal_main)
     terminal_lay.add_widget(scroll_terminal)
     scatter_terminal.add_widget(terminal_lay)
     self.layout.add_widget(scatter_terminal)
Пример #13
0
def base_window(build_place):  # Шаблон для окна
    scatter = ScatterLayout()
    menu = MenuLayout()
    inside_menu = InsideMenuLayout()
    main_box = BoxLayout(orientation='horizontal', minimum_size=(700, 400))
    left_box = BoxLayout(orientation='vertical', size_hint_x=.3)
    right_box = BoxLayout(size_hint_x=.7)
    bottom_box = BoxLayout(size_hint=(.95, .8))
    icon_box = FrameBoxLayout(orientation='vertical', size_hint_y=.4)
    statistic_grid = GridLayout(cols=1, spacing=10, padding=5)
    icon_box.add_widget(Image(source=config.empty_icon))
    left_box.add_widget(icon_box)
    bottom_box.add_widget(statistic_grid)
    left_box.add_widget(bottom_box)
    main_box.add_widget(left_box)
    main_box.add_widget(right_box)
    inside_menu.add_widget(main_box)
    close_b = CloseMenuButton(build_place, scatter)
    menu.add_widget(inside_menu)
    menu.add_widget(close_b)
    scatter.add_widget(menu)
    return scatter, icon_box, statistic_grid, right_box
Пример #14
0
def menu_content(build_place):
    tb = TabbedPanel(do_default_tab=False, tab_width=150)
    tab_all = TabbedPanelHeader(text='Все')
    tab_war = TabbedPanelHeader(text='Военные')
    tab_prod = TabbedPanelItem(text='Производственные')
    tab_social = TabbedPanelHeader(text='Социальные')
    scatter = ScatterLayout(id='scatter_layout')  # size_hint_max=(1000, 800)
    name_label = PlaceLabel(text=f'Место для строительства: {build_place.id}')
    menu = MenuLayout()
    inside_menu = InsideMenuLayout()
    tb.add_widget(tab_all)
    tb.add_widget(tab_war)
    tb.add_widget(tab_social)
    tb.add_widget(tab_prod)
    for tab in tb.tab_list:
        tab.content = create_building_list(tab.text, build_place, scatter)
    inside_menu.add_widget(tb)
    menu.add_widget(inside_menu)
    menu.add_widget(name_label)
    close_b = CloseMenuButton(build_place, scatter)
    menu.add_widget(close_b)
    scatter.add_widget(menu)
    return scatter
    def __init__(self, **kwargs):
        # 父类构造方法
        super().__init__(**kwargs)

        # 设置背景颜色(可忽略)
        with self.canvas:
            # 背景颜色
            Color(1, 1, 1, 1)
            # 浮动布局矩形 = 矩形(位置=布局位置,大小=布局大小)
            self.rect = Rectangle(pos=self.pos, size=self.size)
            # 浮动布局绑定(位置=布局矩形位置,大小=设置背景尺寸)
            self.bind(pos=self.update_rect, size=self.update_rect)

        # 缩放布局
        scatter_layout = ScatterLayout()

        # 异步图片
        image = AsyncImage(source='http://sck.rjkflm.com/images/logo1.png')

        # 布局加组件(异步图片)
        scatter_layout.add_widget(image)

        # 布局加组件(缩放布局)
        self.add_widget(scatter_layout)
Пример #16
0
    def build(self):
        appLayout = FloatLayout(size=(800, 600))

        bg = Image(source='Images/Metal2.jpg', pos=(0, 0), size=(1500, 840))

        g1 = Gauge()
        g1s = ScatterLayout(scale=0.5, size=g1.size, pos=(30, 80))
        g1s.add_widget(g1)

        g2 = Gauge()
        g2s = ScatterLayout(scale=0.5, size=g1.size, pos=(200, 80))
        g2s.add_widget(g2)

        g3 = Gauge()
        g3s = ScatterLayout(scale=0.5, size=g1.size, pos=(300, 80))
        g3s.add_widget(g3)

        head = Header()
        headscat = Scatter(size=head.size, pos=(0, 530), do_translation=False)
        headscat.add_widget(head)

        foot = Footer()
        Footer.updatedate(foot)
        #Clock.schedule_interval(foot.updatetime, 1)
        Clock.schedule_interval(partial(Footer.updatetime, foot), 1)
        Clock.schedule_interval(partial(Footer.updatedate, foot), 3600)
        #footscat = Scatter(size=foot.size, pos=(0,-10), do_translation=False)
        #footscat.add_widget(foot)

        appLayout.add_widget(bg)
        appLayout.add_widget(g1s)
        appLayout.add_widget(g2s)
        appLayout.add_widget(g3s)
        appLayout.add_widget(headscat)
        appLayout.add_widget(foot)

        Window.size = (800, 600)
        return appLayout
Пример #17
0
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.add2 = 0
        self.add2_shop_list = []
        self.add2_temp_list = []
        self.add2_rent_list = []
        self.add2_bound = []

        self.add3 = 0
        self.add3_shop_list = []
        self.add3_temp_list = []
        self.add3_rent_list = []
        self.add3_bound = []

        # 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_normal='',
            background_color=[0, 0.3, 0.7, 1])
        self.spinner.option_cls.font_name = 'msjhbd.ttc'
        # self.spinner.option_cls.background_color = [3, 3, 3, 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):
        neigh = self.spinner.text + neigh
        shop_list = gd.get_shop_codata(neigh, clist)
        # print(shop_list)
        #self.add1 += 1
        #print(self.add1)

        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)

    def clear_shop(self, password):

        if (password == 1):

            for marker in self.add1_shop_list:
                self.map.remove_marker(marker)
            self.add1_shop_list.clear()
        elif (password == 2):

            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):

        neigh = self.spinner.text + neigh
        temp_list = gd.get_temp_codata(neigh)

        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)
                    elif (password == 3):
                        self.add3_temp_list.append(marker)
        else:
            print("")

    def clear_temp(self, password):

        if (password == 1):

            for marker in self.add1_temp_list:

                self.map.remove_marker(marker)
            self.add1_temp_list.clear()
        elif (password == 2):

            for marker in self.add2_temp_list:

                self.map.remove_marker(marker)
            self.add2_temp_list.clear()
        elif (password == 3):
            for marker in self.add3_temp_list:

                self.map.remove_marker(marker)
            self.add3_temp_list.clear()

    def add_rent(self, password, neigh, Min_price=0, Max_price=100000000):

        neigh = self.spinner.text + neigh
        # 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['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):

        if (password == 1):

            for marker in self.add1_rent_list:
                self.map.remove_marker(marker)
            self.add1_rent_list.clear()
        elif (password == 2):

            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):

        if (password == 1):
            self.bound1 = GeoJsonMapLayer()
            self.bound1.source = os.path.realpath(sys.argv[0]).strip(
                sys.argv[0]
            ) + "data\\" + "鄰里邊界\\" + self.spinner.text + "\\" + self.rank1.text + ".json"
            print(self.bound1.source)
            self.add1_bound.append(self.bound1)
            self.map.add_layer(self.bound1)
            print(self.rank1.text + "邊界")
        elif (password == 2):
            self.bound2 = GeoJsonMapLayer()
            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)
            print(self.rank2.text + "邊界")
        elif (password == 3):
            self.bound3 = GeoJsonMapLayer()
            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)
            print(self.rank3.text + "邊界")

    def remove_boundary(self, password):

        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()

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

    acard = None

    def pressed(self, instance):
        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.spinner.text)
        print("實際的前三名:", end="")
        print(top3_rank)
        if not self.acard:
            self.rank1 = ThreeLineIconListItem(
                text=top3_rank[0][0].split('區')[1],
                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]
            self.rank1.children[1].height = 110
            # 從另一個預先寫好、計算各里指標分數的模組final_combiner引進final_rank函數,取得前三名的區域及其各項指標分數後用top3_rank變數紀錄起來
            # 接著改寫、擴充kivy套件內的工具(ThreeLineIconListItem),做成資訊卡,同時使其擁有按鈕的特性讓使用者做點選

            self.rank2 = ThreeLineIconListItem(
                text=top3_rank[1][0].split('區')[1],
                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].split('區')[1],
                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.lll = ScatterLayout(size_hint=[0.2, 0.6])
            self.myLast = MDGridLayout(cols=1,
                                       size_hint=[0.8, 0.85],
                                       md_bg_color=[0.39, 0.4, 0.8, 0.8])
            self.myLast.add_widget(self.rank1)  # 0.285,0.5
            self.myLast.add_widget(self.rank2)
            self.myLast.add_widget(self.rank3)
            self.lll.add_widget(self.myLast)
            from kivy.core.window import Window
            Window.add_widget(self.lll)
            self.lll.center = (640, 328)
            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)

            lat = 0
            lon = 0
            try:
                with open(os.path.realpath(sys.argv[0]).strip(sys.argv[0]) +
                          'district.json',
                          'r',
                          encoding='utf-8') as q:
                    q = json.load(q)
                    lat = q["臺中市" + self.spinner.text][0][0]
                    lon = q["臺中市" + self.spinner.text][0][1]

            except:
                print(self.spinner.text + "經緯度有問題")

            self.map.zoom = 12
            self.map.center_on(float(lat), float(lon))

    ''' 當初設計沒有想好架構,導致要再次定義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.spinner.text)
        print("實際的前三名:", end="")
        print(top3_rank)
        self.rank1.text = top3_rank[0][0].split('區')[1]
        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.text = top3_rank[1][0].split('區')[1]
        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.text = top3_rank[2][0].split('區')[1]
        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)

        lat = 0
        lon = 0
        try:
            with open(os.path.realpath(sys.argv[0]).strip(sys.argv[0]) +
                      'district.json',
                      'r',
                      encoding='utf-8') as q:
                q = json.load(q)
                lat = q["臺中市" + self.spinner.text][0][0]
                lon = q["臺中市" + self.spinner.text][0][1]

        except:
            print(self.spinner.text + "經緯度有問題")
        self.map.zoom = 12
        self.map.center_on(float(lat), float(lon))

    def add_renk1_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.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)
            lat = 0
            lon = 0
            try:
                with open('village.json', 'r', encoding='utf-8') as q:
                    q = json.load(q)
                    lat = q["臺中市" + self.spinner.text + self.rank1.text][0][0]
                    lon = q["臺中市" + self.spinner.text + self.rank1.text][0][1]
            except:
                print(self.spinner.text + self.rank1.text + "經緯度有問題")
            self.map.zoom = 15
            self.map.center_on(float(lat), float(lon))
        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)

        # 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)
            lat = 0
            lon = 0
            try:
                with open('village.json', 'r', encoding='utf-8') as q:
                    q = json.load(q)
                    lat = q["臺中市" + self.spinner.text + self.rank2.text][0][0]
                    lon = q["臺中市" + self.spinner.text + self.rank2.text][0][1]
            except:
                print(self.spinner.text + self.rank1.text + "經緯度有問題")
            self.map.zoom = 15
            self.map.center_on(float(lat), float(lon))
        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)
            lat = 0
            lon = 0
            try:
                with open('village.json', 'r', encoding='utf-8') as q:
                    q = json.load(q)
                    lat = q["臺中市" + self.spinner.text + self.rank3.text][0][0]
                    lon = q["臺中市" + self.spinner.text + self.rank3.text][0][1]
            except:
                print(self.spinner.text + self.rank1.text + "經緯度有問題")
            self.map.zoom = 15
            self.map.center_on(float(lat), float(lon))
        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)
Пример #18
0
class Application(GridLayout):
    def __init__(self, **kwargs):
        super(Application, self).__init__(**kwargs)
        Clock.schedule_interval(self.update, 0)
        self.time = 0

        self.packetLength = 46080  #Packet length determined for 20 packets containing  640x480 pixel frame

        self.sumData = []
        self.bimage = b''  #Byte variables used for frame operations
        self.transfer = b''
        self.texData = b''
        self.tmp = b''

        self.threads = []  #Used for threading

        self.image = ""

        #IP adress container
        self.ip = [
            TextInput(multiline=False, font_size=12),
            TextInput(multiline=False, font_size=12),
            TextInput(multiline=False, font_size=12),
            TextInput(multiline=False, font_size=12)
        ]

        self.port = TextInput(multiline=False, font_size=12)  #Port container
        self.password = TextInput(multiline=False, password=True,
                                  font_size=12)  #Password container

        self.UDP_IP_ADDRESS = "192.168.56.1"
        self.UDP_PORT_NO = 6789
        self.Message = "ip: " + self.ip[0].text + "." + self.ip[
            1].text + "." + self.ip[2].text + "." + self.ip[
                3].text + " port: " + self.port.text

        self.clientSock = socket.socket(
            socket.AF_INET, socket.SOCK_DGRAM)  #Socket initialization
        self.clientSock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF,
                                   921600)  #Socket options

        self.popupWindow = Popup(title="Enter ip, port and password to access."
                                 )  #Popup window initialization

        self.cols = 1

        self.texture = Texture.create(
            size=(640, 480),
            colorfmt='rgb')  #Texture for camera frames initalization
        self.texture.flip_vertical()
        self.data = b'\xff\x00\x00' * 320 * 480 + (b'\x00\xff\x00' * 320 * 480)
        self.texture.blit_buffer(self.data, colorfmt='bgr')
        self.img = Image(size=self.texture.size, texture=self.texture)
        self.cent = ScatterLayout(
            do_rotation=False,
            do_scale=False,
            do_translation_y=False,
            do_translation_x=False,
        )
        self.add_widget(self.cent)
        self.cent.rotation = 90
        self.cent.add_widget(self.img)

        self.buttonsLay = GridLayout()

        self.buttonsLay.cols = 3  #3x4 buttons grid setup
        self.add_widget(self.buttonsLay)

        self.BtnTL = Button(background_normal="arrowUL.png",
                            background_down="arrowULNeg.png",
                            pos_hint={
                                "x": 0.3,
                                "top": 0.3
                            })
        self.BtnTL.bind(on_release=partial(self.BTN, message="TL"))
        self.buttonsLay.add_widget(self.BtnTL)

        self.BtnT = Button(background_normal="arrowUp.png",
                           background_down="arrowUpNeg.png",
                           pos_hint={
                               "x": 0.3,
                               "top": 0.3
                           })
        self.BtnT.bind(on_release=partial(self.BTN, message="TM"))
        self.buttonsLay.add_widget(self.BtnT)

        self.BtnTR = Button(background_normal="arrowUR.png",
                            background_down="arrowURNeg.png",
                            pos_hint={
                                "x": 0.3,
                                "top": 0.3
                            })
        self.BtnTR.bind(on_release=partial(self.BTN, message="TR"))
        self.buttonsLay.add_widget(self.BtnTR)

        self.BtnL = Button(background_normal="arrowLeft.png",
                           background_down="arrowLeftNeg.png",
                           pos_hint={
                               "x": 0.3,
                               "top": 0.3
                           })
        self.BtnL.bind(on_release=partial(self.BTN, message="ML"))
        self.buttonsLay.add_widget(self.BtnL)

        self.Btn = Button(background_normal="arrowMiddle.png",
                          background_down="arrowMiddleNeg.png",
                          pos_hint={
                              "x": 0.3,
                              "top": 0.3
                          })
        self.Btn.bind(on_release=partial(self.BTN, message="MM"))
        self.buttonsLay.add_widget(self.Btn)

        self.BtnR = Button(background_normal="arrowRight.png",
                           background_down="arrowRightNeg.png",
                           pos_hint={
                               "x": 0.3,
                               "top": 0.3
                           })
        self.BtnR.bind(on_release=partial(self.BTN, message="MR"))
        self.buttonsLay.add_widget(self.BtnR)

        self.BtnBL = Button(background_normal="arrowDL.png",
                            background_down="arrowDLNeg.png",
                            pos_hint={
                                "x": 0.3,
                                "top": 0.3
                            })
        self.BtnBL.bind(on_release=partial(self.BTN, message="BL"))
        self.buttonsLay.add_widget(self.BtnBL)

        self.BtnB = Button(background_normal="arrowDown.png",
                           background_down="arrowDownNeg.png",
                           pos_hint={
                               "x": 0.3,
                               "top": 0.3
                           })
        self.BtnB.bind(on_release=partial(self.BTN, message="BM"))
        self.buttonsLay.add_widget(self.BtnB)

        self.BtnBR = Button(background_normal="arrowDR.png",
                            background_down="arrowDRNeg.png",
                            pos_hint={
                                "x": 0.3,
                                "top": 0.3
                            })
        self.BtnBR.bind(on_release=partial(self.BTN, message="BR"))
        self.buttonsLay.add_widget(self.BtnBR)

        self.popupBtn = Button(background_normal="connect.png",
                               background_down="connectNeg.png",
                               pos_hint={
                                   "x": 0.3,
                                   "top": 0.3
                               })
        self.popupBtn.bind(on_release=self.showPopup)
        self.buttonsLay.add_widget(self.popupBtn)

        self.popupBtn = Button(background_normal="screenshot.png",
                               background_down="screenshotNeg.png",
                               pos_hint={
                                   "x": 0.3,
                                   "top": 0.3
                               })
        self.popupBtn.bind(on_release=self.frameShot)
        self.buttonsLay.add_widget(self.popupBtn)

        self.popupBtn = Button(background_normal="rec.png",
                               background_down="recNeg.png",
                               pos_hint={
                                   "x": 0.3,
                                   "top": 0.3
                               })
        self.popupBtn.bind(on_release=partial(self.BTN, message="MM"))
        self.buttonsLay.add_widget(self.popupBtn)

        self.initPopup(self)

    #Screenshot function with name generation in format of date and hour
    def frameShot(self, instance):
        self.dateRaw = time.ctime()
        self.date = ''
        for i in self.dateRaw:
            if not (i == ':' or i == ' '):
                self.date += i
            else:
                self.date += '_'
        self.texture.save(self.date + '.png', flipped=0)

    #Update function executing roughly every 50ms recieving streamed packets and updating camera screen
    def update(self, dt):

        #Force updating the the camera screen with additional widget
        self.texTmp = Texture.create(size=(1, 1), colorfmt='rgb')
        self.dataTmp = b'\xff\xff\xff'
        self.texTmp.blit_buffer(self.dataTmp, colorfmt='bgr')
        self.imgTmp = Image(size=self.texTmp.size, texture=self.texTmp)
        self.add_widget(self.imgTmp)
        self.remove_widget(self.imgTmp)

        #Checking if there is a socket connection
        ready = select.select([self.clientSock], [], [], 0)

        if ready[0]:
            #Reciving the packets and merging the byte data into a frame
            for i in range(20):
                #try:
                self.bimage, addr = self.clientSock.recvfrom(
                    self.packetLength + 1)
                self.tmp = self.bimage[:1]
                self.tmp = self.tmp.hex()
                self.tmp = int(self.tmp, 16)
                #Checking for charcteristic byte data combination that keeps the synchronization between the server and client
                if self.bimage == b'\x01\x01\x01\x01':
                    break
                #Merging the byte data
                self.sumData[self.tmp * self.packetLength:(self.tmp + 1) *
                             self.packetLength] = list(self.bimage[1:])

        #Adding the valid frame data into texture blit_buffer to show it on screen
        if len(self.sumData) >= self.packetLength * 20:
            self.texData = b''
            self.texData += bytes(self.sumData)
            self.texture.blit_buffer(self.texData, colorfmt='bgr')

    #Function handling the connection data and sending the information abput connection to server
    def submitIP(self, instance):
        #Checking if the ip address and port are not null
        if self.ip[0].text != "" and self.ip[1].text != "" and self.ip[
                2].text != "" and self.ip[3].text != "":
            self.UDP_IP_ADDRESS = self.ip[0].text + "." + self.ip[
                1].text + "." + self.ip[2].text + "." + self.ip[3].text
        else:
            self.UDP_IP_ADDRESS = "192.168.56.1"
        if self.port.text != "":
            self.UDP_PORT_NO = int(self.port.text)
        else:
            self.UDP_PORT_NO = 6789
        #Appending new thread that send connection data to server
        newthread = ClientThread(self.UDP_IP_ADDRESS, self.UDP_PORT_NO,
                                 self.clientSock, "message from client")
        newthread.start()
        self.threads.append(newthread)
        #Closing the popup
        self.popupWindow.dismiss()

    #Function initalizing the popup window
    def initPopup(self, instance):
        #Structuring the interface and adding the labels and text fields
        content = GridLayout()
        content.cols = 1

        inside = GridLayout()
        content.add_widget(inside)
        inside.cols = 2

        labelIP = BoxLayout()
        labelIP.width = 70
        labelIP.size_hint_x = None
        labelIP.add_widget(Label(text="IP:"))
        inside.add_widget(labelIP)

        ipGrid = BoxLayout()
        inside.add_widget(ipGrid)

        for ipGrid.i in self.ip:
            tmp = AnchorLayout(anchor_x='center', anchor_y='center')
            ipGrid.add_widget(tmp)
            ipGrid.i.size_hint = (1, 0.45)

            tmp.add_widget(ipGrid.i)

        labelPort = BoxLayout()
        labelPort.width = 70
        labelPort.size_hint_x = None
        labelPort.add_widget(Label(text="Port:"))
        inside.add_widget(labelPort)

        tmp = AnchorLayout(anchor_x='center', anchor_y='center')
        inside.add_widget(tmp)
        self.port.size_hint = (0.5, 0.45)
        tmp.add_widget(self.port)

        labelPass = BoxLayout()
        labelPass.width = 70
        labelPass.size_hint_x = None
        labelPass.add_widget(Label(text="Password"))
        inside.add_widget(labelPass)

        tmp = AnchorLayout(anchor_x='center', anchor_y='center')
        inside.add_widget(tmp)
        self.password.size_hint = (1, 0.45)
        tmp.add_widget(self.password)

        #Adding submit button at the bottom of the popup window
        btnLay = AnchorLayout(anchor_x='center', anchor_y='center')
        btnLay.size_hint = (1, 0.2)
        content.add_widget(btnLay)
        btnLay.submitIPBtn = Button(text="Submit",
                                    font_size=0.025 * 720,
                                    size_hint=(0.4, 0.9))
        btnLay.submitIPBtn.bind(on_release=self.submitIP)
        btnLay.add_widget(btnLay.submitIPBtn)

        self.popupWindow = Popup(
            title="Enter ip, port and password to access.",
            content=content,
            size_hint=(0.8, 0.6))

    #Function opening the popup window
    def showPopup(self, instance):
        self.popupWindow.open()

    #Funcition sending movement data to server on a new thread
    def BTN(self, *args, message):
        newthread = ClientThread(self.UDP_IP_ADDRESS, self.UDP_PORT_NO,
                                 self.clientSock, message)
        newthread.start()
        self.threads.append(newthread)
Пример #19
0
    def build(self):
        sl = ScatterLayout()
        al = AnchorLayout()
        bl = BoxLayout(orientation='vertical', padding=[.05, .05], spacing=2)
        bl1 = BoxLayout(orientation='horizontal', spacing=0)
        bl2 = BoxLayout(orientation='horizontal', spacing=0)
        bl3 = BoxLayout(orientation='horizontal', spacing=0)
        bl4 = BoxLayout(orientation='horizontal', spacing=0)
        bl5 = BoxLayout(orientation='horizontal', spacing=0)
        bl6 = BoxLayout(orientation='horizontal', spacing=0)
        bl7 = BoxLayout(orientation='horizontal', spacing=0)
        bl8 = BoxLayout(orientation='horizontal', spacing=0)
        bl9 = BoxLayout(orientation='horizontal',
                        spacing=0,
                        size_hint=(1, .5),
                        padding=[0])

        self.lab1 = Label(text='Зона №1')
        self.lab1.bind(size=self._update_rect1, pos=self._update_rect1)
        with self.lab1.canvas.before:
            Color(0, 43, 230, 255)
            self.rect1 = Rectangle(size=self.lab1.size, pos=self.lab1.pos)
        self.bt1 = Button(text='Вкл', size_hint=(.2, 1))
        self.bt1.bind(on_press=self.pressing1)

        self.lab2 = Label(text='Зона №2')
        self.lab2.bind(size=self._update_rect2, pos=self._update_rect2)
        with self.lab2.canvas.before:
            Color(0, 43, 230, 255)  # green; colors range from 0-1 not 0-255
            self.rect2 = Rectangle(size=self.lab2.size, pos=self.lab2.pos)
        self.bt2 = Button(text='Вкл', size_hint=(.2, 1))
        self.bt2.bind(on_press=self.pressing2)

        self.lab3 = Label(text='Зона №3')
        self.lab3.bind(size=self._update_rect3, pos=self._update_rect3)
        with self.lab3.canvas.before:
            Color(0, 43, 230, 255)  # green; colors range from 0-1 not 0-255
            self.rect3 = Rectangle(size=self.lab3.size, pos=self.lab3.pos)
        self.bt3 = Button(text='Вкл', size_hint=(.2, 1))
        self.bt3.bind(on_press=self.pressing3)

        self.lab4 = Label(text='Зона №4')
        self.lab4.bind(size=self._update_rect4, pos=self._update_rect4)
        with self.lab4.canvas.before:
            Color(0, 43, 230, 255)  # green; colors range from 0-1 not 0-255
            self.rect4 = Rectangle(size=self.lab4.size, pos=self.lab4.pos)
        self.bt4 = Button(text='Вкл', size_hint=(.2, 1))
        self.bt4.bind(on_press=self.pressing4)

        self.lab5 = Label(text='Зона №5')
        self.lab5.bind(size=self._update_rect5, pos=self._update_rect5)
        with self.lab5.canvas.before:
            Color(0, 43, 230, 255)  # green; colors range from 0-1 not 0-255
            self.rect5 = Rectangle(size=self.lab5.size, pos=self.lab5.pos)
        self.bt5 = Button(text='Вкл', size_hint=(.2, 1))
        self.bt5.bind(on_press=self.pressing5)

        self.lab6 = Label(text='Зона №6')
        self.lab6.bind(size=self._update_rect6, pos=self._update_rect6)
        with self.lab6.canvas.before:
            Color(0, 43, 230, 255)  # green; colors range from 0-1 not 0-255
            self.rect6 = Rectangle(size=self.lab6.size, pos=self.lab6.pos)
        self.bt6 = Button(text='Вкл', size_hint=(.2, 1))
        self.bt6.bind(on_press=self.pressing6)

        self.lab7 = Label(text='Зона №7')
        self.lab7.bind(size=self._update_rect7, pos=self._update_rect7)
        with self.lab7.canvas.before:
            Color(0, 43, 230, 255)  # green; colors range from 0-1 not 0-255
            self.rect7 = Rectangle(size=self.lab7.size, pos=self.lab7.pos)
        self.bt7 = Button(text='Вкл', size_hint=(.2, 1))
        self.bt7.bind(on_press=self.pressing7)

        self.lab8 = Label(text='Зона №8')
        self.lab8.bind(size=self._update_rect8, pos=self._update_rect8)
        with self.lab8.canvas.before:
            Color(0, 43, 230, 255)  # green; colors range from 0-1 not 0-255
            self.rect8 = Rectangle(size=self.lab8.size, pos=self.lab8.pos)
        self.bt8 = Button(text='Вкл', size_hint=(.2, 1))
        self.bt8.bind(on_press=self.pressing8)

        self.lab9 = Label()
        self.bt9 = Button(text='Подключиться', size_hint=(1, 1))
        self.bt9.bind(on_press=self.pressing9)
        self.lab10 = Label()

        sl.add_widget(al)
        al.add_widget(bl)
        bl.add_widget(bl1)
        bl1.add_widget(self.lab1)
        bl1.add_widget(self.bt1)
        bl.add_widget(bl2)
        bl2.add_widget(self.lab2)
        bl2.add_widget(self.bt2)
        bl.add_widget(bl3)
        bl3.add_widget(self.lab3)
        bl3.add_widget(self.bt3)
        bl.add_widget(bl4)
        bl4.add_widget(self.lab4)
        bl4.add_widget(self.bt4)
        bl.add_widget(bl5)
        bl5.add_widget(self.lab5)
        bl5.add_widget(self.bt5)
        bl.add_widget(bl6)
        bl6.add_widget(self.lab6)
        bl6.add_widget(self.bt6)
        bl.add_widget(bl7)
        bl7.add_widget(self.lab7)
        bl7.add_widget(self.bt7)
        bl.add_widget(bl8)
        bl8.add_widget(self.lab8)
        bl8.add_widget(self.bt8)
        bl.add_widget(bl9)
        bl9.add_widget(self.lab9)
        bl9.add_widget(self.bt9)
        bl9.add_widget(self.lab10)

        self.data1 = '0'
        self.data2 = '0'
        self.data3 = '0'
        self.data4 = '0'
        self.data5 = '0'
        self.data6 = '0'
        self.data7 = '0'
        self.data8 = '0'
        return sl
Пример #20
0
 def build(self):
     scatter = ScatterLayout()
     label = Label(text='hello, world', font_size=60)
     scatter.add_widget(label)
     return scatter
Пример #21
0
    def building_content(self, build_place, build):
        building = config.buildings[build]
        scatter = ScatterLayout(id='town_hall_scatter')
        name_label = PlaceLabel(text=f'{build}, id: {build_place.id}')
        menu = MenuLayout()
        inside_menu = InsideMenuLayout()
        top_layout = BoxLayout(orientation='horizontal', size_hint_y=.3)
        bottom_layout = BoxLayout(orientation='vertical', size_hint_y=.3)
        right_layout = BoxLayout(orientation='vertical')
        upgrade_layout = BoxLayout(orientation='horizontal', size_hint_y=.3)
        description_layout = BoxLayout(size_hint_y=.7)
        description_label = Label(text='Описание здания')
        description_layout.add_widget(description_label)
        icon_rel = BoxLayout(size_hint_x=.3)
        icon = Image(source=building[3])
        icon_rel.add_widget(icon)
        upgrade_label = Label(text=f'{building[1]} сек', size_hint_x=.9)
        upgrade_res_layout = BoxLayout(orientation='horizontal')
        for i, res_cost in enumerate(building[2]):
            if res_cost > 0:
                res_box = BoxLayout(orientation='horizontal', size_hint_x=.5)
                help_lay_res = RelativeLayout()
                help_lay_res.add_widget(
                    Image(source=f'{config.resources[res_list[i]][2]}',
                          size=(25, 25),
                          pos_hint=({
                              'right': 1
                          }),
                          size_hint=(None, 1)))
                add_lay = GridLayout(cols=2,
                                     size_hint=(1, 1),
                                     pos_hint=({
                                         'center_x': .5,
                                         'center_y': .5
                                     }))
                add_lay.add_widget(help_lay_res)
                add_lay.add_widget(BuildResLabel(text=f'{res_cost}'))
                res_box.add_widget(add_lay)
                upgrade_res_layout.add_widget(res_box)
        upgrade_button = Button(text='Up', size_hint_x=.1)
        upgrade_layout.add_widget(upgrade_button)
        upgrade_layout.add_widget(upgrade_label)
        upgrade_layout.add_widget(upgrade_res_layout)
        right_layout.add_widget(upgrade_layout)
        right_layout.add_widget(description_layout)
        top_layout.add_widget(icon_rel)
        top_layout.add_widget(right_layout)
        middle_lay = BoxLayout(size_hint_y=.4)
        slider_layout = BoxLayout(orientation='vertical', size_hint_y=.7)
        input_layout = BoxLayout(orientation='horizontal',
                                 size_hint=(.3, 1),
                                 pos_hint=({
                                     'right': 1
                                 }))
        text_input = UnitTextInput(text='0',
                                   size_hint_y=.9,
                                   pos_hint=({
                                       'center_y': .5
                                   }),
                                   multiline=False)
        total_res_layout = BoxLayout(orientation='horizontal',
                                     size_hint_x=.65,
                                     padding=5)
        self.slider = UnitSlider(text_input, size_hint_y=.55, padding=10)
        total_inside = TotalInsideLayout(orientation='horizontal',
                                         slider=self.slider)
        time_label = TotalTimeLabel(size_hint_y=.3, halign='left')
        total_res_label = TotalResLabel(text='Стоимость:', size_hint_x=.35)
        text_input.slider = self.slider
        self.slider.total_inside = total_inside
        self.slider.time_label = time_label
        self.slider.total_res_label = total_res_label
        hire_button = HireUnitsButton(text='Нанять',
                                      disabled=True,
                                      slider=self.slider,
                                      build_root=self)
        count_box = BoxLayout(orientation='vertical',
                              size_hint_x=.25,
                              padding=1,
                              spacing=1)
        up_button = UpButton(opacity=0, slider=self.slider)
        down_button = DownButton(opacity=0, slider=self.slider)
        bottom_slider_lay = BoxLayout(orientation='horizontal',
                                      size_hint_y=.45)
        scroll_unit = ScrollView(do_scroll_x=False,
                                 scroll_distance=50,
                                 size_hint_y=.8,
                                 pos_hint=({
                                     'center_y': .5
                                 }))
        butt_list = [up_button, down_button]
        self.unit_grid = GridLayout(cols=1,
                                    padding=5,
                                    spacing=5,
                                    size_hint_y=None,
                                    opacity=0)
        self.unit_grid.bind(minimum_height=self.unit_grid.setter('height'))
        self.available_list = []
        checkbox_group_list = []

        for unit_name in building[5]:
            unit = config.units[unit_name]
            checkbox = UnitCheckBox(group='units',
                                    size_hint_x=.05,
                                    slider=self.slider,
                                    txt_inp=text_input,
                                    unit=unit_name,
                                    hb=hire_button,
                                    bl=butt_list,
                                    trl=total_res_label,
                                    tl=time_label)
            checkbox.bind(active=on_checkbox_active)
            checkbox_group_list.append(checkbox)
            grid_layout = UnitGridLayout(cols=6,
                                         size_hint_y=None,
                                         height=40,
                                         checkbox=checkbox)
            unit_icon = Image(source=unit[3], size_hint_x=.05)
            unit_name_label = Label(text=f'{unit_name}', size_hint_x=.2)
            unit_cost = BoxLayout(orientation='horizontal', size_hint_x=.45)
            for i, res_cost in enumerate(unit[2]):
                if res_cost > 0:
                    res_box = BoxLayout(orientation='horizontal',
                                        size_hint_x=.5)
                    help_lay_res = RelativeLayout()
                    help_lay_res.add_widget(
                        Image(source=f'{config.resources[res_list[i]][2]}',
                              size=(25, 25),
                              pos_hint=({
                                  'right': 1
                              }),
                              size_hint=(None, 1)))
                    add_lay = GridLayout(cols=2,
                                         size_hint=(1, 1),
                                         pos_hint=({
                                             'center_x': .5,
                                             'center_y': .5
                                         }))
                    add_lay.add_widget(help_lay_res)
                    add_lay.add_widget(BuildResLabel(text=f'{res_cost}'))
                    res_box.add_widget(add_lay)
                    unit_cost.add_widget(res_box)
            unit_time = Label(text=f'{unit[1]} сек', size_hint_x=.15)
            how_many_lay = BoxLayout(orientation='horizontal', size_hint_x=.1)
            available_label = Label(text='8',
                                    size_hint_y=.8,
                                    pos_hint=({
                                        'center_y': .5
                                    }))
            checkbox.available_label = available_label
            self.available_list.append(available_label)
            all_button = AllUnitButton(text='All',
                                       size_hint_y=.6,
                                       pos_hint=({
                                           'center_y': .5
                                       }),
                                       checkbox=checkbox)
            how_many_lay.add_widget(all_button)
            how_many_lay.add_widget(available_label)
            grid_layout.add_widget(checkbox)
            grid_layout.add_widget(unit_icon)
            grid_layout.add_widget(unit_name_label)
            grid_layout.add_widget(unit_cost)
            grid_layout.add_widget(unit_time)
            grid_layout.add_widget(how_many_lay)
            self.unit_grid.add_widget(grid_layout)

        self.slider.group_list = checkbox_group_list
        scroll_unit.add_widget(self.unit_grid)
        count_box.add_widget(up_button)
        count_box.add_widget(down_button)
        input_layout.add_widget(count_box)
        input_layout.add_widget(text_input)
        input_layout.add_widget(hire_button)
        slider_layout.add_widget(self.slider)
        total_res_layout.add_widget(total_res_label)
        total_res_layout.add_widget(total_inside)
        bottom_slider_lay.add_widget(total_res_layout)
        bottom_slider_lay.add_widget(input_layout)
        slider_layout.add_widget(bottom_slider_lay)
        middle_lay.add_widget(scroll_unit)
        bottom_layout.add_widget(slider_layout)
        bottom_layout.add_widget(time_label)
        inside_menu.add_widget(top_layout)
        inside_menu.add_widget(middle_lay)
        inside_menu.add_widget(bottom_layout)
        menu.add_widget(inside_menu)
        menu.add_widget(name_label)
        close_b = CloseMenuButton(self, scatter)
        menu.add_widget(close_b)
        scatter.add_widget(menu)
        self.update_available_units()
        anim_opacity_up.start(self.unit_grid)
        return scatter
Пример #22
0
sidetitle = Label(text="Optionen",font_size="25sp",color=(0,0,0,1))
sidetitle.pos_hint = {"x":0,"y":.45}
sidebar.add_widget(sidetitle)
titlescat.size = 48,48
titlescat.pos_hint = {"x":0.025,"y":.25}
mencanv = RootWidget()
mencanv.size_hint= .1,.6
mencanv.pos_hint = {"x":0.025,"y":.2}
#titlebar.add_widget(mencanv)
titlebar.add_widget(titlescat)
titleflow = Button(background_normal="school.png",background_down="school.png")
titleflow.size_hint = None,None
titleflow.size = 48,48
titleflow.pos_hint = {"x":0,"y":0}
titleflow.bind(on_release=openmen)
titlescat.add_widget(titleflow)
titlebar.add_widget(titlelab)
mainscreen.add_widget(titlebar)
sm.add_widget(mainscreen)
sm.add_widget(terms)
sm.current = "logonscreen"

logo = Image(source="school.png")
#mainscreen.add_widget(logo)
mainscreen.add_widget(sidebar)





us1 = data("usrname")