Exemple #1
0
                def scope(info):
                    btn = Button(text="Open in Browser")

                    def f(*a):
                        self.openInBrowser("http://" + info['hash'] +
                                           ".localhost:7009")

                    btn.bind(on_press=f)

                    l.add_widget(btn)

                    btn = Button(text="Copy URL")

                    def f(*a):
                        try:
                            from kivy.core.clipboard import Clipboard
                            Clipboard.copy("http://" + info['hash'] +
                                           ".localhost:7009")
                        except:
                            logging.exception("Could not copy to clipboard")

                    btn.bind(on_press=f)

                    self.localServicesListBox.add_widget(
                        MDToolbar(title=str(info.get('title', 'no title'))))

                    l.add_widget(btn)
Exemple #2
0
    def makeButtonForStream(self, name):
        "Make a button that, when pressed, edits the stream in the title"

        btn = Button(text=name)

        def f(*a):
            self.editStream(name)

        btn.bind(on_press=f)
        return btn
    def makeButtonForLocalService(self, name, c=None):
        "Make a button that, when pressed, edits the local service in the title"

        btn = Button(text=name)

        def f(*a):
            self.editLocalService(name, c)

        btn.bind(on_press=f)

        return btn
    def makeSettingsPage(self):
        page = Screen(name='Settings')

        layout = BoxLayout(orientation='vertical')
        page.add_widget(layout)
        label = MDToolbar(title="Settings and Tools")
        layout.add_widget(label)

        layout.add_widget(self.makeBackButton())

        log = Button(text='System Logs')

        btn1 = Button(text='Local Services')
        label1 = Label(halign="center",
                       text='Share a local webservice with the world')

        log.bind(on_release=self.gotoLogs)
        btn1.bind(on_press=self.goToLocalServices)
        layout.add_widget(log)

        layout.add_widget(btn1)
        layout.add_widget(label1)

        btn = Button(text='Global Settings')

        btn.bind(on_press=self.goToGlobalSettings)
        layout.add_widget(btn)

        # Start/Stop
        btn3 = Button(text='Stop')
        btn3.bind(on_press=self.stop_service)
        label3 = Label(
            size_hint=(1, None),
            halign="center",
            text=
            'Stop the background process.  It must be running to acess hardline sites.  Starting may take a few seconds.'
        )
        layout.add_widget(btn3)
        layout.add_widget(label3)

        btn4 = Button(text='Start or Restart.')
        btn4.bind(on_press=self.start_service)
        label4 = Label(
            size_hint=(1, None),
            halign="center",
            text='Restart the process. It will show in your notifications.')
        layout.add_widget(btn4)
        layout.add_widget(label4)

        layout.add_widget(Widget())

        return page
    def goToGlobalSettings(self, *a):
        if os.path.exists(hardline.globalSettingsPath):
            with open(hardline.globalSettingsPath) as f:
                globalConfig = toml.load(f)
        else:
            globalConfig = {}

        self.localSettingsBox.clear_widgets()

        self.localSettingsBox.add_widget(
            Label(size_hint=(1, 6), halign="center", text='OpenDHT Proxies'))
        self.localSettingsBox.add_widget(
            Label(size_hint=(1, None),
                  text='Proxies are tried in order from 1-3'))

        self.localSettingsBox.add_widget(
            self.settingButton(globalConfig, "DHTProxy", 'server1'))
        self.localSettingsBox.add_widget(
            self.settingButton(globalConfig, "DHTProxy", 'server2'))
        self.localSettingsBox.add_widget(
            self.settingButton(globalConfig, "DHTProxy", 'server3'))

        self.localSettingsBox.add_widget(
            Label(size_hint=(1, 6), halign="center", text='Stream Server'))
        self.localSettingsBox.add_widget(
            Label(
                size_hint=(1, None),
                text=
                'To allow others to sync to this node as a DrayerDB Stream server, set a server title to expose a service'
            ))

        self.localSettingsBox.add_widget(
            self.settingButton(globalConfig, "DrayerDB", 'serverName'))

        btn1 = Button(text='Save')

        def save(*a):
            with open(hardline.globalSettingsPath, 'w') as f:
                toml.dump(globalConfig, f)
            if platform == 'android':
                self.stop_service()
                self.start_service()
            else:
                daemonconfig.loadDrayerServerConfig()

            self.screenManager.current = "Main"

        btn1.bind(on_press=save)
        self.localSettingsBox.add_widget(btn1)
        self.screenManager.current = "GlobalSettings"
    def makeLocalServicesPage(self):

        screen = Screen(name='LocalServices')
        self.servicesScreen = screen

        layout = BoxLayout(orientation='vertical', spacing=10)
        screen.add_widget(layout)

        label = Label(
            size_hint=(1, None),
            halign="center",
            text=
            'WARNING: Running a local service may use a lot of data and battery.\nChanges may require service restart.'
        )

        labelw = Label(
            size_hint=(1, None),
            halign="center",
            text=
            'WARNING 2: This app currently prefers the external SD card for almost everything including the keys.'
        )

        layout.add_widget(self.makeBackButton())

        layout.add_widget(label)
        layout.add_widget(labelw)

        btn2 = Button(text='Create a service')

        btn2.bind(on_press=self.promptAddService)
        layout.add_widget(btn2)

        self.localServicesListBoxScroll = ScrollView(size_hint=(1, 1))

        self.localServicesListBox = BoxLayout(orientation='vertical',
                                              size_hint=(1, None),
                                              spacing=10)
        self.localServicesListBox.bind(
            minimum_height=self.localServicesListBox.setter('height'))

        self.localServicesListBoxScroll.add_widget(self.localServicesListBox)

        layout.add_widget(self.localServicesListBoxScroll)

        return screen
