From 821493724540da71deef36097664cb4e17eb297d Mon Sep 17 00:00:00 2001 From: quadrismegistus Date: Mon, 10 Aug 2020 17:37:42 +0100 Subject: [PATCH] finished separating screens --- client/main.kv | 244 +----------------- client/main.py | 103 +------- client/screens/__init__.py | 0 client/screens/__init__.pyc | Bin 0 -> 106 bytes client/screens/base.py | 25 ++ client/screens/base.pyc | Bin 0 -> 1232 bytes client/screens/feed/feed.kv | 115 +++++++++ client/screens/feed/feed.py | 85 ++++++ client/screens/login/login.kv | 69 +++++ client/screens/login/login.py | 9 + client/screens/messages/messages.kv | 4 + client/screens/messages/messages.py | 4 + client/screens/notifications/notifications.kv | 4 + client/screens/notifications/notifications.py | 4 + client/screens/post/post.kv | 4 + client/screens/post/post.py | 3 + 16 files changed, 337 insertions(+), 336 deletions(-) create mode 100644 client/screens/__init__.py create mode 100644 client/screens/__init__.pyc create mode 100644 client/screens/base.py create mode 100644 client/screens/base.pyc create mode 100644 client/screens/feed/feed.kv create mode 100644 client/screens/feed/feed.py create mode 100644 client/screens/login/login.kv create mode 100644 client/screens/login/login.py create mode 100644 client/screens/messages/messages.kv create mode 100644 client/screens/messages/messages.py create mode 100644 client/screens/notifications/notifications.kv create mode 100644 client/screens/notifications/notifications.py create mode 100644 client/screens/post/post.kv create mode 100644 client/screens/post/post.py diff --git a/client/main.kv b/client/main.kv index e888603..fb851d5 100644 --- a/client/main.kv +++ b/client/main.kv @@ -1,3 +1,10 @@ +#:include screens/login/login.kv +#:include screens/feed/feed.kv +#:include screens/post/post.kv +#:include screens/messages/messages.kv +#:include screens/notifications/notifications.kv + + #:import get_color_from_hex kivy.utils.get_color_from_hex #:import images_path kivymd.images_path #:import colors kivymd.color_definitions.colors @@ -9,6 +16,7 @@ + ## CLASS DEFS : @@ -34,110 +42,6 @@ font_family: 'Courier' -: - id: post_title - text: '' - size_hint_y: None - height: self.texture_size[1] - font_style: 'H5' - halign: 'center' - height: '25' - size_hint_y: None - -: - # height: '25' - size_hint_y: None - -: - 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 - - -: - 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 - -: - 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) - -: - 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') - - - - - - -: - 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' - - -: - 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 - - - - - - @@ -169,7 +73,6 @@ MyLayout: background_palette: 'Red' background_hue: '500' specific_text_color: 1,0,0,1 - # right_action_items: [['radio-tower', partial(root.change_screen, 'feed')], ['account-group', partial(root.change_screen, 'people')], ['calendar', partial(root.change_screen, 'events')], ['message-processing-outline', partial(root.change_screen, 'messages')], ['bell-outline', partial(root.change_screen, 'notifications')]] right_action_items: [['post-outline', partial(root.change_screen, 'feed')], ['pencil-plus-outline', partial(root.change_screen, 'post')], ['message-processing-outline', partial(root.change_screen, 'messages')], ['bell-outline', partial(root.change_screen, 'notifications')], ['account-circle-outline', partial(root.change_screen, 'notifications')]] #left_action_items: [[f"assets/fist2.png", partial(root.change_screen, 'feed')]] font_context: None @@ -180,137 +83,8 @@ MyLayout: id: scr_mngr # transition: NoTransition() - - - - ### - # LOGIN SCREEN - ### - 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} - - - - WelcomeScreen: - name: 'welcome' - - MyBoxLayout: - size_hint:0.666,0.666 - - #MyLabel: - # text: "Welcome!" - # font_style: "H3" - # pos_hint: {'center_y':0.85} - - MyLabel: - text: "\n\nTurning and turning in the widening gyre \nThe falcon cannot hear the falconer;\nThings fall apart; the centre cannot hold;\nMere anarchy is loosed upon the world,\nThe blood-dimmed tide is loosed, and everywhere \nThe ceremony of innocence is drowned;\nThe best lack all conviction, while the worst \nAre full of passionate intensity.\n\nSurely some revelation is at hand..." - - - PeopleScreen: - name: 'people' - - ScrollView: - id: scroll - size_hint: (1, 1) - pos_hint: {'center_x': .5, 'y': 0} - do_scroll_x: False - bar_width: 0 - scroll_type: ['content'] - - MDList: - id: container - # size_hint_y: None - # height: '100dp' - #padding: 0, self._list_vertical_padding - - - - - FeedScreen: - name: 'feed' - #MyLabel: - # text: "The falcon cannot hear the falconer..." - Carousel: - id: post_carousel - direction: 'right' - - AddPostScreen: - name: 'post' - - - - EventsScreen: - name: 'events' - + PostScreen: MessagesScreen: - name: 'messages' - NotificationsScreen: - name: 'notifications' - diff --git a/client/main.py b/client/main.py index 2e49bb1..6cf39da 100644 --- a/client/main.py +++ b/client/main.py @@ -28,14 +28,12 @@ from kivy.core.text import LabelBase Window.size = (640, 1136) #(2.65 * 200, 5.45 * 200) - -root = None -app = None - def log(x): with open('log.txt','a+') as of: of.write(str(x)+'\n') + + class MyLayout(MDBoxLayout): scr_mngr = ObjectProperty(None) @@ -47,110 +45,13 @@ class MyBoxLayout(MDBoxLayout): pass class MyLabel(MDLabel): pass -### 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) - -##### - #### LOGIN -class ProtectedScreen(MDScreen): - def on_pre_enter(self): - global app - if not app.is_logged_in(): - app.root.change_screen('login') - -class WelcomeScreen(ProtectedScreen): pass -class LoginScreen(MDScreen): - #def on_pre_enter(self): - # global app - # if app.is_logged_in(): - # app.root.change_screen('feed') - pass - -class PeopleScreen(ProtectedScreen): pass -class AddPostScreen(ProtectedScreen): pass -class EventsScreen(ProtectedScreen): pass -class MessagesScreen(ProtectedScreen): pass -class NotificationsScreen(ProtectedScreen): pass - - -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) - root.ids.post_carousel.add_widget(post) diff --git a/client/screens/__init__.py b/client/screens/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/client/screens/__init__.pyc b/client/screens/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bf26a0b77133898ec5a0af094789c2824912c492 GIT binary patch literal 106 zcmZSn%*!>s*f2hs0SXv_v;zfv@$s2? dnI-Y@dIgmw96)iK-29Z%oK!oI?h+to001V-5pe(j literal 0 HcmV?d00001 diff --git a/client/screens/base.py b/client/screens/base.py new file mode 100644 index 0000000..ede3afc --- /dev/null +++ b/client/screens/base.py @@ -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') + diff --git a/client/screens/base.pyc b/client/screens/base.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5bb7b03d6d2eba521b64818ab4cf1fa8c602a032 GIT binary patch literal 1232 zcma)5O>fgc5S_L2T}p}s{Q(@1PeI%fg3@Cf(B_0MD<|Ft2Y<=lREfj^sr+Mp0L+_p zgNiB<+q>(TwP)VEHyi#soy6{qSy6X|yuRnr{@^L)M^R2xD2f#+*a77M6(Pl;w?oQ% zRP-tCd%H*ZfQli-LvQyfA5k%;c+B>ItfCu5>5zUB-4T6>CzOuJPQ*Jtcuy#u&>}iv z5ZQ0OBE@fR#MAZVV%1n%de2k#d|Gbo%6)FC+BRe@|sy+~T?BOka3;O5c3;>i*yumMN`c4j0LQ{9_A(u)ZHtN`|Yd_({w_)fIp zM{!x$o6DyT5E6#apRK(43;bY8VoB#Q$GgzW=S;7tUA!Uutv ztM;Xs0c}DY0aja;avr?Ga|cX$wa&^2prjNBj9F{gy|$^zN~zL8pw-u;TwCMyJCNM|0TX0LA$ zxM!VknQb))bkBL}zTalM*|OT@a?mswb!QKEbDTI0ywU^`kXuc9P=iPfP)C55-{1O< QdIuaWz@Mq^9-fc?0B?2I0RR91 literal 0 HcmV?d00001 diff --git a/client/screens/feed/feed.kv b/client/screens/feed/feed.kv new file mode 100644 index 0000000..2d97384 --- /dev/null +++ b/client/screens/feed/feed.kv @@ -0,0 +1,115 @@ +#:import FeedScreen screens.feed.feed.FeedScreen + +: + name: 'feed' + #MyLabel: + # text: "The falcon cannot hear the falconer..." + Carousel: + id: post_carousel + direction: 'right' + + + +: + id: post_title + text: '' + size_hint_y: None + height: self.texture_size[1] + font_style: 'H5' + halign: 'center' + height: '25' + size_hint_y: None + +: + # height: '25' + size_hint_y: None + +: + 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 + + +: + 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 + +: + 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) + +: + 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') + + + + + + +: + 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' + + +: + 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 + + + + + diff --git a/client/screens/feed/feed.py b/client/screens/feed/feed.py new file mode 100644 index 0000000..fb0a884 --- /dev/null +++ b/client/screens/feed/feed.py @@ -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) diff --git a/client/screens/login/login.kv b/client/screens/login/login.kv new file mode 100644 index 0000000..1ec476f --- /dev/null +++ b/client/screens/login/login.kv @@ -0,0 +1,69 @@ +#:import LoginScreen screens.login.login.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} + \ No newline at end of file diff --git a/client/screens/login/login.py b/client/screens/login/login.py new file mode 100644 index 0000000..047a489 --- /dev/null +++ b/client/screens/login/login.py @@ -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 + \ No newline at end of file diff --git a/client/screens/messages/messages.kv b/client/screens/messages/messages.kv new file mode 100644 index 0000000..b42c68e --- /dev/null +++ b/client/screens/messages/messages.kv @@ -0,0 +1,4 @@ +#:import MessagesScreen screens.messages.messages.MessagesScreen + +: + name: 'messages' diff --git a/client/screens/messages/messages.py b/client/screens/messages/messages.py new file mode 100644 index 0000000..8592fed --- /dev/null +++ b/client/screens/messages/messages.py @@ -0,0 +1,4 @@ +from screens.base import ProtectedScreen + + +class MessagesScreen(ProtectedScreen): pass \ No newline at end of file diff --git a/client/screens/notifications/notifications.kv b/client/screens/notifications/notifications.kv new file mode 100644 index 0000000..c4ddd03 --- /dev/null +++ b/client/screens/notifications/notifications.kv @@ -0,0 +1,4 @@ +#:import NotificationsScreen screens.notifications.notifications.NotificationsScreen + +: + name: 'notifications' diff --git a/client/screens/notifications/notifications.py b/client/screens/notifications/notifications.py new file mode 100644 index 0000000..090b839 --- /dev/null +++ b/client/screens/notifications/notifications.py @@ -0,0 +1,4 @@ +from screens.base import ProtectedScreen + + +class NotificationsScreen(ProtectedScreen): pass diff --git a/client/screens/post/post.kv b/client/screens/post/post.kv new file mode 100644 index 0000000..50cfd33 --- /dev/null +++ b/client/screens/post/post.kv @@ -0,0 +1,4 @@ +#:import PostScreen screens.post.post.PostScreen + +: + name: 'post' \ No newline at end of file diff --git a/client/screens/post/post.py b/client/screens/post/post.py new file mode 100644 index 0000000..358a639 --- /dev/null +++ b/client/screens/post/post.py @@ -0,0 +1,3 @@ +from screens.base import ProtectedScreen + +class PostScreen(ProtectedScreen): pass