def __init__(self, rootpath, test_mod=0): self.name = 'AppWishList' self.rootpath = rootpath self.appService = AppService(rootpath) self.configService = ConfigService(rootpath) self.isUpdating = False self.orientation = self.LANDSCAPE self.divice = self.IPAD self.test_mod = test_mod self.activity_indicator = ui.ActivityIndicator(flex='LTRB') self.activity_indicator.style = 10 if self.test_mod == self.NORMAL: self.width, self.height = ui.get_window_size() elif self.test_mod == self.TEST_IPHOE_P: # iPhone test self.width, self.height = 414, 736 else: self.width, self.height = 736, 414 if (self.width + self.height < 1024 + 768): self.divice = self.IPHONE self.mainTable = MainTable(self) self.nav_view = ui.NavigationView(self.mainTable) self.nav_view.flex = "WHLRTB" self.nav_view.add_subview(self.activity_indicator) self.add_subview(self.nav_view) self.loadUI() self.activity_indicator.bring_to_front()
def __init__(self, rootpath, test_mod=0): self.name = 'IstaTranslator' self.rootpath = rootpath self.configService = ConfigService(rootpath + "config.ini") self.logger = logging.getLogger(self.__class__.__name__) self.orientation = self.LANDSCAPE self.test_mod = test_mod self.trans_history = [] self.viewKind = self.TRANSLATE self.translateDeep = 0 self.recordDeep = 0 self.settingDeep = 0 self.isLestenningClipbord = self.configService.GetIsLestenningClipbord( ) if self.isLestenningClipbord: self.lesteningStatus = self.LESTENNING else: self.lesteningStatus = self.STOP # 状态指示器 self.activity_indicator = ui.ActivityIndicator(flex='LTRB') self.activity_indicator.center = self.center self.activity_indicator.style = ui.ACTIVITY_INDICATOR_STYLE_GRAY # 中心导航视图 self.translateView = TranslateView(self) self.recordView = RecordView(self) self.settingView = SettingView(self) self.translateNavi = ui.NavigationView(self.translateView) self.recordNavi = ui.NavigationView(self.recordView) self.settingNavi = ui.NavigationView(self.settingView) # 底部栏 self.bottomView = ui.View() self.translateBtn = ui.Button() self.recordBtn = ui.Button() self.settingBtn = ui.Button() # 将按钮加入底部栏 self.bottomView.add_subview(self.translateBtn) self.bottomView.add_subview(self.recordBtn) self.bottomView.add_subview(self.settingBtn) # 将所有视图加入主窗口 self.add_subview(self.translateNavi) self.add_subview(self.recordNavi) self.add_subview(self.settingNavi) self.add_subview(self.bottomView) self.add_subview(self.activity_indicator) self.LoadUI() self.activity_indicator.bring_to_front()
def __init__(self, rootpath, test_mod=0): self.name = 'AppWishList' self.rootpath = rootpath self.appService = AppService(rootpath) self.configService = ConfigService(rootpath) self.orientation = self.LANDSCAPE self.divice = self.IPAD self.test_mod = test_mod self.isUpdating = False self.viewKind = self.STAR self.starDeep = 0 self.favoriteDeep = 0 self.moreDeep = 0 if self.test_mod == self.NORMAL: self.width, self.height = ui.get_window_size() elif self.test_mod == self.TEST_IPHOE_P: # iPhone test self.width, self.height = 414, 736 else: self.width, self.height = 736, 414 if (self.width + self.height < 1024 + 768): self.divice = self.IPHONE self.activity_indicator = ui.ActivityIndicator(flex='LTRB') self.activity_indicator.center = self.center self.activity_indicator.style = ui.ACTIVITY_INDICATOR_STYLE_GRAY self.starView = WishListView(self) self.favoriteView = CategoryView(self) self.moreView = SettingView(self) self.starNavi = ui.NavigationView(self.starView) self.favoriteNavi = ui.NavigationView(self.favoriteView) self.moreNavi = ui.NavigationView(self.moreView) self.bottomView = ui.View() self.starBtn = ui.Button() self.favoriteBtn = ui.Button() self.moreBtn = ui.Button() self.bottomView.add_subview(self.starBtn) self.bottomView.add_subview(self.favoriteBtn) self.bottomView.add_subview(self.moreBtn) self.add_subview(self.starNavi) self.add_subview(self.favoriteNavi) self.add_subview(self.moreNavi) self.add_subview(self.bottomView) self.add_subview(self.activity_indicator) self.loadUI() self.activity_indicator.bring_to_front()
def main(rootpath="data/"): logger = Logger(rootpath + "log.txt", "ExtAddApp.py", True) configService = ConfigService(rootpath) if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return url = appex.get_url() if not url: console.alert("Error", "No input URL found.", 'OK', hide_cancel_button=True) if (configService.getLog().getData() == 1): logger.error("No input URL found.") return # 选择添加到愿望单还是收藏夹 star = True if (console.alert("添加应用", "请选择添加到愿望单还是收藏夹", "愿望单", "收藏夹", hide_cancel_button=True) == 2): star = False console.hud_alert("正在抓取数据,请等待...", "success") appSerVice = AppService(rootpath) res = appSerVice.addApp(url, star) if (res.equal(ResultEnum.APP_UPDATE)): console.hud_alert("应用更新成功!", 'success') elif (res.equal(ResultEnum.SUCCESS)): console.hud_alert("应用添加成功!", 'success') else: console.hud_alert(res.getInfo(), 'error') appex.finish()
def main(rootpath="data/"): logger = Logger(rootpath + "log.txt", "AutoUpdateApp.py.py", True) configService = ConfigService(rootpath) if (configService.getLog().getData() == 1): logger.info("开始自动更新:") if (not isConnected("http://www.baidu.com")): if (configService.getLog().getData() == 1): logger.error("网络连接超时!\n") return serv = AppService(rootpath) res = serv.updateAllApps() if (not res.equal(ResultEnum.SUCCESS)): if (configService.getLog().getData() == 1): logger.error("自动更新出错: " + res.toString()) else: if (configService.getLog().getData() == 1): logger.info("自动更新完成。\n")
class MainWindow(ui.View): LANDSCAPE = 0 PORTRAIT = 1 IPAD = 0 IPHONE = 1 NORMAL = 0 TEST_IPHOE_L = 1 TEST_IPHOE_P = 2 STAR = 0 FAVORITE = 1 MORE = 2 BTN_ON_COLOR = '#27a2f1' BTN_OFF_COLOR = '#8e8e8e' def __init__(self, rootpath, test_mod=0): self.name = 'AppWishList' self.rootpath = rootpath self.appService = AppService(rootpath) self.configService = ConfigService(rootpath) self.orientation = self.LANDSCAPE self.divice = self.IPAD self.test_mod = test_mod self.isUpdating = False self.viewKind = self.STAR self.starDeep = 0 self.favoriteDeep = 0 self.moreDeep = 0 if self.test_mod == self.NORMAL: self.width, self.height = ui.get_window_size() elif self.test_mod == self.TEST_IPHOE_P: # iPhone test self.width, self.height = 414, 736 else: self.width, self.height = 736, 414 if (self.width + self.height < 1024 + 768): self.divice = self.IPHONE self.activity_indicator = ui.ActivityIndicator(flex='LTRB') self.activity_indicator.center = self.center self.activity_indicator.style = ui.ACTIVITY_INDICATOR_STYLE_GRAY self.starView = WishListView(self) self.favoriteView = CategoryView(self) self.moreView = SettingView(self) self.starNavi = ui.NavigationView(self.starView) self.favoriteNavi = ui.NavigationView(self.favoriteView) self.moreNavi = ui.NavigationView(self.moreView) self.bottomView = ui.View() self.starBtn = ui.Button() self.favoriteBtn = ui.Button() self.moreBtn = ui.Button() self.bottomView.add_subview(self.starBtn) self.bottomView.add_subview(self.favoriteBtn) self.bottomView.add_subview(self.moreBtn) self.add_subview(self.starNavi) self.add_subview(self.favoriteNavi) self.add_subview(self.moreNavi) self.add_subview(self.bottomView) self.add_subview(self.activity_indicator) self.loadUI() self.activity_indicator.bring_to_front() def loadUI(self): self.favoriteNavi.hidden = True self.moreNavi.hidden = True self.bottomView.background_color = '#f1f1f1' self.starBtn.image = ui.Image.named('iob:ios7_star_32') self.starBtn.title = '愿望单' self.starBtn.action = self.Star_act self.starBtn.tint_color = self.BTN_ON_COLOR self.favoriteBtn.image = ui.Image.named('iob:filing_32') self.favoriteBtn.title = '收藏夹' self.favoriteBtn.action = self.Favorite_act self.favoriteBtn.tint_color = self.BTN_OFF_COLOR self.moreBtn.image = ui.Image.named('iob:ios7_more_outline_32') self.moreBtn.title = '更多' self.moreBtn.action = self.More_act self.moreBtn.tint_color = self.BTN_OFF_COLOR def layout(self): if self.width > self.height: self.orientation = self.LANDSCAPE else: self.orientation = self.PORTRAIT bottomView_h = 50 if (not self.isIpad()): bottomView_h = 60 self.starNavi.frame = (0, 0, self.width, self.height - bottomView_h) self.favoriteNavi.frame = (0, 0, self.width, self.height - bottomView_h) self.moreNavi.frame = (0, 0, self.width, self.height - bottomView_h) self.bottomView.frame = (0, self.height - bottomView_h, self.width, bottomView_h) margin = (self.width - 300) / 4 self.starBtn.frame = (margin, 0, 100, 50) self.favoriteBtn.frame = (margin * 2 + 100, 0, 100, 50) self.moreBtn.frame = (margin * 3 + 200, 0, 100, 50) def launch(self): if self.test_mod == self.NORMAL: self.present(style='fullscreen', hide_title_bar=True) else: self.present(style='sheet', hide_title_bar=True) self.configService.runTimesAddOne() def isIpad(self): return self.divice == self.IPAD def Star_act(self, sender): if self.viewKind == self.STAR: return self.activity_indicator.start() try: self.starView.updateData() self.starNavi.hidden = False self.favoriteNavi.hidden = True self.moreNavi.hidden = True for i in range(self.favoriteDeep): self.favoriteNavi.pop_view() for i in range(self.moreDeep): self.moreNavi.pop_view() except Exception as e: console.hud_alert('愿望单页面加载失败!', 'error', 1.0) finally: self.viewKind = self.STAR self.starBtn.tint_color = self.BTN_ON_COLOR self.favoriteBtn.tint_color = self.BTN_OFF_COLOR self.moreBtn.tint_color = self.BTN_OFF_COLOR self.activity_indicator.stop() def Favorite_act(self, sender): if self.viewKind == self.FAVORITE: return self.activity_indicator.start() try: self.favoriteView.updateData() self.favoriteNavi.hidden = False self.starNavi.hidden = True self.moreNavi.hidden = True for i in range(self.starDeep): self.starNavi.pop_view() for i in range(self.moreDeep): self.moreNavi.pop_view() except Exception as e: console.hud_alert('收藏夹页面加载失败!', 'error', 1.0) finally: self.viewKind = self.FAVORITE self.starBtn.tint_color = self.BTN_OFF_COLOR self.favoriteBtn.tint_color = self.BTN_ON_COLOR self.moreBtn.tint_color = self.BTN_OFF_COLOR self.activity_indicator.stop() def More_act(self, sender): if self.viewKind == self.MORE: return self.activity_indicator.start() try: self.moreView.updateData() self.moreNavi.hidden = False self.starNavi.hidden = True self.favoriteNavi.hidden = True for i in range(self.starDeep): self.starNavi.pop_view() for i in range(self.favoriteDeep): self.favoriteNavi.pop_view() except Exception as e: console.hud_alert('更多设置页面加载失败!', 'error', 1.0) finally: self.viewKind = self.MORE self.starBtn.tint_color = self.BTN_OFF_COLOR self.favoriteBtn.tint_color = self.BTN_OFF_COLOR self.moreBtn.tint_color = self.BTN_ON_COLOR self.activity_indicator.stop() def Close_act(self, sender): self.close()
class MainWindow(ui.View): LANDSCAPE = 0 PORTRAIT = 1 IPAD = 0 IPHONE = 1 NORMAL = 0 TEST_IPHOE_L = 1 TEST_IPHOE_P = 2 def __init__(self, rootpath, test_mod=0): self.name = 'AppWishList' self.rootpath = rootpath self.appService = AppService(rootpath) self.configService = ConfigService(rootpath) self.isUpdating = False self.orientation = self.LANDSCAPE self.divice = self.IPAD self.test_mod = test_mod self.activity_indicator = ui.ActivityIndicator(flex='LTRB') self.activity_indicator.style = 10 if self.test_mod == self.NORMAL: self.width, self.height = ui.get_window_size() elif self.test_mod == self.TEST_IPHOE_P: # iPhone test self.width, self.height = 414, 736 else: self.width, self.height = 736, 414 if (self.width + self.height < 1024 + 768): self.divice = self.IPHONE self.mainTable = MainTable(self) self.nav_view = ui.NavigationView(self.mainTable) self.nav_view.flex = "WHLRTB" self.nav_view.add_subview(self.activity_indicator) self.add_subview(self.nav_view) self.loadUI() self.activity_indicator.bring_to_front() def loadUI(self): self.nav_view.frame = (0, 0, self.width, self.height) self.activity_indicator.frame = (0, 0, self.nav_view.width, self.nav_view.height) def layout(self): if self.width > self.height: self.orientation = self.LANDSCAPE else: self.orientation = self.PORTRAIT def launch(self): if self.test_mod == self.NORMAL: self.present(style='fullscreen') else: self.present(style='sheet') self.configService.runTimesAddOne() def isIpad(self): return self.divice == self.IPAD
class MainWindow(ui.View): # 方向 LANDSCAPE = 0 PORTRAIT = 1 # 测试 NORMAL = 0 TEST_1OF3 = 1 # 页面 TRANSLATE = 0 RECORD = 1 SETTING = 3 # 剪贴板监听 LESTENNING = 0 STOP = 1 # 按钮颜色 BTN_ON_COLOR = '#27a2f1' BTN_OFF_COLOR = '#8e8e8e' def __init__(self, rootpath, test_mod=0): self.name = 'IstaTranslator' self.rootpath = rootpath self.configService = ConfigService(rootpath + "config.ini") self.logger = logging.getLogger(self.__class__.__name__) self.orientation = self.LANDSCAPE self.test_mod = test_mod self.trans_history = [] self.viewKind = self.TRANSLATE self.translateDeep = 0 self.recordDeep = 0 self.settingDeep = 0 self.isLestenningClipbord = self.configService.GetIsLestenningClipbord( ) if self.isLestenningClipbord: self.lesteningStatus = self.LESTENNING else: self.lesteningStatus = self.STOP # 状态指示器 self.activity_indicator = ui.ActivityIndicator(flex='LTRB') self.activity_indicator.center = self.center self.activity_indicator.style = ui.ACTIVITY_INDICATOR_STYLE_GRAY # 中心导航视图 self.translateView = TranslateView(self) self.recordView = RecordView(self) self.settingView = SettingView(self) self.translateNavi = ui.NavigationView(self.translateView) self.recordNavi = ui.NavigationView(self.recordView) self.settingNavi = ui.NavigationView(self.settingView) # 底部栏 self.bottomView = ui.View() self.translateBtn = ui.Button() self.recordBtn = ui.Button() self.settingBtn = ui.Button() # 将按钮加入底部栏 self.bottomView.add_subview(self.translateBtn) self.bottomView.add_subview(self.recordBtn) self.bottomView.add_subview(self.settingBtn) # 将所有视图加入主窗口 self.add_subview(self.translateNavi) self.add_subview(self.recordNavi) self.add_subview(self.settingNavi) self.add_subview(self.bottomView) self.add_subview(self.activity_indicator) self.LoadUI() self.activity_indicator.bring_to_front() def LoadUI(self): self.recordNavi.hidden = True self.settingNavi.hidden = True self.bottomView.background_color = '#f1f1f1' self.translateBtn.image = ui.Image.named('iow:search_32') self.translateBtn.title = '翻译' self.translateBtn.action = self.TranslateAct self.translateBtn.tint_color = self.BTN_ON_COLOR self.recordBtn.image = ui.Image.named('iow:ios7_bookmarks_32') self.recordBtn.title = '记录' self.recordBtn.action = self.RecordAct self.recordBtn.tint_color = self.BTN_OFF_COLOR self.settingBtn.image = ui.Image.named('iow:ios7_gear_32') self.settingBtn.title = '设置' self.settingBtn.action = self.SettingAct self.settingBtn.tint_color = self.BTN_OFF_COLOR def layout(self): if self.width > self.height: self.orientation = self.LANDSCAPE else: self.orientation = self.PORTRAIT bottomView_h = 60 self.translateNavi.frame = (0, 0, self.width, self.height - bottomView_h) self.recordNavi.frame = (0, 0, self.width, self.height - bottomView_h) self.settingNavi.frame = (0, 0, self.width, self.height - bottomView_h) self.bottomView.frame = (0, self.height - bottomView_h, self.width, bottomView_h) btn_w = 100 btn_margin = (self.width - btn_w * 3) / 4 self.translateBtn.frame = (btn_margin, 0, btn_w, bottomView_h) self.recordBtn.frame = (btn_margin * 2 + btn_w, 0, btn_w, bottomView_h) self.settingBtn.frame = (btn_margin * 3 + btn_w * 2, 0, btn_w, bottomView_h) def launch(self): self.logger.info("启动程序") if self.test_mod == self.NORMAL: self.present(style='fullscreen', hide_title_bar=True) else: self.present(style='sheet', hide_title_bar=True) self.configService.RunTimesAddOne() self.configService.UpdateTransChartStatistic() def TranslateAct(self, sender): if self.viewKind == self.TRANSLATE: return self.activity_indicator.start() if self.isLestenningClipbord: self.lesteningStatus = self.LESTENNING else: self.lesteningStatus = self.STOP try: self.translateView.updateData() self.translateNavi.hidden = False self.recordNavi.hidden = True self.settingNavi.hidden = True for i in range(self.recordDeep): self.recordNavi.pop_view() for i in range(self.settingDeep): self.settingNavi.pop_view() except Exception as e: console.hud_alert('翻译页面加载失败!', 'error', 1.0) self.logger.fatal("翻译页面加载失败!") finally: self.viewKind = self.TRANSLATE self.translateBtn.tint_color = self.BTN_ON_COLOR self.recordBtn.tint_color = self.BTN_OFF_COLOR self.settingBtn.tint_color = self.BTN_OFF_COLOR self.activity_indicator.stop() self.logger.info("切换到翻译页面") def RecordAct(self, sender): if self.viewKind == self.RECORD: return self.activity_indicator.start() self.lesteningStatus = self.STOP try: self.recordView.updateData() self.translateNavi.hidden = True self.recordNavi.hidden = False self.settingNavi.hidden = True for i in range(self.translateDeep): self.recordNavi.pop_view() for i in range(self.settingDeep): self.settingNavi.pop_view() except Exception as e: console.hud_alert('记录页面加载失败!', 'error', 1.0) self.logger.fatal("记录页面加载失败!") finally: self.viewKind = self.RECORD self.translateBtn.tint_color = self.BTN_OFF_COLOR self.recordBtn.tint_color = self.BTN_ON_COLOR self.settingBtn.tint_color = self.BTN_OFF_COLOR self.activity_indicator.stop() self.logger.info("切换到记录页面") def SettingAct(self, sender): if self.viewKind == self.SETTING: return self.activity_indicator.start() self.lesteningStatus = self.STOP try: self.settingView.updateData() self.translateNavi.hidden = True self.recordNavi.hidden = True self.settingNavi.hidden = False for i in range(self.translateDeep): self.recordNavi.pop_view() for i in range(self.recordDeep): self.settingNavi.pop_view() except Exception as e: console.hud_alert('设置页面加载失败!', 'error', 1.0) self.logger.fatal("设置页面加载失败!") finally: self.viewKind = self.SETTING self.translateBtn.tint_color = self.BTN_OFF_COLOR self.recordBtn.tint_color = self.BTN_OFF_COLOR self.settingBtn.tint_color = self.BTN_ON_COLOR self.activity_indicator.stop() self.logger.info("切换到设置页面") def CloseAct(self, sender): self.lesteningStatus = self.STOP self.close() self.logger.info("程序关闭")