Exemple #7
0
class Class_Screen1(MDFloatLayout):

    #################################################
    def __init__(self, **kwargs):
        super(Class_Screen1, self).__init__(**kwargs)
        ###
        self.Drawing = Draw_Stuff()
        ###
        self.Now_Press_Me_Button = MDFillRoundFlatButton()
        self.Press_Me_Button = MDFillRoundFlatButton()
        self.Clear_Screen_Button = MDFillRoundFlatButton()
        self.BStop = MDFillRoundFlatButton()
        self.TFDisplay = MDTextField()
        ###
        self.LH = 0
        self.LW = 0
        self.Xo = 0
        self.Xf = 0
        self.Xc = 0
        self.Yo = 0
        self.Yf = 0
        self.Yc = 0
        self.StrTime = ''
        self.To = time.time()
        self.Tf = time.time()
        ###
        return

    #################################################
    def Initialize(self):
        ##############################
        # Universal Screen Dimensions
        self.size = Window.size
        self.LW = self.width
        self.LH = self.height
        if (self.LW >= self.LH):
            min = self.LH
        else:
            min = self.LW
        self.LW = int(min * 0.5)
        self.LH = int(min * 0.5)
        ##############################
        self.Xc = int(self.width * 0.5)
        self.Yc = int(self.height * 0.5)
        self.Xo = self.Xc - int(self.LW * 0.5)
        self.Xf = self.width - 5
        self.Yo = self.Yc - int(self.height * 0.5) + 5
        self.Yf = self.height - 5
        ##############################
        LHeight = self.height
        LHeight = int(LHeight / 16)
        ##############################
        self.Clear_Drawing_Window()
        self.Drawing.Draw_Frame(pScreen=self,
                                pXo=self.Xo,
                                pXf=self.Xf,
                                pYo=self.Yo,
                                pYf=self.Yf)
        self.Drawing.Show_Instructions(pScreen=self)
        ##############################
        self.Now_Press_Me_Button.size_hint_y = None
        self.Now_Press_Me_Button.text = 'NOW PRESS ME'
        self.Now_Press_Me_Button.height = LHeight
        self.Now_Press_Me_Button.x = int(self.Xo * 0.1)
        self.Now_Press_Me_Button.y = self.height - int(LHeight * 2)
        if (self.Now_Press_Me_Button.parent != None):
            self.remove_widget(self.Now_Press_Me_Button)
        ##############################
        self.BStop.size_hint_y = None
        self.BStop.text = 'TIMER'
        self.BStop.height = self.Now_Press_Me_Button.height
        self.BStop.x = self.Now_Press_Me_Button.x
        self.BStop.y = self.Now_Press_Me_Button.y - int(LHeight * 2)
        if (self.BStop.parent != None):
            self.remove_widget(self.BStop)
        ##############################
        self.Press_Me_Button.size_hint_y = None
        self.Press_Me_Button.text = 'PRESS ME'
        self.Press_Me_Button.height = self.Now_Press_Me_Button.height
        self.Press_Me_Button.x = self.Now_Press_Me_Button.x
        self.Press_Me_Button.y = self.BStop.y - int(LHeight * 2)
        if (self.Press_Me_Button.parent == None):
            self.add_widget(self.Press_Me_Button)
        ##############################
        self.Clear_Screen_Button.size_hint_y = None
        self.Clear_Screen_Button.text = 'Clear Screen'
        self.Clear_Screen_Button.height = self.Now_Press_Me_Button.height
        self.Clear_Screen_Button.x = self.Now_Press_Me_Button.x
        self.Clear_Screen_Button.y = self.Press_Me_Button.y - int(LHeight * 2)
        if (self.Clear_Screen_Button.parent == None):
            self.add_widget(self.Clear_Screen_Button)
        ##############################
        Y1 = self.Clear_Screen_Button.y - LHeight
        self.TFDisplay.size_hint = (None, None)
        self.TFDisplay.height = int(Y1 * 0.9)
        self.TFDisplay.width = int(self.Xo * 0.8)
        self.TFDisplay.x = self.Now_Press_Me_Button.x
        self.TFDisplay.y = self.Clear_Screen_Button.y - int(
            LHeight * 2) - self.TFDisplay.height
        self.TFDisplay.text = self.StrTime
        self.TFDisplay.multiline = True
        self.TFDisplay.readonly = True
        self.TFDisplay.hint_text = 'Time (sec)'
        self.TFDisplay.helper_text = 'Press TIMER when you see it'
        self.TFDisplay.helper_text_mode = 'persistent'
        self.TFDisplay.line_color_normal = (0, 0, 0, 1)
        self.TFDisplay.current_hint_text_color = (0, 0, 0, 1)
        if (self.TFDisplay.parent == None):
            self.add_widget(self.TFDisplay)
        ##############################
        self.Now_Press_Me_Button.bind(
            on_release=self.Press_Now_Press_Me_Button)
        self.Press_Me_Button.bind(on_release=self.Press_Press_Me_Button)
        self.Clear_Screen_Button.bind(
            on_release=self.Press_Clear_Screen_Button)
        self.BStop.bind(on_release=self.Press_STOP_Button)
        ##############################
        return

    #################################################
    def Press_Now_Press_Me_Button(self, instance):
        self.To = time.time()
        self.Clear_Drawing_Window()
        self.Drawing.Draw_ManyLines(pScreen = self, \
                                    pXo = self.Xo, \
                                    pXf = self.Xf, \
                                    pYo = self.Yo, \
                                    pYf = self.Yf, \
                                    pR  = 0, \
                                    pG  = 1, \
                                    pB  = 1, \
                                    pOffset = 2)
        self.Drawing.Show_Instructions(pScreen=self)
        #############################################
        if (self.TFDisplay.parent == None):
            self.add_widget(self.TFDisplay)
        if (self.Clear_Screen_Button.parent == None):
            self.add_widget(self.Clear_Screen_Button)
        if (self.BStop.parent == None):
            self.add_widget(self.BStop)
        if (self.Press_Me_Button.parent == None):
            self.add_widget(self.Press_Me_Button)
        #############################################
        if (self.Now_Press_Me_Button.parent != None):
            self.remove_widget(self.Now_Press_Me_Button)
        #############################################
        return

    #################################################
    def Press_STOP_Button(self, instance):
        self.Tf = time.time()
        Tdiff = self.Tf - self.To
        Ftmp = round(Tdiff, 6)
        self.StrTime += 't = ' + str(Ftmp) + ' (sec)\n'
        self.TFDisplay.text = self.StrTime
        #############################################
        if (self.BStop.parent != None):
            self.remove_widget(self.BStop)
        #############################################
        return

    #################################################
    def Press_Press_Me_Button(self, instance):
        self.Clear_Drawing_Window()
        self.Drawing.Draw_Frame(pScreen=self,
                                pXo=self.Xo,
                                pXf=self.Xf,
                                pYo=self.Yo,
                                pYf=self.Yf)
        self.Drawing.Show_Instructions(pScreen=self)
        #############################################
        if (self.Now_Press_Me_Button.parent == None):
            self.add_widget(self.Now_Press_Me_Button)
        if (self.TFDisplay.parent == None):
            self.add_widget(self.TFDisplay)
        if (self.Clear_Screen_Button.parent == None):
            self.add_widget(self.Clear_Screen_Button)
        #############################################
        if (self.BStop.parent != None):
            self.remove_widget(self.BStop)
        if (self.Press_Me_Button.parent != None):
            self.remove_widget(self.Press_Me_Button)
        #############################################
        return

    #################################################
    def Press_Clear_Screen_Button(self, instance):
        self.StrTime = ''
        self.Clear_Screen()
        self.Initialize()
        #############################################
        if (self.Now_Press_Me_Button.parent == None):
            self.add_widget(self.Now_Press_Me_Button)
        if (self.TFDisplay.parent == None):
            self.add_widget(self.TFDisplay)
        if (self.Press_Me_Button.parent == None):
            self.add_widget(self.Press_Me_Button)
        if (self.Clear_Screen_Button.parent == None):
            self.add_widget(self.Clear_Screen_Button)
        #############################################
        if (self.Now_Press_Me_Button.parent != None):
            self.remove_widget(self.Now_Press_Me_Button)
        if (self.BStop.parent != None):
            self.remove_widget(self.BStop)
        #############################################
        return

    #################################################
    def Unbind_All(self):
        self.Now_Press_Me_Button.unbind(
            on_release=self.Press_Now_Press_Me_Button)
        self.Press_Me_Button.unbind(on_release=self.Press_Press_Me_Button)
        self.Clear_Screen_Button.unbind(
            on_release=self.Press_Clear_Screen_Button)
        self.BStop.unbind(on_release=self.Press_STOP_Button)
        return

    #################################################
    def Clear_Drawing_Window(self):
        self.Drawing.Clear_IG()
        return

    #################################################
    def Clear_Screen(self):
        self.Unbind_All()
        self.Clear_Drawing_Window()
        self.clear_widgets()
        self.canvas.clear()
        return
Exemple #8
0
    def goToStreams(self, *a):

        "Go to a page wherein we can list user-modifiable services."
        self.streamsEditPanel.clear_widgets()

        layout = self.streamsEditPanel

        bar = BoxLayout(spacing=10, adaptive_height=True, size_hint=(1, None))

        stack = StackLayout(spacing=10,
                            adaptive_height=True,
                            size_hint=(1, None))
        layout.add_widget(bar)
        layout.add_widget(MDToolbar(title="My Streams"))

        layout.add_widget(stack)

        def upOne(*a):
            self.gotoMainScreen()

        btn1 = Button(text='Up')

        btn1.bind(on_press=upOne)

        bar.add_widget(btn1)
        bar.add_widget(self.makeBackButton())

        btn2 = Button(text='Create a Stream')

        btn2.bind(on_press=self.promptAddStream)
        stack.add_widget(btn2)

        def f(selection):
            if selection:
                dn = 'file:' + os.path.basename(selection)
                while dn in daemonconfig.userDatabases:
                    dn = dn + '2'
                try:
                    daemonconfig.loadUserDatabase(selection, dn)
                    self.editStream(dn)
                except:
                    logging.exception(dn)

            self.openFM.close()

        #This lets us view notebook files that aren't installed.
        def promptOpen(*a):

            try:
                #Needed for android
                self.getPermission('files')
            except:
                logging.exception("cant ask permission")

            from .kivymdfmfork import MDFileManager
            from . import directories
            self.openFM = MDFileManager(select_path=f)

            if os.path.exists("/storage/emulated/0/Documents") and os.access(
                    "/storage/emulated/0/Documents", os.W_OK):
                self.openFM.show("/storage/emulated/0/Documents")
            elif os.path.exists(
                    os.path.expanduser("~/Documents")) and os.access(
                        os.path.expanduser("~/Documents"), os.W_OK):
                self.openFM.show(os.path.expanduser("~/Documents"))
            else:
                self.openFM.show(directories.externalStorageDir
                                 or directories.settings_path)

        btn1 = Button(text='Open Book File')

        btn1.bind(on_press=promptOpen)

        stack.add_widget(btn1)

        def goHere():
            self.screenManager.current = "Streams"

        self.backStack.append(goHere)
        self.backStack = self.backStack[-50:]

        layout.add_widget(MDToolbar(title="Open Streams:"))

        try:
            s = daemonconfig.userDatabases
            time.sleep(0.5)
            for i in s:
                layout.add_widget(self.makeButtonForStream(i))
                try:
                    for j in daemonconfig.userDatabases[i].connectedServers:
                        if daemonconfig.userDatabases[i].connectedServers[
                                j] > (time.time() - (10 * 60)):
                            w = 'online'
                        else:
                            w = 'idle/offline'
                        layout.add_widget(
                            self.saneLabel(j[:28] + ": " + w, layout))
                except:
                    logging.exception("Error showing node status")

        except Exception:
            logging.info(traceback.format_exc())

        self.screenManager.current = "Streams"
