This commit is contained in:
yumoqing 2022-10-14 13:50:29 +08:00
parent 167ff968e3
commit 267ddcd92b
6 changed files with 68 additions and 1 deletions

7
kivyblocks/download.py Normal file
View File

@ -0,0 +1,7 @@
from kivy.properties import StringProperty
class DownloadFile(ClickableIconText):
def __init__(self, **kw):
pass

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
kivyblocks/imgs/upload.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -191,7 +191,7 @@ class MarkdownBody(VBox):
self.md_obj = md_obj
super().__init__(**kw)
self.padding=padding
self.size_hint = None,None
self.size_hint = 1,None
self.bind(parent=self.resize)
self.resize()
@ -205,6 +205,7 @@ class MarkdownBody(VBox):
f(v)
def resize(self, *args):
return
Logger.info('MDBody:resize called')
if self.parent:
ps = [0,0,0,0]

View File

@ -42,10 +42,12 @@ from .block_test import BlockTest
from .hierarchy import Hierarchy
from .price import PriceView
from .ffpyplayer_video import FFVideo
from .upload import UploadFile
r = Factory.register
# if kivy.platform in ['win','linux', 'macosx']:
# r('ScreenWithMic', ScreenWithMic)
r('UploadFile', UploadFile)
r('FFVideo', FFVideo)
r('AnchorBox', AnchorBox)
r('FloatBox', FloatBox)

57
kivyblocks/upload.py Normal file
View File

@ -0,0 +1,57 @@
import os
from kivy.properties import StringProperty, ListProperty
from kivyblocks.utils import blockImage, CSize
import requests
from plyer import filechooser
from .i18n import I18n
from .clickable import ClickableIconText
from .baseWidget import Running
from .message import Error
class UploadFile(ClickableIconText):
upload_url = StringProperty(None)
name = StringProperty('upfile')
# suffixes = ListProperty([])
def __init__(self, **kw):
super().__init__(**kw)
self.otext = 'please select file'
self.img_kw = {
"size_hint":[None, None],
"width":CSize(1),
"height":CSize(1)
}
self.source = blockImage('upload.png')
self.file_url = None
self.running = None
def getValue(self):
return {
self.name:self.file_url
}
def on_press(self, *args):
i18n = I18n()
filechooser.open_file(title=i18n('open file'),
on_selection=self.file_selected)
def file_selected(self, files):
running = Running(self)
def readfile(f):
with open(f, 'rb') as o:
d = o.read(102400)
if not d:
return
yield d
fpath = files[0]
fn = os.path.basename(fpath)
print('fn=', fn)
headers={
'Content-Type': 'application/octet-stream',
'Content-Disposition':'attachments;filename={}'.format(fn)
}
r = requests.post(self.upload_url,
data=readfile(files[0]),
headers=headers
)
running.dismiss()