finished separating screens
parent
59f4410286
commit
8214937245
Binary file not shown.
@ -0,0 +1,25 @@
|
||||
from kivymd.uix.screen import MDScreen
|
||||
from kivy.properties import ObjectProperty
|
||||
from kivymd.uix.boxlayout import MDBoxLayout
|
||||
from kivymd.uix.label import MDLabel
|
||||
from kivy.app import App
|
||||
|
||||
|
||||
|
||||
### Layout
|
||||
|
||||
### Base screens
|
||||
class BaseScreen(MDScreen):
|
||||
@property
|
||||
def root(self):
|
||||
return self.app.root
|
||||
|
||||
@property
|
||||
def app(self):
|
||||
return App.get_running_app()
|
||||
|
||||
class ProtectedScreen(BaseScreen):
|
||||
def on_pre_enter(self):
|
||||
if not self.app.is_logged_in():
|
||||
self.root.change_screen('login')
|
||||
|
Binary file not shown.
@ -0,0 +1,115 @@
|
||||
#:import FeedScreen screens.feed.feed.FeedScreen
|
||||
|
||||
<FeedScreen>:
|
||||
name: 'feed'
|
||||
#MyLabel:
|
||||
# text: "The falcon cannot hear the falconer..."
|
||||
Carousel:
|
||||
id: post_carousel
|
||||
direction: 'right'
|
||||
|
||||
|
||||
|
||||
<PostTitle>:
|
||||
id: post_title
|
||||
text: ''
|
||||
size_hint_y: None
|
||||
height: self.texture_size[1]
|
||||
font_style: 'H5'
|
||||
halign: 'center'
|
||||
height: '25'
|
||||
size_hint_y: None
|
||||
|
||||
<PostImage>:
|
||||
# height: '25'
|
||||
size_hint_y: None
|
||||
|
||||
<PostGridLayout>:
|
||||
cols: 1
|
||||
size_hint: (1,None)
|
||||
pos_hint: {'center_x':0.5, 'center_y':0}
|
||||
md_bg_color: 1,1,0,1
|
||||
height: self.minimum_height
|
||||
|
||||
|
||||
<PostAuthorLayout>:
|
||||
cols: 2
|
||||
orientation: 'horizontal'
|
||||
size_hint: (1,None)
|
||||
# size_hint:(None,None)
|
||||
# pos_hint:(None,None)
|
||||
pos_hint: {'center_x':0.5, 'center_y':0}
|
||||
# md_bg_color: 1,1,0,1
|
||||
height: '100dp' #self.minimum_height
|
||||
# radius:[20,]
|
||||
# border_radius:20
|
||||
|
||||
<PostAuthorAvatar>:
|
||||
size_hint:(None,None)
|
||||
pos_hint:{'center_x':1,'x':1}
|
||||
# padding:'10dp'
|
||||
# canvas:
|
||||
# Color:
|
||||
# rgb: 1,0,0,1
|
||||
# Line:
|
||||
# width: 1
|
||||
# rectangle: (self.x, self.y, self.width, self.height)
|
||||
|
||||
<PostAuthorLabel>:
|
||||
id: post_author_label
|
||||
text: ''
|
||||
pos_hint: {'center_y':0.5, 'center_x':0.5}
|
||||
# font_size:'100dp'
|
||||
# font_style:'H5'
|
||||
# font_style: 'custom'
|
||||
#font_name: "Strengthen"
|
||||
# height: '400'
|
||||
size_hint_y: None
|
||||
# size_hint_x: 100
|
||||
text_color:1,0,0,1
|
||||
theme_text_color: 'Custom'
|
||||
halign: 'left'
|
||||
padding: ('10dp','0dp')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<PostContent>:
|
||||
id: post_content
|
||||
text: ''
|
||||
pos_hint: {'center_y':1}
|
||||
font_size:'58dp'
|
||||
font_style:'H5'
|
||||
#font_name: "Strengthen"
|
||||
# height: '400'
|
||||
size_hint_y: None
|
||||
text_color:1,0,0,1
|
||||
theme_text_color: 'Custom'
|
||||
halign: 'left'
|
||||
|
||||
|
||||
<PostCard>:
|
||||
id: post
|
||||
orientation: "vertical"
|
||||
padding: "20dp"
|
||||
size_hint: (0.9, None)
|
||||
pos_hint: {"center_x": .5, "center_y": .5}
|
||||
md_bg_color: (0,0,0,1)
|
||||
height: self.minimum_height
|
||||
radius:[20,]
|
||||
border_radius:20
|
||||
# canvas:
|
||||
# Color:
|
||||
# rgb: 1,0,0,1
|
||||
# Line:
|
||||
# width: 1
|
||||
# rectangle: (self.x, self.y, self.width, self.height)
|
||||
# # radius:[20,]
|
||||
# # border_radius:20
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,85 @@
|
||||
from kivymd.uix.label import MDLabel
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.image import AsyncImage
|
||||
from kivymd.uix.boxlayout import MDBoxLayout
|
||||
from kivymd.uix.card import MDCard
|
||||
from screens.base import ProtectedScreen
|
||||
|
||||
|
||||
### POST CODE
|
||||
class PostTitle(MDLabel): pass
|
||||
class PostGridLayout(GridLayout): pass
|
||||
class PostImage(AsyncImage): pass
|
||||
|
||||
class PostContent(MDLabel):
|
||||
def __init__(self,**kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.bind(width=lambda s, w: s.setter('text_size')(s, (w, None)))
|
||||
self.bind(texture_size=self.setter('size'))
|
||||
self.font_name='assets/overpass-mono-regular.otf'
|
||||
#pass
|
||||
|
||||
class PostAuthorLayout(MDBoxLayout): pass
|
||||
|
||||
class PostAuthorLabel(MDLabel):
|
||||
def __init__(self,**kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.bind(width=lambda s, w: s.setter('text_size')(s, (w, None)))
|
||||
self.bind(texture_size=self.setter('size'))
|
||||
self.font_name='assets/overpass-mono-regular.otf'
|
||||
pass
|
||||
class PostAuthorAvatar(AsyncImage): pass
|
||||
|
||||
class PostCard(MDCard):
|
||||
def __init__(self, author = None, title = None, img_src = None, content = None):
|
||||
super().__init__()
|
||||
self.author = author
|
||||
self.title = title
|
||||
self.img_src = img_src
|
||||
self.content = content
|
||||
self.bind(minimum_height=self.setter('height'))
|
||||
|
||||
# pieces
|
||||
author_section_layout = PostAuthorLayout()
|
||||
author_label = PostAuthorLabel(text=self.author)
|
||||
author_label.font_size = '28dp'
|
||||
author_avatar = PostAuthorAvatar(source=self.img_src)
|
||||
author_section_layout.add_widget(author_avatar)
|
||||
author_section_layout.add_widget(author_label)
|
||||
# author_section_layout.add_widget(author_avatar)
|
||||
self.add_widget(author_section_layout)
|
||||
|
||||
|
||||
title = PostTitle(text=self.title)
|
||||
# image = PostImage(source=self.img_src)
|
||||
content = PostContent(text=self.content)
|
||||
|
||||
#content = PostContent()
|
||||
|
||||
# add to screen
|
||||
self.add_widget(title)
|
||||
# self.add_widget(image)
|
||||
self.add_widget(content)
|
||||
#self.add_widget(layout)
|
||||
|
||||
#####
|
||||
|
||||
|
||||
class FeedScreen(ProtectedScreen):
|
||||
def on_enter(self):
|
||||
i=0
|
||||
lim=5
|
||||
with open('tweets.txt') as f:
|
||||
for ln in f:
|
||||
if ln.startswith('@') or ln.startswith('RT '): continue
|
||||
i+=1
|
||||
if i>lim: break
|
||||
|
||||
#post = Post(title=f'Marx Zuckerberg', content=ln.strip())
|
||||
post = PostCard(
|
||||
author='Marx Zuckerberg',
|
||||
title='',
|
||||
img_src='avatar.jpg',
|
||||
content=ln.strip())
|
||||
print(post)
|
||||
self.ids.post_carousel.add_widget(post)
|
@ -0,0 +1,69 @@
|
||||
#:import LoginScreen screens.login.login.LoginScreen
|
||||
|
||||
<LoginScreen>:
|
||||
name: "login"
|
||||
# text: "Login"
|
||||
# icon: "login"
|
||||
|
||||
MyBoxLayout:
|
||||
id: loginbox
|
||||
size_hint:0.5,0.18
|
||||
|
||||
MDTextField:
|
||||
id: username
|
||||
hint_text: "username"
|
||||
required: True
|
||||
write_tab: False
|
||||
multiline: False
|
||||
helper_text_mode: "on_error"
|
||||
color_mode: 'custom'
|
||||
line_color_focus: 1,0,0,1
|
||||
line_color_normal: 1,0,0,1
|
||||
current_hint_text_color: 1,0,0,1
|
||||
|
||||
MDTextField:
|
||||
id: password
|
||||
password: True
|
||||
hint_text: "password"
|
||||
required: True
|
||||
write_tab: False
|
||||
multiline: False
|
||||
helper_text_mode: "on_error"
|
||||
color_mode: 'custom'
|
||||
line_color_focus: 1,0,0,1
|
||||
line_color_normal: 1,0,0,1
|
||||
current_hint_text_color: 1,0,0,1
|
||||
|
||||
|
||||
MDBoxLayout:
|
||||
id: buttonbox
|
||||
size_hint_y: None
|
||||
adaptive_width: True
|
||||
height: '56dp'
|
||||
spacing: '10dp'
|
||||
pos_hint: {'center_x': .5}
|
||||
|
||||
MDRectangleFlatButton:
|
||||
text: "login"
|
||||
on_release:
|
||||
app.login(username.text, password.text)
|
||||
#app.root.change_screen("welcome")
|
||||
theme_text_color: "Custom"
|
||||
text_color: 1,0,0,1
|
||||
md_bg_color: 0,0,0,1
|
||||
|
||||
|
||||
MDRectangleFlatButton:
|
||||
text: "register"
|
||||
on_release:
|
||||
app.register(username.text, password.text)
|
||||
theme_text_color: "Custom"
|
||||
text_color: 1,0,0,1
|
||||
md_bg_color: 0,0,0,1
|
||||
|
||||
MDLabel:
|
||||
id: login_status
|
||||
text:""
|
||||
theme_text_color: 'Error'
|
||||
pos_hint:{'center_x':.5}
|
||||
|
@ -0,0 +1,9 @@
|
||||
from screens.base import BaseScreen
|
||||
|
||||
class LoginScreen(BaseScreen):
|
||||
#def on_pre_enter(self):
|
||||
# global app
|
||||
# if app.is_logged_in():
|
||||
# app.root.change_screen('feed')
|
||||
pass
|
||||
|
@ -0,0 +1,4 @@
|
||||
#:import MessagesScreen screens.messages.messages.MessagesScreen
|
||||
|
||||
<MessagesScreen>:
|
||||
name: 'messages'
|
@ -0,0 +1,4 @@
|
||||
from screens.base import ProtectedScreen
|
||||
|
||||
|
||||
class MessagesScreen(ProtectedScreen): pass
|
@ -0,0 +1,4 @@
|
||||
#:import NotificationsScreen screens.notifications.notifications.NotificationsScreen
|
||||
|
||||
<NotificationsScreen>:
|
||||
name: 'notifications'
|
@ -0,0 +1,4 @@
|
||||
from screens.base import ProtectedScreen
|
||||
|
||||
|
||||
class NotificationsScreen(ProtectedScreen): pass
|
@ -0,0 +1,4 @@
|
||||
#:import PostScreen screens.post.post.PostScreen
|
||||
|
||||
<PostScreen>:
|
||||
name: 'post'
|
@ -0,0 +1,3 @@
|
||||
from screens.base import ProtectedScreen
|
||||
|
||||
class PostScreen(ProtectedScreen): pass
|
Loading…
Reference in New Issue