Exemple #9
0
    def editStream(self, name):
        if not name in daemonconfig.userDatabases:
            self.goToStreams()
        db = daemonconfig.userDatabases[name]
        c = db.config
        try:
            c.add_section("Service")
        except:
            pass
        try:
            c.add_section("Info")
        except:
            pass

        self.streamEditPanel.clear_widgets()
        topbar = BoxLayout(size_hint=(1, None),
                           adaptive_height=True,
                           spacing=5)

        stack = StackLayout(size_hint=(1, None),
                            adaptive_height=True,
                            spacing=5)

        def upOne(*a):
            self.goToStreams()

        btn1 = Button(text='Up')

        btn1.bind(on_press=upOne)

        topbar.add_widget(btn1)

        topbar.add_widget(self.makeBackButton())

        self.streamEditPanel.add_widget(topbar)
        self.streamEditPanel.add_widget(MDToolbar(title=name))

        def goHere():
            self.editStream(name)

        self.backStack.append(goHere)
        self.backStack = self.backStack[-50:]

        btn2 = Button(text='Notebook View')

        def goPosts(*a):
            self.gotoStreamPosts(name)

        btn2.bind(on_press=goPosts)
        stack.add_widget(btn2)

        btn2 = Button(text='Feed View')

        def goPosts(*a):
            self.gotoStreamPosts(name, parent=None)

        btn2.bind(on_press=goPosts)
        stack.add_widget(btn2)

        btn2 = Button(text='Stream Settings')

        def goSettings(*a):
            self.editStreamSettings(name)

        btn2.bind(on_press=goSettings)
        stack.add_widget(btn2)

        if name.startswith('file:'):
            btn2 = Button(text='Close Stream')

            def close(*a):
                daemonconfig.closeUserDatabase(name)
                self.goToStreams()

            btn2.bind(on_press=close)
            stack.add_widget(btn2)

        importData = Button(text="Import Data File")

        def promptSet(*a):
            try:
                #Needed for android
                self.getPermission('files')
            except:
                logging.exception("cant ask permission")

            def f(selection):
                if selection:

                    def f2(x):
                        if x:
                            with daemonconfig.userDatabases[name]:
                                with open(selection) as f:
                                    daemonconfig.userDatabases[
                                        name].importFromToml(f.read())
                            daemonconfig.userDatabases[name].commit()

                    self.askQuestion("Really import?", "yes", cb=f2)
                self.openFM.close()

            from .kivymdfmfork import MDFileManager
            from . import directories
            self.openFM = MDFileManager(select_path=f)

            if os.path.exists("/storage/emulated/0/Documents") and os.access(
                    "/storage/emulated/0/Documents", os.W_OK):
                self.openFM.show("/storage/emulated/0/Documents")
            elif os.path.exists(
                    os.path.expanduser("~/Documents")) and os.access(
                        os.path.expanduser("~/Documents"), os.W_OK):
                self.openFM.show(os.path.expanduser("~/Documents"))
            else:
                self.openFM.show(directories.externalStorageDir
                                 or directories.settings_path)

        importData.bind(on_release=promptSet)
        stack.add_widget(importData)

        export = Button(text="Export All Posts")

        def promptSet(*a):
            from .kivymdfmfork import MDFileManager
            from .. import directories
            try:
                #Needed for android
                self.getPermission('files')
            except:
                logging.exception("cant ask permission")

            def f(selection):
                if selection:
                    if not selection.endswith(".toml"):
                        selection = selection + ".toml"

                    def g(a):
                        if a == 'yes':

                            r = daemonconfig.userDatabases[
                                name].getDocumentsByType('post', parent='')
                            data = daemonconfig.userDatabases[
                                name].exportRecordSetToTOML(
                                    [i['id'] for i in r])

                            logging.info("Exporting data to:" + selection)
                            with open(selection, 'w') as f:
                                f.write(data)
                        self.openFM.close()

                    if os.path.exists(selection):
                        self.askQuestion("Overwrite?", 'yes', g)
                    else:
                        g('yes')

            #Autocorrect had some fun with the kivymd devs
            self.openFM = MDFileManager(select_path=f,
                                        save_mode=(name + '.toml'))

            if os.path.exists("/storage/emulated/0/Documents") and os.access(
                    "/storage/emulated/0/Documents", os.W_OK):
                self.openFM.show("/storage/emulated/0/Documents")
            elif os.path.exists(
                    os.path.expanduser("~/Documents")) and os.access(
                        os.path.expanduser("~/Documents"), os.W_OK):
                self.openFM.show(os.path.expanduser("~/Documents"))
            else:
                self.openFM.show(directories.externalStorageDir
                                 or directories.settings_path)

        export.bind(on_release=promptSet)

        stack.add_widget(export)

        self.streamEditPanel.add_widget(stack)

        #Show recent changes no matter where they are in the tree.
        #TODO needs to be hideable for anti-spoiler purposes in fiction.
        self.streamEditPanel.add_widget(MDToolbar(title="Recent Changes:"))

        for i in daemonconfig.userDatabases[name].getDocumentsByType(
                'post', orderBy='arrival DESC', limit=5):
            x = self.makePostWidget(name, i, includeParent=True)
            self.streamEditPanel.add_widget(x)

        self.screenManager.current = "EditStream"
    def makeBackButton(self,width=1):
        btn1 = Button(text='Back')

        btn1.bind(on_press=self.goBack)
        return btn1
    def gotoMainScreen(self):
        self.mainScreenlayout.clear_widgets()
        layout=self.mainScreenlayout

    
        label = MDToolbar(title="Drayer Journal")
        label.icon=os.path.join(os.path.dirname(os.path.abspath("__file__")),'assets','icons',"Craftpix.net",'medival','cart.jpg')
        layout.add_widget(label)

        stack = StackLayout(size_hint=(1,None),adaptive_height=True,spacing=5)

      
        l = self.saneLabel("Notice: streams may be stored on the SD card. Some other apps may be able to read them",layout)
        layout.add_widget(l)
            
        btn1 = Button(text='My Streams')

        stack.add_widget(btn1)

        btn1.bind(on_press=self.goToStreams)

        btn1 = Button(text='Discover Services')
     

        btn1.bind(on_press=self.goToDiscovery)
        stack.add_widget(btn1)

        btn5 = Button(text='Settings+Tools')

        btn5.bind(on_press=self.goToSettings)

        stack.add_widget(btn5)


        btn6 = Button(text='Help')

        btn6.bind(on_press=self.goToHelp)

        stack.add_widget(btn6)

        layout.add_widget(stack)

        label = MDToolbar(title="Bookmarks")
        layout.add_widget(label)

        for i in sorted(list(daemonconfig.getBookmarks().keys())):
            bw =BoxLayout(orientation='horizontal',
                           spacing=10, size_hint=(1, None),adaptive_height=True)
            b = Button(text=i[:32])
            bd = Button(text="Del")


            def dlbm(*a,i=i):
                def f(a):
                    if a:
                        daemonconfig.setBookmark(a,None,None)
                        self.gotoMainScreen()
                self.askQuestion("Delete Bookmark?",i,f)
            bd.bind(on_press=dlbm)

            def bm(*a,i=i):
                self.gotoBookmark(i)
            b.bind(on_press=bm)
            bw.add_widget(b)
            bw.add_widget(bd)
            layout.add_widget(bw)

        self.screenManager.current = "Main"
Exemple #12
0
    def gotoStreamRow(self,
                      stream,
                      postID,
                      document=None,
                      noBack=False,
                      template=None):
        "Editor/viewer for ONE specific row"
        self.streamEditPanel.clear_widgets()
        self.streamEditPanel.add_widget(
            MDToolbar(title="Table Row in " + stream))

        self.streamEditPanel.add_widget(self.makeBackButton())

        if not noBack:

            def goHere():
                self.gotoStreamRow(stream, postID)

            self.backStack.append(goHere)
            self.backStack = self.backStack[-50:]

        document = document or daemonconfig.userDatabases[
            stream].getDocumentByID(postID, allowOrphans=True)
        if 'type' in document and not document['type'] == 'row':
            raise RuntimeError("Document is not a row")
        document['type'] = 'row'

        title = Label(text=document.get("name", ''), font_size='22sp')

        #Our default template if none exists
        #Give it a name because eventually we may want to have multiple templates.
        #Give it an ID so it can override any existing children of that template.
        #Use only the direct ID of the parent record in cade we want to move it eventually.
        oldTemplate = {
            'type':
            "row.template",
            'leafNode':
            True,
            'parent':
            document['parent'],
            'name':
            'default',
            'id':
            uuid.uuid5(uuid.UUID(document['parent'].split("/")[-1]),
                       ".rowtemplate.default")
        }

        for i in daemonconfig.userDatabases[stream].getDocumentsByType(
                "row.template",
                parent=document['parent'],
                limit=1,
                allowOrphans=True):
            oldTemplate = i

        template = template or oldTemplate

        def post(*a):
            with daemonconfig.userDatabases[stream]:
                #Make sure system knows this is not an old document
                try:
                    del document['time']
                except:
                    pass
                daemonconfig.userDatabases[stream].setDocument(document)

                #If the template has changed, that is how we know we need to save template changes at the same time as data changes
                if not template.get('time', 0) == oldTemplate.get('time', 1):
                    daemonconfig.userDatabases[stream].setDocument(template)
                daemonconfig.userDatabases[stream].commit()
                self.unsavedDataCallback = None

            self.goBack()

        btn1 = Button(text='Save Changes')
        btn1.bind(on_release=post)

        self.streamEditPanel.add_widget(title)

        buttons = BoxLayout(orientation="horizontal",
                            spacing=10,
                            adaptive_height=True)

        if daemonconfig.userDatabases[stream].writePassword:
            self.streamEditPanel.add_widget(buttons)
            buttons.add_widget(btn1)

        def delete(*a):
            def reallyDelete(v):
                if v == postID:
                    with daemonconfig.userDatabases[stream]:
                        daemonconfig.userDatabases[stream].setDocument({
                            'type':
                            'null',
                            'id':
                            postID
                        })
                        daemonconfig.userDatabases[stream].commit()
                    self.gotoStreamPosts(stream)

            self.askQuestion("Delete table row permanently on all nodes?",
                             postID, reallyDelete)

        btn1 = Button(text='Delete')
        btn1.bind(on_release=delete)

        if daemonconfig.userDatabases[stream].writePassword:
            buttons.add_widget(btn1)

        names = {}

        self.streamEditPanel.add_widget(MDToolbar(title="Data Columns:"))

        for i in template:
            if i.startswith('row.'):
                names[i] = ''

        for i in document:
            if i.startswith('row.'):
                if i in template:
                    names[i] = ''
                else:
                    #In the document but not the template, it is an old/obsolete column, show that to user.
                    names[i] = '(removed)'

        for i in names:
            self.streamEditPanel.add_widget(Button(text=i[4:]))
            d = document.get(i, '')
            try:
                d = float(d)
            except:
                pass

            x = MDTextField(text=str(d) + names[i],
                            mode='fill',
                            multiline=False,
                            font_size='22sp')

            def oc(*a, i=i, x=x):
                d = x.text.strip()
                if isinstance(d, str):
                    d = d.strip()
                try:
                    d = float(d or 0)
                except:
                    pass
                document[i] = d

            x.bind(text=oc)
            self.streamEditPanel.add_widget(x)

            if isinstance(d, float) or not d.strip():
                l = BoxLayout(orientation="horizontal",
                              spacing=10,
                              adaptive_height=True)
                b = MDRoundFlatButton(text="--")

                def f(*a, i=i, x=x):
                    d = document.get(i, '')
                    if isinstance(d, str):
                        d = d.strip()
                    try:
                        d = float(d or 0)
                    except:
                        return
                    document[i] = d - 1
                    x.text = str(d - 1)

                b.bind(on_release=f)

                b2 = MDRoundFlatButton(text="++")

                def f(*a, i=i, x=x):
                    d = document.get(i, '')
                    if isinstance(d, str):
                        d = d.strip()
                    try:
                        d = float(d or 0)
                    except:
                        return
                    document[i] = d + 1
                    x.text = str(document[i])

                b2.bind(on_release=f)

                l.add_widget(b)
                l.add_widget(b2)
                self.streamEditPanel.add_widget(l)

        b = MDRoundFlatButton(text="Add Column")

        def f(*a):
            def f2(r):
                if r:
                    template['row.' + r] = ''
                    #Remove time field which marks it as a new record that will get a new timestamp rather than
                    #being ignored when we go to save it, for being old.
                    template.pop('time', None)
                    #Redraw the whole page, it is lightweight, no DB operation needed.
                    self.gotoStreamRow(stream,
                                       postID,
                                       document=document,
                                       noBack=True,
                                       template=template)

            self.askQuestion("Name of new column?", cb=f2)

        b.bind(on_release=f)
        self.streamEditPanel.add_widget(b)

        b = MDRoundFlatButton(text="Del Column")

        def f(*a):
            def f2(r):
                if r:
                    try:
                        del template['row.' + r]
                        template.pop('time', None)
                    except:
                        pass
                    #Redraw the whole page, it is lightweight, no DB operation needed.
                    self.gotoStreamRow(stream,
                                       postID,
                                       document=document,
                                       noBack=True,
                                       template=template)

            self.askQuestion("Column to delete?", cb=f2)

        b.bind(on_release=f)
        self.streamEditPanel.add_widget(b)

        self.screenManager.current = "EditStream"
