|
@@ -1,9 +1,8 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
-import ConfigParser
|
|
|
-import socket
|
|
|
-
|
|
|
+import os
|
|
|
import pygame
|
|
|
+import glob
|
|
|
#import math
|
|
|
import commands
|
|
|
|
|
@@ -16,7 +15,7 @@ from UI.constants import Width,Height,ICON_TYPES
|
|
|
from UI.page import Page,PageSelector
|
|
|
from UI.label import Label
|
|
|
from UI.fonts import fonts
|
|
|
-from UI.util_funcs import midRect,FileExists
|
|
|
+from UI.util_funcs import midRect,FileExists,IsExecutable
|
|
|
from UI.keys_def import CurKeys
|
|
|
from UI.scroller import ListScroller
|
|
|
from UI.icon_pool import MyIconPool
|
|
@@ -26,8 +25,56 @@ from UI.lang_manager import MyLangManager
|
|
|
from UI.multilabel import MultiLabel
|
|
|
from UI.info_page_list_item import InfoPageListItem
|
|
|
from UI.info_page_selector import InfoPageSelector
|
|
|
+from UI.skin_manager import MySkinManager
|
|
|
+
|
|
|
+class NotifyJobListItem(InfoPageListItem):
|
|
|
+
|
|
|
+ _CanvasHWND = None
|
|
|
+
|
|
|
+ def Init(self,text):
|
|
|
+
|
|
|
+ #self._Fonts["normal"] = fonts["veramono12"]
|
|
|
+ self._CanvasHWND = self._Parent._CanvasHWND
|
|
|
+
|
|
|
+ l = Label()
|
|
|
+ l._PosX = 10
|
|
|
+ l.SetCanvasHWND(self._Parent._CanvasHWND)
|
|
|
+
|
|
|
+ l.Init(text,self._Fonts["normal"])
|
|
|
+ self._Labels["Text"] = l
|
|
|
+
|
|
|
+ done_icon = IconItem()
|
|
|
+ done_icon._ImgSurf = MyIconPool._Icons["done"]
|
|
|
+ done_icon._CanvasHWND = self._Parent._CanvasHWND
|
|
|
+ done_icon._Parent = self
|
|
|
+
|
|
|
+ self._Icons["done"] = done_icon
|
|
|
+
|
|
|
+ def Draw(self):
|
|
|
+ if self._ReadOnly == False:
|
|
|
+ self._Labels["Text"].SetColor(MySkinManager.GiveColor("ReadOnlyText"))
|
|
|
+ else:
|
|
|
+ self._Labels["Text"].SetColor(MySkinManager.GiveColor("Text"))
|
|
|
|
|
|
+
|
|
|
+ self._Labels["Text"]._PosX = self._Labels["Text"]._PosX + self._PosX
|
|
|
+ self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
|
|
|
+ self._Labels["Text"].Draw()
|
|
|
+ self._Labels["Text"]._PosX = self._Labels["Text"]._PosX - self._PosX
|
|
|
|
|
|
+ if "Small" in self._Labels:
|
|
|
+ self._Labels["Small"]._PosX = self._Width - self._Labels["Small"]._Width-5
|
|
|
+
|
|
|
+ self._Labels["Small"]._PosY = self._PosY + (self._Height - self._Labels["Small"]._Height)/2
|
|
|
+ self._Labels["Small"].Draw()
|
|
|
+
|
|
|
+ if self._ReadOnly:
|
|
|
+ self._Icons["done"].NewCoord(self._Width - 25,5)
|
|
|
+ self._Icons["done"].Draw()
|
|
|
+
|
|
|
+ pygame.draw.line(self._Parent._CanvasHWND,MySkinManager.GiveColor('Line'),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
|
|
|
+
|
|
|
+
|
|
|
class NotificationPage(Page):
|
|
|
_FootMsg = ["Nav","","","Back","Toggle"]
|
|
|
_MyList = []
|
|
@@ -44,55 +91,56 @@ class NotificationPage(Page):
|
|
|
_Scroller = None
|
|
|
|
|
|
_EasingDur = 30
|
|
|
-
|
|
|
- _GSNOTIFY_CFG="gsnotify/gsnotify.cfg"
|
|
|
+
|
|
|
+ _GSNOTIFY_JOBS = "gsnotify/Jobs"
|
|
|
_GSNOTIFY_SOCKET="/tmp/gsnotify.sock"
|
|
|
_Config =None
|
|
|
+ _AllowedExts = [".sh",".lsp",".lua",".bin",".py",".js"]
|
|
|
|
|
|
def __init__(self):
|
|
|
Page.__init__(self)
|
|
|
self._Icons = {}
|
|
|
-
|
|
|
- def ReadConfig(self,fname):
|
|
|
- if FileExists(fname):
|
|
|
- if self._Config == None:
|
|
|
- self._Config = ConfigParser.ConfigParser()
|
|
|
- self._Config.optionxform = str
|
|
|
-
|
|
|
- self._Config.read(fname)
|
|
|
- else:
|
|
|
- print(fname, "not found")
|
|
|
|
|
|
def GenList(self):
|
|
|
- if self._Config == None:
|
|
|
- return
|
|
|
|
|
|
- self._AList = {}
|
|
|
self._MyList = []
|
|
|
## map ini to self._AList
|
|
|
- for i,v in enumerate(self._Config.items("Settings")):
|
|
|
- self._AList[v[0]] = v[1] ## {'BGCOLOR': '#eab934', 'Enabled': 'False',...}
|
|
|
-
|
|
|
+ files_path = glob.glob(self._GSNOTIFY_JOBS+"/*")
|
|
|
+
|
|
|
|
|
|
start_x = 10
|
|
|
start_y = 0
|
|
|
|
|
|
- for i,v in enumerate( self._AList):
|
|
|
- li = InfoPageListItem()
|
|
|
- li._Parent = self
|
|
|
- li._PosX = start_x
|
|
|
- li._PosY = start_y + i*InfoPageListItem._Height
|
|
|
- li._Width = Width-10
|
|
|
- li._Fonts["normal"] = self._ListFontObj
|
|
|
- li._Fonts["small"] = fonts["varela12"]
|
|
|
+ for i,v in enumerate( files_path):
|
|
|
+ filename, file_extension = os.path.splitext(v)
|
|
|
+ alias_file = filename + ".alias"
|
|
|
|
|
|
- li.Init( v )
|
|
|
- li._Flag = v
|
|
|
- li.SetSmallText( self._AList[v] )
|
|
|
- if v != "Enabled":
|
|
|
- li._ReadOnly=True
|
|
|
+ if file_extension in self._AllowedExts:
|
|
|
+ li = NotifyJobListItem()
|
|
|
+ li._Parent = self
|
|
|
+ li._PosX = start_x
|
|
|
+ li._PosY = start_y + i*InfoPageListItem._Height
|
|
|
+ li._Width = Width-10
|
|
|
+ li._Fonts["normal"] = self._ListFontObj
|
|
|
+ li._Fonts["small"] = fonts["varela12"]
|
|
|
+
|
|
|
+ if IsExecutable(v):
|
|
|
+ li._ReadOnly = True
|
|
|
|
|
|
- self._MyList.append(li)
|
|
|
+ if os.path.isfile(alias_file):
|
|
|
+ fp = open(alias_file, "r")
|
|
|
+ alias = fp.read()
|
|
|
+ alias = alias.strip()
|
|
|
+ label_text = alias.decode("utf8")
|
|
|
+ li.Init( label_text )
|
|
|
+ fp.close()
|
|
|
+ else:
|
|
|
+ li.Init( os.path.basename(v) )
|
|
|
+ li._Flag = v
|
|
|
+ ##li.SetSmallText( v )
|
|
|
+
|
|
|
+ self._MyList.append(li)
|
|
|
+
|
|
|
|
|
|
def Init(self):
|
|
|
if self._Screen != None:
|
|
@@ -110,8 +158,6 @@ class NotificationPage(Page):
|
|
|
self._Ps = ps
|
|
|
self._PsIndex = 0
|
|
|
|
|
|
- self.ReadConfig(self._GSNOTIFY_CFG)
|
|
|
-
|
|
|
self._Scroller = ListScroller()
|
|
|
self._Scroller._Parent = self
|
|
|
self._Scroller._PosX = 2
|
|
@@ -146,37 +192,14 @@ class NotificationPage(Page):
|
|
|
return
|
|
|
|
|
|
cur_li = self._MyList[self._PsIndex]
|
|
|
- print("Click ",cur_li._Flag)
|
|
|
-
|
|
|
- def SendMsgToUnixSocket(self,msg):
|
|
|
- if FileExists(self._GSNOTIFY_SOCKET) == False:
|
|
|
- print(self._GSNOTIFY_SOCKET," not existed")
|
|
|
- return
|
|
|
-
|
|
|
- try:
|
|
|
- s = socket.socket(socket.AF_UNIX)
|
|
|
- s.settimeout(1) # 1 second timeout
|
|
|
- s.connect(self._GSNOTIFY_SOCKET)
|
|
|
- s.send(msg)
|
|
|
- data = s.recv(1024)
|
|
|
- print("received: {}".format(data))
|
|
|
- s.close()
|
|
|
- except Exception as err:
|
|
|
- print(err) ## print error ,but ignore it
|
|
|
-
|
|
|
+ #print("Click ",cur_li._Flag)
|
|
|
+ if IsExecutable(cur_li._Flag):
|
|
|
+ os.system("chmod -x "+cur_li._Flag)
|
|
|
+ else:
|
|
|
+ os.system("chmod +x "+cur_li._Flag)
|
|
|
|
|
|
- def ToggleEnable(self):
|
|
|
- print("ToggleEnable")
|
|
|
- if self._Config == None:
|
|
|
- return
|
|
|
-
|
|
|
- e = self._Config.get("Settings","Enabled")
|
|
|
+ self.GenList()
|
|
|
|
|
|
- if e == "False":
|
|
|
- self.SendMsgToUnixSocket("Enable")
|
|
|
- else:
|
|
|
- self.SendMsgToUnixSocket("Disable")
|
|
|
-
|
|
|
|
|
|
def OnLoadCb(self):
|
|
|
self._Scrolled = 0
|
|
@@ -196,13 +219,14 @@ class NotificationPage(Page):
|
|
|
self._Screen.SwapAndShow()
|
|
|
|
|
|
if event.key == CurKeys["B"]:
|
|
|
- self.ToggleEnable()
|
|
|
+
|
|
|
self._Screen._MsgBox.SetText("Applying")
|
|
|
self._Screen._MsgBox.Draw()
|
|
|
self._Screen.SwapAndShow()
|
|
|
- pygame.time.delay(1000)
|
|
|
- self.ReadConfig(self._GSNOTIFY_CFG)
|
|
|
- self.GenList()
|
|
|
+
|
|
|
+ pygame.time.delay(638)
|
|
|
+
|
|
|
+ self.Click()
|
|
|
|
|
|
self._Screen.Draw()
|
|
|
self._Screen.SwapAndShow()
|
|
@@ -218,9 +242,7 @@ class NotificationPage(Page):
|
|
|
self._Screen.SwapAndShow()
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
def Draw(self):
|
|
|
self.ClearCanvas()
|
|
|
self._Ps.Draw()
|