def main():
    """
    Open a file called show_ip_int_brie.txt.

    Parse through interface data and create an Interface object for each one found.
    """
    interfaces = []
    INTERFACE_REGEX = '^(FastEthernet|GigabitEthernet)([0-9]+) .*(up|down)'
    # open the file called 'show_ip_int_brief.txt'
    with open('show_ip_int_brief.txt', 'r') as interface_info:
        for line in interface_info:
            # Iterate over each line and match against the string INTERFACE_REGEX
            m = re.match(INTERFACE_REGEX, line)
            if m is not None:
                # When the line matches the REGEX, create an Interface() object
                interface = Interface(m.group(1) + m.group(2), m.group(3))
                # Append the interface to the list, so we can iterate over it
                interfaces.append(interface)

    # for each interface print the name and status
    for interface in interfaces:
        interface.prints()

    # call the check_down() function to print any interfaces in the down state with a warning
    for interface in interfaces:
        interface.check_down()
示例#2
0
 def __init__(self, screen, book):
     self.screen = screen
     self.clock = pygame.time.Clock()
     # init interface
     self.interface = Interface()
     # init books
     self.book = book
     # init the player
     self.music = Player(self.book)
示例#3
0
 def __init__(self, screen, funcs, hardware_instance, book):
     # declare important variables
     self.screen = screen
     # important for framerate
     self.clock = pygame.time.Clock()
     # contain all interface methods
     self.interface = Interface()
     # functions for the menu items
     self.funcs = funcs
     # cached book for last played window
     self.book = book
示例#4
0
 def __init__(self, screen, library, function):
     # define screen variables
     self.screen = screen
     # define music folder
     self.library = library
     # important for framerate
     self.clock = pygame.time.Clock()
     # contain all interface methods
     self.interface = Interface()
     # declare functions
     self.function = function
示例#5
0
def main():
    """Simple main method calling our function."""
    list_interfaces = []
    result = get_interface_state(HOST, PORT, USER, PASS, FILE)
    print(xml.dom.minidom.parseString(result.xml).toprettyxml())
    # get a list of interfaces by parsing for the <interface> element
    interfaces = xml.dom.minidom.parseString(
        result.xml).getElementsByTagName('interface')
    # iterate over each instance of the <interface> element
    for each in interfaces:
        # parse out the <name> and <oper-status> nodes when the
        # <name> text node contains "GigabitEthernet|FastEthernet"
        if re.match('(Gigabit|Fast)Ethernet',
                    each.getElementsByTagName('name')[0].firstChild.nodeValue):

            # instantiate an Interface() object for each instance of an interface
            interface = Interface(
                each.getElementsByTagName('name')[0].firstChild.nodeValue,
                each.getElementsByTagName('oper-status')
                [0].firstChild.nodeValue)
            list_interfaces.append(interface)

    # call the prints() method to print the interface data
    for each in list_interfaces:
        each.prints()

    # call the check_down() method to print each down interface and a warning
    for each in list_interfaces:
        each.check_down()
示例#6
0
class MainMenu():
    ''' generate the start interface for accessing all other screens'''
    def __init__(self, screen, funcs, hardware_instance, book):
        # declare important variables
        self.screen = screen
        # important for framerate
        self.clock = pygame.time.Clock()
        # contain all interface methods
        self.interface = Interface()
        # functions for the menu items
        self.funcs = funcs
        # cached book for last played window
        self.book = book

    #define function that checks for mouse location
    def on_click(self):
        click_pos = (pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])
        # select last played item
        if 10 <= click_pos[0] <= 310 and 120 <= click_pos[1] <= 185:
            self.funcs['Continue'](self.book)
        # go to library screen
        if 10 <= click_pos[0] <= 205 and 190 <= click_pos[1] <= 230:
            self.funcs['Select Book']()
        # exit gui
        if 265 <= click_pos[0] <= 315 and 190 <= click_pos[1] <= 230:
            self.interface.exit_interface(self.screen)

    def run(self):
        '''run method for drawing the screen to dispay'''
        mainloop = True
        # use infinity loop for showing the screen
        while mainloop:
            # Limit frame speed to 30 FPS
            self.clock.tick(30)
            self.interface.main_interface(self.screen, self.book)
            # wait for a pressed button or exit infinity loop
            for event in pygame.event.get():
                # recognize mouse and touchscreen activity
                if event.type == pygame.MOUSEBUTTONDOWN:
                    pos = (pygame.mouse.get_pos()[0],
                           pygame.mouse.get_pos()[1])
                    pygame.draw.circle(self.screen, YELLOW, pos, 10, 0)
                    self.on_click()
            # update the screen
            pygame.display.flip()