Exemple #13
0
    def gotoTableView(self, stream, parent='', search=''):
        "Data records can be attatched to a post."
        self.currentPageNewRecordHandler = None
        self.streamEditPanel.clear_widgets()
        s = daemonconfig.userDatabases[stream]
        parentDoc = daemonconfig.userDatabases[stream].getDocumentByID(
            parent, allowOrphans=True)
        if not parentDoc:
            logging.error("nonexistent parent document")
            return
        themeColor = getColor(parentDoc)
        self.streamEditPanel.add_widget(self.makeBackButton())

        postWidget = self.makePostWidget(stream,
                                         parentDoc,
                                         indexAssumption=False)
        self.streamEditPanel.add_widget(postWidget)
        t = (MDToolbar(title="Data Table View"))

        if themeColor:
            t.md_bg_color = themeColor
            t.specific_text_color = getFGForColor(themeColor)

        self.streamEditPanel.add_widget(t)

        topbar = BoxLayout(orientation="horizontal",
                           spacing=10,
                           adaptive_height=True)

        searchBar = BoxLayout(orientation="horizontal",
                              spacing=10,
                              adaptive_height=True)

        searchQuery = MDTextField(size_hint=(0.68, None),
                                  multiline=False,
                                  text=search)
        searchButton = MDRoundFlatButton(text="Search")
        searchBar.add_widget(searchQuery)
        searchBar.add_widget(searchButton)

        def doSearch(*a):
            self.currentPageNewRecordHandler = None
            self.gotoTableView(stream, parent, searchQuery.text.strip())

        searchButton.bind(on_release=doSearch)

        def goHere():
            self.currentPageNewRecordHandler = None
            self.gotoTableView(stream, parent, search)

        self.backStack.append(goHere)
        self.backStack = self.backStack[-50:]

        newEntryBar = BoxLayout(orientation="horizontal",
                                spacing=10,
                                adaptive_height=True)

        newRowName = MDTextField(size_hint=(0.68, None),
                                 multiline=False,
                                 text=search)

        def write(*a):
            for i in newRowName.text:
                if i in "[]{}:,./\\":
                    return

            if newRowName.text.strip():
                id = uuid.uuid5(
                    uuid.UUID(parent),
                    newRowName.text.strip().lower().replace(' ', ""))
                #That name already exists, jump to it
                if daemonconfig.userDatabases[stream].getDocumentByID(
                        id, allowOrphans=True):
                    self.currentPageNewRecordHandler = None
                    self.gotoStreamRow(stream, id)
                    return
            else:
                id = str(uuid.uuid4())

            x = daemonconfig.userDatabases[stream].getDocumentsByType(
                "row.template", parent=parent, limit=1, allowOrphans=True)
            newDoc = {
                'parent': parent,
                'id': id,
                'name': newRowName.text.strip() or id,
                'type': 'row',
                'leafNode': True
            }

            #Use the previously created or modified row as the template
            for i in x:
                for j in i:
                    if j.startswith('row.'):
                        newDoc[j] = ''

            self.currentPageNewRecordHandler = None
            self.gotoStreamRow(stream, id, newDoc)

        btn1 = Button(text='New Entry')

        btn1.bind(on_press=write)
        newEntryBar.add_widget(newRowName)
        newEntryBar.add_widget(btn1)

        if s.writePassword:
            topbar.add_widget(newEntryBar)

        self.streamEditPanel.add_widget(topbar)

        if not search:
            p = s.getDocumentsByType("row",
                                     limit=1000,
                                     parent=parent,
                                     allowOrphans=True)
        else:
            p = s.searchDocuments(search, "row", limit=1000, parent=parent)

        t = MDToolbar(title="Data Rows")

        if themeColor:
            t.md_bg_color = themeColor
            t.specific_text_color = getFGForColor(themeColor)

        self.streamEditPanel.add_widget(t)
        self.streamEditPanel.add_widget(searchBar)

        for i in p:
            self.streamEditPanel.add_widget(self.makeRowWidget(stream, i))
        self.screenManager.current = "EditStream"

        def onNewRecord(db, r, sig):
            if db is daemonconfig.userDatabases[stream]:
                if r.get('parent', '') == parentDoc.get(
                        'parent', '') and r['type'] == "post":
                    if not self.unsavedDataCallback:
                        self.gotoStreamPost(stream, postID, noBack=True)

                elif parentDoc['id'] in r.get("parent", ''):
                    postWidget.body.text = renderPostTemplate(
                        daemonconfig.userDatabases[stream], parentDoc['id'],
                        parentDoc.get("body", ''))[0]

        self.currentPageNewRecordHandler = onNewRecord
    def editLocalService(self, name, c=None):
        if not c:
            c = configparser.RawConfigParser(
                dict_type=cidict.CaseInsensitiveDict)

        try:
            c.add_section("Service")
        except:
            pass
        try:
            c.add_section("Info")
        except:
            pass

        self.localServiceEditPanel.clear_widgets()

        self.localServiceEditorName.text = name

        def save(*a):
            logging.info("SAVE BUTTON WAS PRESSED")
            # On android this is the bg service's job
            daemonconfig.makeUserService(
                None,
                name,
                title=c['Info'].get("title", 'Untitled'),
                service=c['Service'].get("service", ""),
                port=c['Service'].get("port", ""),
                cacheInfo=c['Cache'],
                noStart=(platform == 'android'),
                useDHT=c['Access'].get("useDHT", "yes"))
            if platform == 'android':
                self.stop_service()
                self.start_service()

            self.goToLocalServices()

        def delete(*a):
            def f(n):
                if n and n == name:
                    daemonconfig.delUserService(None, n)
                    if platform == 'android':
                        self.stop_service()
                        self.start_service()
                    self.goToLocalServices()

            self.askQuestion("Really delete?", name, f)

        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None), halign="center", text='Service'))

        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Service", "service"))
        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Service", "port"))
        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Info", "title"))

        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None), halign="center", text='Cache'))
        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None),
                  text='Cache mode only works for static content'))

        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Cache", "directory"))

        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Cache", "maxAge"))

        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None),
                  text='Try to refresh after maxAge seconds(default 1 week)'))

        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Cache", "maxSize", '256'))

        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None),
                  text='Max size to use for the cache in MB'))

        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Cache", "downloadRateLimit", '1200'))

        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None), text='Max MB per hour to download'))

        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Cache", "dynamicContent", 'no'))

        self.localServiceEditPanel.add_widget(
            Label(
                size_hint=(1, None),
                text=
                'Allow executing code in protected @mako files in the cache dir. yes to enable. Do not use with untrusted @mako'
            ))

        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Cache", "allowListing", 'no'))

        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None),
                  text='Allow directory listing of cached content'))

        self.localServiceEditPanel.add_widget(
            Label(
                size_hint=(1, None),
                text=
                'Directory names are subfolders within the HardlineP2P cache folder,\nand can also be used to share\nstatic files by leaving the service blank.'
            ))

        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None), halign="center",
                  text='Access Settings'))
        self.localServiceEditPanel.add_widget(
            Label(size_hint=(1, None),
                  text='Cache mode only works for static content'))

        self.localServiceEditPanel.add_widget(
            self.settingButton(c, "Access", "useDHT", 'yes'))

        self.localServiceEditPanel.add_widget(
            Label(
                size_hint=(1, None),
                text=
                'DHT Discovery uses a proxy server on Android. \nDisabling this saves bandwidth but makes access from outside your network\nunreliable.'
            ))

        btn1 = Button(text='Save Changes')

        btn1.bind(on_press=save)
        self.localServiceEditPanel.add_widget(btn1)

        btn2 = Button(text='Delete this service')

        btn2.bind(on_press=delete)
        self.localServiceEditPanel.add_widget(btn2)

        self.screenManager.current = "EditLocalService"
