Skip to content

Instantly share code, notes, and snippets.

@aurorapar
Last active June 16, 2021 06:18
Show Gist options
  • Save aurorapar/27958fd1547d58e57f76881e791c452a to your computer and use it in GitHub Desktop.
Save aurorapar/27958fd1547d58e57f76881e791c452a to your computer and use it in GitHub Desktop.
<LoginScreen@LoadScreen>:
id: login_screen
name: "login_screen"
MDTextField:
id: password_textfield
name: 'password_textfield'
hint_text: "Enter Password"
helper_text: "(or click on forgot forgot)"
helper_text_mode: "persistent"
pos_hint: {'center_x': .5, 'center_y': .5}
size_hint_x: None
width: 300
MDRectangleFlatButton:
id: forgot_password_button
name: 'forgot_password_button'
text: "Forgot Password"
pos_hint: {'center_x': .4, 'center_y': .4}
theme_text_color: 'Custom'
text_color: (100 / 255.0, 100 / 255.0, 100 / 255.0, .8)
on_release: root.show_data()
from utils import load_kv
from kivymd.uix.screen import Screen
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFlatButton
from kivy.lang import Builder
class LoginScreen(Screen):
def show_data(self):
if len(self.password_textfield.text) < 1:
return
self.password_dialogue = MDDialog()
self.password_dialogue.text = f'You entered: {self.password_textfield.text}'
self.password_dialogue_button = MDFlatButton()
self.password_dialogue_button.text = 'Close'
self.password_dialogue_button.on_release = self.close_dialogue
self.password_dialogue.open()
def close_dialogue(self, obj):
self.password_dialogue.dismiss()
load_kv()
#:import TitleScreen title_screen.title_screen
#:import LoginScreen login_screen.login_screen
ScreenManager:
id: manager
LoadScreen:
TitleScreen:
LoginScreen:
<LoadScreen>:
id: load_screen
name: "load_screen"
Label:
id: load_screen_label
name: "load_screen_label"
text: "Loading..."
import os
import sys
from pathlib import Path
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
os.environ["KIVY_PROFILE_LANG"] = "1"
if getattr(sys, "frozen", False): # bundle mode with PyInstaller
os.environ["UNNATURAL_SELECTION_ROOT"] = sys._MEIPASS
else:
sys.path.append(os.path.abspath(__file__))
os.environ["UNNATURAL_SELECTION_ROOT"] = str(Path(__file__).parent)
os.environ["UNNATURAL_SELECTION_ASSETS"] = os.path.join(
os.environ["UNNATURAL_SELECTION_ROOT"], f"assets{os.sep}"
)
class LoadScreen(Screen):
#lets do Database and Animation stuff here
pass
class UnnaturalSelectionApp(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.theme_cls.theme_style = "Dark"
def build(self):
return Builder.load_file(
os.path.join(
os.environ["UNNATURAL_SELECTION_ROOT"], 'main.kv'
)
)
def change_screen(self, screen_name):
self.root.current = screen_name
def on_start(self):
self.change_screen('title_screen')
app = UnnaturalSelectionApp()
app.run()
<TitleScreen@LoadScreen>:
id: title_screen
name: "title_screen"
MDLabel:
text: "Unnatural\n Selection"
font_style: "H1"
theme_text_color: 'Custom'
text_color: (100 / 255.0, 100 / 255.0, 100 / 255.0, .6)
pos_hint: {'center_x': .5, 'center_y': .5}
halign: 'center'
from utils import load_kv
from kivy.uix.screenmanager import Screen
from kivy.app import App
class TitleScreen(Screen):
def on_touch_up(self, touch):
app = App.get_running_app()
app.change_screen('login_screen')
load_kv()
import inspect
from os.path import extsep, exists, splitext
from kivy.lang import Builder
def load_kv():
'''This magical function lookup module name, and load the kv file
with the same name (in the same directory)
https://gist.github.com/tshirtman/d8423695fe821440b65688b8dbd22b0c
'''
filename = inspect.currentframe().f_back.f_code.co_filename
f = extsep.join((splitext(filename)[0], 'kv'))
if exists(f) and f not in Builder.files:
Builder.load_file(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment