def _scroll_h(self, e: Event, x: int) -> None: if x == self.left: Event.trigger(Event(Event.SCROLL_LEFT, e.target)) elif y == self.right: Event.trigger(Event(Event.SCROLL_RIGHT, e.target)) else: Event.trigger( Event(Event.SCROLL_H, e.target, r=(x - self.left) / self.width))
def _scroll_v(self, e: Event, y: int) -> None: if y == self.top: Event.trigger(Event(Event.SCROLL_DOWN, e.target)) elif y == self.bottom: Event.trigger(Event(Event.SCROLL_UP, e.target)) else: r = (y - self.top - 1) / (self.height - 2) Event.trigger(Event(Event.SCROLL_V, e.target, r=r))
def _on_click(self, e: Event, x: int, y: int) -> None: Event.trigger(Event(Event.FOCUS_OUT, self.focus)) if not self._modal: for uid in reversed(self._z_stack): if self._windows[uid].contains(x, y): self.raise_to_top(uid) break Event.trigger(Event(Event.CLICK, self.focus, x=x, y=y)) Event.trigger(Event(Event.FOCUS_IN, self.focus))
def __init__(self, x=0, y=0, width=80): super().__init__(x, y, width) self._text = '' self._place_holder = ' ' * width self._max_len = width self._color = Color.INPUT_FIELD self.on(Event.FOCUS_IN, lambda _: Event.trigger(Event(Event.CURSOR_ON))) self.on(Event.FOCUS_OUT, lambda _: Event.trigger(Event(Event.CURSOR_OFF))) self.on(Event.KEY_BACKSPACE, self._on_key_backspace) self.on(Event.KEY_PRESSED, self._on_key_pressed)
def paint(self): self._window.border() self._window.refresh() self._window_manager.on_event(Event(Event.PAINT)) self._dirty = False
def get_zero_seven_events(sportName, season_year_start, season_year_end): conn = connect() season = Season(conn=conn, sportName=sportName, year_start=season_year_start, year_end=season_year_end) cursor = conn.cursor(buffered=True) query = ( "SELECT * FROM `Event` WHERE `seasonId` = '%s' AND `dateUTC` BETWEEN %s AND %s ORDER BY dateUTC ASC" ) cursor.execute(query, (season.seasonId, datetime.datetime.utcnow(), datetime.datetime.utcnow() + timedelta(days=7))) data = cursor.fetchall() events = [] if len(data) > 0: for i in data: events.append( Event(conn=conn, stubhubId=i[0], dateUTC=i[1], sportName=sportName, seasonName=season.name, teamId=i[2])) return events
def _on_linefeed_id(self, e: Event) -> None: Event.trigger( Event(Event.CLICK, self, x=self.left + self._field_passwd.left, y=self.top + self._field_passwd.top)) return self._field_id.value
def _on_text(self, e: Event, entity: str, who: str, text: str) -> None: words = text.split() if len(words): Event.trigger(Event(words[0], self, entity=entity, args=words[1:])) else: text = f'你要作什麼?' Channel.toRole(entity, Message.TEXT, text)
def _read(self, entity: str, socket: socket) -> None: for msg in InStream.instance(entity).read(socket): Event.trigger( Event( msg.type, self._servant, entity=entity, **msg.kwargs ) )
def _on_read(self, socket: socket, entity: str) -> None: msg_buffer = InStream.instance(entity).read(socket) for msg in msg_buffer: Event.trigger( Event(msg.type, Servant.instance(), entity=entity, **msg.kwargs))
def _on_click(self, e: Event, x: int, y: int) -> bool: for element in self.elements: if element.contains(x - self.x, y - self.y): Event.trigger(Event(Event.CLICK, element, x=x, y=y)) if element.focusable: self._focus = element break return False
def _on_click(self, e: Event, x: int, y: int) -> bool: for widget in self.components: if widget.contains(x - self.x, y - self.y): Event.trigger(Event(Event.CLICK, widget, x=x, y=y)) if widget.focusable: self._focus = widget break return False
def _on_sign_in( self, e: Event, entity: str, user_id: str = '', passwd: str = '' ) -> None: role = Stats.text('entity', user_id) Stats.update_text('binding', entity, role) room = Stats.text('at_room', role) Stats.list_append('guest', room, Link(entity, role)) text = f'歡迎來到 MUTE: Multi-User Texting Environment' Channel.to_role(entity, Message.SYSTEM, text) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
def create_new_event(event_creation_info: json): """ This function creates new event and saves it in the events dictionary :param event_creation_info: a json with info about the new event to create :return: pin code of the new event, None if error occurred """ try: new_event = Event(event_creation_info) pin_code = new_event.get_pin_code() AppEngine.events_dict[pin_code] = new_event return pin_code except KeyError: raise
def _on_sign_in(self, e: Event, entity: str, user_id: str = '', passwd: str = '') -> None: role = Role.instance(user_id, name=user_id) Name.instance(entity, name=role.name) Room.instance(role.room).enter(entity) text = f'歡迎來到 MUTE: Multi-User Texting Environment' Channel.toRole(entity, Message.SYSTEM, text) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
def _on_new_connection(self, socket: socket) -> None: connection, address = socket.accept() # Should be ready to read print(f'Connected by: {address}') connection.setblocking(False) mask = selectors.EVENT_READ | selectors.EVENT_WRITE entity = Entity.eid() self._multiplexer.register(connection, mask, entity) Event.trigger(Event(Event.RECEPTION, Servant.instance(), entity=entity))
def _check_input(self) -> None: try: e = self._window.get_wch() if e == 'q': Event.trigger(Event(Event.EXIT, self)) elif e == curses.KEY_MOUSE: _, x, y, _, _ = curses.getmouse() Event.trigger( Event(Event.CLICK, self._window_manager, x=x, y=y)) elif type(e) == str: LogCat.log(f'keypressed: {e}') # elif e > 0: Event.trigger( Event(Event.KEY_PRESSED, self._window_manager.focus, key=e)) else: Event.trigger(Event(e, self._window_manager.focus)) except curses.error: pass self._in_stream()
def _on_cmd_move( self, e: Event, entity: str = '', args: List[str] = [] ) -> None: role = Role.instance(entity) exit = Exit.instance(role.room) room = exit.to(e.type[0]) if None != room: Room.instance(role.room).leave(entity) Room.instance(room).enter(entity) role.enter(room) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity)) else: Channel.to_role(entity, Message.TEXT, f' 這裡沒有出口')
def _on_cmd_move( self, e: Event, entity: str = '', args: Sequence[str] = [] ) -> None: role = Stats.text('binding', entity) at = Stats.text('at_room', role) exit = Stats.text('exit', at) try: room = exit[e.type[0]] Stats.list_remove('guest', at, Link(entity, role)) Stats.update_text('at_room', role, room) Stats.list_append('guest', room, Link(entity, role)) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity)) except KeyError: Channel.to_role(entity, Message.TEXT, f' 這裡沒有出口')
def get_fifteen_up_to_collect(sportName, season_year_start, season_year_end, hour, minute): conn = connect() season = Season(conn=conn, sportName=sportName, year_start=season_year_start, year_end=season_year_end) cursor = conn.cursor(buffered=True) # First get team for this time slot query = ( "SELECT teamId FROM `Cron_Schedule` WHERE `seasonId`='%s' AND `time_hour` = '%s' AND `time_minute`= '%s'" ) cursor.execute(query, (season.seasonId, hour, minute)) data = cursor.fetchall() # If there is a team for this time, get their events that are 15 + days away events = [] if len(data) > 0: teamId = data[0][0] query = ( "SELECT * FROM `Event` WHERE teamId = '%s' AND `dateUTC` BETWEEN %s AND %s ORDER BY dateUTC ASC" ) cursor.execute( query, (teamId, datetime.datetime.utcnow() + timedelta(days=15), datetime.datetime.utcnow() + timedelta(days=250))) data = cursor.fetchall() for i in data: events.append( Event(conn=conn, stubhubId=i[0], dateUTC=i[1], sportName=sportName, seasonName=season.name, teamId=teamId)) return events
def createEvent( self, analyst, name=None, description=None, type: EventType = EventType.VERIFICATION_OF_FIXES, version=None, date=None, organizationName=None, securityClassificationTitleGuide=None, eventClassification: EventClassification = EventClassification. TOP_SECRET, classifiedBy=None, derivedFrom=None, declassificationDate=None, customerName=None, archiveStatus=None, eventTeam=None): event = Event( name=name, description=description, type=type, version=version, date=date, organizationName=organizationName, securityClassificationTitleGuide=securityClassificationTitleGuide, eventClassification=eventClassification, classifiedBy=classifiedBy, derivedFrom=derivedFrom, declassificationDate=declassificationDate, customerName=customerName, archiveStatus=archiveStatus, eventTeam=eventTeam) event.setId(self.updateEvent(analyst=analyst, event=event)) self.__event = event return
def insert_all_events(conn, sportName, seasonName, fileName): with open('game_schedules/%s/%s.csv' % (sportName, fileName), 'rU') as f: reader = csv.reader(f) reader.next() for row in reader: event = Event(conn=conn, stubhubId=row[3], sportName=sportName, seasonName=seasonName, teamId=row[0], teamCity=row[1], teamName=row[2], dateUTC=dparser.parse(row[4]), dateLocal=dparser.parse(row[5])) try: event.insert_event(conn) except: print("Error with inserting event %s - could be duplicate" % row[3])
def _on_dlg_cancel(self, e: Event) -> None: Event.trigger(Event(Event.EXIT, self))
def generate_empty_event(cls): return Event(Helpers.get_random_ip())
def test_add_different_events_to_ball(self): e1 = Event("source") self.ball.add(e1) e2 = Event("source") self.ball.add(e2) self.assertEqual(len(self.ball), 2)
def _in_stream(self) -> None: for msg in InStream.instance('').read(self._socket): Event.trigger(Event(msg.type, self, **msg.kwargs))
def _on_text(self, e: Event, entity: str, who: str, text: str) -> None: words = text.split() Event.trigger(Event(words[0], self, entity=entity, args=words[1:]))
def emit(self, event_type: str, event_values): event = Event(self.source_id(), event_type, event_values) EventManager().delegate(event)
def _on_linefeed_passwd(self, e: Event) -> None: Event.trigger(Event(Event.FOCUS_OUT, self)) Event.trigger(Event(Event.CLICK, self.button_ok, x=0, y=0)) return self._field_passwd.value
def _on_msg_sign_in(self, e: Event, who: str) -> None: Event.trigger( Event(Event.WIN_DISPLAY, self, uid=self._sign_in.uid, display=True))