示例#7
0
 def __init__(self, screen, book):
   self.screen = screen
   self.clock = pygame.time.Clock()
   # init interface 
   self.interface = Interface()
   # init books
   self.book = book
   # init the player 
   self.music = Player(self.book)
示例#8
0
class MainMenu():
    ''' generate the start interface for accessing all other screens'''
    def __init__(self, screen, funcs, hardware_instance, book):
    	# declare important variables
        self.screen = screen
        # important for framerate
        self.clock = pygame.time.Clock()
        # contain all interface methods
        self.interface = Interface()
        # functions for the menu items
        self.funcs = funcs
        # cached book for last played window
        self.book = book

    #define function that checks for mouse location
    def on_click(self):
        click_pos = (pygame.mouse.get_pos() [0], pygame.mouse.get_pos() [1])
        # select last played item
        if 10 <= click_pos[0] <= 310 and 120 <= click_pos[1] <= 185:
            self.funcs['Continue'](self.book)
        # go to library screen 
        if 10 <= click_pos[0] <= 205 and 190 <= click_pos[1] <= 230:
            self.funcs['Select Book']()
        # exit gui
        if 265 <= click_pos[0] <= 315 and 190 <= click_pos[1] <= 230:
            self.interface.exit_interface(self.screen)

    def run(self):
        '''run method for drawing the screen to dispay'''
        mainloop = True
        # use infinity loop for showing the screen
        while mainloop:
            # Limit frame speed to 30 FPS
            self.clock.tick(30)
            self.interface.main_interface(self.screen, self.book)
            # wait for a pressed button or exit infinity loop
            for event in pygame.event.get():
                # recognize mouse and touchscreen activity
                if event.type == pygame.MOUSEBUTTONDOWN:
                    pos = (pygame.mouse.get_pos() [0], pygame.mouse.get_pos() [1])
                    pygame.draw.circle(self.screen, YELLOW, pos, 10, 0)
                    self.on_click()
            # update the screen
            pygame.display.flip()
示例#9
0
 def __init__(self, screen, library, function):
     # define screen variables
     self.screen = screen
     # define music folder
     self.library = library
     # important for framerate
     self.clock = pygame.time.Clock()
     # contain all interface methods
     self.interface = Interface()
     # declare functions
     self.function = function
示例#10
0
 def __init__(self, screen, funcs, hardware_instance, book):
 	# declare important variables
     self.screen = screen
     # important for framerate
     self.clock = pygame.time.Clock()
     # contain all interface methods
     self.interface = Interface()
     # functions for the menu items
     self.funcs = funcs
     # cached book for last played window
     self.book = book
示例#11
0
def main():
    """
    Open a file called show_ip_int_brie.txt.

    Parse through interface data and create an Interface object for each one found.
    """
    interfaces = []
    INTERFACE_REGEX = '^(FastEthernet|GigabitEthernet)([0-9]+) .*(up|down)'
    # open the file called 'show_ip_int_brief.txt'
    with open('show_ip_int_brief.txt', 'r') as interface_info:
        for line in interface_info:
            # Iterate over each line and match against the string INTERFACE_REGEX
            m = re.match(INTERFACE_REGEX, line)
            if m is not None:
                # When the line matches the REGEX, create an Interface() object
                interface = Interface(m.group(1) + m.group(2), m.group(3))
                # Append the interface to the list, so we can iterate over it
                interfaces.append(interface)

    # for each interface print the name and status
    for interface in interfaces:
        interface.prints()

    # call the check_down() function to print any interfaces in the down state with a warning
    for interface in interfaces:
        interface.check_down()
示例#12
0
	def __init__(self, book):
		# init the mixer of pygame module
		self.mixer = pygame.mixer
		self.mixer.init()
		# init the interface module
		self.interface = Interface()
		# load actual audio book object
		self.book = book
		self.chapter = self.book.get_chapter()
		# set position to position in audio book class
		self.position = self.book.get_pos()
		# set playing status
		self.playing = False
