示例#1
0
 def __init__(self):
     QWidget.__init__(self)
     self.setWindowTitle("Color Chooser")
     
     self.__mainLayout = QVBoxLayout()
     
     self.__buttonLayout = QVBoxLayout()
     self.__makeColorButtons()
     
     self.__controlLayout = QHBoxLayout()
     cancelButton = QPushButton("Cancel")
     cancelButton.clicked.connect(self.__cancelClicked)
     
     self.__controlLayout.addStretch(1)
     self.__controlLayout.addWidget(cancelButton)
     
     self.__mainLayout.addLayout(self.__buttonLayout)
     self.__mainLayout.addLayout(self.__controlLayout)
     
     self.setLayout(self.__mainLayout)
     self.__selectedColor = None
     
     self.connect(self, SIGNAL("tagPushButtonClicked(PyQt_PyObject)"), self.__colorClicked)
     
     self.ColorSelected = Event()
     self.CancelSelected = Event()
     
     self.show()
示例#2
0
    def addRecord(self, context_id: str, record_time: datetime, value: str,
                  attributes: str) -> State:

        state = State()

        state.state_id = None
        state.domain = self.__domain
        state.entity_id = self.__entity_id
        state.state = value
        state.attributes = attributes
        state.event_id = 0
        state.last_changed = record_time
        state.last_updated = record_time
        state.created = record_time
        state.context_id = None
        state.context_user_id = None

        if len(self.__event_state_history) > 0:
            state.old_state_id = self.__event_state_history[-1][1].state_id
        else:
            state.old_state_id = None

        event = Event()
        event.event_id = 0
        event.event_type = "state_changed"
        event.event_data = "{}"
        event.origin = "LOCAL"
        event.time_fired = record_time
        event.created = record_time
        event.context_id = context_id

        self.__event_state_history.append((event, state))

        return state
示例#3
0
    def __init__(self, maze, mice):
        self._maze = maze
        self.mice = mice

        self.current_tick = None
        self.num_ticks = None

        self.before_run = Event()
        self.after_run = Event()
        self.before_tick = Event()
        self.after_tick = Event()
示例#4
0
    def __init__(self, config, maze):
        self._logger = init_logger(self)
        self._config = config
        self._maze = maze
        self._training_mode = None

        self.id = 1
        self.location = None

        self.before_move = Event()
        self.after_move = Event()
示例#5
0
    def __init__(self, maze, mice):
        self.maze = maze
        self.mice = mice
        self.trial = Trial(self.maze, self.mice)

        self.train = None
        self.num_trials = None
        self.num_ticks = None

        self.before_experiment = Event()
        self.after_experiment = Event()
        self.before_trial = Event()
        self.after_trial = Event()
示例#6
0
    def handleEvent(self, event_p):
        #{{{
        #         print(event_p)
        # Create standardized event
        event = Event(event_p)

        # No event type, get out
        if event.type == None:
            return 0

        # Message event, pass to message handler
        elif event.type == "message":
            #{{{
            # Display user and their message
            if event.text:
                self.logger.log(DiagMessage("BOT0010U", event.user,
                                            event.text))
            response = self.msg_handler.act(event)

            # Send message if one was returned
            if response:
                util.sendMessage(event.channel, response, event.user)
                return 0
            # None response signals an update needed
            elif response == None:
                util.sendMessage(event.channel,
                                 "Shutting down for update. Kweh! :duckbot:")
                return 2
            # Otherwise do nothing
            else:
                return 0
        #}}}

        # Bot message event
        elif event.type == "bot_message":
            #{{{
            self.bot_handler.checkBotId(event.user)
            # Do something sassy with the bot
            if not self.cooldown_g:
                self.cooldown_g = 120
                self.bot_handler.act(event)
            return 0
        #}}}

        # Update event, respond based on the event subtype
        elif event.type == "update":
            #{{{
            # channel_purpose and channel_joined require channel list update
            if (event.subtype == "channel_purpose"
                    or event.subtype == "channel_joined"):
                self._channelListUpdate(event)
            return 0
        #}}}

        # Unhandled event type
        else:
            # Don't do anything right now
            return 0
示例#7
0
    def save(self, event: Event) -> int:

        insert_query = text(
            "insert into events (event_type, event_data, origin, time_fired, created, context_id) values (:event_type, :event_data, :origin, :time_fired, :created, :context_id)"
        )

        self.__connection.execute(insert_query, event.to_dict())

        select_query = text(EventDAO.__QUERY_BY_ENGINE["last_insert_id"][
            self.__connection.engine.name])

        result = self.__connection.execute(select_query)

        row = result.fetchone()

        event.event_id = row["event_id"]

        return event.event_id
示例#8
0
 def __init__(self, options):
     # Events: are binding sites for other classes sharing GenericInterface.
     # One class may in this way share its status with another class.
     events = getattr(options, "events", [])
     self.events = {}
     for each in events:
         self.events[each] = Event()
         self.events[each].append((lambda a, b: lambda *c: console.log(
             "Event [{}] triggered by {}".format(a, b), c))(
                 each, self.__class__.__name__))
示例#9
0
    def load(self, event_id: int) -> Event:

        query = text(f"select * from events where event_id={event_id}")

        result = self.__connection.execute(query)

        row = result.fetchone()

        res = Event.create(dict(row))

        return res
