def __init__(self, handle): super(PhysicsActivity, self).__init__(handle) self._collab = CollabWrapper(self) self._collab.message.connect(self.__message_cb) self.metadata['mime_type'] = 'application/x-physics-activity' self.add_events(Gdk.EventMask.ALL_EVENTS_MASK | Gdk.EventMask.VISIBILITY_NOTIFY_MASK) self.connect('visibility-notify-event', self._focus_event) self.connect('window-state-event', self._window_event) self.game = physics.main(self) self.game.canvas = sugargame.canvas.PygameCanvas( self, main=self.game.run, modules=[pygame.display, pygame.font]) self.preview = None self._sample_window = None self._notebook = Gtk.Notebook(show_tabs=False) self._notebook.add(self.game.canvas) w = Gdk.Screen.width() h = Gdk.Screen.height() - 2 * GRID_CELL_SIZE self.game.canvas.set_size_request(w, h) self._constructors = {} self.build_toolbar() self.set_canvas(self._notebook) Gdk.Screen.get_default().connect('size-changed', self.__configure_cb) self.show_all() self._collab.setup()
def _new_tube_cb(self, id, initiator, type, service, params, state): """ Create a new tube. """ debug_output( 'New tube: ID=%d initator=%d type=%d service=%s \ params=%r state=%d' % (id, initiator, type, service, params, state), self._tw.running_sugar) if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE): if state == telepathy.TUBE_STATE_LOCAL_PENDING: self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES]\ .AcceptDBusTube(id) self.collab = CollabWrapper(self) self.collab.message.connect(self.event_received_cb) self.collab.setup() # Now that we have the tube, we can ask for the turtle dictionary. if self.waiting_for_turtles: # A joiner must wait for turtles. debug_output('Sending a request for the turtle dictionary', self._tw.running_sugar) # We need to send our own nick, colors, and turtle position colors = self._get_colors() event = data_to_string([self._get_nick(), colors]) debug_output(event, self._tw.running_sugar) self.send_event("t", {"payload": event})
def _setup_collab(self): ''' Setup the Collab Wrapper. ''' self.initiating = None # sharing (True) or joining (False) self._collab = CollabWrapper(self) self._collab.connect('message', self.__message_cb) owner = self._collab._leader self.owner = owner self._game.set_sharing(True) self._collab.setup()
def __init__(self, activity): Gtk.VBox.__init__(self) self.collab = CollabWrapper(activity) self.collab.connect('message', self.__message_cb) self.collab.connect('joined', self.__joined_cb) self.view = View() self.view.connect("insert-char", self.__insert_char_cb) self.view.connect("cursor-position-changed", self.__cursor_position_changed_cb) self.view.connect("tag-applied", self.__tag_applied_cb) self.view.connect("tag-removed", self.__tag_removed_cb) self.pack_start(self.view, True, True, 0)
def __init__(self, file_path, url): GObject.GObject.__init__(self) logging.debug('websocket url %s', url) # base64 encode the file self._file = tempfile.TemporaryFile(mode='r+') base64.encode(open(file_path, 'r'), self._file) self._file.seek(0) self.buddies = {} self.collab = CollabWrapper(self) self.collab.message.connect(self._on_message) self.collab.setup() self._chunk = str(self._file.read(CHUNK_SIZE)) self.start()
def _new_tube_cb(self, id, initiator, type, service, params, state): """ Create a new tube. """ print('New tube: ID=%d initator=%d type=%d service=%s params=%r \ state=%d' % (id, initiator, type, service, params, state)) if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE): if state == telepathy.TUBE_STATE_LOCAL_PENDING: self.tubes_chan[ \ telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id) self.collab = CollabWrapper(self) self.collab.message.connect(self.event_received_cb) self.collab.setup() # Let the sharer know joiner is waiting for a hand. if self.waiting_for_hand: self.send_event("j", json_dump([self.nick, self.colors]))
def _new_tube_cb(self, id, initiator, type, service, params, state): ''' Create a new tube. ''' _logger.debug( 'Newtube: ID=%d initator=%d type=%d service=%s params=%r state=%d', id, initiator, type, service, params, state) if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE): if state == telepathy.TUBE_STATE_LOCAL_PENDING: self.tubes_chan[ \ telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id) self.collab = CollabWrapper(self) self.collab.message.connect(self.event_received_cb) self.collab.setup() # Let the sharer know a new joiner has arrived. if self.waiting_for_fraction: self.send_event( 'j', {"data": (json_dump([self.nick, self._colors]))})
def _new_tube_cb(self, id, initiator, type, service, params, state): ''' Create a new tube. ''' _logger.debug( 'New tube: ID=%d initator=%d type=%d service=%s ' 'params=%r state=%d', id, initiator, type, service, params, state) if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE): if state == telepathy.TUBE_STATE_LOCAL_PENDING: self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube( id) self.collab = CollabWrapper(self) self.collab.message.connect(self.event_received_cb) self.collab.setup() if self._waiting_for_reflections: self.send_event(JOIN_CMD, {}) self._joined_alert = Alert() self._joined_alert.props.title = _('Please wait') self._joined_alert.props.msg = _('Requesting reflections...') self.add_alert(self._joined_alert)
def __init__(self, handle): super(PhysicsActivity, self).__init__(handle) self._collab = CollabWrapper(self) self._collab.message.connect(self.__message_cb) self.metadata['mime_type'] = 'application/x-physics-activity' self.add_events(Gdk.EventMask.ALL_EVENTS_MASK | Gdk.EventMask.VISIBILITY_NOTIFY_MASK) self.connect('visibility-notify-event', self._focus_event) self.connect('window-state-event', self._window_event) self.game_canvas = sugargame.canvas.PygameCanvas(self) self.game = physics.main(self) self.preview = None self._sample_window = None self._fixed = Gtk.Fixed() self._fixed.put(self.game_canvas, 0, 0) w = Gdk.Screen.width() h = Gdk.Screen.height() - 2 * GRID_CELL_SIZE self.game_canvas.set_size_request(w, h) self._constructors = {} self.build_toolbar() self.set_canvas(self._fixed) Gdk.Screen.get_default().connect('size-changed', self.__configure_cb) logging.debug(os.path.join( activity.get_activity_root(), 'data', 'data')) self.game_canvas.run_pygame(self.game.run) self.show_all() self._collab.setup()
def __init__(self, handle): activity.Activity.__init__(self, handle) self._has_read_file = False self._collab = CollabWrapper(self) self._collab.message.connect(self.__message_cb) screen = Gdk.Screen.get_default() css_provider = Gtk.CssProvider.get_default() css_provider.load_from_path('style.css') context = Gtk.StyleContext() context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER) toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) activity_button.show() html = ToolButton('export-as-html') html.set_tooltip(_('Save as HTML')) html.connect('clicked', self.__export_as_html_cb) activity_button.props.page.insert(html, -1) html.show() abiword = ToolButton('export-as-abiword') abiword.set_tooltip(_('Save as a Write document')) abiword.connect('clicked', self.__export_as_abiword_cb) activity_button.props.page.insert(abiword, -1) abiword.show() add_button = AddToolButton(ALL_TYPE_NAMES) add_button.connect('add-type', self.__add_type_cb) toolbar_box.toolbar.insert(add_button, -1) add_button.show() browse = ToolButton('import-browse') browse.set_tooltip(_('Add Web Pages from Browse Entry')) browse.connect('clicked', self.__import_from_browse_cb) toolbar_box.toolbar.insert(browse, -1) browse.show() separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) separator.show() stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbar_box) toolbar_box.show() self._main_sw = Gtk.ScrolledWindow() self._main_sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS) self._main_sw.connect('key-press-event', self.__key_press_event_cb) self._main_list = MainList(self._main_sw, self._collab) self._main_list.connect('edit-row', self.__edit_row_cb) self._main_list.connect('deleted-row', self.__deleted_row_cb) self._main_sw.add(self._main_list) self._main_list.show() self._empty_message = EmptyMessage() self.set_canvas(self._empty_message) self._empty_message.show() self._collab.setup()
def __init__(self, handle): ''' Initialize the toolbars and the gnuchess ''' try: super(GNUChessActivity, self).__init__(handle) except dbus.exceptions.DBusException as e: _logger.error(str(e)) self.game_data = None self.playing_white = True self.playing_mode = 'easy' self.playing_robot = True self.showing_game_history = False self._restoring = True self.stopwatch_running = False self.time_interval = None self.timer_panel_visible = False self.nick = profile.get_nick_name() if profile.get_color() is not None: self.colors = profile.get_color().to_string().split(',') else: self.colors = ['#A0FFA0', '#FF8080'] self.buddy = None self.opponent_colors = None self.hardware = get_hardware() self._setup_toolbars() self._setup_dispatch_table() # Create a canvas canvas = Gtk.DrawingArea() canvas.set_size_request(Gdk.Screen.width(), Gdk.Screen.height()) self.set_canvas(canvas) canvas.show() self.show_all() self.old_cursor = self.get_window().get_cursor() self._gnuchess = Gnuchess(canvas, parent=self, path=activity.get_bundle_path(), colors=self.colors) self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb) self._restoring = False self.collab = CollabWrapper(self) self.collab.connect('message', self._message_cb) self.collab.connect('joined', self._joined_cb) self.collab.setup() # Send the nick to our opponent if not self.collab.props.leader: self.send_nick() # And let the sharer know we've joined self.send_join() if self.game_data is not None: # 'saved_game' in self.metadata: self._restore() else: self._gnuchess.new_game()