Exemple #15
0
    def editStreamSettings(self, name):
        db = daemonconfig.userDatabases[name]
        c = db.config

        self.streamEditPanel.clear_widgets()

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None), halign="center", text=name))
        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  text="file:" + db.filename))

        self.streamEditPanel.add_widget(self.makeBackButton())

        def save(*a):
            logging.info("SAVE BUTTON WAS PRESSED")
            # On android this is the bg service's job
            db.saveConfig()

            if platform == 'android':
                self.stop_service()
                self.start_service()
            else:
                db.close()
                daemonconfig.loadUserDatabases(
                    None,
                    only=name,
                    callbackFunction=self.onDrayerRecordChange)

        def delete(*a):
            def f(n):
                if n and n == name:
                    daemonconfig.delDatabase(None, n)
                    if platform == 'android':
                        self.stop_service()
                        self.start_service()
                    self.goToStreams()

            self.askQuestion("Really delete?", name, f)

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  font_size="24sp",
                  text='Sync'))

        self.streamEditPanel.add_widget(
            keyBox := self.settingButton(c, "Sync", "syncKey"))

        self.streamEditPanel.add_widget(
            pBox := self.settingButton(c, "Sync", "writePassword"))

        self.streamEditPanel.add_widget(
            Label(
                size_hint=(1, None),
                halign="center",
                font_size="12sp",
                text=
                'Keys have a special format, you must use the generator to change them.'
            ))

        def promptNewKeys(*a, **k):
            def makeKeys(a):
                if a == 'yes':
                    import base64
                    vk, sk = libnacl.crypto_sign_keypair()
                    vk = base64.b64encode(vk).decode()
                    sk = base64.b64encode(sk).decode()
                    keyBox.text = vk
                    pBox.text = sk

            self.askQuestion("Overwrite with random keys?", 'yes', makeKeys)

        keyButton = Button(text='Generate New Keys')
        keyButton.bind(on_press=promptNewKeys)
        self.streamEditPanel.add_widget(keyButton)

        self.streamEditPanel.add_widget(
            serverBox := self.settingButton(c, "Sync", "server"))

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  text='Do not include the http:// '))

        self.streamEditPanel.add_widget(
            self.settingButton(c, "Sync", "serve", 'yes'))

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  text='Set serve=no to forbid clients to sync'))

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  font_size="24sp",
                  text='Application'))

        self.streamEditPanel.add_widget(
            self.settingButton(c, "Application", "notifications", 'no'))

        def f(*a):
            def g(a):
                try:
                    import json
                    a = json.loads(a)
                    serverBox.text = c['Sync'][
                        'server'] = a['sv'] or c['Sync']['server']
                    keyBox.text = c['Sync']['syncKey'] = a['vk']
                    pBox.text = c['Sync']['writePassword'] = a['sk']

                except:
                    pass

            self.askQuestion("Enter Sharing Code", cb=g, multiline=True)

        keyButton = Button(text='Load from Code')
        keyButton.bind(on_press=f)
        self.streamEditPanel.add_widget(keyButton)

        def f(*a):
            self.showSharingCode(name, c)

        keyButton = Button(text='Show Sharing Code')
        keyButton.bind(on_press=f)
        self.streamEditPanel.add_widget(keyButton)

        def f(*a):
            self.showSharingCode(name, c, wp=False)

        keyButton = Button(text='Readonly Sharing Code')
        keyButton.bind(on_press=f)
        self.streamEditPanel.add_widget(keyButton)

        btn1 = Button(text='Save Changes')

        btn1.bind(on_press=save)
        self.streamEditPanel.add_widget(btn1)

        btn2 = Button(text='Delete this stream')

        btn2.bind(on_press=delete)
        self.streamEditPanel.add_widget(btn2)

        def gotoOrphans(*a, **k):
            self.gotoStreamPosts(name, orphansMode=True)

        oButton = Button(text='Show Unreachable Garbage')
        oButton.bind(on_press=gotoOrphans)
        self.streamEditPanel.add_widget(oButton)

        noSpreadsheet = Button(text="Spreadsheet on/off")

        def promptSet(*a):
            from .kivymdfmfork import MDFileManager
            from .. import directories
            try:
                #Needed for android
                self.getPermission('files')
            except:
                logging.exception("cant ask permission")

            def f(selection):
                if selection == 'on':
                    daemonconfig.userDatabases[
                        name].enableSpreadsheetEval = True
                else:
                    daemonconfig.userDatabases[
                        name].enableSpreadsheetEval = False

            if hasattr(daemonconfig.userDatabases[name],
                       'enableSpreadsheetEval'):
                esf = daemonconfig.userDatabases[name].enableSpreadsheetEval
            else:
                esf = True

            self.askQuestion("Allow Spreadsheet Functions?",
                             'on' if esf else 'off', f)

        noSpreadsheet.bind(on_release=promptSet)
        self.streamEditPanel.add_widget(noSpreadsheet)
        self.streamEditPanel.add_widget(
            self.saneLabel(
                "Disabling only takes effect for this session. Use this feature if a stream is loading too slowly, to allow you to fix the offending expression.",
                self.streamEditPanel))

        self.screenManager.current = "EditStream"
Exemple #16
0
class AKProgressbutton(BoxLayout):
    
    success_icon= StringProperty('check')
    success_text= StringProperty('Success')
    success_color= ListProperty([0,0.7,0,1])

    failure_icon= StringProperty('close')
    failure_text= StringProperty('Failed')
    failure_color= ListProperty([1,0,0,1])

    duration= NumericProperty(0.2)
    animation = StringProperty('out_quad')

    _success_box_size= ListProperty([0,0])
    _failure_box_size= ListProperty([0,0])
    _success_opacity= NumericProperty(0)
    _failure_opacity=NumericProperty(0)

    reset_timeout= NumericProperty(2)

    def __init__(self,button=None,spinner=None, **kwargs):
        super().__init__(**kwargs) 
        Clock.schedule_once(lambda x: self._update())
        self.button= button
        self.spinner= spinner

    def _update(self):  
        
        if not self.button:
            self.button= MDFillRoundFlatButton(text="Ok")

        if not self.spinner:
            self.spinner= AKSpinnerDoubleBounce()
            
        self.button.pos_hint= {'center_x': .5, 'center_y': .5}
        self.button.bind(on_release=self._submit)

        self.spinner.pos_hint= {'center_x': .5, 'center_y': .5}

        self.ids.float_box.add_widget(self.button)
        self.ids.float_box.add_widget(self.spinner)

        self.ids.float_box.size = self.button.size
        self.spinner.spinner_size= self.button.height

        self._success_box_size= [0,self.button.height ]
        self._failure_box_size= [0,self.button.height ]

    def _spinner_state(self,state):
        self.spinner.active= state

    def _submit(self, instance):
        self._spinner_state(True)
        self._hide_button()

    def _hide_button(self,*args):
        anim = Animation(opacity=0, duration=self.duration, t=self.animation)
        anim.start(self.button )
        self.button.disabled= True

    def success(self):
        self._spinner_state(False)
        anim_box = Animation(_success_opacity=1,_success_box_size=self.button.size, duration=self.duration, t=self.animation)
        anim_label = Animation(opacity=1, duration=self.duration, t=self.animation)
        
        anim_box.start(self)
        anim_label.start(self.ids._success_label)

        Clock.schedule_once(lambda x: self._reset(), self.reset_timeout+self.duration)

    def failure(self):
        self._spinner_state(False)
        anim_box = Animation(_failure_opacity=1,_failure_box_size=self.button.size, duration=self.duration, t=self.animation)
        anim_label = Animation(opacity=1, duration=self.duration, t=self.animation)
        
        anim_box.start(self)
        anim_label.start(self.ids._failure_label)

        Clock.schedule_once(lambda x: self._reset(), self.reset_timeout+self.duration)

    def _reset(self):
        self.button.disabled= False
        self._spinner_state(False)
        button_anim = Animation(opacity=1, duration=self.duration, t=self.animation)

        success_box = Animation(_success_opacity=0,_success_box_size=[0,self.button.height], duration=self.duration, t=self.animation)
        success_label = Animation(opacity=0, duration=self.duration, t=self.animation)

        failure_box = Animation(_failure_opacity=0,_failure_box_size=[0,self.button.height], duration=self.duration, t=self.animation)
        failure_label = Animation(opacity=0, duration=self.duration, t=self.animation)
        
        button_anim.start(self.button )
        success_box.start(self)
        success_label.start(self.ids._success_label)
        failure_box.start(self)
        failure_label.start(self.ids._failure_label)
