Dropbox script/Do 下载完成后的东西
Dropbox script/Do something when download done
也许我在查看 Dropbox 上传器时遗漏了什么 https://github.com/andreafabrizi/Dropbox-Uploader 。我正在创建一个 python 脚本,用于从插入 RPi 的 USB 上传文件,但需要它,以便在上传完成时,布尔值变为 false。有没有办法检测到这一点?在我希望发生这种情况的地方对代码进行了注释。
import pygame
from pygame.locals import *
from subprocess import call
uploadSym = pygame.image.load('uploadsymbol.png')
loadingSym = pygame.image.load('loading.png')
uploadSym = pygame.transform.scale(uploadSym, (250,300))
loadingSym = pygame.transform.scale(loadingSym, (300,300))
rect = uploadSym.get_rect()
rect = rect.move((200,60))
rect = loadingSym.get_rect()
rect = rect.move((200,60))
firstSlide = False
def toggle_fullscreen():
screen = pygame.display.get_surface()
tmp = screen.convert()
caption = pygame.display.get_caption()
cursor = pygame.mouse.get_cursor()
w,h = screen.get_width(),screen.get_height()
flags = screen.get_flags()
bits = screen.get_bitsize()
pygame.display.quit()
pygame.display.init()
screen = pygame.display.set_mode((w,h),flags^FULLSCREEN,bits)
screen.blit(tmp,(0,0))
pygame.display.set_caption(*caption)
pygame.key.set_mods(0)
pygame.mouse.set_cursor( *cursor )
return screen
if __name__ == '__main__':
SW,SH = 640,480
screen = pygame.display.set_mode((SW,SH),pygame.NOFRAME)
pygame.display.set_caption('Uploader')
_quit = False
while not _quit:
for e in pygame.event.get():
if (e.type is KEYDOWN and e.key == K_RETURN and (e.mod&(KMOD_LALT|KMOD_RALT)) != 0):
toggle_fullscreen()
elif e.type is QUIT:
_quit = True
elif e.type is KEYDOWN and e.key == K_ESCAPE:
_quit = True
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
screen = pygame.display.get_surface()
screen.fill([255, 255, 255])
#Click within the given area and upload begins
if 450 > mouse[0] > 250 and 360 > mouse[1] > 60 and click[0] == 1:
firstSlide = True
#T/F keeps png up for new slide
elif firstSlide == True:
loadRot = pygame.transform.rotate(loadingSym,0)
screen.blit(loadRot, rect)
#Upload test file to dropbox
Upload = "/home/pi/Uploader/Dropbox-Uploader/dropbox_uploader.sh upload loading.png /"
call ([Upload], shell=True)
#Here I need an if statement that says, when upload done firstSlide = False
#{
#
#
#}
else:
screen.blit(uploadSym, rect)
pygame.display.update()
subprocess.call()
function return 是命令的退出代码。所以 call()
将(应该) return 0
成功,并且非零错误。
所以:
uploaded_ok = ( subprocess.call( Upload, shell=True) == 0 )
会给你 True/False 成功。
注意:Link 到 2.7 doco,因为 OP 标记了问题 Python2.7
也许我在查看 Dropbox 上传器时遗漏了什么 https://github.com/andreafabrizi/Dropbox-Uploader 。我正在创建一个 python 脚本,用于从插入 RPi 的 USB 上传文件,但需要它,以便在上传完成时,布尔值变为 false。有没有办法检测到这一点?在我希望发生这种情况的地方对代码进行了注释。
import pygame
from pygame.locals import *
from subprocess import call
uploadSym = pygame.image.load('uploadsymbol.png')
loadingSym = pygame.image.load('loading.png')
uploadSym = pygame.transform.scale(uploadSym, (250,300))
loadingSym = pygame.transform.scale(loadingSym, (300,300))
rect = uploadSym.get_rect()
rect = rect.move((200,60))
rect = loadingSym.get_rect()
rect = rect.move((200,60))
firstSlide = False
def toggle_fullscreen():
screen = pygame.display.get_surface()
tmp = screen.convert()
caption = pygame.display.get_caption()
cursor = pygame.mouse.get_cursor()
w,h = screen.get_width(),screen.get_height()
flags = screen.get_flags()
bits = screen.get_bitsize()
pygame.display.quit()
pygame.display.init()
screen = pygame.display.set_mode((w,h),flags^FULLSCREEN,bits)
screen.blit(tmp,(0,0))
pygame.display.set_caption(*caption)
pygame.key.set_mods(0)
pygame.mouse.set_cursor( *cursor )
return screen
if __name__ == '__main__':
SW,SH = 640,480
screen = pygame.display.set_mode((SW,SH),pygame.NOFRAME)
pygame.display.set_caption('Uploader')
_quit = False
while not _quit:
for e in pygame.event.get():
if (e.type is KEYDOWN and e.key == K_RETURN and (e.mod&(KMOD_LALT|KMOD_RALT)) != 0):
toggle_fullscreen()
elif e.type is QUIT:
_quit = True
elif e.type is KEYDOWN and e.key == K_ESCAPE:
_quit = True
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
screen = pygame.display.get_surface()
screen.fill([255, 255, 255])
#Click within the given area and upload begins
if 450 > mouse[0] > 250 and 360 > mouse[1] > 60 and click[0] == 1:
firstSlide = True
#T/F keeps png up for new slide
elif firstSlide == True:
loadRot = pygame.transform.rotate(loadingSym,0)
screen.blit(loadRot, rect)
#Upload test file to dropbox
Upload = "/home/pi/Uploader/Dropbox-Uploader/dropbox_uploader.sh upload loading.png /"
call ([Upload], shell=True)
#Here I need an if statement that says, when upload done firstSlide = False
#{
#
#
#}
else:
screen.blit(uploadSym, rect)
pygame.display.update()
subprocess.call()
function return 是命令的退出代码。所以 call()
将(应该) return 0
成功,并且非零错误。
所以:
uploaded_ok = ( subprocess.call( Upload, shell=True) == 0 )
会给你 True/False 成功。
注意:Link 到 2.7 doco,因为 OP 标记了问题 Python2.7