示例#13
0
class Library:
    '''generate a library screen for scrolling through the audio books'''

    def __init__(self, screen, library, function):
        # define screen variables
        self.screen = screen
        # define music folder
        self.library = library
        # important for framerate
        self.clock = pygame.time.Clock()
        # contain all interface methods
        self.interface = Interface()
        # declare functions
        self.function = function

    def on_click(self, index):
      '''recognize touchscreen and mouse selections to 
      run functionalities of buttons'''
      # get actual position of mouse click 
      click_pos = pressed()
      # go back to main screen
      if 10 <= click_pos[0] <= 55 and 190 <= click_pos[1] <= 235:
        return 999
      # scroll to left
      if 155 <= click_pos[0] <= 200 and 190 <= click_pos[1] <= 235:
        index -=1
        # make negative index to max index to start new round
        if index == -1:
          index = len(self.library) -1
        return index
      # scroll to right
      if 210 <= click_pos[0] <= 255 and 190 <= click_pos[1] <= 235:
        index = index + 1
        # set max index to 0 for start new round 
        if index >= len(self.library):
          index = 0
        return index
      # select a book
      if 265 <= click_pos[0] <= 310 and 190 <= click_pos[1] <= 235:
        # select actual book and go to play window
        self.function(self.library[index])
      return index

    def run(self):
      '''run method for drawing the screen to dispay'''
      mainloop = True
      # set index of list to first item
      index = 0
      # use infinity loop for drawing screen
      while mainloop:
        # Limit frame speed to 30 FPS
        self.clock.tick(30)
        for event in pygame.event.get():
          # draw interface on screen
          self.interface.list_interface(self.screen, 
            self.library[index].get_title(), self.library[index].get_artist(),
            self.library[index].get_total_playtime(), self.library[index].get_cover())
          # wit for touchscreen event
          if event.type == pygame.MOUSEBUTTONDOWN:
            # draw circle for touchscreen feedback
            pygame.draw.circle(self.screen, YELLOW, pressed(), 10, 0)
            # update index in library
            index = self.on_click(index)
            # exit mainloop
            if index == 999: mainloop = False
            
        # update display
        pygame.display.flip()
示例#14
0
class Library:
    '''generate a library screen for scrolling through the audio books'''
    def __init__(self, screen, library, function):
        # define screen variables
        self.screen = screen
        # define music folder
        self.library = library
        # important for framerate
        self.clock = pygame.time.Clock()
        # contain all interface methods
        self.interface = Interface()
        # declare functions
        self.function = function

    def on_click(self, index):
        '''recognize touchscreen and mouse selections to 
      run functionalities of buttons'''
        # get actual position of mouse click
        click_pos = pressed()
        # go back to main screen
        if 10 <= click_pos[0] <= 55 and 190 <= click_pos[1] <= 235:
            return 999
        # scroll to left
        if 155 <= click_pos[0] <= 200 and 190 <= click_pos[1] <= 235:
            index -= 1
            # make negative index to max index to start new round
            if index == -1:
                index = len(self.library) - 1
            return index
        # scroll to right
        if 210 <= click_pos[0] <= 255 and 190 <= click_pos[1] <= 235:
            index = index + 1
            # set max index to 0 for start new round
            if index >= len(self.library):
                index = 0
            return index
        # select a book
        if 265 <= click_pos[0] <= 310 and 190 <= click_pos[1] <= 235:
            # select actual book and go to play window
            self.function(self.library[index])
        return index

    def run(self):
        '''run method for drawing the screen to dispay'''
        mainloop = True
        # set index of list to first item
        index = 0
        # use infinity loop for drawing screen
        while mainloop:
            # Limit frame speed to 30 FPS
            self.clock.tick(30)
            for event in pygame.event.get():
                # draw interface on screen
                self.interface.list_interface(
                    self.screen, self.library[index].get_title(),
                    self.library[index].get_artist(),
                    self.library[index].get_total_playtime(),
                    self.library[index].get_cover())
                # wit for touchscreen event
                if event.type == pygame.MOUSEBUTTONDOWN:
                    # draw circle for touchscreen feedback
                    pygame.draw.circle(self.screen, YELLOW, pressed(), 10, 0)
                    # update index in library
                    index = self.on_click(index)
                    # exit mainloop
                    if index == 999: mainloop = False

            # update display
            pygame.display.flip()
