コード例 #1
0
ファイル: galrywidget.py プロジェクト: lijinhui/galry
 def process_interaction(self, event=None, args=None, do_update=None):
     """Process user interaction.
     
     This method is called after each user action (mouse, keyboard...).
     It finds the right action associated to the command, then the event 
     associated to that action.
     
     Arguments:
       * event=None: if None, the current event associated to the current
         user action is retrieved. Otherwise, an event can be directly
         passed here to force the trigger of any interaction event.
       * args=None: the arguments of the event if event is not None.
     
     """
     if event is None:
         # get current event from current user action
         event, args = self.get_current_event()
     
     prev_event = self.interaction_manager.prev_event
     
     # handle interaction mode change
     if event == 'SwitchInteractionMode':
         binding = self.switch_interaction_mode()
         log_info("Switching interaction mode to %s." % \
             binding.__class__.__name__)
     
     # process the interaction event
     self.interaction_manager.process_event(event, args)
     
     # raise a signal if there is one associated to the current event
     if event in self.events_to_signals:
         self.events_to_signals[event].emit(*args)
     
     # set cursor
     self.set_current_cursor()
     
     # clean current action (unique usage)
     self.user_action_generator.clean_action()
     
     # update the OpenGL view
     if do_update is None:
         do_update = (
             # (not isinstance(self, GalryTimerWidget)) and
             (event is not None or prev_event is not None))
             
     if do_update:
         self.updateGL()
コード例 #2
0
ファイル: galrywidget.py プロジェクト: ValrynMilly/galry
 def set_autodestruct(self, autodestruct=None):
     # by default, use global variable
     if autodestruct is None:
         # use the autodestruct option in command line by default
         autodestruct = "autodestruct" in sys.argv
         if autodestruct is False:
             global AUTODESTRUCT
             autodestruct = AUTODESTRUCT
     # option for autodestructing the window after a fixed number of
     # seconds: useful for automatic testing
     if autodestruct is True:
         # 3 seconds by default, if True
         global DEFAULT_AUTODESTRUCT
         autodestruct = DEFAULT_AUTODESTRUCT
     if autodestruct:
         log_info("window autodestruction in %d second(s)" % (autodestruct / 1000.0))
     self.autodestruct = autodestruct
コード例 #3
0
 def set_autodestruct(self, autodestruct=None):
     # by default, use global variable
     if autodestruct is None:
         # use the autodestruct option in command line by default
         autodestruct = "autodestruct" in sys.argv
         if autodestruct is False:
             global AUTODESTRUCT
             autodestruct = AUTODESTRUCT
     # option for autodestructing the window after a fixed number of 
     # seconds: useful for automatic testing
     if autodestruct is True:
         # 3 seconds by default, if True
         global DEFAULT_AUTODESTRUCT
         autodestruct = DEFAULT_AUTODESTRUCT
     if autodestruct:
         log_info("window autodestruction in %d second(s)" % (autodestruct / 1000.))
     self.autodestruct = autodestruct
コード例 #4
0
ファイル: tools.py プロジェクト: DBGray/galry
def find_best_size(font="segoe", size=32):
    """Find the closest font size in the existing font files."""
    filename = font + str(size)
    path = os.path.dirname(os.path.realpath(__file__))
    fnt = os.path.join(path, "%s.fnt" % filename)
    if os.path.exists(fnt):
        return size
    else:
        # we go through all .fnt files
        files = [file for file in os.listdir(path) if file.startswith(font) \
            and file.endswith('.fnt')]
        files.sort()
        # we take the largest existing size that is smaller to the requested
        # size
        newsize = 0
        for file in files:
            m = re.match(font + "([0-9]+)", file)
            if m:
                if int(m.group(1)) > size:
                    break
                newsize = int(m.group(1))
        log_info("font %s %d does not exist, loading size %d instead" % \
            (font, size, newsize))
        return newsize