def win_animation(self): ship_position = self.main_win.objects[self.p1.stacking_order].x1 distance = self.main_win.max_x - ship_position + 2 self.main_win.auto_refresh = False self.main_win.show(self.p1.thruster) self.p1.thruster.step = 1 speed = 0.25 while distance >= 0: self.main_win.move_relative(self.p1, x=1) self.p1.thruster.update() self.main_win.move_relative(self.p1.thruster, x=1) self.main_win.refresh() time.sleep(speed) speed -= 0.005 if speed < 0.04: speed = 0.04 distance -= 1 self.main_win.auto_refresh = True msg = Alert('!!! CONGRATULATIONS !!!\nTHE GUMMIES HAVE BEEN SAVED') msg.show(self.main_win) time.sleep(3) msg.hide()
def intro(self): self.midpoint_x = round( self.main_win.width * (self.screens - 0.5)/self.screens ) midpoint_y = self.main_win.height // 2 outline = Outline(self.p2) self.main_win.add_object( outline, self.midpoint_x + self.ship_space - 1, midpoint_y - self.p2.height // 2 - 1 ) outline = Outline(self.p1) self.main_win.add_object( outline, self.midpoint_x - self.ship_space - self.p1.width, midpoint_y - self.p1.height // 2 - 1 ) self.main_win.add_object( self.p2, self.midpoint_x + self.ship_space, midpoint_y - self.p2.height // 2 ) self.main_win.add_object( self.p1, 4, midpoint_y - self.p1.height // 2 ) self.main_win.add_object( self.p1.thruster, 2, midpoint_y + 1 ) self.main_win.display(0, 7) self.main_win.auto_refresh = False position = self.p1.scene.objects[self.p1.stacking_order] distance = self.midpoint_x - self.ship_space - position.x2 speed = 0.04 while distance > 0: self.main_win.move_relative(self.p1, x=1) self.main_win.move_relative(self.p1.thruster, x=1) self.p1.thruster.update() self.main_win.pan(x=1) self.main_win.refresh() time.sleep(speed) if distance == 40: self.main_win.hide(self.p1.thruster) if distance < 40: speed += 0.005 distance -= 1 msg = Alert('!!! WARNING !!!\nENEMY WEAPONS LOCKED') msg.show(self.main_win) self.main_win.refresh() time.sleep(3) msg.hide() self.main_win.refresh()
def __get_pull_requests(self, repository_name, feature_name=None, only_active=False): if repository_name not in self.settings['repo_id']: Alert.show("Couldn't find this repository on your TFS") return [] auth = self.__get_auth() baseUrl = self.settings['url'] repo_id = self.settings['repo_id'][repository_name] feature_filter = '&sourceRefName=refs/heads/' + feature_name if feature_name else "" pull_requests = requests.get(baseUrl + '/_apis/git/repositories/' + repo_id + '/pullRequests?api-version=2.0&status=active' + feature_filter, auth=auth).json()['value'] if not only_active: pull_requests = pull_requests + requests.get(baseUrl + '/_apis/git/repositories/' + repo_id + '/pullRequests?api-version=2.0&status=completed' + feature_filter, auth=auth).json()['value'] pull_requests = pull_requests + requests.get(baseUrl + '/_apis/git/repositories/' + repo_id + '/pullRequests?api-version=2.0&status=abandoned' + feature_filter, auth=auth).json()['value'] return pull_requests
class PiGlow_Status_Server: def __init__(self): self.cfg = PiGlow_Status_Config() self.commands = PiGlow_Status_Commands() self.idle_job = self.commands.CLOCK self.jobs = [] self.running = None self.locked_thread = None self.check_jobs_thread = None self.socket_manager_thread = None self.piglow = None self.clock = None self.alert = None self.in_progress = None self.job_interval = 0.1 self.quiet_time = False def start(self): """Creates the socket and starts the threads""" try: self.piglow = PiGlow() except IOError as e: if e[0] == errno.EACCES: print >> sys.stderr, "Permission denied, try running as root" else: print >> sys.stderr, "Unknown error accessing the PiGlow" sys.exit(1) self.piglow.all(0) self.clock = Clock(self.piglow) self.alert = Alert(self.piglow) self.in_progress = In_Progress(self.piglow) address = (self.cfg.HOST, self.cfg.PORT) serversock = socket(AF_INET, SOCK_STREAM) serversock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) serversock.bind(address) serversock.listen(5) self.check_jobs_thread = Thread(None, self.check_jobs, None, ()) self.socket_manager_thread = Thread(None, self.socket_manager, None, (serversock, )) self.start_threads() while self.running == True: sleep(1) self.stop() def stop(self): """Closes the threads and returns""" self.stop_threads() self.piglow.all(0) def start_threads(self): """Starts the threads""" self.running = True self.check_jobs_thread.start() self.socket_manager_thread.start() def stop_threads(self): """Stops the threads""" self.running = False self.unlock() try: self.check_jobs_thread.join() except (KeyboardInterrupt, SystemExit): pass try: self.socket_manager_thread.join() except (KeyboardInterrupt, SystemExit): pass def check_jobs(self): """Performs the actions in the job list""" while self.running == True: if self.quit_requested(): self.running = False break if self.entering_quiet_time() == True: self.unlock() self.piglow.all(0) if self.in_quiet_time() == False: if self.locked_thread is None: # No currently locking jobs, we can process the next job in the list as # normal or run the idle task if none are scheduled self.run_jobs() else: # A locking job is currently running, screen the job list for tasks # relating to it. self.check_locked_jobs() sleep(self.job_interval) def quit_requested(self): """Returns true if the quit command is in the job list""" for job in self.jobs: if job[0] == self.commands.QUIT: return True return False def check_locked_jobs(self): """Goes through the job list searching for tasks relating to the current locked job""" jobs = self.jobs self.jobs = [] for job in jobs: if job[0] == self.commands.CYCLE: try: self.in_progress.set_speed(job[1]) except IndexError: pass elif job[0] == self.commands.UNLOCK: self.unlock() elif job[0] == self.commands.OFF: self.unlock() self.jobs.append(job) else: self.jobs.append(job) def run_jobs(self): """First the first job in the list or the current idle job""" if len(self.jobs) > 0: job = self.jobs[:1].pop() self.jobs = self.jobs[1:] self.handle_job(job) else: if self.idle_job is not None: self.run_idle_job() else: self.piglow.all(0) def run_idle_job(self): """Runs the current idle job""" if self.idle_job == self.commands.CLOCK: self.clock.run() def handle_job(self, job): """Performs the given job""" command = job[:1].pop() args = job[1:] if command == self.commands.QUIT: self.running = False elif command == self.commands.CYCLE: self.locked_thread = self.in_progress if len(args) > 0: self.in_progress.set_speed(args[0]) self.in_progress.start() elif command == self.commands.ALERT: self.alert.show(*args) elif command == self.commands.OFF: self.idle_job = None elif command == self.commands.CLOCK: self.idle_job = self.commands.CLOCK def unlock(self): """Stops the currently locking thread""" if self.locked_thread is None: return self.locked_thread.stop() self.locked_thread = None def socket_manager(self, serversock): """Creates handlers for new data given to this process via the socket""" rlist = [serversock] wlist = [] xlist = [] while self.running == True: readable, writable, errored = select.select( rlist, wlist, xlist, self.cfg.TIMEOUT) for s in readable: if s is serversock: clientsock, addr = serversock.accept() self.socket_buffer_handler(clientsock) def socket_buffer_handler(self, clientsock): """Handles data in the socket buffer""" data = clientsock.recv(self.cfg.BUFF).rstrip() command = data.split(" ") if command == self.commands.CLOSE: clientsock.close() else: self.add_job(command) def add_job(self, job): """Adds a job to the list""" if self.cfg.quiet_time() == False or job == self.command.QUIT: self.jobs.append(job) def entering_quiet_time(self): """Returns true if we're entering quiet time""" return self.quiet_time == False and self.cfg.quiet_time() == True def in_quiet_time(self): """Returns true if we're in quiet time""" self.quiet_time = self.cfg.quiet_time() return self.quiet_time
class PiGlow_Status_Server: def __init__ (self): self.cfg = PiGlow_Status_Config () self.commands = PiGlow_Status_Commands () self.idle_job = self.commands.CLOCK self.jobs = [] self.running = None self.locked_thread = None self.check_jobs_thread = None self.socket_manager_thread = None self.piglow = None self.clock = None self.alert = None self.in_progress = None self.job_interval = 0.1 self.quiet_time = False def start (self): """Creates the socket and starts the threads""" try: self.piglow = PiGlow () except IOError as e: if e[0] == errno.EACCES: print >> sys.stderr, "Permission denied, try running as root" else: print >> sys.stderr, "Unknown error accessing the PiGlow" sys.exit (1) self.piglow.all (0) self.clock = Clock (self.piglow) self.alert = Alert (self.piglow) self.in_progress = In_Progress (self.piglow) address = (self.cfg.HOST, self.cfg.PORT) serversock = socket (AF_INET, SOCK_STREAM) serversock.setsockopt (SOL_SOCKET, SO_REUSEADDR, 1) serversock.bind (address) serversock.listen (5) self.check_jobs_thread = Thread (None, self.check_jobs, None, ()) self.socket_manager_thread = Thread (None, self.socket_manager, None, (serversock, )) self.start_threads () while self.running == True: sleep (1) self.stop () def stop (self): """Closes the threads and returns""" self.stop_threads () self.piglow.all (0) def start_threads (self): """Starts the threads""" self.running = True self.check_jobs_thread.start () self.socket_manager_thread.start () def stop_threads (self): """Stops the threads""" self.running = False self.unlock () try: self.check_jobs_thread.join () except (KeyboardInterrupt, SystemExit): pass try: self.socket_manager_thread.join () except (KeyboardInterrupt, SystemExit): pass def check_jobs (self): """Performs the actions in the job list""" while self.running == True: if self.quit_requested (): self.running = False break if self.entering_quiet_time () == True: self.unlock () self.piglow.all (0) if self.in_quiet_time () == False: if self.locked_thread is None: # No currently locking jobs, we can process the next job in the list as # normal or run the idle task if none are scheduled self.run_jobs () else: # A locking job is currently running, screen the job list for tasks # relating to it. self.check_locked_jobs () sleep (self.job_interval) def quit_requested (self): """Returns true if the quit command is in the job list""" for job in self.jobs: if job[0] == self.commands.QUIT: return True return False def check_locked_jobs (self): """Goes through the job list searching for tasks relating to the current locked job""" jobs = self.jobs self.jobs = [] for job in jobs: if job[0] == self.commands.CYCLE: try: self.in_progress.set_speed (job[1]) except IndexError: pass elif job[0] == self.commands.UNLOCK: self.unlock () elif job[0] == self.commands.OFF: self.unlock () self.jobs.append (job) else: self.jobs.append (job) def run_jobs (self): """First the first job in the list or the current idle job""" if len (self.jobs) > 0: job = self.jobs[:1].pop () self.jobs = self.jobs[1:] self.handle_job (job) else: if self.idle_job is not None: self.run_idle_job () else: self.piglow.all (0) def run_idle_job (self): """Runs the current idle job""" if self.idle_job == self.commands.CLOCK: self.clock.run () def handle_job (self, job): """Performs the given job""" command = job[:1].pop () args = job[1:] if command == self.commands.QUIT: self.running = False elif command == self.commands.CYCLE: self.locked_thread = self.in_progress if len (args) > 0: self.in_progress.set_speed (args[0]) self.in_progress.start () elif command == self.commands.ALERT: self.alert.show (*args) elif command == self.commands.OFF: self.idle_job = None elif command == self.commands.CLOCK: self.idle_job = self.commands.CLOCK def unlock (self): """Stops the currently locking thread""" if self.locked_thread is None: return self.locked_thread.stop () self.locked_thread = None def socket_manager (self, serversock): """Creates handlers for new data given to this process via the socket""" rlist = [serversock] wlist = [] xlist = [] while self.running == True: readable, writable, errored = select.select (rlist, wlist, xlist, self.cfg.TIMEOUT) for s in readable: if s is serversock: clientsock, addr = serversock.accept () self.socket_buffer_handler (clientsock) def socket_buffer_handler (self, clientsock): """Handles data in the socket buffer""" data = clientsock.recv (self.cfg.BUFF).rstrip () command = data.split (" ") if command == self.commands.CLOSE: clientsock.close () else: self.add_job (command) def add_job (self, job): """Adds a job to the list""" if self.cfg.quiet_time () == False or job == self.command.QUIT: self.jobs.append (job) def entering_quiet_time (self): """Returns true if we're entering quiet time""" return self.quiet_time == False and self.cfg.quiet_time () == True def in_quiet_time (self): """Returns true if we're in quiet time""" self.quiet_time = self.cfg.quiet_time () return self.quiet_time
def lose_animation(self): msg = Alert('YOUR SHIP HAS BEEN DESTROYED') msg.show(self.main_win) time.sleep(5) msg.hide()
def show(message): Alert.show(message) click.confirm("Do you want to continue?", abort=True)