def __init__(self, handle): activity.Activity.__init__(self, handle) self.set_title('SocialCalc') self._logger = logging.getLogger('OnePageWiki-Activity') # The XOCom object helps us communicate with the browser # This uses web/index.html as the default page to load self.xocom = XOCom(self.control_sending_text) #REMEMBER THAT I HAVE STILL TO SEND THE ARGUMENT IN THE XOCOM CLASS toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.show() ##self.xocom.send_to_browser_localize(['initlocalize']) self.set_canvas( self.xocom.create_webview() ) self.hellotube = None # Shared session #REQUIRED self.initiating = False self.pservice = presenceservice.get_instance() owner = self.pservice.get_owner() self.owner = owner self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb) self.filename='' #ADDED SPECIFICALLY TO CALL WRITE AND READ METHODS self.content='' #calling to initialize strings in localization #should wait for init complete from browser gobject.timeout_add(4000, self.xocom.send_to_browser_localize,['initlocalize'])
def __init__(self, handle): sugar.activity.activity.Activity.__init__(self, handle) self.set_title(_("Typing Turtle")) self.build_toolbox() self.screens = [] self.screenbox = gtk.VBox() self.owner = presenceservice.get_instance().get_owner() # All data which is saved in the Journal entry is placed in this dictionary. self.data = { 'motd': 'welcome', 'level': 0, 'history': [], 'medals': {} } if DEBUG_LESSONS: self.data['level'] = 1000 # This has to happen last, because it calls the read_file method when restoring from the Journal. self.set_canvas(self.screenbox) # Start with the main screen. self.mainscreen = mainscreen.MainScreen(self) self.push_screen(self.mainscreen) self.show_all() # Hide the sharing button from the activity toolbar since we don't support sharing. activity_toolbar = self.tbox.get_activity_toolbar() activity_toolbar.share.props.visible = False
def __init__(self, handle, *args, **kwargs): ''' Initialize the ShareableActivity class. Kwargs: service_path ''' activity.Activity.__init__(self, handle, *args, **kwargs) self._sync_hid = None self._message_cbs = {} self._connection = None self._tube_conn = None self._pservice = presenceservice.get_instance() self._owner = self._pservice.get_owner() self._owner_id = str(self._owner.props.nick) self._service_path = kwargs.get('service_path', self._generate_service_path()) self._dbus_object = None _logger.debug('Setting service name %s, service path %s', \ IFACE, self._service_path) self._connect_to_ps()
def _get_buddy(self, cs_handle): """Get a Buddy from a (possibly channel-specific) handle.""" # XXX This will be made redundant once Presence Service # provides buddy resolution from sugar.presence import presenceservice # Get the Presence Service pservice = presenceservice.get_instance() # Get the Telepathy Connection tp_name, tp_path = pservice.get_preferred_connection() conn = Connection(tp_name, tp_path) group = self._text_chan[CHANNEL_INTERFACE_GROUP] my_csh = group.GetSelfHandle() if my_csh == cs_handle: handle = conn.GetSelfHandle() elif group.GetGroupFlags() & \ CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES: handle = group.GetHandleOwners([cs_handle])[0] else: handle = cs_handle # XXX: deal with failure to get the handle owner assert handle != 0 return pservice.get_buddy_by_telepathy_handle( tp_name, tp_path, handle)
def __init__(self, handle): """ __init__ function initializes the variables needed """ self.chatbox = ChatBox() super(ChatStudioSelf, self).__init__(handle) self.entry = None root = self.make_root() self.set_canvas(root) root.show_all() self.entry.grab_focus() self.local_first_num = 0 self.local_second_num = 0 self.limit_num = 50 self.calculated_sum = 0 self.calculated_diff = 0 self.second_attempt_flag = False self.metadata_dict = {} self.mode_of_game = "" self.game_metadata = False self.difficulty_level = "Easy" self.first_come_check = 0 self.create_toolbar() self.entry.set_sensitive(False) pservice = presenceservice.get_instance() self.owner = pservice.get_owner() # Chat is room or one to one: self._chat_is_room = False
def __init__(self): gtk.ScrolledWindow.__init__(self) self.owner = presenceservice.get_instance().get_owner() # Auto vs manual scrolling: self._scroll_auto = True self._scroll_value = 0.0 self._last_msg_sender = None # Track last message, to combine several messages: self._last_msg = None self._chat_log = '' self._conversation = gtk.VBox() self._conversation.set_homogeneous(False) self._conversation.props.spacing = style.LINE_WIDTH self._conversation.props.border_width = style.LINE_WIDTH evbox = gtk.EventBox() evbox.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) evbox.add(self._conversation) self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.add_with_viewport(evbox) vadj = self.get_vadjustment() vadj.connect('changed', self._scroll_changed_cb) vadj.connect('value-changed', self._scroll_value_changed_cb)
def __init__(self): gtk.ScrolledWindow.__init__(self) self.owner = presenceservice.get_instance().get_owner() # Auto vs manual scrolling: self._scroll_auto = True self._scroll_value = 0.0 self._last_msg_sender = None # Track last message, to combine several messages: self._last_msg = None self._chat_log = '' self._conversation = gtk.VBox() self._conversation.set_homogeneous(False) self._conversation.props.spacing = style.LINE_WIDTH self._conversation.props.border_width = style.LINE_WIDTH evbox = gtk.EventBox() #evbox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#00FFFF')) evbox.add(self._conversation) self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.add_with_viewport(evbox) vadj = self.get_vadjustment() vadj.connect('changed', self._scroll_changed_cb) vadj.connect('value-changed', self._scroll_value_changed_cb)
def _new_instance(self): if self._first_time: # self.voices.connect('changed', self.__changed_voices_cb) self.pitchadj.connect('value_changed', self._pitch_adjusted_cb, self.pitchadj) self.rateadj.connect('value_changed', self._rate_adjusted_cb, self.rateadj) if self._active_number_of_eyes is None: self._number_of_eyes_changed_event_cb(None, None, 'two', True) if self._active_eyes is None: self._eyes_changed_event_cb(None, None, 'eyes', True) self._mouth_changed_cb(None, True) self.face.look_ahead() presenceService = presenceservice.get_instance() self.owner = presenceService.get_owner() if self._first_time: # say hello to the user if self._tablet_mode: self._entry.props.text = _('Hello %s.') \ % self.owner.props.nick.encode('utf-8', 'ignore') self.face.say_notification(_('Hello %s. Please Type something.') % self.owner.props.nick) else: if self._tablet_mode: self._entry.props.text = _('Welcome back %s.') \ % self.owner.props.nick.encode('utf-8', 'ignore') self.face.say_notification(_('Welcome back %s.') % self.owner.props.nick) self._set_idle_phrase(speak=False) self._first_time = False
def add_buddy(self, buddy): """ Passes buddy nick to ovc """ if buddy == presenceservice.get_instance().get_owner(): return if buddy: nick = buddy.props.nick else: nick = '???' self.__activity.net_cb('buddy_add', nick)
def _send_invites(self): while self._invites_queue: account_path, contact_id = self._invites_queue.pop() pservice = presenceservice.get_instance() buddy = pservice.get_buddy(account_path, contact_id) if buddy: self.shared_activity.invite(buddy, '', self._invite_response_cb) else: logging.error('Cannot invite %s %s, no such buddy', account_path, contact_id)
def init_mesh(main_log): global log log = main_log # get the Presence Service pservice = presenceservice.get_instance() # Buddy object for you owner = pservice.get_owner() olpcgames.ACTIVITY.connect("shared", _shared_cb) olpcgames.ACTIVITY.connect("joined", _joined_cb)
def __init__(self, activity, buddy_joined_cb, buddy_left_cb, play_cb, undostack, bootstrap): self.activity = activity self.buddy_joined = buddy_joined_cb self.buddy_left = buddy_left_cb self.Play_cb = play_cb self.undostack = undostack self.bootstrap = bootstrap self.world = False self.entered = False self.presence_service = presenceservice.get_instance() self.owner = self.presence_service.get_owner()
def _send_invites(self): while self._invites_queue: account_path, contact_id = self._invites_queue.pop() pservice = presenceservice.get_instance() buddy = pservice.get_buddy(account_path, contact_id) if buddy: self.shared_activity.invite( buddy, '', self._invite_response_cb) else: logging.error('Cannot invite %s %s, no such buddy', account_path, contact_id)
def _setup_presence_service(self): ''' Setup the Presence Service. ''' self.pservice = presenceservice.get_instance() self.initiating = None # sharing (True) or joining (False) owner = self.pservice.get_owner() self.owner = owner self.buddies = [owner] self._share = '' self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb)
def setup(self): # TODO: hand off role of master if sharer leaves self.pservice = presenceservice.get_instance() self.initiating = None # sharing (True) or joining (False) # Add my buddy object to the list owner = self.pservice.get_owner() self.owner = owner self._tw.buddies.append(self.owner) self._share = '' self._activity.connect('shared', self._shared_cb) self._activity.connect('joined', self._joined_cb)
def _setup(self): # sets up the tubes... if not self.activity.get_shared_activity(): logger.error('_setup: Failed to share or join activity') return pservice = presenceservice.get_instance() try: name, path = pservice.get_preferred_connection() self._connection = telepathy.client.Connection(name, path) except: logger.error('_setup: Failed to get_preferred_connection') # Work out what our room is called and whether we have Tubes already bus_name, conn_path, channel_paths = self.activity._shared_activity.get_channels( ) room = None tubes_chan = None text_chan = None for channel_path in channel_paths: channel = telepathy.client.Channel(bus_name, channel_path) htype, handle = channel.GetHandle() if htype == telepathy.HANDLE_TYPE_ROOM: logger.debug( 'Found our room: it has handle#%d "%s"', handle, self._connection.InspectHandles(htype, [handle])[0]) room = handle ctype = channel.GetChannelType() if ctype == telepathy.CHANNEL_TYPE_TUBES: logger.debug('Found our Tubes channel at %s', channel_path) tubes_chan = channel elif ctype == telepathy.CHANNEL_TYPE_TEXT: logger.debug('Found our Text channel at %s', channel_path) text_chan = channel if not room: logger.error("Presence service didn't create a room") return if not text_chan: logger.error("Presence service didn't create a text channel") return # Make sure we have a Tubes channel - PS doesn't yet provide one if not tubes_chan: logger.debug("Didn't find our Tubes channel, requesting one...") tubes_chan = self._connection.request_channel( telepathy.CHANNEL_TYPE_TUBES, telepathy.HANDLE_TYPE_ROOM, room, True) self._tubes_channel = tubes_chan[telepathy.CHANNEL_TYPE_TUBES] self._text_channel = text_chan[telepathy.CHANNEL_INTERFACE_GROUP] self._tubes_channel.connect_to_signal('NewTube', self._new_tube_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) self._name = handle self.metadata['mime_type'] = 'application/x-kandid-activity' self._print_greetings(handle) self._status = ka_status.Status.instance() self._joined_buddies = set([]) self._new_tubes = [] # Set title for our Activity self.set_title('Kandid') # Attach sugar toolbox (Share, ...) try: # try sugar 0.86 ka_debug.info('searching sugar 0.86, sugar.graphics.toolbarbox') import sugar.graphics.toolbarbox toolbar_box = sugar.graphics.toolbarbox.ToolbarBox() self._add_toolbar_buttons(toolbar_box) self.set_toolbar_box(toolbar_box) except: ka_debug.err('failed sugar 0.86 toolbarbox [%s] [%s]' % \ (sys.exc_info()[0], sys.exc_info()[1])) traceback.print_exc(file=sys.__stderr__) # try sugar 0.82 toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) # Create the main container main_view = gtk.HBox() self._widget = ka_widget.KandidWidget() main_view.pack_start(self._widget.get_widget_tree()) # Create a controller to connect view and model self._controller = ka_controller.KandidController( \ self._widget, self.get_activity_root(), handle.object_id is None) self._controller.create_pages() self.set_canvas(main_view) self.kandidtube = None # Shared session self.initiating = False self.telepathy_conn = None self.tubes_chan = None self.text_chan = None # get the Presence Service self.pservice = presenceservice.get_instance() self._start_collaboration() self.show_all() if handle.object_id is None: self._controller.switch_page('GettingstartedController')
def _setup_presence_service(self): ''' Setup the Presence Service. ''' self.pservice = presenceservice.get_instance() self.initiating = None # sharing (True) or joining (False) owner = self.pservice.get_owner() self.owner = owner self.bounce_window.buddies.append(self.nick) self._player_colors = [self.colors] self._player_pixbuf = [svg_str_to_pixbuf( generate_xo_svg(scale=0.8, colors=self.colors))] self._share = '' self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb)
def _setup_presence_service(self): """ Setup the Presence Service. """ self.pservice = presenceservice.get_instance() self.initiating = None # sharing (True) or joining (False) owner = self.pservice.get_owner() self.owner = owner self._game.buddies.append(self.nick) self._player_colors = [self.colors] self._player_pixbuf = [svg_str_to_pixbuf( generate_xo(scale=0.8, colors=self.colors))] self._share = "" self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb)
def _setup(self): # sets up the tubes... if not self.activity.get_shared_activity(): logger.error('_setup: Failed to share or join activity') return pservice = presenceservice.get_instance() try: name, path = pservice.get_preferred_connection() self._connection = telepathy.client.Connection(name, path) except: logger.error('_setup: Failed to get_preferred_connection') # Work out what our room is called and whether we have Tubes already bus_name, conn_path, channel_paths = self.activity._shared_activity.get_channels() room = None tubes_chan = None text_chan = None for channel_path in channel_paths: channel = telepathy.client.Channel(bus_name, channel_path) htype, handle = channel.GetHandle() if htype == telepathy.HANDLE_TYPE_ROOM: logger.debug('Found our room: it has handle#%d "%s"', handle, self._connection.InspectHandles(htype, [handle])[0]) room = handle ctype = channel.GetChannelType() if ctype == telepathy.CHANNEL_TYPE_TUBES: logger.debug('Found our Tubes channel at %s', channel_path) tubes_chan = channel elif ctype == telepathy.CHANNEL_TYPE_TEXT: logger.debug('Found our Text channel at %s', channel_path) text_chan = channel if not room: logger.error("Presence service didn't create a room") return if not text_chan: logger.error("Presence service didn't create a text channel") return # Make sure we have a Tubes channel - PS doesn't yet provide one if not tubes_chan: logger.debug("Didn't find our Tubes channel, requesting one...") tubes_chan = self._connection.request_channel(telepathy.CHANNEL_TYPE_TUBES, telepathy.HANDLE_TYPE_ROOM, room, True) self._tubes_channel = tubes_chan[telepathy.CHANNEL_TYPE_TUBES] self._text_channel = text_chan[telepathy.CHANNEL_INTERFACE_GROUP] self._tubes_channel.connect_to_signal('NewTube', self._new_tube_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) self.max_participants = 10 # toolbar with the new toolbar redesign toolbar_box = ToolbarBox() activity_button = ActivityButton(self) toolbar_box.toolbar.insert(activity_button, 0) activity_button.show() title_entry = TitleEntry(self) toolbar_box.toolbar.insert(title_entry, -1) title_entry.show() share_button = ShareButton(self) toolbar_box.toolbar.insert(share_button, -1) share_button.show() stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() self.back_button = BackButton() self.back_button.connect('clicked', self.show_options1) toolbar_box.toolbar.insert(self.back_button, 0) self.back_button.show() self.set_toolbar_box(toolbar_box) toolbar_box.show() self.show_options() self._logger = logging.getLogger('hellomesh-activity') self.hellotube = None # Shared session self.initiating = False # get the Presence Service self.pservice = presenceservice.get_instance() # Buddy object for you owner = self.pservice.get_owner() self.owner = owner self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) self.max_participants = 10 # toolbar with the new toolbar redesign toolbar_box = ToolbarBox() activity_button = ActivityButton(self) toolbar_box.toolbar.insert(activity_button, 0) activity_button.show() title_entry = TitleEntry(self) toolbar_box.toolbar.insert(title_entry, -1) title_entry.show() share_button = ShareButton(self) toolbar_box.toolbar.insert(share_button, -1) share_button.show() stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() self.back_button = BackButton() self.back_button.connect("clicked", self.show_options1) toolbar_box.toolbar.insert(self.back_button, 0) self.back_button.show() self.set_toolbar_box(toolbar_box) toolbar_box.show() self.show_options() self._logger = logging.getLogger("hellomesh-activity") self.hellotube = None # Shared session self.initiating = False # get the Presence Service self.pservice = presenceservice.get_instance() # Buddy object for you owner = self.pservice.get_owner() self.owner = owner self.connect("shared", self._shared_cb) self.connect("joined", self._joined_cb)
def new_instance(self): self.voices.connect('changed', self.__changed_voices_cb) self.pitchadj.connect("value_changed", self.pitch_adjusted_cb, self.pitchadj) self.rateadj.connect("value_changed", self.rate_adjusted_cb, self.rateadj) self.mouth_shape_combo.connect('changed', self.mouth_changed_cb, False) self.mouth_changed_cb(self.mouth_shape_combo, True) self.numeyesadj.connect("value_changed", self.eyes_changed_cb, False) self.eye_shape_combo.connect('changed', self.eyes_changed_cb, False) self.eyes_changed_cb(None, True) self.face.look_ahead() # say hello to the user presenceService = presenceservice.get_instance() xoOwner = presenceService.get_owner() self.face.say_notification(_("Hello %s. Please Type something.") \ % xoOwner.props.nick)
def __map_event_cb(self, event, activity): logger.debug('__map_event_cb') # set custom keybindings for Write logger.debug("Loading keybindings") keybindings_file = os.path.join( get_bundle_path(), "keybindings.xml" ) self.abiword_canvas.invoke_cmd( 'com.abisource.abiword.loadbindings.fromURI', keybindings_file, 0, 0) # no ugly borders please self.abiword_canvas.set_property("shadow-type", gtk.SHADOW_NONE) # we only do per-word selections (when using the mouse) self.abiword_canvas.set_word_selections(True) # we want a nice border so we can select paragraphs easily self.abiword_canvas.set_show_margin(True) # activity sharing self.participants = {} pservice = presenceservice.get_instance() bus = dbus.Bus() name, path = pservice.get_preferred_connection() self.conn = telepathy.client.Connection(name, path) self.initiating = None self.joined = False self.connect('shared', self._shared_cb) if self._shared_activity: # we are joining the activity logger.debug("We are joining an activity") self.connect('joined', self._joined_cb) self._shared_activity.connect('buddy-joined', self._buddy_joined_cb) self._shared_activity.connect('buddy-left', self._buddy_left_cb) if self.get_shared(): # # oh, OK, we've already joined self._joined_cb() else: # we are creating the activity logger.debug("We are creating an activity") owner = pservice.get_owner()
def __got_channel_cb(self, wait_loop, connection_path, channel_path, handle_type): logging.debug('Activity.__got_channel_cb') pservice = presenceservice.get_instance() if handle_type == CONNECTION_HANDLE_TYPE_ROOM: connection_name = connection_path.replace('/', '.')[1:] bus = dbus.SessionBus() channel = bus.get_object(connection_name, channel_path) room_handle = channel.Get(CHANNEL, 'TargetHandle') mesh_instance = pservice.get_activity_by_handle( connection_path, room_handle) else: mesh_instance = pservice.get_activity(self._activity_id, warn_if_none=False) self._set_up_sharing(mesh_instance, SCOPE_PRIVATE) wait_loop.quit()
def share(self, private=False): """Request that the activity be shared on the network. private -- bool: True to share by invitation only, False to advertise as shared to everyone. Once the activity is shared, its privacy can be changed by setting its 'private' property. """ if self.shared_activity and self.shared_activity.props.joined: raise RuntimeError('Activity %s already shared.' % self._activity_id) verb = private and 'private' or 'public' logging.debug('Requesting %s share of activity %s.', verb, self._activity_id) pservice = presenceservice.get_instance() pservice.connect('activity-shared', self.__share_cb) pservice.share_activity(self, private=private)
def __got_channel_cb(self, wait_loop, connection_path, channel_path, handle_type): logging.debug('Activity.__got_channel_cb') pservice = presenceservice.get_instance() if handle_type == CONNECTION_HANDLE_TYPE_ROOM: connection_name = connection_path.replace('/', '.')[1:] bus = dbus.SessionBus() channel = bus.get_object(connection_name, channel_path) room_handle = channel.Get(CHANNEL, 'TargetHandle') mesh_instance = pservice.get_activity_by_handle(connection_path, room_handle) else: mesh_instance = pservice.get_activity(self._activity_id, warn_if_none=False) self._set_up_sharing(mesh_instance, SCOPE_PRIVATE) wait_loop.quit()
def __init__(self, activity, deck, work_path): gobject.GObject.__init__(self) self.__activity = activity self.__deck = deck self.__logger = logging.getLogger('Shared') self.__is_initiating = True # defaults to instructor self.__shared_slides = None self.__got_dbus_tube = False self.__locked = False self.__pservice = presenceservice.get_instance() #self.__owner = self.__pservice.get_owner() self.__cpxo_path = os.path.join(work_path, 'deck.cpxo') self.__activity.connect('shared', self.shared_cb) self.__activity.connect('joined', self.joined_cb)
def __init__(self, activity, deck, work_path): gobject.GObject.__init__(self) self.__activity = activity self.__deck = deck self.__logger = logging.getLogger('Shared') self.__is_initiating = True # defaults to instructor self.__shared_slides = None self.__got_dbus_tube = False self.__locked = False self.__pservice = presenceservice.get_instance() #self.__owner = self.__pservice.get_owner() self.__cpxo_path = os.path.join(work_path, 'deck.cpxo') print 'cpxo_path', self.__cpxo_path self.__activity.connect('shared', self.shared_cb) self.__activity.connect('joined', self.joined_cb)
def __init__(self, tube_class, service): """Set up the tubes for this activity.""" self.tube_class = tube_class self.service = service self.pservice = presenceservice.get_instance() #bus = dbus.Bus() name, path = self.pservice.get_preferred_connection() self.tp_conn_name = name self.tp_conn_path = path #self.conn = telepathy.client.Connection(name, path) self.game_tube = False self.initiating = None # Buddy object for you owner = self.pservice.get_owner() self.owner = owner self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb)
def __init__(self, arbiter, work_path): gobject.GObject.__init__(self) self.__arbiter = arbiter self.__logger = logging.getLogger('Shared') self.__logger.setLevel(logging.DEBUG) self.__sharing = False self.__shared_slides = None self.__got_dbus_tube = False self.__locked = False self.__pservice = presenceservice.get_instance() #self.__owner = self.__pservice.get_owner() self.__cpxo_path = os.path.join(work_path, 'deck.cpxo') self.__arbiter.connect_shared(self.shared_cb) self.__arbiter.connect_joined(self.joined_cb) self.__logger.debug('Hello from Shared. Waiting to become sharer or joiner.')
def __init__(self, buddy, file_name, title, description, mime_type): presence_service = presenceservice.get_instance() name, path = presence_service.get_preferred_connection() connection = Connection(name, path, ready_handler=self.__connection_ready_cb) BaseFileTransfer.__init__(self, connection) self.connect('notify::state', self.__notify_state_cb) self._file_name = file_name self._socket_address = None self._socket = None self._splicer = None self._output_stream = None self.buddy = buddy self.title = title self.file_size = os.stat(file_name).st_size self.description = description self.mime_type = mime_type
def create_activity_id(): """Generate a new, unique ID for this activity""" pservice = presenceservice.get_instance() # create a new unique activity ID i = 0 act_id = None while i < 10: act_id = util.unique_id() i += 1 # check through network activities found = False activities = pservice.get_activities() for act in activities: if act_id == act.props.id: found = True break if not found: return act_id raise RuntimeError("Cannot generate unique activity id.")
def __init__(self, activity): self._logger = logging.getLogger('GeoModel') self._logger.setLevel(constants.LOG_LEVEL) self.activity = activity self.activity.set_model(self) # Init the player list self.mynickname = profile.get_nick_name() self.pservice = presenceservice.get_instance() self.owner = self.pservice.get_owner() # create shared datastructure for players self.players = CausalDict(value_translator=player_translator) activity.cloud.players = self.players this_player = Player(self.mynickname) self.players[self.mynickname] = this_player #gobject.timeout_add(3000, self.print_dict) # only for debugging activity.connect('position_changed', this_player.set_position) self._logger.debug("INIT GEOSPACEMODEL DONE.")
def __init__(self): hippo.CanvasScrollbars.__init__(self) self.owner = presenceservice.get_instance().get_owner() # Auto vs manual scrolling: self._scroll_auto = True self._scroll_value = 0.0 self._last_msg_sender = None # Track last message, to combine several messages: self._last_msg = None self._chat_log = '' self._conversation = hippo.CanvasBox( spacing=0, background_color=COLOR_WHITE.get_int()) self.set_policy(hippo.ORIENTATION_HORIZONTAL, hippo.SCROLLBAR_NEVER) self.set_root(self._conversation) vadj = self.props.widget.get_vadjustment() vadj.connect('changed', self._scroll_changed_cb) vadj.connect('value-changed', self._scroll_value_changed_cb)
def _get_buddy(self, cs_handle): """Get a Buddy from a (possibly channel-specific) handle.""" # XXX This will be made redundant once Presence Service # provides buddy resolution # Get the Presence Service pservice = presenceservice.get_instance() # Get the Telepathy Connection tp_name, tp_path = pservice.get_preferred_connection() conn = Connection(tp_name, tp_path) group = self._text_chan[CHANNEL_INTERFACE_GROUP] my_csh = group.GetSelfHandle() if my_csh == cs_handle: handle = conn.GetSelfHandle() elif group.GetGroupFlags() & \ CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES: handle = group.GetHandleOwners([cs_handle])[0] else: handle = cs_handle # XXX: deal with failure to get the handle owner assert handle != 0 return pservice.get_buddy_by_telepathy_handle(tp_name, tp_path, handle)
def get_buddy(self, cs_handle): """Retrieve a Buddy object given a telepathy handle. cs_handle: A channel-specific CONTACT type handle. returns: sugar.presence Buddy object or None """ pservice = presenceservice.get_instance() if self.self_handle == cs_handle: # It's me, just get my global handle handle = self._conn.GetSelfHandle() elif self._group_iface.GetGroupFlags() & \ CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES: # The group (channel) has channel specific handles handle = self._group_iface.GetHandleOwners([cs_handle])[0] else: # The group does not have channel specific handles handle = cs_handle # deal with failure to get the handle owner if handle == 0: return None return pservice.get_buddy_by_telepathy_handle( self._conn.service_name, self._conn.object_path, handle)
def get_buddy(self, cs_handle): """Retrieve a Buddy object given a telepathy handle. cs_handle: A channel-specific CONTACT type handle. returns: sugar.presence Buddy object or None """ pservice = presenceservice.get_instance() if self.self_handle == cs_handle: # It's me, just get my global handle handle = self._conn.GetSelfHandle() elif self._group_iface.GetGroupFlags() & \ CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES: # The group (channel) has channel specific handles handle = self._group_iface.GetHandleOwners([cs_handle])[0] else: # The group does not have channel specific handles handle = cs_handle # deal with failure to get the handle owner if handle == 0: return None return pservice.get_buddy_by_telepathy_handle(self._conn.service_name, self._conn.object_path, handle)
def __init__(self, handle): activity.Activity.__init__(self, handle) self.glade_prefix = utils.get_glade_prefix() self._session_tag = self._get_session_tag() self._feedlist = None #feed_id, feed_info['title'], feed_info['url'] logging.debug("Activity ID: %s" % (str(self._session_tag),)) toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.show() logging.debug("Loading DB") self._db = ptvDB.ptvDB() newdb = self._db.maybe_initialize_db() if newdb: self._import_defaults() self._update_thread = None self.set_canvas(self._build_ui()) #self.connect('destroy', self.do_quit) self.newsreader_tube = None #shared activity self.initiating = None # I initiated the activity # get the Presence Service self.pservice = presenceservice.get_instance() # Buddy object for you self.owner = self.pservice.get_owner() self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb) self.connect('feed-polled', self._feed_polled_cb) gobject.idle_add(self._post_show_init, toolbox)
def __init__(self, handle): activity.Activity.__init__(self, handle) self.glade_prefix = utils.get_glade_prefix() self._session_tag = self._get_session_tag() self._feedlist = None #feed_id, feed_info['title'], feed_info['url'] logging.debug("Activity ID: %s" % (str(self._session_tag), )) toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.show() logging.debug("Loading DB") self._db = ptvDB.ptvDB() newdb = self._db.maybe_initialize_db() if newdb: self._import_defaults() self._update_thread = None self.set_canvas(self._build_ui()) #self.connect('destroy', self.do_quit) self.newsreader_tube = None #shared activity self.initiating = None # I initiated the activity # get the Presence Service self.pservice = presenceservice.get_instance() # Buddy object for you self.owner = self.pservice.get_owner() self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb) self.connect('feed-polled', self._feed_polled_cb) gobject.idle_add(self._post_show_init, toolbox)
def __init__(self, handle): # self.initiating indicates whether this instance has initiated sharing # it always starts false, but will be set to true if this activity # initiates sharing. In particular, if Activity.__init__ calls # self.share(), self.initiating will be set to True. self.initiating = False # self._processed_share indicates whether when_shared() has been called self._processed_share = False # self.initialized tracks whether the Activity's display is up and running self.initialized = False self.early_setup() super(GroupActivity, self).__init__(handle) self.dbus_name = self.get_bundle_id() self.logger = logging.getLogger(self.dbus_name) self._handle = handle ##gobject.threads_init() self._sharing_completed = not self._shared_activity self._readfile_completed = not handle.object_id if self._shared_activity: self.message = self.message_joining elif handle.object_id: self.message = self.message_loading else: self.message = self.message_preparing if OLD_TOOLBAR: self.toolbox = ActivityToolbox(self) self.set_toolbox(self.toolbox) self.toolbox.show() self.set_toolbox(self.toolbox) else: toolbar_box = ToolbarBox() self.activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(self.activity_button, 0) self.set_toolbar_box(toolbar_box) v = gtk.VBox() self.startup_label = gtk.Label(self.message) v.pack_start(self.startup_label) Window.set_canvas(self, v) self.show_all() # The show_all method queues up draw events, but they aren't executed # until the mainloop has a chance to process them. We want to process # them immediately, because we need to show the waiting screen # before the waiting starts, not after. exhaust_event_loop() # exhaust_event_loop() provides the possibility that write_file could # be called at this time, so write_file is designed to trigger read_file # itself if that path occurs. self.tubebox = groupthink.TubeBox() self.timer = groupthink.TimeHandler("main", self.tubebox) self.cloud = groupthink.Group(self.tubebox) # self.cloud is extremely important. It is the unified reference point # that contains all state in the system. Everything else is stateless. # self.cloud has to be defined before the call to self.set_canvas, because # set_canvas can trigger almost anything, including pending calls to read_file, # which relies on self.cloud. # get the Presence Service self.pservice = presenceservice.get_instance() # Buddy object for you owner = self.pservice.get_owner() self.owner = owner self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb) if self.get_shared(): if self.initiating: self._shared_cb(self) else: self._joined_cb(self) self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK) self.connect("visibility-notify-event", self._visible_cb) self.connect("notify::active", self._active_cb) if not self._readfile_completed: self.read_file(self._jobject.file_path) elif not self._shared_activity: gobject.idle_add(self._initialize_cleanstart)
def __init__(self, handle, create_jobject=True): """Initialise the Activity handle -- sugar.activity.activityhandle.ActivityHandle instance providing the activity id and access to the presence service which *may* provide sharing for this application create_jobject -- boolean define if it should create a journal object if we are not resuming Side effects: Sets the gdk screen DPI setting (resolution) to the Sugar screen resolution. Connects our "destroy" message to our _destroy_cb method. Creates a base gtk.Window within this window. Creates an ActivityService (self._bus) servicing this application. Usage: If your Activity implements __init__(), it should call the base class __init()__ before doing Activity specific things. """ Window.__init__(self) # process titles will only show 15 characters # but they get truncated anyway so if more characters # are supported in the future we will get a better view # of the processes proc_title = "%s <%s>" % (get_bundle_name(), handle.activity_id) util.set_proc_title(proc_title) self.connect('realize', self.__realize_cb) self.connect('delete-event', self.__delete_event_cb) self._active = False self._activity_id = handle.activity_id self._pservice = presenceservice.get_instance() self.shared_activity = None self._share_id = None self._join_id = None self._updating_jobject = False self._closing = False self._quit_requested = False self._deleting = False self._max_participants = 0 self._invites_queue = [] self._jobject = None self._read_file_called = False self._session = _get_session() self._session.register(self) self._session.connect('quit-requested', self.__session_quit_requested_cb) self._session.connect('quit', self.__session_quit_cb) accel_group = gtk.AccelGroup() self.set_data('sugar-accel-group', accel_group) self.add_accel_group(accel_group) self._bus = ActivityService(self) self._owns_file = False share_scope = SCOPE_PRIVATE if handle.object_id: self._jobject = datastore.get(handle.object_id) self.set_title(self._jobject.metadata['title']) if self._jobject.metadata.has_key('share-scope'): share_scope = self._jobject.metadata['share-scope'] # handle activity share/join mesh_instance = self._pservice.get_activity(self._activity_id, warn_if_none=False) logging.debug("*** Act %s, mesh instance %r, scope %s", self._activity_id, mesh_instance, share_scope) if mesh_instance is not None: # There's already an instance on the mesh, join it logging.debug("*** Act %s joining existing mesh instance %r", self._activity_id, mesh_instance) self.shared_activity = mesh_instance self.shared_activity.connect('notify::private', self.__privacy_changed_cb) self._join_id = self.shared_activity.connect("joined", self.__joined_cb) if not self.shared_activity.props.joined: self.shared_activity.join() else: self.__joined_cb(self.shared_activity, True, None) elif share_scope != SCOPE_PRIVATE: logging.debug("*** Act %s no existing mesh instance, but used to " \ "be shared, will share" % self._activity_id) # no existing mesh instance, but activity used to be shared, so # restart the share if share_scope == SCOPE_INVITE_ONLY: self.share(private=True) elif share_scope == SCOPE_NEIGHBORHOOD: self.share(private=False) else: logging.debug("Unknown share scope %r" % share_scope) if handle.object_id is None and create_jobject: logging.debug('Creating a jobject.') self._jobject = datastore.create() title = _('%s Activity') % get_bundle_name() self._jobject.metadata['title'] = title self.set_title(self._jobject.metadata['title']) self._jobject.metadata['title_set_by_user'] = '******' self._jobject.metadata['activity'] = self.get_bundle_id() self._jobject.metadata['activity_id'] = self.get_id() self._jobject.metadata['keep'] = '0' self._jobject.metadata['preview'] = '' self._jobject.metadata['share-scope'] = SCOPE_PRIVATE if self.shared_activity is not None: icon_color = self.shared_activity.props.color else: client = gconf.client_get_default() icon_color = client.get_string('/desktop/sugar/user/color') self._jobject.metadata['icon-color'] = icon_color self._jobject.file_path = '' # Cannot call datastore.write async for creates: # https://dev.laptop.org/ticket/3071 datastore.write(self._jobject)
# import olpcgames.mesh as mesh from sugar.presence import presenceservice import sys import types import pygame #from threades import * import threades import threading from time import sleep,time,ctime import gui #from gui import * presenceService = presenceservice.get_instance() _is_shared=False _is_connected=False Flag_Trading_Unicast_Recieve_Sell = False Flag_Trading_Unicast_Recieve_Buy = False Flag_Trading_Unicast_Acknowledge = False players_in_game={} buddy=None check_withBuddy=False def withBuddy(buddy1): global buddy global check_withBuddy
def __init__(self, handle, create_jobject=True): """Initialise the Activity handle -- sugar.activity.activityhandle.ActivityHandle instance providing the activity id and access to the presence service which *may* provide sharing for this application create_jobject -- boolean define if it should create a journal object if we are not resuming Side effects: Sets the gdk screen DPI setting (resolution) to the Sugar screen resolution. Connects our "destroy" message to our _destroy_cb method. Creates a base gtk.Window within this window. Creates an ActivityService (self._bus) servicing this application. Usage: If your Activity implements __init__(), it should call the base class __init()__ before doing Activity specific things. """ # Stuff that needs to be done early icons_path = os.path.join(get_bundle_path(), 'icons') gtk.icon_theme_get_default().append_search_path(icons_path) sugar_theme = 'sugar-72' if 'SUGAR_SCALING' in os.environ: if os.environ['SUGAR_SCALING'] == '100': sugar_theme = 'sugar-100' # This code can be removed when we grow an xsettings daemon (the GTK+ # init routines will then automatically figure out the font settings) settings = gtk.settings_get_default() settings.set_property('gtk-font-name', '%s %f' % (style.FONT_FACE, style.FONT_SIZE)) settings.set_property('gtk-theme-name', sugar_theme) settings.set_property('gtk-icon-theme-name', 'sugar') settings.set_property('gtk-icon-sizes', 'gtk-large-toolbar=%s,%s' % (style.STANDARD_ICON_SIZE, style.STANDARD_ICON_SIZE)) Window.__init__(self) if 'SUGAR_ACTIVITY_ROOT' in os.environ: # If this activity runs inside Sugar, we want it to take all the # screen. Would be better if it was the shell to do this, but we # haven't found yet a good way to do it there. See #1263. self.connect('window-state-event', self.__window_state_event_cb) screen = gtk.gdk.screen_get_default() screen.connect('size-changed', self.__screen_size_changed_cb) self._adapt_window_to_screen() # process titles will only show 15 characters # but they get truncated anyway so if more characters # are supported in the future we will get a better view # of the processes proc_title = '%s <%s>' % (get_bundle_name(), handle.activity_id) util.set_proc_title(proc_title) self.connect('realize', self.__realize_cb) self.connect('delete-event', self.__delete_event_cb) self._active = False self._activity_id = handle.activity_id self.shared_activity = None self._join_id = None self._updating_jobject = False self._closing = False self._quit_requested = False self._deleting = False self._max_participants = 0 self._invites_queue = [] self._jobject = None self._read_file_called = False self._session = _get_session() self._session.register(self) self._session.connect('quit-requested', self.__session_quit_requested_cb) self._session.connect('quit', self.__session_quit_cb) accel_group = gtk.AccelGroup() self.set_data('sugar-accel-group', accel_group) self.add_accel_group(accel_group) self._bus = ActivityService(self) self._owns_file = False share_scope = SCOPE_PRIVATE if handle.object_id: self._jobject = datastore.get(handle.object_id) if 'share-scope' in self._jobject.metadata: share_scope = self._jobject.metadata['share-scope'] if 'launch-times' in self._jobject.metadata: self._jobject.metadata['launch-times'] += ', %d' % \ int(time.time()) else: self._jobject.metadata['launch-times'] = \ str(int(time.time())) self.shared_activity = None self._join_id = None if handle.object_id is None and create_jobject: logging.debug('Creating a jobject.') self._jobject = self._initialize_journal_object() if handle.invited: wait_loop = gobject.MainLoop() self._client_handler = _ClientHandler( self.get_bundle_id(), partial(self.__got_channel_cb, wait_loop)) # FIXME: The current API requires that self.shared_activity is set # before exiting from __init__, so we wait until we have got the # shared activity. http://bugs.sugarlabs.org/ticket/2168 wait_loop.run() else: pservice = presenceservice.get_instance() mesh_instance = pservice.get_activity(self._activity_id, warn_if_none=False) self._set_up_sharing(mesh_instance, share_scope) if not create_jobject: self.set_title(get_bundle_name()) return if self.shared_activity is not None: self._jobject.metadata['title'] = self.shared_activity.props.name self._jobject.metadata['icon-color'] = \ self.shared_activity.props.color else: self._jobject.metadata.connect('updated', self.__jobject_updated_cb) self.set_title(self._jobject.metadata['title']) bundle = get_bundle_instance(get_bundle_path()) self.set_icon_from_file(bundle.get_icon())
def __init__(self, handle): # self.initiating indicates whether this instance has initiated sharing # it always starts false, but will be set to true if this activity # initiates sharing. In particular, if Activity.__init__ calls # self.share(), self.initiating will be set to True. self.initiating = False # self._processed_share indicates whether when_shared() has been called self._processed_share = False # self.initialized tracks whether the Activity's display is up and running self.initialized = False self.early_setup() super(GroupActivity, self).__init__(handle) self.dbus_name = self.get_bundle_id() self.logger = logging.getLogger(self.dbus_name) self._handle = handle ##gobject.threads_init() self._sharing_completed = not self._shared_activity self._readfile_completed = not handle.object_id if self._shared_activity: self.message = self.message_joining elif handle.object_id: self.message = self.message_loading else: self.message = self.message_preparing # top toolbar with share and close buttons: toolbox = ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.show() v = gtk.VBox() self.startup_label = gtk.Label(self.message) v.pack_start(self.startup_label) Window.set_canvas(self,v) self.show_all() # The show_all method queues up draw events, but they aren't executed # until the mainloop has a chance to process them. We want to process # them immediately, because we need to show the waiting screen # before the waiting starts, not after. exhaust_event_loop() # exhaust_event_loop() provides the possibility that write_file could # be called at this time, so write_file is designed to trigger read_file # itself if that path occurs. self.tubebox = groupthink.TubeBox() self.timer = groupthink.TimeHandler("main", self.tubebox) self.cloud = groupthink.Group(self.tubebox) # self.cloud is extremely important. It is the unified reference point # that contains all state in the system. Everything else is stateless. # self.cloud has to be defined before the call to self.set_canvas, because # set_canvas can trigger almost anything, including pending calls to read_file, # which relies on self.cloud. # get the Presence Service self.pservice = presenceservice.get_instance() # Buddy object for you owner = self.pservice.get_owner() self.owner = owner self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb) if self.get_shared(): if self.initiating: self._shared_cb(self) else: self._joined_cb(self) self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK) self.connect("visibility-notify-event", self._visible_cb) self.connect("notify::active", self._active_cb) if not self._readfile_completed: self.read_file(self._jobject.file_path) elif not self._shared_activity: gobject.idle_add(self._initialize_cleanstart)
def __init__(self, handle, create_jobject=True): """Initialise the Activity handle -- sugar.activity.activityhandle.ActivityHandle instance providing the activity id and access to the presence service which *may* provide sharing for this application create_jobject -- boolean define if it should create a journal object if we are not resuming Side effects: Sets the gdk screen DPI setting (resolution) to the Sugar screen resolution. Connects our "destroy" message to our _destroy_cb method. Creates a base gtk.Window within this window. Creates an ActivityService (self._bus) servicing this application. Usage: If your Activity implements __init__(), it should call the base class __init()__ before doing Activity specific things. """ # Stuff that needs to be done early icons_path = os.path.join(get_bundle_path(), 'icons') gtk.icon_theme_get_default().append_search_path(icons_path) sugar_theme = 'sugar-72' if 'SUGAR_SCALING' in os.environ: if os.environ['SUGAR_SCALING'] == '100': sugar_theme = 'sugar-100' # This code can be removed when we grow an xsettings daemon (the GTK+ # init routines will then automatically figure out the font settings) settings = gtk.settings_get_default() settings.set_property('gtk-font-name', '%s %f' % (style.FONT_FACE, style.FONT_SIZE)) settings.set_property('gtk-theme-name', sugar_theme) settings.set_property('gtk-icon-theme-name', 'sugar') settings.set_property( 'gtk-icon-sizes', 'gtk-large-toolbar=%s,%s' % (style.STANDARD_ICON_SIZE, style.STANDARD_ICON_SIZE)) Window.__init__(self) if 'SUGAR_ACTIVITY_ROOT' in os.environ: # If this activity runs inside Sugar, we want it to take all the # screen. Would be better if it was the shell to do this, but we # haven't found yet a good way to do it there. See #1263. self.connect('window-state-event', self.__window_state_event_cb) screen = gtk.gdk.screen_get_default() screen.connect('size-changed', self.__screen_size_changed_cb) self._adapt_window_to_screen() # process titles will only show 15 characters # but they get truncated anyway so if more characters # are supported in the future we will get a better view # of the processes proc_title = '%s <%s>' % (get_bundle_name(), handle.activity_id) util.set_proc_title(proc_title) self.connect('realize', self.__realize_cb) self.connect('delete-event', self.__delete_event_cb) self._active = False self._activity_id = handle.activity_id self.shared_activity = None self._join_id = None self._updating_jobject = False self._closing = False self._quit_requested = False self._deleting = False self._max_participants = 0 self._invites_queue = [] self._jobject = None self._read_file_called = False self._session = _get_session() self._session.register(self) self._session.connect('quit-requested', self.__session_quit_requested_cb) self._session.connect('quit', self.__session_quit_cb) accel_group = gtk.AccelGroup() self.set_data('sugar-accel-group', accel_group) self.add_accel_group(accel_group) self._bus = ActivityService(self) self._owns_file = False share_scope = SCOPE_PRIVATE if handle.object_id: self._jobject = datastore.get(handle.object_id) if 'share-scope' in self._jobject.metadata: share_scope = self._jobject.metadata['share-scope'] if 'launch-times' in self._jobject.metadata: self._jobject.metadata['launch-times'] += ', %d' % \ int(time.time()) else: self._jobject.metadata['launch-times'] = \ str(int(time.time())) self.shared_activity = None self._join_id = None if handle.object_id is None and create_jobject: logging.debug('Creating a jobject.') self._jobject = self._initialize_journal_object() if handle.invited: wait_loop = gobject.MainLoop() self._client_handler = _ClientHandler( self.get_bundle_id(), partial(self.__got_channel_cb, wait_loop)) # FIXME: The current API requires that self.shared_activity is set # before exiting from __init__, so we wait until we have got the # shared activity. http://bugs.sugarlabs.org/ticket/2168 wait_loop.run() else: pservice = presenceservice.get_instance() mesh_instance = pservice.get_activity(self._activity_id, warn_if_none=False) self._set_up_sharing(mesh_instance, share_scope) if not create_jobject: self.set_title(get_bundle_name()) return if self.shared_activity is not None: self._jobject.metadata['title'] = self.shared_activity.props.name self._jobject.metadata['icon-color'] = \ self.shared_activity.props.color else: self._jobject.metadata.connect('updated', self.__jobject_updated_cb) self.set_title(self._jobject.metadata['title']) bundle = get_bundle_instance(get_bundle_path()) self.set_icon_from_file(bundle.get_icon())
import olpcgames.mesh as mesh from sugar.presence import presenceservice import sys import types #from threades import * import threades import threading import pygame import gui from gettext import gettext as _ from olpcgames import pangofont #from gui import * presenceService = presenceservice.get_instance() _is_shared = False _is_connected = False Flag_Trading_Unicast_Recieve_Sell = False Flag_Trading_Unicast_Recieve_Buy = False Flag_Trading_Unicast_Acknowledge = False players_in_game = {} buddy = None check_withBuddy = False def withBuddy(buddy1): global buddy
def __init__(self): gtk.EventBox.__init__(self) self.messenger = None self.me = None self.quiet = False self._buddies = {} # buddies box self._buddies_sw = gtk.ScrolledWindow() self._buddies_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER) self._buddies_sw.set_size_request(BUDDY_SIZE, BUDDY_SIZE) self._buddies_box = gtk.HBox() self._buddies_box.set_size_request(BUDDY_SIZE, BUDDY_SIZE) self._buddies_sw.add_with_viewport(self._buddies_box) self._buddies_box.show() # chat entry self._owner = presenceservice.get_instance().get_owner() self._chat = ChatBox(self._owner, _is_tablet_mode()) self._chat.set_size_request( -1, gtk.gdk.screen_height() - style.GRID_CELL_SIZE - BUDDY_SIZE) self.me, my_face_widget = self._new_face(self._owner, ENTRY_COLOR) my_face_widget.set_size_request(BUDDY_SIZE, BUDDY_SIZE) # add owner to buddy list self._buddies[self._owner] = { 'box': my_face_widget, 'face': self.me, 'lang': '' } self.chat_post = gtk.Entry() entry_height = int(BUDDY_SIZE) entry_width = gtk.gdk.screen_width() - \ max(1, min(5, len(self._buddies))) * BUDDY_SIZE self.chat_post.set_size_request(entry_width, entry_height) self.chat_post.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) self.chat_post.modify_base(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) self.chat_post.modify_font(pango.FontDescription(str='sans bold 24')) self.chat_post.connect('activate', self._activate_cb) self.chat_post.connect('key-press-event', self._key_press_cb) chat_post_box = gtk.VBox() chat_post_box.pack_start(self.chat_post, padding=ENTRY_XPAD) self.chat_post.show() chat_entry = gtk.HBox() self._buddies_box.pack_start(my_face_widget) chat_entry.pack_start(self._buddies_sw) my_face_widget.show() chat_entry.pack_start(chat_post_box) chat_post_box.show() if _is_tablet_mode(): chat_box = gtk.VBox() chat_box.pack_start(chat_entry) chat_entry.show() chat_box.pack_start(self._chat, expand=True) self._chat.show() else: chat_box = gtk.VBox() chat_box.pack_start(self._chat, expand=True) self._chat.show() chat_box.pack_start(chat_entry) chat_entry.show() # desk self._desk = gtk.HBox() self._desk.pack_start(chat_box) self.add(self._desk) self._desk.show()
def __init__(self, handle): """Set up the StopWatch activity.""" Activity.__init__(self, handle) self._logger = logging.getLogger('stopwatch-activity') gobject.threads_init() # top toolbar with share and close buttons: OLD_TOOLBAR = False try: from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton from sugar.activity.widgets import ActivityToolbarButton, StopButton, \ ShareButton, TitleEntry, ActivityButton except ImportError: OLD_TOOLBAR = True if OLD_TOOLBAR: toolbox = ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.show() else: toolbar_box = ToolbarBox() self.activity_button = ActivityButton(self) toolbar_box.toolbar.insert(self.activity_button, 0) self.activity_button.show() title_entry = TitleEntry(self) toolbar_box.toolbar.insert(title_entry, -1) title_entry.show() try: from sugar.activity.widgets import DescriptionItem description_item = DescriptionItem(self) toolbar_box.toolbar.insert(description_item, -1) description_item.show() except: pass share_button = ShareButton(self) toolbar_box.toolbar.insert(share_button, -1) share_button.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) self.tubebox = dobject.TubeBox() self.timer = dobject.TimeHandler("main", self.tubebox) self.gui = stopwatch.GUIView(self.tubebox, self.timer) self.set_canvas(self.gui.display) self.show_all() self.initiating = False # get the Presence Service self.pservice = presenceservice.get_instance() # Buddy object for you owner = self.pservice.get_owner() self.owner = owner self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb) self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK) self.connect("visibility-notify-event", self._visible_cb) self.connect("notify::active", self._active_cb)
class SimCityActivity(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle) self.set_title(_('SimCity Activity')) self.connect('destroy', self._destroy_cb) self.connect('focus-in-event', self._focus_in_cb) self.connect('focus-out-event', self._focus_out_cb) signal.signal(signal.SIGCHLD, self._sigchild_handler) self._bundle_path = get_bundle_path() if False: # FIXME: Plug SimCity's window into a gtk socket. # Doesn't work yet, but it would be cool if it did. socket = gtk.Socket() try: self.set_canvas(socket) except AttributeError: self.add(socket) socket.show() socket.connect('plug-added', self._plug_added_cb) socket.connect('plug-removed', self._plug_removed_cb) win = socket.get_id() command = os.path.join(self._bundle_path, 'SimCity') args = [ command, #'-R', str(win), # Set root window to socket window id '-t', # Interactive tty mode, so we can send it commands. ] logging.debug("CWD: " + self._bundle_path) logging.debug("SIMCITY ARGS: " + repr(args)) self._process = subprocess.Popen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True, cwd=self._bundle_path, preexec_fn=lambda: os.chdir(self._bundle_path)) logging.debug("STARTING THREAD... " + str(self._stdout_thread_function)) t = None try: t = thread.start_new(self._stdout_thread_function, ()) except Exception, e: logging.debug("EXCEPTION " + str(e)) self._stdout_thread = t logging.debug("STARTED THREAD. " + str(t)) uri = handle.uri or '' logging.debug("SIMCITYACTIVITY SUGARSTARTUP URI " + repr(uri)) self.send_process('SugarStartUp "' + QuoteTCL(uri) + '"\n') nick = profile.get_nick_name() or '' logging.debug("SIMCITYACTIVITY SUGARNICKNAME NICK " + repr(nick)) self.send_process('SugarNickName "' + QuoteTCL(nick) + '"\n') #logging.debug("started SimCity, pid " + repr(self._pid)) ps = presenceservice.get_instance() for buddy in ps.get_buddies(): self._buddy_appeared_cb(ps, buddy) ps.connect("buddy-appeared", self._buddy_appeared_cb) ps.connect("buddy-disappeared", self._buddy_disappeared_cb)
import os import gtk from sugar.presence import presenceservice import port.json as json from theme import * from source import * from object_model import ObjectModel from source_ds_rich import DatastoreRichSource source = DatastoreRichSource(default_order=('timestamp', gtk.SORT_DESCENDING)) local_source = source object_model = ObjectModel() owner = presenceservice.get_instance().get_owner() class Model(dict): def __init__(self): dict.__init__(self) self['activity'] = { 'sidebar_visible' : True, 'sidebar_position' : 1, 'sidebar_separator' : gtk.gdk.screen_width() / 4 * 3, 'objects_view' : 0 } self['tag_sidebar'] = { 'page': 0, `TAGS_OBJECTIVE` : { 'cloud_active' : False, 'cloud_by_size': False,