# Import system modules
from random import randrange
import sqlite3

# Import Kivy modules
#from kivy.app import App
from kivymd.app import MDApp
from kivy.lang import Builder

from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label

from kivy.core.window import Window

from kivy.graphics import Rectangle

# Import local modules
from forestmapview import ForestMapView
from searchpopupmenu import SearchPopupMenu
from gpshelper import GpsHelper
from settings import SampleBoxLayout
from game import GameWidget

# MOTD
motd = """]
] GlobalForest 0.1 by afx"""

Builder.load_string("""
<ScreenOne>:
    BoxLayout:
        Button:
            text: "Go to Screen 2"
            on_press:
                root.manager.transition.direction = "left"
                root.manager.transition.duration = 1
                root.manager.current = "screen_two"
                
<ScreenTwo>:
    BoxLayout:
        Button:
            text: "Go to Screen 1"
            on_press:
                root.manager.transition.direction = "right"
                root.manager.transition.duration = 1
                root.manager.current = "screen_one"
""")

class ScreenOne(Screen):
    pass

class ScreenTwo(Screen):
    pass

class MainApp(MDApp):
    connection = None
    cursor = None
    search_menu = None
    
    def build(self):
        pass
        #Window.clearcolor = (0, 0, 0, 0)
        #return SampleBoxLayout()
    
    def on_start(self):
        # Welcome
        print(motd)
        
        self.theme_cls.primary_palette = 'BlueGray'
        
        # Initialize GPS
        GpsHelper().run()
        
        # Connect to database
        self.connection = sqlite3.connect("databases/fountains.db")
        self.cursor = self.connection.cursor()
        
        # Instantiate SearchPopupMenu
        self.search_menu = SearchPopupMenu()

if __name__ == '__main__':
    #screen_manager = ScreenManager()
    #screen_manager.add_widget(ScreenOne(name="screen_one"))
    #screen_manager.add_widget(ScreenTwo(name="screen_two"))
    app = MainApp()
    app.run()

