示例#1
0
    def test_call_function(self):
        def function(sender, earg):
            assert sender == 'sender'
            earg.append('earg')

        handler = event.EventHandler(function)
        earg = []
        assert handler('sender', earg) == handler
        assert earg == ['earg']
示例#2
0
    def test_call_method(self):
        class Class(object):
            def method(self, sender, earg):
                assert sender == 'sender'
                earg.append('earg')

        handler = event.EventHandler(Class().method)
        earg = []
        assert handler('sender', earg) == handler
        assert earg == ['earg']
示例#3
0
    def __init__(self, name, **args):
        object.__init__(self)

        self.__name = name

        # Contains the args hash.
        self.__args = self.get_default_args(args)

        # Default the layer type to the Render type as
        # defined in the constants module
        self.__type = None
        self.set_type(args.get("type", constants.LAYER_TYPES[0]))

        # A set of arguments that is required before
        # the Layer can be launched.
        self.__req_args = set()

        # A list to store what this layer depends on.
        self.__depends = []

        # If this layer is embedded within a another layer
        # the parent value will point to that layer.
        self.__parent = None

        # Contains IO objects that are considered input.
        self.__input = {}

        # Contains IO objects that are considered output.
        self.__output = {}

        # A dictionary of environment variables to apply before execute.
        self.__env = {}
        self.__env.update(args.get("env", {}))

        # Children are unregistered layers that are executed
        # after the parent layer.
        self.__children = []

        # The default name of the service.
        self.__service = self.__args.get("service", "shell")

        # The current frame number.
        self.__frame = None

        # Initialize the outline instance.
        self.__outline = None

        # Register an event handler.
        self.__evh = event.EventHandler(self)

        # Keep an array of all pre-process frames.
        self.__preprocess_layers = []

        logger.debug("module %s loaded from %s" %
                     (self.__class__.__name__, os.path.realpath(__file__)))
示例#4
0
 def handle_check(self, event):  # wxGlade: main_wx.<event_handler>
     city = self.choice_1.GetSelection()
     pref_venues = self.text_ctrl_2.GetLineText(0)
     movie = self.text_ctrl_1.GetLineText(0)
     date = self.datepicker_ctrl_1.GetValue()
     ev_id = self.list_ctrl_1.Append([
         len(self.event_handlers),
         self.choice_1.GetString(city), pref_venues, movie,
         date.Format('%Y%m%d')
     ])
     ev = evh.EventHandler(self, len(self.event_handlers), city,
                           pref_venues, movie, date)
     ev.start()
     self.event_handlers.append(ev)
     event.Skip()
示例#5
0
    def __init__(self, event_config, control_opts={}):
        '''
        base class initializer, creates an `event.EventHandler` as 
        `self.event_handler` and a `control.EventController` as 
        `self.event_controller

        event_config -- A dictionary containing keyword arugments for the
                        EventHandler
        control_opts -- a dict of opts for `control.EventController` init
        '''

        # Get an EventHandler and an EventController
        self.event_handler = event.EventHandler(**event_config)
        self.event_controller = control.EventController(
            self.event_handler, **control_opts)

        # Add an exit thread for the module
        self._exit = threading.Event()
        self._exit.clear()

        logging.info('Created base handler.')
示例#6
0
    def newGame(self):
        """Sets up a brand new game"""
        my.map = map.Map()
        my.map.completeGen()
        my.camera = map.Camera()
        my.eventHandler = event.EventHandler()

        my.resources = {}
        for resourceName in my.STARTRESOURCES.keys():
            my.resources[resourceName] = my.STARTRESOURCES[resourceName]
            my.RESOURCENAMEORDER = ['wood', 'coal', 'iron', 'gold', 'ingot'
                                    ]  # displayed on the screen at all times

        # HUMANS FOR TESTING
        for i in range(6):
            human = mob.Human((int(my.MAPXCELLS / 2), int(my.MAPYCELLS / 2)))
            human.destination = (random.randint(
                int(my.MAPXCELLS / 2) - 5,
                int(my.MAPXCELLS / 2) + 5),
                                 random.randint(
                                     int(my.MAPYCELLS / 2) - 5,
                                     int(my.MAPYCELLS / 2) + 5))

        # UNCOMMENT LINES BELOW TO ADD SOME MORE ENTITIES
        # WARNING: MOST OF THESE FEATURES ARE INCOMPLETE OR BUGGY

        # for i in range(1):
        # 	mob.DeathWolf((random.randint(int(my.MAPXCELLS / 2) - 5, int(my.MAPXCELLS / 2) + 5),
        # 						random.randint(int(my.MAPYCELLS / 2) - 5, int(my.MAPYCELLS / 2) + 5)))
        #for i in range(2):
        #	mob.Enemy((int(my.MAPXCELLS / 2 - 20), int(my.MAPYCELLS / 2 + 0)))
        #for i in range(6):
        #	item.Sword(1, (random.randint(int(my.MAPXCELLS / 2) - 5, int(my.MAPXCELLS / 2) + 5),
        #			   random.randint(int(my.MAPYCELLS / 2) - 5, int(my.MAPYCELLS / 2) + 5)))

        mission.initMissions(0)