示例#15
0
class PlayerInterface:

    def __init__(self, screen, book):
      self.screen = screen
      self.clock = pygame.time.Clock()
      # init interface 
      self.interface = Interface()
      # init books
      self.book = book
      # init the player 
      self.music = Player(self.book)

    def on_click(self):
      ''' recognize touchscreen and mouse selections to 
      run functionalities of buttons '''
      click_pos = pressed()
      # stop music and return to previous screen
      if 10 <= click_pos[0] <= 55 and 190 <= click_pos[1] <= 235:
        self.music.stop()
        return False
      # play previous chapter
      if 65 <= click_pos[0] <= 110 and 190 <= click_pos[1] <= 235:
        self.music.previous_chapter()
      # play next chapter
      if 115 <= click_pos[0] <= 160 and 190 <= click_pos[1] <= 235:
        self.music.next_chapter()
      # pause/unpause the music
      if 165 <= click_pos[0] <= 210 and 190 <= click_pos[1] <= 235:
        self.music.pause()
      # stop the music the music        
      if 215 <= click_pos[0] <= 260 and 190 <= click_pos[1] <= 235:
        self.music.stop()
      # play the music
      if 265 <= click_pos[0] <= 310 and 190 <= click_pos[1] <= 235:
        self.music.play()
      # skip to selected position on the progress bar 
      if 10 <= click_pos[0] <= 310 and 160 <= click_pos[1] <= 185:
        self.music.set_pos(click_pos[0])
      return True

    def run(self):
      '''run method for drawing the screen to dispay'''
      mainloop = True
      while mainloop:
        # Limit frame speed to 30 FPS
        self.clock.tick(30)
        # draw interface to screen
        self.interface.player_interface(self.screen, self.book.get_title(),
          self.book.get_artist(), self.music.get_chapter() + 1, self.book.get_num_chapter(),
          self.book.get_chapter_playtime()[self.music.get_chapter()], 
          self.music.get_pos(), self.book.get_cover())
        for event in pygame.event.get():
          if event.type == pygame.USEREVENT:
            # start playing next chapter when a song ends
            self.music.next_chapter()
          # wait for touchscreen pressed
          if event.type == pygame.MOUSEBUTTONDOWN:
            # draw touchscreen feedback to screen
            pygame.draw.circle(self.screen, YELLOW, pressed(), 10, 0)
            # run functionalities
            mainloop = self.on_click()
        # update display
        pygame.display.flip()
示例#16
0
class PlayerInterface:
    def __init__(self, screen, book):
        self.screen = screen
        self.clock = pygame.time.Clock()
        # init interface
        self.interface = Interface()
        # init books
        self.book = book
        # init the player
        self.music = Player(self.book)

    def on_click(self):
        ''' recognize touchscreen and mouse selections to 
      run functionalities of buttons '''
        click_pos = pressed()
        # stop music and return to previous screen
        if 10 <= click_pos[0] <= 55 and 190 <= click_pos[1] <= 235:
            self.music.stop()
            return False
        # play previous chapter
        if 65 <= click_pos[0] <= 110 and 190 <= click_pos[1] <= 235:
            self.music.previous_chapter()
        # play next chapter
        if 115 <= click_pos[0] <= 160 and 190 <= click_pos[1] <= 235:
            self.music.next_chapter()
        # pause/unpause the music
        if 165 <= click_pos[0] <= 210 and 190 <= click_pos[1] <= 235:
            self.music.pause()
        # stop the music the music
        if 215 <= click_pos[0] <= 260 and 190 <= click_pos[1] <= 235:
            self.music.stop()
        # play the music
        if 265 <= click_pos[0] <= 310 and 190 <= click_pos[1] <= 235:
            self.music.play()
        # skip to selected position on the progress bar
        if 10 <= click_pos[0] <= 310 and 160 <= click_pos[1] <= 185:
            self.music.set_pos(click_pos[0])
        return True

    def run(self):
        '''run method for drawing the screen to dispay'''
        mainloop = True
        while mainloop:
            # Limit frame speed to 30 FPS
            self.clock.tick(30)
            # draw interface to screen
            self.interface.player_interface(
                self.screen, self.book.get_title(), self.book.get_artist(),
                self.music.get_chapter() + 1, self.book.get_num_chapter(),
                self.book.get_chapter_playtime()[self.music.get_chapter()],
                self.music.get_pos(), self.book.get_cover())
            for event in pygame.event.get():
                if event.type == pygame.USEREVENT:
                    # start playing next chapter when a song ends
                    self.music.next_chapter()
                # wait for touchscreen pressed
                if event.type == pygame.MOUSEBUTTONDOWN:
                    # draw touchscreen feedback to screen
                    pygame.draw.circle(self.screen, YELLOW, pressed(), 10, 0)
                    # run functionalities
                    mainloop = self.on_click()
            # update display
            pygame.display.flip()