Merge pull request #5 from cuu/master

fix bug in compare git versions and main_screen's MsgBox
This commit is contained in:
clockworkpi 2018-05-27 20:30:26 +08:00 committed by GitHub
commit 3bb88eb892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 25 deletions

View File

@ -21,6 +21,7 @@ from UI.download import Download
from UI.download_process_page import DownloadProcessPage
from libs.roundrects import aa_round_rect
from libs.DBUS import is_wifi_connected_now
import config
@ -285,6 +286,8 @@ class UpdatePage(Page):
cur_dir = os.getcwd()
os.chdir("/home/cpi/apps/launcher")
current_git_version = get_git_revision_short_hash()
current_git_version = current_git_version.strip("\n")
current_git_version = current_git_version.strip("\t")
os.chdir(cur_dir)
if current_git_version != json_["gitversion"]:
self._ConfirmPage._URL = None
@ -302,7 +305,7 @@ class UpdatePage(Page):
self._Screen._MsgBox.SetText("Out of update")
self._Screen._MsgBox.Draw()
self._Screen.SwapAndShow()
pygame.time.delay(600)
pygame.time.delay(765)
return True
except Exception, e:
@ -324,12 +327,18 @@ class UpdatePage(Page):
self._Screen.SwapAndShow()
if event.key == CurKeys["X"]:
if self.CheckUpdate() == True:
self._Screen.Draw()
self._Screen.SwapAndShow()
if is_wifi_connected_now():
if self.CheckUpdate() == True:
self._Screen.Draw()
self._Screen.SwapAndShow()
else:
self._Screen.Draw()
self._Screen._MsgBox.SetText("Checking update failed")
self._Screen._MsgBox.Draw()
self._Screen.SwapAndShow()
else:
self._Screen.Draw()
self._Screen._MsgBox.SetText("Checking update failed")
self._Screen._MsgBox.SetText("Please Check your Wi-Fi connection")
self._Screen._MsgBox.Draw()
self._Screen.SwapAndShow()

View File

@ -13,6 +13,8 @@ from UI.util_funcs import midRect
from UI.keys_def import CurKeys
from UI.icon_item import IconItem
from libs.roundrects import aa_round_rect
from textarea import Textarea
from text_item import TextItem
from icons import preload
@ -43,14 +45,15 @@ class KeyboardSelector(PageSelector):
x = self._Parent._SecsKeys[sec_idx][row_idx][idx]._PosX
y = self._Parent._SecsKeys[sec_idx][row_idx][idx]._PosY
w = self._Parent._SecsKeys[sec_idx][row_idx][idx]._Width
h = self._Parent._SecsKeys[sec_idx][row_idx][idx]._Height
w = self._Parent._SecsKeys[sec_idx][row_idx][idx]._Width+6
h = self._Parent._SecsKeys[sec_idx][row_idx][idx]._Height+1
rect = midRect(x,y,w,h,self._Parent._Width,self._Parent._Height)
if rect.width <=0 or rect.height <= 0 :
return
pygame.draw.rect(self._Parent._CanvasHWND,(0,0,0),rect,1)
aa_round_rect(self._Parent._CanvasHWND,rect, (126,206,244),4,1,(255,255,255))
# pygame.draw.rect(self._Parent._CanvasHWND,(0,0,0),rect,1)
class Keyboard(Page):
_PosX = 0
@ -328,6 +331,7 @@ class Keyboard(Page):
def Draw(self):
self.ClearCanvas()
self._Ps.Draw()
for i in range(0,self._SectionNumbers):
for j in self._SecsKeys[i]:
for u in j:
@ -335,6 +339,5 @@ class Keyboard(Page):
self._Textarea.Draw()
self._Ps.Draw()

View File

@ -32,7 +32,7 @@ class RomSoConfirmPage(ConfirmPage):
f = open(config.Battery)
except IOError:
print( "RomSoConfirmPage open %s failed" % config.Battery)
return 0
return 6
else:
with f:
bat_uevent = {}

View File

@ -19,7 +19,7 @@ from page import Page,PageStack
from title_bar import TitleBar
from foot_bar import FootBar
from constants import Width,Height,bg_color
from util_funcs import FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable
from util_funcs import midRect,FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable
from fonts import fonts
from keys_def import CurKeys
from label import Label
@ -29,19 +29,69 @@ from Emulator import MyEmulator
class MessageBox(Label):
_Parent = None
def __init__(self):
pass
def Init(self,text,font_obj,color=pygame.Color(83,83,83)):
self._Color = color
self._FontObj = font_obj
self._Text = text
self._Width = 0
self._Height = 0
self._CanvasHWND = pygame.Surface( ( int(self._Parent._Width),int(self._Parent._Height)))
self._HWND = self._Parent._CanvasHWND
def SetText(self,text):
self._Text = text
def Draw(self):
my_text = self._FontObj.render( self._Text,True,self._Color)
w = my_text.get_width()
h = my_text.get_height()
x = (self._Parent._Width - w)/2
y = (self._Parent._Height - h)/2
padding = 10
pygame.draw.rect(self._CanvasHWND,(255,255,255),(x-padding,y-padding, w+padding*2,h+padding*2))
self._CanvasHWND.fill( (255,255,255))
pygame.draw.rect(self._CanvasHWND,(0,0,0),(x-padding,y-padding, w+padding*2,h+padding*2),1)
words = self._Text.split(' ')
space = self._FontObj.size(' ')[0]
max_width = self._Parent._Width-40
x ,y = (0,0)
row_total_width = 0
lines = 0
self._CanvasHWND.blit(my_text,(x,y,w,h))
for word in words:
word_surface = self._FontObj.render(word, True, self._Color)
word_width = word_surface.get_width()
word_height = word_surface.get_height()
row_total_width += word_width
if lines == 0:
lines += word_height
if row_total_width+space >= max_width:
x = 0 # Reset the x.
y += word_height # Start on new row.
row_total_width = 0
lines += word_height
self._CanvasHWND.blit(word_surface, (x, y))
x += word_width + space
if x > self._Width:
self._Width = x
if lines >= (self._Parent._Height - 40):
break
self._Height = lines
padding = 5
x = (self._Parent._Width - self._Width)/2
y = (self._Parent._Height - self._Height)/2
print("x %d y %d w %d h %d" %(x,y,self._Width,self._Height ))
pygame.draw.rect(self._HWND,(255,255,255),(x-padding,y-padding, self._Width+padding*2,self._Height+padding*2))
if self._HWND != None:
rect = midRect(self._Parent._Width/2,self._Parent._Height/2,self._Width,self._Height,Width,Height)
self._HWND.blit(self._CanvasHWND,rect,(0,0,self._Width,self._Height))
pygame.draw.rect(self._HWND,(0,0,0),(x-padding,y-padding, self._Width+padding*2,self._Height+padding*2),1)
python_package_flag = "__init__.py"
@ -74,7 +124,6 @@ class MainScreen(object):
self._CanvasHWND = pygame.Surface((self._Width,self._Height))
self._MsgBox= MessageBox()
self._MsgBox._Parent= self
self._MsgBox.SetCanvasHWND(self._CanvasHWND)
self._MsgBox.Init(" ", self._MsgBoxFont)
def FartherPages(self):

View File

@ -38,7 +38,7 @@ class MultiLabel: ##Multi Line Label
def SetText(self,text):
self._Text = text
self.blit_text(text)
self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj)
def Width(self):
return self._Width