def SwitchMobileqq(self, d, z, slotId): z.toast("开始切换到普通QQ") z.generate_serial("com.tencent.mobileqq") # 随机生成手机特征码 z.toast("随机生成手机特征码") serial = d.server.adb.device_serial() self.slot = Slot(serial, self.type) d.server.adb.cmd("shell", "pm clear com.tencent.tim").communicate() # 清除缓存 self.slot.restore(slotId, "com.tencent.mobileqq") # 有time_limit分钟没用过的卡槽情况,切换卡槽 z.server.adb.run_cmd( "shell", "am start -n com.tencent.mobileqq/com.tencent.mobileqq.activity.SplashActivity" ) z.sleep(3) z.toast("判断是否成功切换到普通QQ") loginStatusList = z.qq_getLoginStatus(d) if loginStatusList is None: z.toast("登陆新页面,现无法判断登陆状态") return None loginStatus = loginStatusList['success'] if loginStatus: z.toast("成功切换到普通QQ,继续执行") else: z.toast("切换到普通QQ失败,重新切换") return "gg"
def action(self, d, z, args): z.toast(u"开始:ping网络是否通畅") i = 0 while i < 200: i += 1 ping = d.server.adb.cmd("shell", "ping -c 3 baidu.com").communicate() print(ping) if 'icmp_seq' and 'bytes from' and 'time' in ping[0]: z.toast(u"网络通畅。开始执行:QQ安全中心登陆备份模块") break z.sleep(2) if i > 200: z.toast(u"网络不通,请检查网络状态") return while True: z.heartbeat() z.generate_serial("com.tencent.token") # 随机生成手机特征码 z.toast(u"随机生成手机特征码") serial = d.server.adb.device_serial() self.slot = Slot(serial, self.type) self.slot.backupToDisk("132132132") # 设备信息,卡槽号,QQ号 print "ok" break
def showSummary(): queues = {} slots = {} #get the slot info slotsData = session.getSlotInfo() #add all the slots to our dictionary for slotData in slotsData: slot = Slot(slotData) slots[slot.id] = slot #now the queue info queuesData = session.getQueueInfo() for queueData in queuesData: queue = Queue(queueData) queues[queue.id] = queue #add this queue to it's parent slot's list of queues slotID = int(queue.slot) slots[slotID].queues.append(queue) #get basic details teamInfo = eval(session.getPreparedResponse("options user team"), {}, {}) print("User {user} is folding for team {team}".format( user=teamInfo["user"], team=teamInfo["team"])) for slot in slots.values(): print(slot.__str__()) for queue in queues.values(): print(queue.__str__())
def __init__(self): self.slot_0 = Slot() self.slot_1 = Slot() self.slot_2 = Slot() self.slot_3 = Slot() self.foundation_0 = Foundation() self.foundation_1 = Foundation() self.foundation_2 = Foundation() self.foundation_3 = Foundation() self.cascade_deck_0 = Cascade_deck() self.cascade_deck_1 = Cascade_deck() self.cascade_deck_2 = Cascade_deck() self.cascade_deck_3 = Cascade_deck() self.cascade_deck_4 = Cascade_deck() self.cascade_deck_5 = Cascade_deck() self.cascade_deck_6 = Cascade_deck() self.cascade_deck_7 = Cascade_deck() self.deck = Deck(1, 13, 4) # lists that contain the all objects from the same class self.list_slot = [self.slot_0, self.slot_1, self.slot_2, self.slot_3] self.list_foundation = [ self.foundation_0, self.foundation_1, self.foundation_2, self.foundation_3 ] self.list_cascade_deck = [ self.cascade_deck_0, self.cascade_deck_1, self.cascade_deck_2, self.cascade_deck_3, self.cascade_deck_4, self.cascade_deck_5, self.cascade_deck_6, self.cascade_deck_7 ]
def test_park_vehicle(self): slot_number = 1 slot = Slot(slot_number) slot.park_vehicle('KA-03-BB-1234', 'White') assert slot.occupied_status == True assert slot.vehicle_number == 'KA-03-BB-1234' assert slot.vehicle_color == 'White'
def action(self, d, z, args): while True: z.toast("正在ping网络是否通畅") i = 0 # while i < 200: # i += 1 # ping = d.server.adb.cmd("shell", "ping -c 3 baidu.com").communicate() # print(ping) # if 'icmp_seq' and 'bytes from' and 'time' in ping[0]: # z.toast(u"网络通畅。开始执行:国际版QQ登录 有卡槽") # break # z.sleep(2) # if i > 200 : # z.toast(u"网络不通,请检查网络状态") # if (args["time_delay"]): # z.sleep(int(args["time_delay"])) # return # # z.heartbeat() # z.generate_serial("com.tencent.mobileqqi") # 随机生成手机特征码 cate_id = args["repo_cate_id"] time_limit1 = args['time_limit1'] numbers = self.repo.GetAccount(cate_id, time_limit1, 1) if len(numbers) == 0: d.server.adb.cmd("shell", "am broadcast -a com.zunyun.zime.toast --es msg \"QQ帐号库%s号仓库无%s分钟未用,开始切换卡槽\"" % (cate_id, time_limit1)).communicate() serial = d.server.adb.device_serial() self.slot = Slot(serial, self.type) slotnum = self.slot.getEmpty() # 取空卡槽 if slotnum == 0 or len(numbers) == 0: #没有空卡槽的话 if self.qiehuan(d, z, args): break else: # 有空卡槽的情况 # d.server.adb.cmd("shell", "settings put global airplane_mode_on 1").communicate() # d.server.adb.cmd("shell", "am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true").communicate() # z.sleep(6) # d.server.adb.cmd("shell", "settings put global airplane_mode_on 0").communicate() # d.server.adb.cmd("shell", "am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false").communicate() z.heartbeat() while True: ping = d.server.adb.cmd("shell", "ping -c 3 baidu.com").communicate() print(ping) if 'icmp_seq'and 'bytes from'and'time' in ping[0]: break z.sleep(2) z.heartbeat() if self.login(d, args, z, numbers): z.heartbeat() featureCodeInfo = z.get_serial("com.tencent.mobileqq") self.slot.backup(slotnum, str(slotnum) + '_' + numbers[0]['number'] + '_' + cate_id) # 设备信息,卡槽号,QQ号 self.repo.BackupInfo(cate_id, 'using', numbers[0]['number'], featureCodeInfo, '%s_%s_%s' % (d.server.adb.device_serial(), self.type, slotnum)) # 仓库号,使用中,QQ号,设备号_卡槽号 break if args["time_delay"]: z.sleep(int(args["time_delay"]))
def slotService(): reqs = request.json action = request.json['action'] if 'id' in request.json: id = request.json['id'] serial = request.json['serial'] type = request.json['type'] if 'remark' in request.json: remark = request.json['remark'] else: remark = "Backed"; if 'page' in reqs: page = reqs['page'] else: page = 1; if not action: return jsonify({'success': False, 'msg': u'paramter action is missed'}) if not serial: return jsonify({'success': False, 'msg': u'paramter serial is missed'}) slot = Slot(serial, type) if action == "save": if remark == "": remark = "BackUp" slot.backup(id, remark) return jsonify({'success': True, 'msg': u'Save slot success'}) if action == "restore": slot.restore(id) return jsonify({'success': True, 'msg': u'Restore slot success'}) if action == "clear": slot.clear(id) return jsonify({'success': True, 'msg': u'Clear slot success'}) if action == "list": result = [] slots = slot.getSlots() if not slots: slots = {}; idFrom = (page - 1)*20 + 1 idTo = (page-1) * 20 + 20 for index in range(idFrom, idTo + 1): if slots.has_key(str(index)) : obj = slots[str(index)] obj['empty'] = False; obj['id'] = index else: obj = {'id':index, 'empty': True} result.append(obj) return jsonify({'slots': result }) return "-"
def action(self, d, z, args): z.generate_serial("com.tencent.tim") # 随机生成手机特征码 z.toast("随机生成手机特征码") serial = d.server.adb.device_serial() cate_id = args["repo_cate_id"] self.slot = Slot(serial, self.type) slotnum = self.slot.getEmpty() # 取空卡槽 if slotnum == 0: QieHuanSolt_Result = self.QieHuanSolt(d, z, args) if QieHuanSolt_Result == "fail": obj = self.slot.getSlotInfo(slotnum) remark = obj['remark'] remarkArr = remark.split("_") QQnumber = remarkArr[1] self.repo.BackupInfo(cate_id, 'frozen', QQnumber, '', '') # 仓库号,使用中,QQ号,设备号_卡槽号QQNumber self.slot.clear(slotnum) # 清空改卡槽,并补登 z.toast("卡槽恢复失败,进行补登") self.action(d, z, args) else: z.toast("卡槽恢复成功,帐号正常") else: Login_Result = self.Login(d, z, args) if Login_Result == "again": self.action(d, z, args) elif Login_Result == "none": # 有空卡槽,单仓库无帐号可登,继续继续切换卡槽 QieHuanSolt_Result = self.QieHuanSolt(d, z, args) if QieHuanSolt_Result == "fail": obj = self.slot.getSlotInfo(slotnum) remark = obj['remark'] remarkArr = remark.split("_") QQnumber = remarkArr[1] self.repo.BackupInfo(cate_id, 'frozen', QQnumber, '', '') # 仓库号,使用中,QQ号,设备号_卡槽号QQNumber self.slot.clear(slotnum) # 清空改卡槽,并补登 z.toast("卡槽恢复失败,进行补登") self.action(d, z, args) else: z.toast("卡槽恢复成功,帐号正常") else: QQnumber = Login_Result self.slot.backup(slotnum, str(slotnum) + '_' + QQnumber) # 设备信息,卡槽号,QQ号 self.repo.BackupInfo(cate_id, 'using', QQnumber, serial, '%s_%s_%s' % (d.server.adb.device_serial(), self.type, slotnum)) # 仓库号,使用中,QQ号,设备号_卡槽号
def __init__(self, cmt): """Accumulator(cmt) cmt is the comment flag """ self._cmt = cmt self._fileset: Set[str] = set() self._filelist: List[str] = [] self.slots: Dict[int, Any] = {} self.slots[SLOT_INITIAL] = Slot(SLOT_INITIAL) self.slots[SLOT_FINAL] = Slot(SLOT_FINAL) self._disableprivslots: bool = False self.repeater_ctrl_type = 'Unknown'
def action(self, d, z, args): z.toast("正在ping网络是否通畅") while True: ping = d.server.adb.cmd("shell", "ping -c 3 baidu.com").communicate() print(ping) if 'icmp_seq' and 'bytes from' and 'time' in ping[0]: z.toast("开始执行:易信登录模块 有卡槽") break z.sleep(2) serial = d.server.adb.device_serial() self.slot = Slot(serial, self.type) slotnum = self.slot.getEmpty() # 取空卡槽 if slotnum == 0: # 没有空卡槽的话 qiehuan_result = self.qiehuan(d, z, args) if qiehuan_result == "fail": self.action(d, z, args) else: login_result = self.login(d, z, args) if login_result == "fail": featureCodeInfo = z.get_serial("im.yixin") self.repo.BackupInfo(args["repo_account_id"], 'frozen', login_result, featureCodeInfo, '') # 仓库号,使用中,QQ号,设备号_卡槽号 self.action(d, z, args) elif login_result is None: qiehuan_result = self.qiehuan(d, z, args) if qiehuan_result == "fail": self.action(d, z, args) else: featureCodeInfo = z.get_serial("im.yixin") # 入库 self.repo.BackupInfo(args["repo_account_id"], 'using', login_result, featureCodeInfo, '%s_%s_%s' % (d.server.adb.device_serial(), self.type, slotnum)) # 仓库号,使用中,QQ号,设备号_卡槽号 # 入卡槽 self.slot.backup(slotnum, str(slotnum) + '_' + login_result + '_' + args["repo_account_id"]) # 设备信息,卡槽号,QQ号 if (args['time_delay']): z.sleep(int(args['time_delay']))
def new_slot(self, data): """ Créé un nouveau slot""" slot_id = data["slot"] = str(len(self.slots_list) + 1) self.slots_list[data['ip']] = Slot(**data) return slot_id
def __init__(self, viewport, gpfile, card): self.card = card self.viewport = viewport self.gpfile = gpfile self.canvas = viewport.canvas self.draw() self.editing = False self.moving = False self.moving_edgescroll_id = None self.resize_state = None self.resize_edgescroll_id = None # slot triggered when geometry (pos/size) changes # fn args: (self, x, y, w, h) self.geom_slot = Slot() self.deletion_slot = Slot() self.new_edge = None
def __getitem__(self, name): composite = aq_parent(aq_inner(self)) slots = composite.filled_slots try: return slots[name] except (KeyError, AttributeError): # Generate a new slot. s = Slot(name) if composite._v_generating: # Persist the slot immediately. slots._setObject(s.getId(), s) else: # Persist automatically if the slot changes jar = AddOnChangeJar(slots) s._p_jar = jar return s.__of__(slots)
def __init__(self, taskDag, processorDag): super(Schedule, self).__init__() self.taskDag = taskDag self.processorDag = processorDag # self.isScheduled = False # store execution slot of each task for easy retrieving self.taskExecutionSlot = [] # store all execution slots of each processor self.processorCoreExecutionSlots = [] schedulePositionId = 0 for i in range(0, len(processorDag.processors)): currentProcessor = processorDag.processors[i] for j in range(0, currentProcessor.noOfCores): self.processorCoreExecutionSlots.append([ Slot(None, ProcessorCore(currentProcessor, j, schedulePositionId), 0, sys.maxint) ]) schedulePositionId += 1 for i in range(0, len(taskDag.tasks)): self.taskExecutionSlot.append(None) # actual finish time of schedule self.aft = 0
def build_interface(self): self.mainlayout = FloatLayout() self.buttonlayout = GridLayout( cols=1, size_hint=(0.75, 0.5), pos_hint={"x": 0.125, "y": 0.25} ) for i in range(1, 6): self.buttonlayout.add_widget(Slot(i, self.switchto_main)) self.mainlayout.add_widget(self.buttonlayout) self.menubutton = RealButton( './media/icons/arrowleft.png', './media/icons/arrowleft_pressed.png', self.switchto_menu, size_hint=(None, None), size=(self.iconsize, self.iconsize), pos_hint={'x': 0, 'y': 0}, source='./media/icons/arrowleft.png', always_release=True ) self.mainlayout.add_widget(self.menubutton) self.add_widget(self.mainlayout)
def __init__(self, parent=None): super().__init__(parent) # Initialize the main widget self.gameWidget = SlotGame() self.setCentralWidget(self.gameWidget) # Window title & status bar self.setWindowTitle('ADProject Slotmachine') self.statusBar = QStatusBar(self) self.setStatusBar(self.statusBar) # Connect button callbacks self.gameWidget.betButton.clicked.connect(self.buttonClicked) self.gameWidget.newGameButton.clicked.connect(self.buttonClicked) self.currentMoney = 1000 self.gameWidget.currentMoney.setText(str(self.currentMoney)) #실행횟수를 5회로 제한 self.currentTrial = 5 self.gameWidget.count.setText("Left trials: " + str(self.currentTrial)) # 게임이 시작될때 슬롯값을 비우는 기능 self.game = Slot() self.slotValue = [None, None, None]
def getFirstFitSlotForTaskOnProcessorCore(self, processorCore, task): # the ready time of the task at which # all required input data has arrived at the current processor readyTime = -1 # loop through all predecessors of the current task # to calculate readyTime for i in range(0, len(task.predecessors)): # get predecessor task in the tuple of (task, dependency) predTask = task.predecessors[i][0] # get dependency of current predecessor predTaskConstraint = task.predecessors[i][1] # get processor which processes the current predecessor task predProcessorCore = self.taskExecutionSlot[predTask.id].processorCore # calculate communication time to transmit data dependency from # processor which is assigned to process the predecessor task to # the processor which is being considered to use to process the current task communicationTime = self.processorDag.getCommunicationTimeBetweenCores(predProcessorCore, processorCore, predTaskConstraint) predecessorSlotEnd = self.taskExecutionSlot[predTask.id].end currentReadyTime = predecessorSlotEnd + communicationTime if currentReadyTime > readyTime: readyTime = currentReadyTime processingTime = task.computationRequired / processorCore.processor.processingRate currentProcessorCoreSlots = self.processorCoreExecutionSlots[processorCore.schedulePositionId] # find the earliest slot for i in range(0, len(currentProcessorCoreSlots)): currentSlot = currentProcessorCoreSlots[i] if currentSlot.task == None: actualStart = max(currentSlot.start, readyTime) actualEnd = actualStart + processingTime if actualEnd <= currentSlot.end: # return the first fit slot for the task on the current processor return Slot(task, processorCore, actualStart, actualEnd) else: continue print("nothing") return Slot(task, processorCore, -1, -1)
def add_slot(self, slot_name, slot_duration): self.session_slots.append( Slot(self.next_slot_time, slot_name, slot_duration)) self.next_slot_time = datetime.datetime.combine( datetime.date(1, 1, 1), self.next_slot_time) + datetime.timedelta(minutes=slot_duration) self.session_filled = self.session_filled + slot_duration self.next_slot_time = self.next_slot_time.time()
def action(self, d, z,args): serial = d.server.adb.device_serial( ) self.slot = Slot( serial, self.type ) time_limit = args['time_limit'] cate_id = args["repo_cate_id"] name = self.slot.getEmpty(d) #取空卡槽 if name ==0: name = self.slot.getSlot(d,time_limit) #没有空卡槽,取2小时没用过的卡槽 while name==0: #2小时没有用过的卡槽也为空的情况 d.server.adb.cmd("shell", "am broadcast -a com.zunyun.qk.toast --es msg \"卡槽全满,无2小时未用\"").communicate() time.sleep(30) name = self.slot.getSlot(d,time_limit) z.set_mobile_data(False) time.sleep(3) self.slot.restore(d,name) #有2小时没用过的卡槽情况,切换卡槽 z.set_mobile_data(True) time.sleep(8) d.server.adb.cmd("shell", "am broadcast -a com.zunyun.qk.toast --es msg \"TIM卡槽切换成功\"").communicate() d.server.adb.cmd("shell","am start -n com.tencent.tim/com.tencent.mobileqq.activity.SplashActivity").communicate() # 拉起来 if d(text='帐号无法登录').exists: info = self.login(d,z,args) #帐号无法登陆则登陆,重新注册登陆 # self.repo.BackupInfo(cate_id, d, name, info) # 将登陆上的仓库cate_id,设备号d,卡槽号name,qq号info,备份到仓库 self.slot.backup(d,name,info) #登陆之后备份 else: return else: #有空卡槽的情况 z.set_mobile_data(False) time.sleep(2) z.set_mobile_data(True) time.sleep(8) info = self.login(d,z,args) # self.repo.BackupInfo(cate_id, d, name, info) # 将登陆上的仓库cate_id,设备号d,卡槽号name,qq号info,备份到仓库 self.slot.backup(d,name,info) if (args["time_delay"]): time.sleep(int(args["time_delay"]))
def schedule(self, talk_list): """Schedule events for a list of events This method takes list of talks as input""" totaltime = self.totaltime(talk_list) possibledays = int(totaltime / self.perday) + 1 talk_list.sort(key=operator.attrgetter('duration')) m = self.combinations(talk_list, possibledays, Slot(3 * 60)) #morning slot self.clear(m) #clearing scheduled talks evening_slot = Slot(4 * 60, 3 * 60) e = self.combinations(talk_list, possibledays, evening_slot) #morning slot self.clear(e) #clearing scheduled talks if (self.talk_list): raise Exception("Unable to schedule all task for conferencing") self.morning = m self.evening = e
def __init__(self, number_of_slots): self.number_of_slots = int(number_of_slots) self.car_slots = [] self.bike_slots = [] n = 1 while n <= self.number_of_slots: slot = Slot(n) self.car_slots.append(slot) n += 1 n = 1 while n <= self.number_of_slots: slot = Slot(n) self.bike_slots.append(slot) n += 1 print "Created a parking lot with " + str(self.number_of_slots) + " car and bike slots each"
def addSlots(self, new_slots): self.slotsList += [ Slot(i) for i in range(self.totalslots, self.totalslots + new_slots) ] self.free_slots_queue += [ i for i in range(self.totalslots, self.totalslots + new_slots) ] self.totalslots += new_slots
def action(self, d, z, args): z.toast( "正在ping网络是否通畅" ) while True: ping = d.server.adb.cmd( "shell", "ping -c 3 baidu.com" ).communicate( ) print(ping) if 'icmp_seq' and 'bytes from' and 'time' in ping[0]: z.toast("开始执行:易信登录模块 有卡槽") break z.sleep( 2 ) z.generate_serial( "im.yixin" ) # 随机生成手机特征码 z.toast( "随机生成手机特征码" ) saveCate = args['repo_account_id'] password = self.GenPassword() serial = d.server.adb.device_serial() self.slot = Slot(serial, self.type) slotnum = self.slot.getEmpty() # 取空卡槽 if slotnum == 0: # 没有空卡槽的话 qiehuan_result = self.qiehuan(d, z, args) if qiehuan_result == "fail": self.action(d, z, args) else: login_result = self.login(d, z, args, password) if login_result == "fail": self.action(d, z, args) elif login_result is None: qiehuan_result = self.qiehuan( d, z, args ) if qiehuan_result == "fail": self.action( d, z, args ) else: # 入库 featureCodeInfo = z.get_serial("im.yixin") self.repo.RegisterAccount(login_result, password, "", saveCate, "using", featureCodeInfo, '%s_%s_%s' % ( d.server.adb.device_serial(), self.type, slotnum)) # 入卡槽 self.slot.backup(slotnum, str(slotnum) + '_' + login_result + '_' + saveCate) # 设备信息,卡槽号,QQ号 if (args['time_delay']): z.sleep(int(args['time_delay']))
def __init__(self): unitSize = settings.UNIT_SIZE self.coords = (-unitSize, unitSize * 11, unitSize * 12, unitSize * 12) self.slots = [[ Slot(coords=(self.coords[0] + self.coords[2] * (7 / 36 * (5 - i) + 1 / 36), self.coords[1] + self.coords[3] * (7 / 36 * j - 6 / 36), self.coords[2] * 6 / 36, self.coords[2] * 6 / 36)) for i in range(j) ] for j in range(1, 6)]
def login(self,d,z,args): serial = d.server.adb.device_serial( ) self.slot = Slot( serial, self.type ) cateId = args['repo_cate_id'] name = self.repo.GetMaterial(cateId,120,1) name = name[0]['content'] d.server.adb.cmd("shell", "pm clear com.tencent.tim").communicate() # 清除缓存 d.server.adb.cmd("shell","am start -n com.tencent.tim/com.tencent.mobileqq.activity.SplashActivity").communicate() # 拉起来 time.sleep(8) d(text='新用户', resourceId='com.tencent.tim:id/btn_register').click() token = self.XunMa.GetToken() phoneNumber = self.XunMa.GetPhoneNumber(token) print(phoneNumber) d(text='请输入你的手机号码', resourceId='com.tencent.tim:id/name').set_text(phoneNumber) d(text='下一步', resourceId='com.tencent.tim:id/name').click() try: vertifyCode = self.XunMa.GetCode(phoneNumber, token) # 获取验证码 except Exception: d(textContains='重新发送', resourceId='com.tencent.tim:id/name').click() vertifyCode = self.XunMa.GetCode(phoneNumber, token) # 获取验证码 d(text='请输入短信验证码', resourceId='com.tencent.tim:id/name').set_text(vertifyCode) d(textContains='重新发送', resourceId='com.tencent.tim:id/name').click() d(text='下一步', resourceId='com.tencent.tim:id/name').click() time.sleep(1) if d(text='绑定新QQ号码', resourceId='com.tencent.tim:id/action_sheet_button').exists: d(text='绑定新QQ号码', resourceId='com.tencent.tim:id/action_sheet_button').click() d(resourceId='com.tencent.tim:id/name', className='android.widget.EditText').click() z.input(name) d(text='完成', resourceId='com.tencent.tim:id/name').click() obj = d(resourceId='com.tencent.tim:id/name',className='android.widget.TextView',index=1).info info = obj['text'] #要保存的qq号 d(text='登录', resourceId='com.tencent.tim:id/name').click() time.sleep(6) # d.server.adb.cmd("shell", "am force-stop com.tencent.tim").wait() # 强制停止 # d.server.adb.cmd("shell", # "am start -n com.tencent.tim/com.tencent.mobileqq.activity.SplashActivity").wait() # 拉起来 return info
def action(self, d, z, args): while True: z.toast("正在ping网络是否通畅") while True: ping = d.server.adb.cmd("shell", "ping -c 3 baidu.com").communicate() print(ping) if 'icmp_seq' and 'bytes from' and 'time' in ping[0]: z.toast("开始执行:易信登录模块 有卡槽") break z.sleep(2) serial = d.server.adb.device_serial() self.slot = Slot(serial, self.type) slotnum = self.slot.getEmpty() # 取空卡槽 if slotnum == 0 or self.flag: # 没有空卡槽的话 if self.qiehuan(d, z, args): z.toast(u'切换成功,程序退出。') break else: if self.login(d, z, args): self.repo.BackupInfo(args["repo_account_id"], 'using', self.PhoneNumber, self.featureCodeInfo, '%s_%s_%s' % ( d.server.adb.device_serial(), self.type, slotnum)) # 仓库号,使用中,QQ号,设备号_卡槽号 self.slot.backup(slotnum, str(slotnum) + '_' + self.PhoneNumber + '_' + args['repo_account_id']) # 设备信息,卡槽号,QQ号 break else: if self.PhoneNumber != '': if d(textContains='您的帐号暂时无法使用').exists: self.repo.BackupInfo(args["repo_account_id"], 'frozen', self.PhoneNumber, '', '') # 仓库号,使用中,QQ号 else: self.repo.BackupInfo(args["repo_account_id"], 'normal', self.PhoneNumber, '', '') # 仓库号,使用中,QQ号 self.PhoneNumber = '' if (args['time_delay']): z.sleep(int(args['time_delay']))
def __init__(self): self.coords = (settings.UNIT_SIZE * 2, settings.UNIT_SIZE * 23.5, settings.UNIT_SIZE * 100 / 6, settings.UNIT_SIZE * 16 / 6) self.slots = [ Slot(coords=(self.coords[0] + settings.UNIT_SIZE * 2 / 6 + settings.UNIT_SIZE * 14 / 6 * i, self.coords[1] + settings.UNIT_SIZE * 2 / 6, settings.UNIT_SIZE * 2, settings.UNIT_SIZE * 2)) for i in range(7) ]
def __init__(self): self.coords = (settings.UNIT_SIZE * 27, settings.UNIT_SIZE * 6, settings.UNIT_SIZE * 7, settings.UNIT_SIZE * 10) self.borderThickness = settings.UNIT_SIZE * 2 / 6 self.slots = [[ Slot(coords=(self.coords[0] + self.borderThickness * 2 + settings.UNIT_SIZE * 1.5 * i, self.coords[1] + self.borderThickness * 2 + settings.UNIT_SIZE * 1.5 * j, settings.UNIT_SIZE * 1.3, settings.UNIT_SIZE * 1.3), isVisible=False) for i in range(4) ] for j in range(6)]
def __init__(self, xpos, ypos, radius, id): self.id = id self.coords = (int(xpos), int(ypos)) self.radius = int(radius) self.slots = [ Slot(coords=(self.coords[0] + settings.UNIT_SIZE * 1.5 * (((0, 0, 1, 1)[i]) - 0.9), self.coords[1] + settings.UNIT_SIZE * 1.5 * (((0, 1, 0, 1)[i]) - 0.9), settings.UNIT_SIZE * 1.3, settings.UNIT_SIZE * 1.3), isVisible=False) for i in range(4) ] self.colors = (settings.COLORS['black'], settings.COLORS['lightblue'])
def test_1append(self): a:Slot = Slot(9) a.append('this is a test\n') l = 'this is test 1\n' ll = ['this is test 2\n'] a.append(l) a.append(ll) self.assertEqual(3, len(a.data)) tst = a.data[:] self.assertTrue('test\n' in tst[0]) self.assertTrue('test 1\n' in tst[1]) self.assertTrue('test 2\n' in tst[2])
def append(self, item): if type(item) is SlotProperties: try: s = Slot(item) if self._cb is not None: s.set_conn_update_callback(self._cb) self[item.name] = s if s.is_shared: self._sort_shared_slots() except Exception as e: rospy.logerr(e) raise e elif type(item) is GroupProperties: try: hostnames = item.hosts if len(item.hosts) == 0: hostnames = rospy.get_param("~default_group_hosts", []) any_shared = False for h in hostnames: rep = item.representative s = Slot(rep, h) if self._cb is not None: s.set_conn_update_callback(self._cb) self[s.name] = s if s.is_shared is True: any_shared = True if any_shared is True: self._sort_shared_slots() except Exception as e: rospy.logerr(e) raise e else: raise TypeError("Invalid item type ('%s')" % type(item))
def _setGridSize(self, grid_size): n_columns, n_rows = grid_size self.removeAllChildren() for row_n in xrange(n_rows): row_size = (n_columns * self.cell_size[0], self.cell_size[1]) row = pychan.HBox(min_size=row_size, max_size=row_size, padding=self.padding) row.border_size = 1 row.opaque = 0 for column_n in xrange(n_columns): index = row_n * n_columns + column_n slot = Slot(min_size=(self.cell_size), max_size=(self.cell_size)) slot.border_size = 1 slot.name = "Slot_%d" % index slot.index = index slot.image = None slot.size = self.cell_size row.addChild(slot) self.addChild(row) self.min_size = ((n_columns * self.cell_size[0]) + 2, (n_rows * self.cell_size[1]) + 2) self.max_size = self.min_size
class ViewportCard(object): """ Manages the graphical representation of a card in a Tkinter canvas. Creates and destroys items as necessary, facilitates editing, and so on and so forth. Members: * card: model.Card * viewport: GPViewport * gpfile: gpfile.GraphPaperFile, contains model.graph() * canvas: TKinter canvas we get drawn on * editing: bool, text is being edited * moving: bool, being dragged * moving_edgescroll_id: callback id to scroll periodically when hovering near edge of screen * resize_state: {} * resize_edgescroll_id: as moving_edgescroll_id * slot: calls callbacks whenever geometry changes * new_edge: if an edge is being dragged out from a handle, this is it. * card_after_new_edge: bool, if we should make a new card when edge is dropped. """ def __init__(self, viewport, gpfile, card): self.card = card self.viewport = viewport self.gpfile = gpfile self.canvas = viewport.canvas self.draw() self.editing = False self.moving = False self.moving_edgescroll_id = None self.resize_state = None self.resize_edgescroll_id = None # slot triggered when geometry (pos/size) changes # fn args: (self, x, y, w, h) self.geom_slot = Slot() self.deletion_slot = Slot() self.new_edge = None def draw(self): self.frame_thickness = 5 self.window = ResizableCanvasFrame( self.canvas, self.card.x, self.card.y, self.card.w, self.card.h, min_width=MIN_CARD_SIZE, min_height=MIN_CARD_SIZE, ) self.text = ScrolledText(self.window, wrap=WORD) self.text.pack(expand=1, fill="both") # set up text for editing, dragging, deleting self.text.bind("<Button-1>", self.mousedown) self.text.bind("<Shift-Button-1>", self.shiftmousedown) self.text.bind("<Double-Button-1>", self.doubleclick) self.text.bind("<B1-Motion>", self.mousemove) self.text.bind("<ButtonRelease-1>", self.mouseup) self.text.bind("<FocusIn>", self.focusin) self.text.bind("<FocusOut>", self.focusout) self.text.bind("<Control-Delete>", self.ctrldelete) self.text.insert(END, self.card.text) # set up frame for resizing self.window.bind("<Configure>", self.configure) self.window.save_callback = self.save_card # draw edge handles self.edge_handles = None # self.redraw_edge_handles() def redraw_edge_handles(self): """ Either creates or modifies the edge handles, little circles poking out the side of the card, based on the current position and width. self.edge_handles is a list of itemids of the circles in (top, right, bottom, left) order. """ def create_circle(bbox): # create circle suitable for edge-handle use new = self.canvas.create_oval(bbox[0], bbox[1], bbox[2], bbox[3], fill="green", outline="") self.canvas.addtag_withtag("card_handle_tag", new) # for z-ordering self.canvas.tag_bind(new, "<Button-1>", self.handle_click) self.canvas.tag_bind(new, "<Shift-Button-1>", self.handle_shift_click) self.canvas.tag_bind(new, "<B1-Motion>", self.handle_mousemove) self.canvas.tag_bind(new, "<ButtonRelease-1>", self.handle_mouseup) return new x, y = self.window.canvas_coords() w, h = self.window.winfo_width(), self.window.winfo_height() # 2*radius should be < MIN_CARD_SIZE, and offset < radius radius = 30 offset = 19 # offset of center of circle from card edge left_coords = (x + offset, y + h / 2) right_coords = (x + w - offset, y + h / 2) top_coords = (x + w / 2, y + offset) bottom_coords = (x + w / 2, y + h - offset) all_coords = (top_coords, right_coords, bottom_coords, left_coords) bboxes = [(x - radius, y - radius, x + radius, y + radius) for x, y in all_coords] if self.edge_handles: # move the edge handles for i, box in enumerate(bboxes): # self.canvas.coords(handle, box[0], box[1], box[2], box[3]) self.canvas.delete(self.edge_handles[i]) self.edge_handles[i] = create_circle(box) # self.canvas.itemconfig(handle, bbox = box) else: # create new ones self.edge_handles = [create_circle(b) for b in bboxes] # have to do this every time, every time we recreate the edge handles self.viewport.fix_z_order() def get_text(self): "gets the text from the actual editor, which may not be saved yet" return self.text.get("0.0", END) def save_text(self): # get text from window text = self.get_text() if text != self.card.text: self.card.text = text self.gpfile.commit() def canvas_coords(self): return self.window.canvas_coords() def start_moving(self, event): # set up state for a drag self.moving = True self.foocoords = (event.x, event.y) self.set_moving_edgescroll_callback() def edge_scroll(self): # if any edges are too close to the edge, move and scroll the canvas canvas_coords = self.canvas_coords() relative_mouse_pos = self.foocoords canvas_mouse_coords = ( canvas_coords[0] + relative_mouse_pos[0] + self.frame_thickness, canvas_coords[1] + relative_mouse_pos[1] + self.frame_thickness, ) scroll_x, scroll_y = self.viewport.edge_scroll(canvas_mouse_coords) # move the opposite direction the viewport scrolled scroll_x, scroll_y = -scroll_x, -scroll_y # print 'card.edgescroll x y', scroll_x, scroll_y, 'relative_mouse_pos', relative_mouse_pos self.window.move(scroll_x, scroll_y) self.viewport.reset_scroll_region() self.set_moving_edgescroll_callback() def set_moving_edgescroll_callback(self): self.moving_edgescroll_id = self.text.after(10, self.edge_scroll) def cancel_moving_edgescroll_callback(self): self.text.after_cancel(self.moving_edgescroll_id) self.moving_edgescroll_id = None def mousedown(self, event): self.window.lift() def doubleclick(self, event): self.start_moving(event) return "break" def shiftmousedown(self, event): self.mousedown(event) self.start_moving(event) return "break" def mousemove(self, event): if self.moving: # coords are relative to card, not canvas if self.foocoords: delta = (event.x - self.foocoords[0], event.y - self.foocoords[1]) else: delta = (event.x, event.y) self.window.move(delta[0], delta[1]) self.geometry_callback() self.viewport.reset_scroll_region() return "break" def mouseup(self, event): if self.moving: self.moving = False new_coords = self.canvas_coords() self.card.x, self.card.y = new_coords[0], new_coords[1] self.gpfile.commit() self.cancel_moving_edgescroll_callback() self.geometry_callback() # next several functions are bound to the circular edge handles def handle_click(self, event): # create new edge self.new_edge = ViewportEdge(self.viewport, self.gpfile, None, self, None) self.new_edge.mousemove(event) # give it a real start pos def handle_shift_click(self, event): self.handle_click(event) self.new_edge.make_new_card = True def handle_mousemove(self, event): if self.new_edge: self.new_edge.mousemove(event) def handle_mouseup(self, event): if self.new_edge: self.new_edge.mouseup(event) self.new_edge = None def configure(self, event): self.redraw_edge_handles() def focusin(self, event): self.editing = True def focusout(self, event): self.editing = False self.save_text() def ctrldelete(self, event): title_sample = self.get_text().split("\n", 1)[0] if len(title_sample) > 20: title_sample = title_sample[:20] + "..." # delete the card if tkMessageBox.askokcancel("Delete?", 'Delete card "%s" and all its edges?' % title_sample): for handle in self.edge_handles: self.canvas.delete(handle) self.deletion_slot.signal() self.viewport.remove_card(self) self.card.delete() self.window.destroy() self.gpfile.commit() return "break" def save_card(self): # grab values from self.window, # and put them in the model.card self.card.x, self.card.y = self.window.canvas_coords() self.card.w, self.card.h = self.window.winfo_width(), self.window.winfo_height() self.geometry_callback() # here so it gets called after resizing self.gpfile.commit() def add_geom_signal(self, fn): return self.geom_slot.add(fn) def remove_geom_signal(self, handle): self.geom_slot.remove(handle) def add_deletion_signal(self, fn): return self.deletion_slot.add(fn) def remove_deletion_signal(self, handle): self.deletion_slot.remove(handle) def geometry_callback(self): x, y = self.canvas_coords() w, h = self.window.winfo_width(), self.window.winfo_height() self.geom_slot.signal(self, x, y, w, h) def highlight(self): self.text.config(background="#ffffa2") def unhighlight(self): self.text.config(background="white")