Beispiel #1
0
    def manageEvent(self, event):
        # Traversing down the events tree. We receieved an event from the parent NavigationViewController.
        # We need to now pass this even down the tree to the corresponding object that the mouse landed on or whatnot.
        for subView in self.subViews:                                                      # Loop Through each SubView that is LISTENING for events.
            if self.isVisible:                                                                      # Ensure this view is visible (It should be if we've already come this far)
                outside = False                                                                     # Some pre-variable for later reference
                mouse = event.pos                                                                       # Get the mouse Position
                if mouse[0] > subView.rect.topleft[0]:                                                  # Check the mouse position in regards to the subView's rectangle.
                    if mouse[1] > subView.rect.topleft[1]:
                        if mouse[0] < subView.rect.bottomright[0]:
                            if mouse[1] < subView.rect.bottomright[1]:
                                # noticer("Mouse within bounds", 0, subView)                                  # Mouse is within the bounds
                                # It's easier to ask forgiveness than to ask permission.                    # Catching exceptions is key here, in case the subView doesn't have a callback method implemented
                                try:
                                    subView.manageEvent(event, self, True)                                      # Method exists, and was used.
                                except (AttributeError, TypeError):
                                    noticer("Method manageEvent() does not exist when inside", 1, subView)                  # Method does not exist.  What now?
                            else:
                                outside = True                                                       # Move back down the tree, setting the outside variable to True if the mouse is outside.
                        else:
                            outside = True
                    else:
                        outside = True
                else:
                    outside = True

                if outside == True:                                                                 # Mouse is outside, Try send the callback method again, except with the parameter inside = False (This fixes mousebuttonups)
                    try:
                        subView.manageEvent(event, self, False)
                    except (AttributeError, TypeError):
                        noticer("Method manageEvent() does not exist when outside", 1, subView)
Beispiel #2
0
 def userCallback(self, event, caller, withinBounds):
     # Method to run the users custom callback. This will catch fatal exceptions (luckily)
     try:
         self.actions(self, event, caller, withinBounds)
         # Method exists, and was used.
     except (AttributeError, TypeError):
         # Method does not exist.  What now?
         noticer("Method self.actions() does not exist", 2, self)
Beispiel #3
0
 def updateView(self):
     # this method basically:
     #   1. Wipes the canvas clean
     #   2. Blits each subView to the canvas, in order that they are in in the list AND only if they are Visible (Saves memory this way)
     #   3. Blits the canvas to the screen
     noticer("Updating Navigation Controller", 0, self)
     self.canvas.fill(self.backgroundcolor)
     for subView in self.subViews:
         if subView['object'].isVisible:
             self.canvas.blit(subView['object'].canvas, (0, 0))
     self.screen.blit(self.canvas, (0, 0))
Beispiel #4
0
 def makeKeyAndVisible(self, identifier):
     # This method is needed to bring a subView/viewController to the front. It re-organises the subViews list.
     i = 0                                                       # Set a counter for the loop
     found = False                                               # Set some defaults
     views = copy.copy(self.subViews)                            # Make a copy of the subViews array so we can modify it without f*****g everything up
     while i < len(views):                                       # Loopy
         if (views[i]['identifier'] == identifier):                  # Check if the identifier we're looking for is this object
             obj = self.subViews.pop(i)                                  # Remove the object from the middle/top of the array, and get it
             obj['object'].isVisible = True                              # Tell the subView of the object that it is now visible on screen (fixes issues with listening for events - listening for objects that are not on screen)
             self.subViews.append(obj)                                   # Re-append the object to the end
             found = True                                                # For later use, say that we did find a view
             break                                                       # Break the loop, we found the one we need, no need to do any more finding. Don't work the processor too hard
         else:                                                       # Didnt find the object for the identifier :(
             self.subViews[i]['object'].isVisible = False                # Seeing as this isn't the object we're looking for, let's tell it that no, it's no longer visible
         i += 1                                                      # Loop increment
     if found != True:                                          # Check to see if we did find one
         noticer("The ViewController with identifier" + identifier + " was not found", 2, self)  # Warn the console and log that we didn't find anything
         # Because we did tell everything to disable itself for interactions, we need to give the top level one interactivity again.
         topView = copy.copy(self.subViews)                          # Get the SubViews Array
         top = topView.pop()                                         # Get the last item in the array (The one that is showing)
         top['object'].isVisible = True                              # Tell the object that it is still visible (because we told it earlier that it wasn't)
     self.updateView()                                          # Now that everything is basically over, update this navigationController, with the new arrangement of subViews