master
marxzuckerburg 4 years ago
parent 8d16d63333
commit 5fc627379f

@ -89,7 +89,7 @@ class MyLayout(MDBoxLayout):
def change_screen(self, screen, *args):
self.scr_mngr.current = screen
self.app.last_screen = self.app.screen
self.app.screen_hist.append(self.app.screen)
self.app.screen = self.screen = screen
# toolbar
@ -446,7 +446,69 @@ class MainApp(MDApp, Logger):
texture = ObjectProperty()
uri='/do/login'
screen='login'
last_screen=None
screen_hist=[]
screen_names = [
'feed',
'messages',
'post',
'profile',
# 'refresh',
# 'login'
]
def go_back(self):
self.change_screen(
self.screen_hist.pop() if self.screen_hist else 'feed'
)
def _on_keyboard_down(self, instance, keyboard, keycode, text, modifiers):
# self.log(f'keyboard:{keyboard}\nkeycode: {keycode}\ntext: {text}\ninstance: {instance}\nmodifiers:\n{modifiers}\n\n')
## arrows
# ctrl left
modifiers=set(modifiers)
# enter? continue
if keycode==40:
if hasattr(self,'msg_dialog') and self.msg_dialog:
self.msg_dialog.ok_to_continue=True
# left
if keycode == 80 and 'ctrl' in modifiers:
# go back
self.go_back()
# down
elif keycode==81 and 'ctrl' in modifiers:
screen_index=self.screen_names.index(self.screen)
new_screen = self.screen_names[screen_index - 1]
self.change_screen(new_screen)
# up
elif keycode==82 and 'ctrl' in modifiers:
screen_index=self.screen_names.index(self.screen)
try:
new_screen = self.screen_names[screen_index +1]
except IndexError:
new_screen = self.screen_names[0]
self.change_screen(new_screen)
## keys
elif text=='f' and 'ctrl' in modifiers:
self.change_screen('feed')
elif text=='m' and 'ctrl' in modifiers:
self.change_screen('messages')
elif text=='c' and 'ctrl' in modifiers:
self.change_screen('post')
elif text=='p' and 'ctrl' in modifiers:
self.change_screen('profile')
elif text=='r' and 'ctrl' in modifiers:
self.change_screen('refresh')
elif text=='e' and 'ctrl' in modifiers:
self.change_screen('login')
def rgb(self,*_): return rgb(*_)
@ -469,10 +531,9 @@ class MainApp(MDApp, Logger):
super().__init__(**kwargs)
self.event_loop_worker = None
self.loop=asyncio.get_event_loop()
# connect to API
self.comrad=None
self._name=''
Window.bind(on_key_down=self._on_keyboard_down)
def build(self):
@ -577,8 +638,10 @@ class MainApp(MDApp, Logger):
self.remove_widget(widg)
def view_profile(self,username):
self.username=username
self.change_screen('profile')
# self.username=self.comrad.name

@ -37,7 +37,8 @@ class PostContent(MDLabel):
self.font_name='assets/overpass-mono-regular.otf'
#pass
class PostAuthorLayout(MDBoxLayout): pass
class PostAuthorLayout(MDBoxLayout):
pass
class PostImageLayout(MDBoxLayout): pass
@ -50,43 +51,28 @@ class PostAuthorLabel(MDLabel):
self.font_name='assets/overpass-mono-regular.otf'
#self.to_changeable=False
# def on_touch_down(self,*x,**y):
# print('weeeeeee')
# stop
#def on_touch_down(self, touch):
# '''Receive a touch down event.
# :Parameters:
# `touch`: :class:`~kivy.input.motionevent.MotionEvent` class
# Touch received. The touch is in parent coordinates. See
# :mod:`~kivy.uix.relativelayout` for a discussion on
# coordinate systems.
# :Returns: bool
# If True, the dispatching of the touch event will stop.
# If False, the event will continue to be dispatched to the rest
# of the widget tree.
# '''
def on_touch_down(self, touch):
'''Receive a touch down event.
:Parameters:
`touch`: :class:`~kivy.input.motionevent.MotionEvent` class
Touch received. The touch is in parent coordinates. See
:mod:`~kivy.uix.relativelayout` for a discussion on
coordinate systems.
:Returns: bool
If True, the dispatching of the touch event will stop.
If False, the event will continue to be dispatched to the rest
of the widget tree.
'''
#if not self.to_changeable: return
# try:
# self.parent.parent.author_dialog.open()
# #for item in self.parent.parent.author_dialog.items:
# # raise Exception([item.disabled, item.text])
# except AttributeError:
# pass
try:
self.parent.parent.parent.open_author_option()
except AttributeError:
pass
#raise Exception(self.text)
# self.text = '!!!'
#self.parent.parent.recipient
#return
#raise Exception(self.parent.parent.recipient)
if self.disabled and self.collide_point(*touch.pos):
if self.collide_point(*touch.pos):
username=self.text.strip().split()[1][1:]
app=App.get_running_app()
app.view_profile(username)
return True
for child in self.children[:]:
if child.dispatch('on_touch_down', touch):
return True
pass
@ -97,7 +83,13 @@ class PostTimestampLabel(MDLabel):
self.bind(texture_size=self.setter('size'))
self.font_name='assets/overpass-mono-regular.otf'
class PostAuthorAvatar(AsyncImage): pass
class PostAuthorAvatar(AsyncImage):
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
print('wiiiiimg')
return True
# stop
pass
class PostLayout(MDBoxLayout): pass
@ -281,10 +273,16 @@ class PostCardInputPopup(PostCardPopup):
class FeedScreen(ProtectedScreen):
posts = ListProperty()
updated = None
def on_pre_enter(self):
if not super().on_pre_enter(): return
if self.updated:
if not self.app.comrad.updated or self.updated>=self.app.comrad.updated:
self.log('NOT UPDATING!')
return
# self.root.clear_widgets()
self.log('UPDATING!')
if self.app.map:
self.app.map.dismiss()
self.root.remove_widget(self.app.map)
@ -312,6 +310,7 @@ class FeedScreen(ProtectedScreen):
post_obj = PostCard(data)
self.posts.append(post_obj)
self.ids.post_carousel.add_widget(post_obj)
self.updated = time.time()
asyncio.create_task(go())
return True