示例#10
0
    def setup(self):

        # load blue alliance key
        with open('tba/key.txt', 'r') as keyfile:
            self.tba_key = keyfile.readline().rstrip('\n')

        self.tba_wrapper = BlueAllianceWrapper(self.tba_key)

        self.elo = FRCElo(qm_K=20, fm_K=5, new_team_rating=1350, init_stdev=50)
        self.process_previous_years()

        ev_dicts = self.tba_wrapper.get_year_events(self.current_year)
        self.events = OrderedDict()
        for ev_dict in ev_dicts:
            event_code = self.current_year_str + ev_dict['event_code']
            self.events[event_code] = Event(event_code, self.elo,
                                            self.tba_wrapper)
示例#11
0
 def listUsers(self, dest):
     users = self.channels.get(dest)
     if users:
         if len(users) > 2:
             msg = "Users listening to (%s): %%s" % dest
             title = "Users listening to (%s)" % dest
             items = [USER_ITEM % (u.id, u.getName()) for u in users]
             pastehelper(SteamIRCBotWrapper(Event(None, target=dest),
                                            self.container, self),
                         msg,
                         items=items,
                         altmsg="%s",
                         title=title)
         else:
             for u in users:
                 self.ircSay(dest, USER_ITEM % (u.id, u.getName()))
     else:
         self.ircSay(dest, "No one listening in here.")
示例#12
0
    def steamCMD(self, sourceid, msg):
        #stolen from dispatcher
        command, argument = commandSplit(msg)
        command = command[len(self.cmdprefix):].lower()
        u = self.getUser(sourceid)
        # TODO: Someone should clean this up a bit... probably.
        if command == "listen":
            if not argument:
                if not u or not u.channels:
                    return self.steamSay(
                        sourceid,
                        'Not listening to any channels. Type "listen <#channelname>" to start snooping.'
                    )
                else:
                    return self.steamSay(
                        sourceid, "Listening to:%s\n" % "\n".join(u.channels))
            else:
                if argument not in self.container.state.channels:
                    return self.steamSay(
                        sourceid, "Can't listen to channel I'm not in.")
                #else listen to channel
                else:
                    u.channels.add(argument)
                    self.channels.setdefault(argument, set([])).add(u)
                    self.ircSay(argument,
                                START_SNOOP % (u.getName(), argument))
                    self.steamSay(sourceid, "Listening to (%s)" % argument)
                    backlog = self.channelbacklog.get(argument, [])
                    if backlog: self.steamSay(sourceid, "\n".join(backlog))
                    return
        elif command == "leave":
            if not argument:
                if not u or not u.channels:
                    return self.steamSay(
                        sourceid,
                        'Not listening to any channels. Type "listen <#channelname>" to start snooping.\n'
                        'and "leave <#channelname>" to leave "channelname", or just "leave" if you are only in a single channel.'
                    )
                else:
                    if len(u.channels) == 1:
                        return self.removeUserFromChannel(
                            u, next(iter(u.channels))
                        )  # to get item without .pop().next()
                    else:
                        return self.steamSay(
                            sourceid,
                            "I need to know what channel you want to stop listening to. You are listening to: (%s)."
                            'Use "leave #channelname" to leave the channel "channelname"'
                            % ", ".join(u.channels))
            else:
                if not u or not u.channels:
                    self.steamSay(
                        sourceid,
                        'Not listening to any channels. Type "listen <#channelname>" to start snooping.\n'
                        'and "leave <#channelname>" to leave "channelname", or just "leave" if you are only in a single channel.'
                    )
                else:
                    if argument not in u.channels:
                        return self.steamSay(
                            sourceid,
                            "You aren't listening to that channel. You are listening to: (%s)."
                            % ", ".join(u.channels))
                    else:
                        return self.removeUserFromChannel(u, argument)
        elif command == "quit" or command == "stop":
            if not u or not u.channels:
                return self.steamSay(
                    sourceid,
                    "You weren't listening to any channels. Bye bye.")
            else:
                for c in list(u.channels):
                    self.removeUserFromChannel(u, c)
                self.steamSay(sourceid, "Bye bye.")
        elif command == "help":
            return self.steamSay(
                sourceid,
                'Use "listen" to join channels. Type messages to me to relay them to a channel.\n'
                'If you are listening to multiple channels you need to prefix the target channel in your message e.g. "#channel hello".\n'
                'Use "leave" to stop listening to a channel. Use "quit" or "stop" to stop listening to all channels.\n'
                'To use my normal "help" function, use "hhelp". (Doesn\'t work yet...)'
            )
        elif command == "hhelp":
            msg.replace("hhelp", "help", 1)

        cont_or_wrap = None
        u = self.getUser(sourceid)
        event = None
        for mapping in self.cmdMap.get(command, ()):
            if not event:
                event = Event(None,
                              nick=u.getName(),
                              command=command,
                              argument=argument,
                              steamuser=u)
            if not cont_or_wrap:
                cont_or_wrap = SteamIRCBotWrapper(
                    event, self.container, self)  # event, botcont, steamchat
            # massive silliness
            reactor.callFromThread(
                self.container._settings.dispatcher._dispatchreally,
                mapping.function, event, cont_or_wrap)
            if mapping.priority == 0: break