class MapaComercios(Screen):
    """La Clase MapaComercios es la única clase que se ejecuta para el despliegue del mapa, como argumento recibe Screen, que es un Widget
    requerido para que se muestren los elementos en pantalla, en esta clase se inicializan todos los widgets que se utilizarán en
    este módulo (Los botones, etiquetas, imagenes, marcadores), además se declarán  todas las variables a utilizar"""
    def __init__(self, **kwargs):
        super().__init__()

        self.app = MDApp.get_running_app()

        self.mapview = MapView(lat=19.60389,
                          lon=-99.01260,
                          zoom=10
                          )

        self.marcadoresches = []
        self.marcadoressor = []
        self.marcadorescomer = []
        self.marcadoreshbe = []
        self.marcadoresbusqueda = []
        self.tipocomercio = ''

        self.datoshbe = {
            'hbe1': {'direccion': 'HDA. CERRO GORDO ',
                    'colonia': 'Balcones Campestre',
                    'lat': 21.156959409958873,
                    'lon': -101.70300001710274,
                    'tel': '8181531100',
                    'cp': '37150',
                    'municipio': 'Leon, Guanajuato'
                    },

            'hbe2': {'direccion': 'BLVD. ADOLFO LÓPEZ MATEOS 2102',
                     'colonia': 'Jardines del Moral',
                     'lat': 21.146246179033383,
                     'lon': -101.68449454293152,
                     'tel': '4777198103',
                     'cp': '37160',
                     'municipio': 'Leon, Guanajuato'
                     },

            'hbe3': {'direccion': 'BLVD. ADOLFO LOPEZ MATEOS 2102',
                     'colonia': 'Jardines del Moral',
                     'lat': 21.146236158514455,
                     'lon': -101.6846125617232,
                     'tel': '4777198103',
                     'cp': '37160',
                     'municipio': 'Leon, Guanajuato'
                     },

            'hbe4': {'direccion': 'AV. Guerrero 2415',
                     'colonia': 'Terracota',
                     'lat':  20.695401634729016,
                     'lon': -101.35843141409075,
                     'tel': '4621190160',
                     'cp': '36620',
                     'municipio': 'Irapuato, Guanajuato'
                     },
        }
        
        
        

        self.datosches = {
            'che1': {'direccion': '4TA. AVENIDA NO. 257 LOTE 1',
                     'colonia': 'Fracc Rey Neza',
                     'lat': 19.40068,
                     'lon': -98.98720,
                     'tel': '54412720',
                     'cp': '57000',
                     'municipio': 'Nezahualcoyotl'
                     },

            'che2': {'direccion': 'AV. TEXCOCO NO. 292',
                     'colonia': 'Pavón',
                     'lat': 19.396626,
                     'lon': -99.048428,
                     'tel': '11038000 ext 37140',
                     'cp': '57610',
                     'municipio': 'Nezahualcoyotl'
                     },

            'che3': {'direccion': 'AV. RIO DE LA LOZA NO. 4 ',
                     'colonia': 'San Miguel Chalma',
                     'lat': 19.545221,
                     'lon': -99.152201,
                     'tel': '11038000 ext 37130',
                     'cp': '07160',
                     'municipio': 'Tlalnepantla'
                     },

            'che4': {'direccion': 'AV. INSURGENTES SIN NUMERO',
                     'colonia': 'Calvario',
                     'lat': 19.60237,
                     'lon': -99.05572,
                     'tel': 'Sin tel',
                     'cp': '55020',
                     'municipio': 'Ecatepec de Morelos'
                     },

            'che5': {'direccion': 'AV ALFREDO DEL MAZO NO. 705',
                     'colonia': 'Tlacopa',
                     'lat': 19.309995,
                     'lon': -99.635682,
                     'tel': '017222379445',
                     'cp': '50100',
                     'municipio': 'Toluca de Lerdo'
                     },

            'che6': {'direccion': 'PROL. GUADALUPE VICTORIA NO. 471',
                     'colonia': 'La Purisima',
                     'lat': 19.258697,
                     'lon': -99.628197,
                     'tel': '017222127113',
                     'cp': '52140',
                     'municipio': 'Metepec'
                     },

            'che7': {'direccion': 'BLVRD JUAN HERRERA Y PIÑA 7',
                     'colonia': 'Barrio Otumba',
                     'lat': 19.204049,
                     'lon': -100.125421,
                     'tel': '7262626942',
                     'cp': '51200',
                     'municipio': 'Valle de Bravo'
                     },

            'che8': {'direccion': 'BLVD. MANUEL AVILA CAMACHO 5',
                     'colonia': 'Lomas de Sotelo',
                     'lat': 19.454290,
                     'lon': -99.219101,
                     'tel': '7262626942',
                     'cp': '53390',
                     'municipio': 'Naucalpan de Juárez'
                     },

            'che9': {'direccion': 'AV. DE LOS BOSQUES NO. 128',
                     'colonia': 'Lomas de Tecamachalco',
                     'lat': 19.411133,
                     'lon': -99.250840,
                     'tel': '5555967887',
                     'cp': '52780',
                     'municipio': 'Huixquilucan'
                     },
            'che10': {'direccion': 'AV. CENTRAL ESQ. AV JARDINES DE MORELOS S/N',
                      'colonia': 'Jardínes de Morelos',
                      'lat': 19.603457,
                      'lon': -99.013337,
                      'tel': '5558371634',
                      'cp': '55065',
                      'municipio': 'Ecatepec de Morelos'
                      },
            'che11': {'direccion': 'AV.AQUILES SERDAN 360',
                      'colonia': 'El Mirador',
                      'lat': 19.257597,
                      'lon': -99.022525,
                      'tel': '5525942726',
                      'cp': '16740',
                      'municipio': 'Xochimilco'
                      },

            'che12': {'direccion': 'CTRA. A SANTIAGO TEPELCATLALPAN 400',
                      'colonia': 'Santiago Tepalcatlalpan',
                      'lat': 19.257736,
                      'lon': -99.122394,
                      'tel': '5555557600',
                      'cp': '16210',
                      'municipio': 'Xochimilco'
                      },

            'che13': {'direccion': 'AV. UNIVERSIDAD 740',
                      'colonia': 'Sta Cruz Atoyac',
                      'lat': 19.373194,
                      'lon': -99.162387,
                      'tel': '8005632222',
                      'cp': '03310',
                      'municipio': 'Benito Juárez'
                      },

            'che14': {'direccion': 'VASCO DE QUIROGA 3800',
                      'colonia': 'Lomas de Santa Fe',
                      'lat': 19.359963,
                      'lon': -99.274583,
                      'tel': '5521678307',
                      'cp': '05348',
                      'municipio': 'Cuajimalpa'
                      },

            'che15': {'direccion': 'AV. BENITO JUAREZ NO. 39 MZ 36',
                      'colonia': 'Presidentes',
                      'lat': 19.376661,
                      'lon': -99.223099,
                      'tel': '5511038000',
                      'cp': '01290',
                      'municipio': 'Álvaro Obregón'
                      },

            'che16': {'direccion': 'AV. CANAL DE TEZONTLE 1512',
                      'colonia': 'Área Federal Central de Abastos',
                      'lat': 19.384808,
                      'lon': -99.082368,
                      'tel': '5511038000',
                      'cp': '09020',
                      'municipio': 'Iztapalapa'
                      },

            'che17': {'direccion': 'BUEN TONO NO. 8',
                      'colonia': 'Centro',
                      'lat': 19.428273,
                      'lon': -99.143175,
                      'tel': '5555124069',
                      'cp': '06070',
                      'municipio': 'Cuahtémoc'
                      },

            'che18': {'direccion': 'BLVD. MIGUEL DE CERVANTES SAAVEDRA 397',
                      'colonia': 'Irrigación',
                      'lat': 19.441866,
                      'lon': -99.206946,
                      'tel': '5555803422',
                      'cp': '11579',
                      'municipio': 'Miguel Hidalgo'
                      },

            'che19': {'direccion': 'AV. CUAUTEPEC NO. 117',
                      'colonia': 'Jorge Negrete',
                      'lat': 19.526125,
                      'lon': -99.141422,
                      'tel': '8009251111',
                      'cp': '07280',
                      'municipio': 'Gustavo A. Madero'
                      },

            'che20': {'direccion': 'AV. FORTUNA 334',
                      'colonia': 'Magdalena de las Salinas',
                      'lat': 19.482093,
                      'lon': -99.130347,
                      'tel': '8009251111',
                      'cp': '07760',
                      'municipio': 'Gustavo A. Madero'
                      },
        }

        self.datossor = {
            'sor1': {'direccion': 'CTRA. MEXICO-TEPEXPAN ESQ. LOS REYES TEXCOCO NO. 8',
                     'colonia': 'San Isidro Atlautenco',
                     'lat': 19.620721,
                     'lon': -98.997171,
                     'tel': '8007074262',
                     'cp': '55064',
                     'municipio': 'Ecatepec de Morelos'
                     },

            'sor2': {'direccion': 'LA PURISIMA NO. 5',
                     'colonia': 'San Cristóbal Lejipaya',
                     'lat': 19.602854,
                     'lon': -98.946640,
                     'tel': '5949569566',
                     'cp': '55800',
                     'municipio': 'Atenco'
                     },

            'sor3': {'direccion': 'AV. CENTRAL 65',
                     'colonia': '1ro de Agosto',
                     'lat': 19.551379,
                     'lon': -99.018549,
                     'tel': '8002201234',
                     'cp': '55100',
                     'municipio': 'Ecatepec de Morelos'
                     },

            'sor4': {'direccion': 'MEXICO NO. 5',
                     'colonia': 'Cd. López Mateos',
                     'lat': 19.568340,
                     'lon': -99.250645,
                     'tel': '5558225029',
                     'cp': '52960',
                     'municipio': 'Atizapán'
                     },

            'sor5': {'direccion': 'AV. 16 DE SEPTIEMBRE 34',
                     'colonia': 'Paraiso II',
                     'lat': 19.631577,
                     'lon': -99.119169,
                     'tel': '8007074262',
                     'cp': '55700',
                     'municipio': 'Coacalco'
                     },

            'sor6': {'direccion': 'AV. CUITLAHUAC 372',
                     'colonia': 'Cuitlahuac',
                     'lat': 19.471089,
                     'lon': -99.170700,
                     'tel': '8002201234',
                     'cp': '02530',
                     'municipio': 'Azcapotzalco'
                     },

            'sor7': {'direccion': 'AV. TOLTECAS S/N',
                     'colonia': 'Hab. Los Reyes',
                     'lat': 19.53765,
                     'lon': -99.189802,
                     'tel': '5516659002',
                     'cp': '54090',
                     'municipio': 'Tlalnepantla'
                     },

            'sor8': {'direccion': 'AV. GUSTAVO BAZ PRADA 250',
                     'colonia': 'Bosques de Echegaray',
                     'lat': 19.491437,
                     'lon': -99.227430,
                     'tel': '5553736844',
                     'cp': '53300',
                     'municipio': 'Naucalpan'
                     },

            'sor9': {'direccion': 'CALLE MEXIQUENSE 31',
                     'colonia': 'Los Héroes Tecámac',
                     'lat': 19.633013,
                     'lon': -99.033405,
                     'tel': '5558369960',
                     'cp': '55765',
                     'municipio': 'Tecámac'
                     },

            'sor10': {'direccion': 'CTRA. MEX-QRT KM 36.8',
                      'colonia': 'Reforma Política',
                      'lat': 19.650797,
                      'lon': -99.195386,
                      'tel': '8002201234',
                      'cp': '54700',
                      'municipio': 'Cuautitlán Izcalli'
                      },

            'sor11': {'direccion': 'AV. STA. FE 46',
                      'colonia': 'Lomas de Santa Fe',
                      'lat': 19.357175,
                      'lon': -99.273897,
                      'tel': 'Sin info',
                      'cp': '01219',
                      'municipio': 'Cuajimalpa'
                      },

            'sor12': {'direccion': 'AV. IMAN 550',
                      'colonia': 'Pedregal de Carrasco',
                      'lat': 19.306898,
                      'lon': -99.164659,
                      'tel': '5555288345',
                      'cp': '04700',
                      'municipio': 'Coyoacán'
                      },

            'sor13': {'direccion': 'ERMITA IZTAPALAPA 3016',
                      'colonia': 'Reforma Politica',
                      'lat': 19.344716,
                      'lon': -99.027594,
                      'tel': '8183299252',
                      'cp': '09730',
                      'municipio': 'Iztapalapa'
                      },

            'sor14': {'direccion': 'CALZ. DE LA VIGA 1805',
                      'colonia': 'Mexicaltzingo',
                      'lat': 19.360090,
                      'lon': -99.123618,
                      'tel': '8183299252',
                      'cp': '09080',
                      'municipio': 'Iztapalapa'
                      },

            'sor15': {'direccion': 'AV. REVOLUCION 780',
                      'colonia': 'San Juan',
                      'lat': 19.379381,
                      'lon': -99.185600,
                      'tel': '5555655046',
                      'cp': '03730',
                      'municipio': 'Benito Juárez'
                      },

            'sor16': {'direccion': 'OBRERO MUNDIAL 320',
                      'colonia': 'Piedad Narvarte',
                      'lat': 19.402383,
                      'lon': -99.154002,
                      'tel': '5583299000',
                      'cp': '03000',
                      'municipio': 'Benito Juárez'
                      },

            'sor17': {'direccion': 'AV. EL ROSARIO 901',
                      'colonia': 'El Rosario',
                      'lat': 19.504132,
                      'lon': -99.200933,
                      'tel': '8007074262',
                      'cp': '02100',
                      'municipio': 'Azcapotzalco'
                      },

            'sor18': {'direccion': 'CALZ. DE LOS MISTERIOS 62',
                      'colonia': 'Tepeyac Insurgentes',
                      'lat': 19.489655,
                      'lon': -99.119282,
                      'tel': '8002201234',
                      'cp': '07020',
                      'municipio': 'Gustavo A. Madero'
                      },

            'sor19': {'direccion': 'AV. EJERCITO NACIONAL 769',
                      'colonia': 'Granada',
                      'lat': 19.439809,
                      'lon': -99.199979,
                      'tel': '5591260960',
                      'cp': '11520',
                      'municipio': 'Miguel Hidalgo'
                      },

            'sor20': {'direccion': 'AV JARDIN 330',
                      'colonia': 'Col del Gas',
                      'lat': 19.468902,
                      'lon': -99.159565,
                      'tel': '8002201234',
                      'cp': '02970',
                      'municipio': 'Azcapotzalco'
                      },
        }

        self.datoscomer = {
            'comer1': {'direccion': 'CALZ DEL HUESO 530',
                       'colonia': 'Fracc. Los Girasoles',
                       'lat': 19.305154,
                       'lon': -99.126231,
                       'tel': '01 800 3777 333',
                       'cp': '4929',
                       'municipio': 'Coyoacan'
                       },

            'comer2': {'direccion': 'ATENAS 6',
                       'colonia': 'Fracc. Valle Dorado',
                       'lat': 19.551346,
                       'lon': -99.209801,
                       'tel': '01 800 3777 333',
                       'cp': '54020',
                       'municipio': 'Tlalnepantla'
                       },

            'comer3': {'direccion': 'BLVD MANUEL AVILA CAMACHO 3228',
                       'colonia': 'Boulevares',
                       'lat': 19.498145,
                       'lon': -99.237891,
                       'tel': '01 800 3777 333',
                       'cp': '53100',
                       'municipio': 'Naucalpan de Juárez'
                       },

            'comer4': {'direccion': 'PLAZUELA DE LA FAMA 1',
                       'colonia': 'La Fama',
                       'lat': 19.288794,
                       'lon': -99.179277,
                       'tel': '01 800 3777 333',
                       'cp': '14410',
                       'municipio': 'Tlalpan'
                       },

            'comer5': {'direccion': 'CIRCUITO MEDICOS 35',
                       'colonia': 'Ciudad Satélite',
                       'lat': 19.509474,
                       'lon': -99.232960,
                       'tel': '01 800 3777 333',
                       'cp': '53100',
                       'municipio': 'Naucalpan de Juárez'
                       },

            'comer6': {'direccion': 'NOGAL 212',
                       'colonia': 'Santa María La Ribera',
                       'lat': 19.451636,
                       'lon': -99.163952,
                       'tel': '01 800 3777 333',
                       'cp': '6400',
                       'municipio': 'Cuauhtémoc'
                       },

            'comer7': {'direccion': 'CTRA A CELAYA 2',
                       'colonia': 'Fracc. La Lejona 2da Sección',
                       'lat': 20.897708,
                       'lon': -100.752716,
                       'tel': '01 800 3777 333',
                       'cp': '37765',
                       'municipio': 'San Miguel Allende'
                       },

            'comer8': {'direccion': 'AV DE LAS TORRES 446',
                       'colonia': 'San José del Olivar',
                       'lat': 19.334798,
                       'lon': -99.227121,
                       'tel': '01 800 3777 333',
                       'cp': '1770',
                       'municipio': 'Álvaro Obregón'
                       },

            'comer9': {'direccion': 'AV MAGNOCENTRO LT 1 MZ 2',
                       'colonia': 'San Fernando Huixquilucan',
                       'lat': 19.399401,
                       'lon': -99.276681,
                       'tel': '01 800 3777 333',
                       'cp': '52796',
                       'municipio': 'Huixquilucan'
                       },

            'comer10': {'direccion': 'XOCHIMILCO 343',
                        'colonia': 'Anahuac',
                        'lat': 19.438072,
                        'lon': -99.179588,
                        'tel': '01 800 3777 333',
                        'cp': '11320',
                        'municipio': 'Miguel Hidalgo'
                        },

            'comer11': {'direccion': 'BOSQUES DE MOCTEZUMA 1B',
                        'colonia': 'Fracc. La Herradura',
                        'lat': 19.416958,
                        'lon': -99.249047,
                        'tel': '01 800 3777 333',
                        'cp': '53920',
                        'municipio': 'Huixquilucan'
                        },

            'comer12': {'direccion': 'CALZ ERMITA IZTAPALAPA 3865',
                        'colonia': 'Santa María Aztahuacán',
                        'lat': 19.351905,
                        'lon': -99.012747,
                        'tel': '01 800 3777 333',
                        'cp': '9730',
                        'municipio': 'Iztapalapa'
                        },

            'comer13': {'direccion': 'PERPETUA 35',
                        'colonia': 'San José Insurgentes',
                        'lat': 19.366372,
                        'lon': -99.182357,
                        'tel': '01 800 3777 333',
                        'cp': '3900',
                        'municipio': 'Benito Juárez'
                        },

            'comer14': {'direccion': 'MIGUEL ANGEL DE QUEVEDO 443',
                        'colonia': 'Romero de Terreros',
                        'lat': 19.345040,
                        'lon': -99.171795,
                        'tel': '01 800 3777 333',
                        'cp': '4310',
                        'municipio': 'Coyoacán'
                        },

            'comer15': {'direccion': 'BOSQUE DE ARRAYAN MZ 5 LT 1',
                        'colonia': 'Fracc. Conjunto Urbano Bosque Esmeralda',
                        'lat': 19.548925,
                        'lon': -99.287349,
                        'tel': '01 800 3777 333',
                        'cp': '52973',
                        'municipio': 'Atizapán de Zaragoza'
                        },

            'comer16': {'direccion': 'AV DE LAS FUENTES 190',
                        'colonia': 'Lomas de Tecamachalco',
                        'lat': 19.421845,
                        'lon': -99.237988,
                        'tel': '01 800 3777 333',
                        'cp': '53950',
                        'municipio': 'Naucalpán de Juárez'
                        },

            'comer17': {'direccion': 'PROLONGACION BOSQUES DE REFORMA 1813',
                        'colonia': 'Vista Hermosa',
                        'lat': 19.382919,
                        'lon': -99.267804,
                        'tel': '01 800 3777 333',
                        'cp': '5109',
                        'municipio': 'Cuajimalpa'
                        },

            'comer18': {'direccion': 'AV. JESUS DEL MONTE 271',
                        'colonia': 'Jesús del Monte',
                        'lat': 19.388758,
                        'lon': -99.293395,
                        'tel': '01 800 3777 333',
                        'cp': '52764',
                        'municipio': 'Huixquilucan'
                        },

            'comer19': {'direccion': 'AV. MIGUEL ANGEL DE QUEVEDO 1144',
                        'colonia': 'Parque San Andrés',
                        'lat': 19.342817,
                        'lon': -99.146703,
                        'tel': 'Sin Datos',
                        'cp': '4040',
                        'municipio': 'Coyoacan'
                        },

            'comer20': {'direccion': 'AV. DEL CARMEN 335',
                        'colonia': 'Fracc. Avandaro',
                        'lat': 19.164580,
                        'lon': -100.125154,
                        'tel': 'Sin Datos',
                        'cp': '51200',
                        'municipio': 'Valle de Bravo'
                        },
        }

        self.entradafield = MDTextFieldRect(pos_hint={"x": .05, "y":.93},
                                        hint_text = "Buscar por Municipio, Colonia, Calle",
                                        size_hint = (.6, .060),
                                        height = "30dp"
                                        )

        self.borramarcador = MDIconButton(pos_hint={"x": .80, "y":.9},
                                                   icon = "map-marker-off",
                                                   user_font_size = "32sp",
                                    )
        self.botonbusqueda = MDIconButton(pos_hint={"x": .65, "y": .9},
                                          icon="magnify",
                                          user_font_size="32sp",
                                          )


        self.botongps = MDIconButton(pos_hint={"x": .75, "y": .03},
                                     icon = "crosshairs-gps",
                                     user_font_size = "32sp"
                                     )

        self.botonayuda = MDIconButton(pos_hint={"x": .75, "y": .13}, #falta agregar funcion para mostrar
                                       icon="help-box",
                                       user_font_size="32sp"
                                       )

        self.botonche = MDFillRoundFlatButton(pos_hint={"x": .1, "y": .05},
                                              size_hint=(.25, .07),
                                              text = "Chedraui",
                                              )
        self.mr = Image(source="imagenes/pinrojo.png",
                        pos_hint={"x": -.385, "y": -.41})

        self.botonhbe = MDFillRoundFlatButton(pos_hint={"x": .5, "y": .05},
                                              size_hint=(.25, .07),
                                              text="HEB"
                                              )
        self.mg = Image(source="imagenes/pingris.png",
                        pos_hint={"x": .013, "y": -.41})

        self.botoncomer = MDFillRoundFlatButton(pos_hint={"x": .1, "y": .15},
                                              size_hint=(.25, .07),
                                              text="La Comer"
                                              )
        self.mv = Image(source="imagenes/pinverde.png",
                        pos_hint={"x": -.385, "y": -.31})

        self.botonsor = MDFillRoundFlatButton(pos_hint={"x": .5, "y": .15},
                                              size_hint=(.25, .07),
                                              text="Soriana"
                                              )
        self.ma = Image(source="imagenes/pinazul.png",
                        pos_hint={"x": .013, "y": -.31})

        self.botongps.bind(on_press=lambda x: self.ActivaGPS())
        self.botonayuda.bind(on_press=lambda x: self.AyudaMapa())
        self.botonche.bind(on_press=lambda x: self.Consulta_Che())
        self.botonsor.bind(on_press=lambda x: self.Consulta_Sor())
        self.botoncomer.bind(on_press=lambda x: self.Consulta_Comer())
        self.botonhbe.bind(on_press=lambda x: self.Consulta_HBE())
        self.borramarcador.bind(on_press=lambda x: self.BorraMarcador())
        self.botonbusqueda.bind(on_press=lambda x: self.Consulta_Busqueda())

        self.add_widget(self.mapview) # Se agrega el mapa en la "capa inferior"
        #self.add_widget(self.botongps) # En una "capa" posterior se agrega el boton para que se vea
        self.add_widget(self.botonbusqueda)
        self.add_widget(self.entradafield)

        self.add_widget(self.botonche)
        self.add_widget(self.botonhbe)
        self.add_widget(self.botoncomer)
        self.add_widget(self.botonsor)
        self.add_widget(self.botonayuda)
        self.add_widget(self.borramarcador)
        self.add_widget(self.mr)
        self.add_widget(self.mv)
        self.add_widget(self.mg)
        self.add_widget(self.ma)

    def ActivaGPS(self):
        """Funcion en desarrollo se pretende poner caracteristicas de GPS para localización"""
        print("GPS")
        pass

    def AyudaMapa(self):
        """Función que muestra un MDDialog donde se incluye información que puede ser de ayuda al usuario cuando use el
        módulo del mapa, se describen algunas caracteristicas que le podrían ser útiles y consenjos de su utilizacion"""
        print("Ingresando a Ayuda")

        self.dialog = MDDialog(title = "Ayuda sobre el mapa",
                               text="Utiliza los botones en la parte inferior para localizar centros comerciales predefinidos, "
                                    " en cada localización que se muestra en el mapa, se puede pulsar sobre el pin para desplegar "
                                    "información sobre el centro comercial en cuestión.\n"
                                    "Si se desea limpiar la pantalla de marcadores pulsa el botón con ícono de pin con una diagonal.\n"
                                    "En la parte superior se puede realizar una búsqueda por municipio, colonia o calle del comercio, al pulsar sobre la "
                                    "lupa se realizará la busqueda ingresada en este campo",
                               size_hint=[.9, .9],
                               auto_dismiss=True,

                               buttons=[MDFlatButton(
                                        text="CERRAR",
                                        on_release=self.dialog_close)
                                        ]
                               )
        self.dialog.open()
        pass

    def PonMarcador(self, diccomercio, tipocomercio):
        """Funcion que agrega marcadores al mapa dependiendo del botón que se haya pulsado, recibe un diccionario del
        comercio que se agregarán marcadores y una cadena sobre el tipo de negocio, se realiza un ciclo for doble para
        obtener los elementos del diccionario, posteriormente se realiza una comparación con los valores y se agrega el
        marcador al mapa"""

        print(tipocomercio)
        for keys, values in diccomercio.items():
            for vkeys, vvalues in values.items():
                if vkeys == 'direccion':
                    dir = vvalues

                if vkeys == 'colonia':
                    col = vvalues

                if vkeys == 'tel':
                    tel = vvalues

                if vkeys == 'cp':
                    cp = vvalues

                if vkeys == 'municipio':
                    mun = vvalues

                if vkeys == 'lat':
                    nlat = vvalues
                    # print("lat: "+str(nlat))

                if vkeys == 'lon':
                    nlon = vvalues
                    # print("lon: "+str(nlon))

            print("lat: " + str(nlat) + " lon: " + str(nlon))

            cadena_final = f'Dir: {dir}\nCol: {col}\nCP: {cp}\nMun: {mun}\nTel: {tel}\n\n'

            if tipocomercio == 'hbe':
                self.marcador = MapMarkerPopup(lat=nlat, lon=nlon, source= "imagenes/pingris.png")
                self.marcador.add_widget(MDLabel(size_hint=(5, .5), text=cadena_final))
                self.mapview.add_marker(self.marcador)

                self.marcadoreshbe.append(self.marcador)

            if tipocomercio == 'che':
                self.marcador = MapMarkerPopup(lat=nlat, lon=nlon, source="imagenes/pinrojo.png")
                self.marcador.add_widget(MDLabel(size_hint=(5, .5), text=cadena_final))

                self.mapview.add_marker(self.marcador)
                self.marcadoresches.append(self.marcador)

            if tipocomercio == 'comer':
                self.marcador = MapMarkerPopup(lat=nlat, lon=nlon, source="imagenes/pinverde.png")
                self.marcador.add_widget(MDLabel(size_hint=(5, .5), text=cadena_final))
                self.mapview.add_marker(self.marcador)
                self.marcadorescomer.append(self.marcador)

            if tipocomercio == 'sor':
                self.marcador = MapMarkerPopup(lat=nlat, lon=nlon, source="imagenes/pinazul.png")
                self.marcador.add_widget(MDLabel(size_hint=(5, .5), text=cadena_final))

                self.mapview.add_marker(self.marcador)
                self.marcadoressor.append(self.marcador)

            if tipocomercio == 'busqueda':
                cadena_analizar = f'{dir} {col} {cp} {mun} {tel}'
                if self.a == 0:
                    colorpin = "imagenes/pinrojo.png"
                if self.a == 1:
                    colorpin = "imagenes/pinazul.png"
                if self.a == 2:
                    colorpin = "imagenes/pinverde.png"
                if self.a == 3:
                    colorpin = "imagenes/pingris.png"

                if ((cadena_analizar.lower()).find(self.entrada) != -1):
                    print("Contains given substring ")

                    self.marcador = MapMarkerPopup(lat=nlat, lon=nlon, source=colorpin)
                    self.marcador.add_widget(MDLabel(size_hint=(5, .5), text=cadena_final))

                    self.mapview.add_marker(self.marcador)
                    self.marcadoresbusqueda.append(self.marcador)
                else:
                    print("Doesn't contains given substring")

           # print(self.marcador)

    def Consulta_Busqueda(self):
        """La funcion se ejecuta al pulsar el botón busqueda, se obtiene los datos ingresados en el campo de entrada, posteriormente se
        realiza un ciclo para mandar la información ingresada a la funcion PonMarcador, se le envia cada uno de los diccionarios asi como el tipo de comercio
        para que  la funcion PonMarcador identifique el comercio correspondiente y despliegue el marcador"""

        self.tipocomercio = 'busqueda'
        self.entrada = self.entradafield.text.lower()
        print(self.entrada)
        print('Estoy en busqueda')
        for self.a in range(4):
            if self.a == 0:
                self.PonMarcador(self.datosches, self.tipocomercio)
            if self.a == 1:
                self.PonMarcador(self.datossor, self.tipocomercio)
            if self.a == 2:
                self.PonMarcador(self.datoscomer, self.tipocomercio)
            if self.a == 3:
                self.PonMarcador(self.datoshbe, self.tipocomercio)

    def Consulta_HBE(self):#poner datos hbe
        """Se realiza una consulta del comercio enviando la informacion del diccionario y el tipo de comercio"""
        self.tipocomercio = 'hbe'


        self.PonMarcador(self.datoshbe, self.tipocomercio) #llamada a la funcion
        self.botonhbe.disabled = True

    def Consulta_Che(self):
        """Se realiza una consulta del comercio enviando la informacion del diccionario y el tipo de comercio"""
        self.tipocomercio = 'che'
        print("Consultando Chedraui")


        self.PonMarcador(self.datosches, self.tipocomercio)  # llamada a la funcion
        self.botonche.disabled = True

    def Consulta_Sor(self):
        """Se realiza una consulta del comercio enviando la informacion del diccionario y el tipo de comercio"""
        self.tipocomercio = 'sor'

        self.PonMarcador(self.datossor, self.tipocomercio)
        self.botonsor.disabled = True

    def Consulta_Comer(self):
        """Se realiza una consulta del comercio enviando la informacion del diccionario y el tipo de comercio"""
        print("Estoy en la comer")
        self.tipocomercio = 'comer'

        self.PonMarcador(self.datoscomer, self.tipocomercio)  # llamada a la funcion
        self.botoncomer.disabled = True

    def dialog_close(self, *args): # Cierra el dialog del boton ayuda
        """La funcion cierra el dialogo de ayuda que se muestra al pulsar el boton ayuda '?' """
        print("Cerrando Dialog")
        self.dialog.dismiss()

    def BorraMarcador(self):
        """Funcion que borra los marcadores que se agregan al mapa, comprobando los valores de las listas correspondientes
        a cada tipo de marcador"""

        print("Funcion  BorraMarcador")

        if not self.marcadoresches:
            print("No hay marcadares de Chedraui")
        else:
            for self.marcador in self.marcadoresches:
                self.mapview.remove_marker(self.marcador)
            self.botonche.disabled = False

        if not self.marcadoressor:
            print("No hay marcadares de Soriana")
        else:
            for self.marcador in self.marcadoressor:
                self.mapview.remove_marker(self.marcador)
            self.botonsor.disabled = False

        if not self.marcadorescomer:
            print("No hay marcadares de La Comer")
        else:
            for self.marcador in self.marcadorescomer:
                self.mapview.remove_marker(self.marcador)
            self.botoncomer.disabled = False

        if not self.marcadoreshbe:
            print("No hay marcadares de HEB")
        else:
            for self.marcador in self.marcadoreshbe:
                self.mapview.remove_marker(self.marcador)
            self.botonhbe.disabled = False

        if not self.marcadoresbusqueda:
            print("No hay marcadares de busqueda")
        else:
            for self.marcador in self.marcadoresbusqueda:
                self.mapview.remove_marker(self.marcador)

    def on_pre_enter(self, *args):
        """La función se ejecuta antes de ingresar a la clase Mapa Comercios, la función actualiza el nombre  del
        modulo correspondiente"""
        self.app.title = "Mapa Comercios"

        snackbar = Snackbar(text="Utiliza el mapa de comercios para encontrar la localizacion de algun Chedraui, La Comer, Soriana o HEB")
        snackbar.show()