what changed?

pull/20/head
quadrismegistus 4 years ago
parent 303ccee9b9
commit b897f5930d

@ -5,7 +5,7 @@ HORIZONTAL = False #random.choice([True,True,True,False])
FACTOR=1
WINDOW_SIZE = (1136*FACTOR,640*FACTOR) if HORIZONTAL else (640*FACTOR,1136*FACTOR)
WINDOW_SIZE=800,800
WINDOW_SIZE=700,700
BG_IMG='assets/bg-brown.png'

@ -368,8 +368,10 @@ class MainApp(MDApp):
async def get_post(self,post_id):
return await self.api.get_post(post_id)
async def get_posts(self):
data = await self.api.get_posts()
async def get_posts(self,uri='/posts/channel/earth'):
self.log(f'app.get_posts(uri={uri} -> ...')
data = await self.api.get_posts(uri)
self.log
newdata=[]
for d in data:
@ -382,7 +384,8 @@ class MainApp(MDApp):
return newdata
async def get_my_posts(self):
return await self.api.get_posts('/author/'+self.username)
self.log(f'get_my_posts({self.username})')
return await self.get_posts(uri='/posts/author/'+self.username)

@ -35,7 +35,7 @@
pos_hint: {'center_x':0.5} #, 'y':0.5}
# height: '100dp' #self.minimum_height
# width: '100dp'
height: '300dp'
height: '300sp'
# spacing:'100dp'
# padding:'100dp'
@ -79,15 +79,17 @@
# 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
height: '100sp' #self.minimum_height
# radius:[20,]
# border_radius:20
# height: self.minimum_height
<PostAuthorAvatar>:
size_hint:(None,None)
pos_hint:{'center_x':1,'x':1}
height:'100sp'
# padding:'10dp'
# canvas:
# Color:
@ -113,6 +115,7 @@
padding: ('10dp','0dp')
bold: True
markup: True
# font_size: '24sp'
<PostTimestampLabel>:
id: post_timestamp_label
@ -139,14 +142,15 @@
id: post_content
text: ''
pos_hint: {'center_y':1}
font_size:'58dp'
font_style:'H5'
font_size:'13sp'
# font_style:'H5'
#font_name: "Strengthen"
# height: '400'
size_hint_y: None
size_hint_y: 1
text_color:rgb(*COLOR_TEXT)
theme_text_color: 'Custom'
halign: 'left'
# adaptive_height: True
<PostScrollView>:
size_hint: (1,None)
@ -157,7 +161,10 @@
id: post
orientation: "vertical"
padding: "20dp"
size_hint: (0.75, None)
size_hint: (None, None)
width: '400sp'
# size:('400sp','800sp')
# adaptive_height: True
pos_hint: {"center_x": .5, "center_y": .5}
md_bg_color: rgb(*COLOR_CARD)
height: self.minimum_height

@ -80,9 +80,9 @@ class PostCard(MDCard):
# pieces
author_section_layout = PostAuthorLayout()
author_label = PostAuthorLabel(text='[b]'+self.author+'[/b]')
author_label.font_size = '28dp'
author_avatar = PostAuthorAvatar(source='avatar.jpg') #self.img_src)
author_label = PostAuthorLabel(text='@'+self.author)
author_label.font_size = '18sp'
author_avatar = PostAuthorAvatar(source='assets/avatar.jpg') #self.img_src)
author_section_layout.add_widget(author_avatar)
author_section_layout.add_widget(author_label)
@ -100,9 +100,9 @@ class PostCard(MDCard):
if self.cache_img_src:
image_layout = PostImageLayout()
self.image = image = PostImage(source=self.cache_img_src)
image.height = '300dp'
image.height = '300sp'
image_layout.add_widget(image)
image_layout.height='300dp'
image_layout.height='300sp'
# self.log(image.image_ratio)
self.post_content = PostContent(text=self.content)
@ -131,10 +131,10 @@ class PostCard(MDCard):
if height<minlen: height=minlen
return height
scroller.size = ('300dp','%sdp' % estimate_height())
scroller.size = ('300sp','%ssp' % estimate_height())
# scroller.bind(size=('300dp',scroller.setter('height'))
# scroller.bind(size=('300sp',scroller.setter('height'))
scroller.add_widget(self.post_content)
self.add_widget(scroller)
# self.add_widget(post_layout)

@ -126,7 +126,7 @@
text_color: rgb(*COLOR_TEXT)
md_bg_color: 0,0,0,1
size_hint:None,None
font_size:'24sp'
# font_size:'24sp'
# pos_hint: {'center_x': .5, 'bottom':1}
<RegisterButton>:
@ -136,7 +136,7 @@
theme_text_color: "Custom"
text_color: rgb(*COLOR_TEXT)
md_bg_color: 0,0,0,1
font_size:'24sp'
# font_size:'24sp'
# size_hint:1,None
<LoginStatus>:

@ -90,8 +90,8 @@ class LoginScreen(BaseScreen):
self.label_title.font_size='22sp'
self.label_password.font_size='18sp'
self.label_username.font_size='18sp'
self.login_button.font_size='18sp'
self.register_button.font_size='18sp'
self.login_button.font_size='12sp'
self.register_button.font_size='12sp'

@ -72,7 +72,7 @@ class PostScreen(ProtectedScreen):
post_TextField.font_name='assets/overpass-mono-regular.otf'
post_TextField.hint_text='word?'
# post.remove_widget(post.scroller)
post.remove_widget(post.scroller)
post.scroller.remove_widget(post.post_content)
post.scroller.add_widget(post_TextField)
post.scroller.size=('300dp','300dp')

@ -316,6 +316,8 @@ class ProfileScreen(BaseScreen):
# add posts
lim=25
posts=await self.app.get_my_posts()
# self.log('POSTS!?',posts)
# stop
for i,post in enumerate(posts):
if i>lim: break

@ -12,6 +12,7 @@ sys.path.append('../p2p')
BSEP=b'\n\n'
BSEP2=b'\t\n'
BSEP3=b'\r\r'
NODE_SLEEP_FOR=5
try:
from .crypto import *
@ -96,7 +97,7 @@ class Api(object):
# self.root.ids.btn1.trigger_action()
i += 1
await asyncio.sleep(1)
await asyncio.sleep(NODE_SLEEP_FOR)
# pass
except (asyncio.CancelledError,KeyboardInterrupt) as e:
self.log('P2P node cancelled', e)
@ -605,13 +606,12 @@ class Api(object):
async def get_json_val(self,uri,get_last=True):
res=await self.get_json(uri,get_last=get_last)
self.log('get_json_val() got',res)
r=None
if type(res) == dict:
r=res.get('val',None) if res is not None else None
elif type(res) == list:
r=[x.get('val',None) for x in res if x is not None]
self.log('get_json_val() giving back',r)
self.log(f'get_json_val() --> {r}')
return r
async def get_post(self,post_id):
@ -619,7 +619,10 @@ class Api(object):
async def get_posts(self,uri='/posts/channel/earth'):
# index = await self.get_json_val('/posts'+uri)
self.log(f'api.get_posts(uri={uri}) --> ...')
index = await self.get_json_val(uri,get_last=False)
if index is None: return []
if type(index)!=list: index=[index]
self.log('got index?',index)

@ -1,11 +1,15 @@
"""
Package for interacting on the network at a high level.
"""
STORE_ANYWHERE=True
import random
import pickle
import asyncio
import logging
from kademlia.protocol import KademliaProtocol
from kademlia.utils import digest
from kademlia.storage import HalfForgetfulStorage
@ -153,7 +157,7 @@ class Server:
result = await self.protocol.ping(addr, self.node.id)
return Node(result[1], addr[0], addr[1]) if result[0] else None
async def get(self, key):
async def get(self, key, store_anywhere=STORE_ANYWHERE):
"""
Get a key if the network has it.
@ -175,7 +179,8 @@ class Server:
found = await spider.find()
# set it locally? @EDIT
self.storage.set(dkey,found)
if store_anywhere:
self.storage.set(dkey,found)
return found
@ -195,7 +200,7 @@ class Server:
#dkey = digest(key)
return await self.set_digest(key, value)
async def set_digest(self, key, value):
async def set_digest(self, key, value, store_anywhere=STORE_ANYWHERE):
"""
Set the given SHA1 digest key (bytes) to the given value in the
network.
@ -216,12 +221,17 @@ class Server:
log.info("setting '%s' on %s", dkey.hex(), list(map(str, nodes)))
# if this node is close too, then store here as well
biggest = max([n.distance_to(node) for n in nodes])
if self.node.distance_to(node) < biggest:
#self.storage[dkey] = value
## IMPOSSIBLE STORING UNDIGESTED IN LOCAL STORAGE FOR NOW @DEBUG @HACK
#self.storage.data_debug[key]=value
if store_anywhere:
self.storage.set(dkey,value,undigested_too=key)
else:
biggest = max([n.distance_to(node) for n in nodes])
if self.node.distance_to(node) < biggest:
#self.storage[dkey] = value
## IMPOSSIBLE STORING UNDIGESTED IN LOCAL STORAGE FOR NOW @DEBUG @HACK
#self.storage.data_debug[key]=value
self.storage.set(dkey,value,undigested_too=key)
results = [self.protocol.call_store(n, dkey, value) for n in nodes]
# return true only if at least one store call succeeded
return any(await asyncio.gather(*results))

Loading…
Cancel
Save