示例#7
0
    def __init__(self,
                 animate_gifs=False,
                 fullscreen=False,
                 show_library=False,
                 open_path=None,
                 open_page=1):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)

        # ----------------------------------------------------------------
        # Attributes
        # ----------------------------------------------------------------
        self.is_fullscreen = False
        self.is_double_page = False
        self.is_manga_mode = False
        self.is_virtual_double_page = False  # I.e. a wide image is displayed
        self.zoom_mode = preferences.ZOOM_MODE_BEST
        self.width = None
        self.height = None

        self._manual_zoom = 100  # In percent of original image size
        self._waiting_for_redraw = False

        self.file_handler = filehandler.FileHandler(self)
        self.thumbnailsidebar = thumbbar.ThumbnailSidebar(self)
        self.statusbar = status.Statusbar()
        self.slideshow = slideshow.Slideshow(self)
        self.cursor_handler = cursor.CursorHandler(self)
        self.enhancer = enhance.ImageEnhancer(self)
        self.glass = lens.MagnifyingGlass(self)
        self.ui_manager = ui.MainUI(self)
        self.menubar = self.ui_manager.get_widget('/Menu')
        self.toolbar = self.ui_manager.get_widget('/Tool')
        self.popup = self.ui_manager.get_widget('/Popup')
        self.actiongroup = self.ui_manager.get_action_groups()[0]
        self.left_image = gtk.Image()
        self.right_image = gtk.Image()

        self._image_box = gtk.HBox(False, 2)
        self._main_layout = gtk.Layout()
        self._event_handler = event.EventHandler(self)
        self._vadjust = self._main_layout.get_vadjustment()
        self._hadjust = self._main_layout.get_hadjustment()
        self._vscroll = gtk.VScrollbar(self._vadjust)
        self._hscroll = gtk.HScrollbar(self._hadjust)

        # ----------------------------------------------------------------
        # Setup
        # ----------------------------------------------------------------
        self.set_title('Comix')
        self.set_size_request(300, 300)  # Avoid making the window *too* small
        self.resize(prefs['window width'], prefs['window height'])

        # This is a hack to get the focus away from the toolbar so that
        # we don't activate it with space or some other key (alternative?)
        self.toolbar.set_focus_child(
            self.ui_manager.get_widget('/Tool/expander'))
        self.toolbar.set_style(gtk.TOOLBAR_ICONS)
        self.toolbar.set_icon_size(gtk.ICON_SIZE_LARGE_TOOLBAR)

        self._image_box.add(self.left_image)
        self._image_box.add(self.right_image)
        self._image_box.show_all()

        self._main_layout.put(self._image_box, 0, 0)
        self.set_bg_colour(prefs['bg colour'])

        self._vadjust.step_increment = 15
        self._vadjust.page_increment = 1
        self._hadjust.step_increment = 15
        self._hadjust.page_increment = 1

        table = gtk.Table(2, 2, False)
        table.attach(self.thumbnailsidebar, 0, 1, 2, 5, gtk.FILL,
                     gtk.FILL | gtk.EXPAND, 0, 0)
        table.attach(self._main_layout, 1, 2, 2, 3, gtk.FILL | gtk.EXPAND,
                     gtk.FILL | gtk.EXPAND, 0, 0)
        table.attach(self._vscroll, 2, 3, 2, 3, gtk.FILL | gtk.SHRINK,
                     gtk.FILL | gtk.SHRINK, 0, 0)
        table.attach(self._hscroll, 1, 2, 4, 5, gtk.FILL | gtk.SHRINK,
                     gtk.FILL, 0, 0)
        table.attach(self.menubar, 0, 3, 0, 1, gtk.FILL | gtk.SHRINK, gtk.FILL,
                     0, 0)
        table.attach(self.toolbar, 0, 3, 1, 2, gtk.FILL | gtk.SHRINK, gtk.FILL,
                     0, 0)
        table.attach(self.statusbar, 0, 3, 5, 6, gtk.FILL | gtk.SHRINK,
                     gtk.FILL, 0, 0)

        if prefs['default double page']:
            self.actiongroup.get_action('double_page').activate()
        if prefs['default fullscreen'] or fullscreen:
            self.actiongroup.get_action('fullscreen').activate()
        if prefs['default manga mode']:
            self.actiongroup.get_action('manga_mode').activate()
        if prefs['default zoom mode'] == preferences.ZOOM_MODE_BEST:
            self.actiongroup.get_action('best_fit_mode').activate()
        elif prefs['default zoom mode'] == preferences.ZOOM_MODE_WIDTH:
            self.actiongroup.get_action('fit_width_mode').activate()
        elif prefs['default zoom mode'] == preferences.ZOOM_MODE_HEIGHT:
            self.actiongroup.get_action('fit_height_mode').activate()
        elif prefs['default zoom mode'] == preferences.ZOOM_MODE_MANUAL:
            # This little ugly hack is to get the activate call on
            # 'fit_manual_mode' to actually create an event (and callback).
            # Since manual mode is the default selected radio button action
            # it won't send an event if we activate it when it is already
            # the selected one.
            self.actiongroup.get_action('best_fit_mode').activate()
            self.actiongroup.get_action('fit_manual_mode').activate()
        if prefs['show toolbar']:
            prefs['show toolbar'] = False
            self.actiongroup.get_action('toolbar').activate()
        if prefs['show menubar']:
            prefs['show menubar'] = False
            self.actiongroup.get_action('menubar').activate()
        if prefs['show statusbar']:
            prefs['show statusbar'] = False
            self.actiongroup.get_action('statusbar').activate()
        if prefs['show scrollbar']:
            prefs['show scrollbar'] = False
            self.actiongroup.get_action('scrollbar').activate()
        if prefs['show thumbnails']:
            prefs['show thumbnails'] = False
            self.actiongroup.get_action('thumbnails').activate()
        if prefs['hide all']:
            prefs['hide all'] = False
            self.actiongroup.get_action('hide all').activate()
        if prefs['keep transformation']:
            prefs['keep transformation'] = False
            self.actiongroup.get_action('keep_transformation').activate()
        else:
            prefs['rotation'] = 0
            prefs['vertical flip'] = False
            prefs['horizontal flip'] = False
        prefs['animate'] = animate_gifs

        self.add(table)
        table.show()
        self._main_layout.show()
        self._display_active_widgets()

        self._main_layout.set_events(gtk.gdk.BUTTON1_MOTION_MASK
                                     | gtk.gdk.BUTTON2_MOTION_MASK
                                     | gtk.gdk.BUTTON_PRESS_MASK
                                     | gtk.gdk.BUTTON_RELEASE_MASK
                                     | gtk.gdk.POINTER_MOTION_MASK)
        self._main_layout.drag_dest_set(
            gtk.DEST_DEFAULT_ALL, [('text/uri-list', 0, 0)],
            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)

        self.connect('delete_event', self.terminate_program)
        self.connect('key_press_event', self._event_handler.key_press_event)
        self.connect('configure_event', self._event_handler.resize_event)
        self._main_layout.connect('button_release_event',
                                  self._event_handler.mouse_release_event)
        self._main_layout.connect('scroll_event',
                                  self._event_handler.scroll_wheel_event)
        self._main_layout.connect('button_press_event',
                                  self._event_handler.mouse_press_event)
        self._main_layout.connect('motion_notify_event',
                                  self._event_handler.mouse_move_event)
        self._main_layout.connect('drag_data_received',
                                  self._event_handler.drag_n_drop_event)

        self.ui_manager.set_sensitivities()
        self.show()
        if open_path is not None:
            self.file_handler.open_file(open_path, open_page)
        if show_library:
            self.actiongroup.get_action('library').activate()
示例#8
0
 def _addHandler(self, method):
     # Add the EventHandlers to our EventHandler list.
     if method.__name__ not in self._handlers:
         log.debug("_addHandler: " + method.__name__)
         self._handlers[method.__name__] = event.EventHandler(method)
示例#9
0
 def __init__(self, app):
     self.delegate = event.EventHandler(app)
示例#10
0
async def init_event_processor(app):
    app.web_req_buf = event.WebRequestBuffer(app)
    app.event_handler = event.EventHandler(app)
    event.run_epic_web_requests(app)
示例#11
0
import event

gWidth = 140
gHeight = 40
gEventHandler = event.EventHandler()