@ -93,7 +93,9 @@ class PostScreen(ProtectedScreen):
self.post_card.add_widget(self.to_whom_btn,1)
self.to_whom_btn.height='100dp'
self.to_whom_btn.size_hint_y=None
except kivy.uix.widget.WidgetException:
self.log('wtf?????')
except kivy.uix.widget.WidgetException as e:
self.log('wtf ',e)
return
def close_author_option(self):

@ -183,7 +183,8 @@ def update_screen_on_carousel_move(self,dt,width=75):
# avatar_layout = copy(screen.avatar_layout)
# avatar_layout.width=dp(100)
# avatar_layout.height=dp(100)
if not self.do_update_screen_on_carousel_move: return
if self.carousel.index:
if not hasattr(self,'avatar_layout_small'):
self.avatar_img.seek(0)
@ -221,7 +222,7 @@ from screens.base import ProtectedScreen
class ProfileScreen(ProtectedScreen):
username = None
clock_scheduled=None
do_update_screen_on_carousel_move=True
def make_profile_img(self,width,do_crop=True,circ_img=None,bw=False,circularize=True):
img_src = os.path.join(PATH_AVATARS, f'{self.app.username}.png')
@ -264,7 +265,7 @@ class ProfileScreen(ProtectedScreen):
def on_pre_enter(self, width=AVATAR_WIDTH):
if not super().on_pre_enter(): return
self.do_update_screen_on_carousel_move=True
if not self.clock_scheduled:
Clock.schedule_interval(partial(update_screen_on_carousel_move, self), 0.1)
self.clock_scheduled=True
@ -381,6 +382,14 @@ class ProfileScreen(ProtectedScreen):
self.carousel.add_widget(post_obj)
def on_pre_leave(self):
self.app.username=self.app.comrad.name
# self.avatar_layout_small_visible=False
if hasattr(self,'avatar_layout_small'):
self.remove_widget(self.avatar_layout_small)
del self.avatar_layout_small
self.do_update_screen_on_carousel_move=False
# def on_touch_move(self, ent):
# if self.carousel.index:
# self.author_name.text='moved!'

@ -16,7 +16,7 @@ class RefreshScreen(ProtectedScreen):
await self.app.comrad.get_updates()
self.app.map.dismiss()
self.app.map=None
self.app.change_screen(self.app.last_screen if self.app.last_screen else 'feed')
self.app.go_back()
asyncio.create_task(go())

@ -16,6 +16,7 @@ class ComradX(Caller):
def __init__(self, name=None, pubkey=None, callbacks={}, getpass_func=None):
# logger.info('booting ComradX with getpass_func:',getpass_func)
self.updated=None
super().__init__(name=name, callbacks=callbacks, getpass_func=getpass_func)
self.log(f'Starting up with callbacks: {self._callbacks}')
# self.boot(create=False)
@ -645,7 +646,7 @@ class ComradX(Caller):
for post in self.posts(post_ids=post_ids):
self.log('adding post to outbox!',post)
self.add_to_post_outbox(
post_id,
post.post_id,
username=post.from_name
)
@ -722,6 +723,7 @@ class ComradX(Caller):
_num=self.num_unread_msgs
res['status']=f'''You have {_nup} unseen post{'s' if _nup!=1 else ''} and {_num} unread msg{'s' if _num!=1 else ''}.'''
self.updated=time.time()
return res
@property

Loading…
Cancel
Save