def read_file(self, file_path): try: with open(file_path, 'r') as f: data = json.load(f) self._view_answer = data['view_answer'] self._remember_last_vote = data['remember_last_vote'] self._play_vote_sound = data['play_vote_sound'] self._use_image = data['use_image'] self._image_size = data['image_size'] self._polls = set() for poll_data in data['polls_data']: # json stores the dictionary keys as strings, # convert to int options = {} for key in poll_data['options']: options[int(key)] = poll_data['options'][key] images_ds_objects = {} for key in poll_data['images_ds_objects']: images_ds_objects[int(key)] = \ poll_data['images_ds_objects'][key] data = {} for key in poll_data['data']: data[int(key)] = poll_data['data'][key] images = self.__create_pixbufs(images_ds_objects) images_ds_object = self.__get_images_ds_objects( images_ds_objects) self._polls.add( Poll(self, poll_data['title'], poll_data['author'], poll_data['active'], date.fromordinal(poll_data['createdate']), poll_data['maxvoters'], poll_data['question'], poll_data['number_of_options'], options, data, poll_data['votes'], images, images_ds_object)) except: # if can't read json, try read with the old format self._old_read_file(file_path) # if there are polls loaded, show the selection screen # if not, show the creation screen if self._polls: self.set_canvas(SelectCanvas(self)) else: emptypanel.show(self, 'new-poll', _('Create a new poll'), _('Create'), self.__button_new_clicked) self.get_toolbar_box().update_configs()
def __init__(self, handle): activity.Activity.__init__(self, handle) self.player = None self._alert = None self._playlist_jobject = None self.set_title(_('Jukebox Activity')) self.max_participants = 1 self._toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) activity_toolbar = activity_button.page self._toolbar_box.toolbar.insert(activity_button, 0) self.title_entry = activity_toolbar.title self._view_toolbar = ViewToolbar() self._view_toolbar.connect('go-fullscreen', self.__go_fullscreen_cb) self._view_toolbar.connect('toggle-playlist', self.__toggle_playlist_cb) view_toolbar_button = ToolbarButton( page=self._view_toolbar, icon_name='toolbar-view') self._view_toolbar.show() self._toolbar_box.toolbar.insert(view_toolbar_button, -1) view_toolbar_button.show() self._control_toolbar = Gtk.Toolbar() self._control_toolbar_button = ToolbarButton( page=self._control_toolbar, icon_name='media-playback-start') self._control_toolbar.show() self._toolbar_box.toolbar.insert(self._control_toolbar_button, -1) self._control_toolbar_button.hide() self.set_toolbar_box(self._toolbar_box) self._toolbar_box.show_all() self.connect('key_press_event', self.__key_press_event_cb) self.connect('playlist-finished', self.__playlist_finished_cb) # We want to be notified when the activity gets the focus or # loses it. When it is not active, we don't need to keep # reproducing the video self.connect('notify::active', self.__notify_active_cb) self._video_canvas = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self._playlist_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.playlist_widget = PlayList() self.playlist_widget.connect('play-index', self.__play_index_cb) self.playlist_widget.connect('missing-tracks', self.__missing_tracks_cb) self.playlist_widget.set_size_request( Gdk.Screen.width() * PLAYLIST_WIDTH_PROP, 0) self.playlist_widget.show() self._playlist_box.pack_start(self.playlist_widget, expand=True, fill=True, padding=0) self._playlist_toolbar = Gtk.Toolbar() move_up = ToolButton("go-up") move_up.set_tooltip(_("Move up")) move_up.connect("clicked", self._move_up_cb) self._playlist_toolbar.insert(move_up, 0) move_down = ToolButton("go-down") move_down.set_tooltip(_("Move down")) move_down.connect("clicked", self._move_down_cb) self._playlist_toolbar.insert(move_down, 1) self._playlist_box.pack_end(self._playlist_toolbar, False, False, 0) self._video_canvas.pack_start(self._playlist_box, False, False, 0) # Create the player just once logging.debug('Instantiating GstPlayer') self.player = GstPlayer() self.player.connect('eos', self.__player_eos_cb) self.player.connect('error', self.__player_error_cb) self.player.connect('play', self.__player_play_cb) self.control = Controls(self, self._toolbar_box.toolbar, self._control_toolbar) self._separator = Gtk.SeparatorToolItem() self._separator.props.draw = False self._separator.set_expand(True) self._separator.show() self._toolbar_box.toolbar.insert(self._separator, -1) self._stop = StopButton(self) self._toolbar_box.toolbar.insert(self._stop, -1) self._empty_widget = Gtk.Label(label="") self._empty_widget.show() self.videowidget = VideoWidget() self.set_canvas(self._video_canvas) self._init_view_area() self.show_all() # need hide the playlist by default self._playlist_box.hide() self._configure_cb() self.player.init_view_area(self.videowidget) self._volume_monitor = Gio.VolumeMonitor.get() self._volume_monitor.connect('mount-added', self.__mount_added_cb) self._volume_monitor.connect('mount-removed', self.__mount_removed_cb) if handle.object_id is None: # The activity was launched from scratch. We need to show # the Empty Widget self.playlist_widget.hide() emptypanel.show(self, 'activity-jukebox', _('No media'), _('Choose media files'), self.control.show_picker_cb) self.control.check_if_next_prev() Gdk.Screen.get_default().connect('size-changed', self._configure_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) self.max_participants = 1 self._document = None self._fileserver = None self._object_id = handle.object_id self._toc_model = None self.filehash = None self.connect('key-press-event', self._key_press_event_cb) self.connect('key-release-event', self._key_release_event_cb) _logger.debug('Starting Read...') self._view = None self.dpi = _get_screen_dpi() self._bookmark_view = BookmarkView() self._bookmark_view.connect('bookmark-changed', self._update_bookmark_cb) tray = HTray() self.set_tray(tray, Gtk.PositionType.BOTTOM) toolbar_box = ToolbarBox() self.activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(self.activity_button, 0) self.activity_button.show() self._edit_toolbar = EditToolbar() self._edit_toolbar.undo.props.visible = False self._edit_toolbar.redo.props.visible = False self._edit_toolbar.separator.props.visible = False self._edit_toolbar.copy.set_sensitive(False) self._edit_toolbar.copy.connect('clicked', self._edit_toolbar_copy_cb) self._edit_toolbar.paste.props.visible = False edit_toolbar_button = ToolbarButton(page=self._edit_toolbar, icon_name='toolbar-edit') self._edit_toolbar.show() toolbar_box.toolbar.insert(edit_toolbar_button, -1) edit_toolbar_button.show() self._highlight = self._edit_toolbar.highlight self._highlight_id = self._highlight.connect('clicked', self.__highlight_cb) self._view_toolbar = ViewToolbar() self._view_toolbar.connect('go-fullscreen', self.__view_toolbar_go_fullscreen_cb) self._view_toolbar.connect('toggle-index-show', self.__toogle_navigator_cb) self._view_toolbar.connect('toggle-tray-show', self.__toogle_tray_cb) view_toolbar_button = ToolbarButton(page=self._view_toolbar, icon_name='toolbar-view') self._view_toolbar.show() toolbar_box.toolbar.insert(view_toolbar_button, -1) view_toolbar_button.show() self._back_button = self._create_back_button() toolbar_box.toolbar.insert(self._back_button, -1) self._back_button.show() self._forward_button = self._create_forward_button() toolbar_box.toolbar.insert(self._forward_button, -1) self._forward_button.show() num_page_item = Gtk.ToolItem() self._num_page_entry = self._create_search() num_page_item.add(self._num_page_entry) self._num_page_entry.show() toolbar_box.toolbar.insert(num_page_item, -1) num_page_item.show() total_page_item = Gtk.ToolItem() self._total_page_label = Gtk.Label() total_page_item.add(self._total_page_label) self._total_page_label.show() self._total_page_label.set_margin_right(5) toolbar_box.toolbar.insert(total_page_item, -1) total_page_item.show() self._bookmarker = ToggleToolButton('emblem-favorite') self._bookmarker_toggle_handler_id = self._bookmarker.connect( 'toggled', self.__bookmarker_toggled_cb) self._bookmarker.show() toolbar_box.toolbar.insert(self._bookmarker, -1) self.speech_toolbar_button = ToolbarButton(icon_name='speak') toolbar_box.toolbar.insert(self.speech_toolbar_button, -1) separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) 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() # This is needed to prevent the call of read_file on # canvas map, becuase interact in a bad way with the emptypanel # the program takes responsability of this task. self._read_file_called = True self._vbox = Gtk.VBox() self._vbox.show() overlay = Gtk.Overlay() self._hbox = Gtk.HBox() self._hbox.show() overlay.add(self._hbox) self._bookmark_view.props.halign = Gtk.Align.END self._bookmark_view.props.valign = Gtk.Align.START # HACK: This is to calculate the scrollbar width # defined in sugar-artwork gtk-widgets.css.em if style.zoom(1): scrollbar_width = 15 else: scrollbar_width = 11 self._bookmark_view.props.margin_right = scrollbar_width overlay.add_overlay(self._bookmark_view) overlay.show() self._vbox.pack_start(overlay, True, True, 0) self.set_canvas(self._vbox) self._navigator = self._create_navigator() # Set up for idle suspend self._idle_timer = 0 self._service = None # start with sleep off self._sleep_inhibit = True self.unused_download_tubes = set() self._want_document = True self._download_content_length = 0 self._download_content_type = None # Status of temp file used for write_file: self._tempfile = None self._close_requested = False fname = os.path.join('/etc', 'inhibit-ebook-sleep') if not os.path.exists(fname): try: bus = dbus.SystemBus() proxy = bus.get_object(_HARDWARE_MANAGER_SERVICE, _HARDWARE_MANAGER_OBJECT_PATH) self._service = dbus.Interface(proxy, _HARDWARE_MANAGER_INTERFACE) self._scrolled.props.vadjustment.connect( "value-changed", self._user_action_cb) self._scrolled.props.hadjustment.connect( "value-changed", self._user_action_cb) self.connect("focus-in-event", self._focus_in_event_cb) self.connect("focus-out-event", self._focus_out_event_cb) self.connect("notify::active", self._now_active_cb) _logger.debug('Suspend on idle enabled') except dbus.DBusException: _logger.info( 'Hardware manager service not found, no idle suspend.') else: _logger.debug('Suspend on idle disabled') self.connect("shared", self._shared_cb) h = hash(self._activity_id) self.port = 1024 + (h % 64511) self._progress_alert = None if self._jobject.file_path is not None and \ self._jobject.file_path != '': self.read_file(self._jobject.file_path) elif handle.uri: self._load_document(handle.uri) # TODO: we need trasfer the metadata and uodate # bookmarks and urls elif self.shared_activity: # We're joining if self.get_shared(): # Already joined for some reason, just get the document self._joined_cb(self) else: self._progress_alert = ProgressAlert() self._progress_alert.props.title = _('Please wait') self._progress_alert.props.msg = _('Starting connection...') self.add_alert(self._progress_alert) # Wait for a successful join before trying to get the document self.connect("joined", self._joined_cb) else: # Not joining, not resuming or resuming session without file emptypanel.show(self, 'activity-read', _('No book'), _('Choose something to read'), self._show_journal_object_picker_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) self.player = None self._alert = None self._playlist_jobject = None self.set_title(_('Jukebox Activity')) self.max_participants = 1 toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) activity_toolbar = activity_button.page toolbar_box.toolbar.insert(activity_button, 0) self.title_entry = activity_toolbar.title self._view_toolbar = ViewToolbar() self._view_toolbar.connect('go-fullscreen', self.__go_fullscreen_cb) self._view_toolbar.connect('toggle-playlist', self.__toggle_playlist_cb) view_toolbar_button = ToolbarButton(page=self._view_toolbar, icon_name='toolbar-view') self._view_toolbar.show() toolbar_box.toolbar.insert(view_toolbar_button, -1) view_toolbar_button.show() self._control_toolbar = Gtk.Toolbar() self._control_toolbar_button = ToolbarButton( page=self._control_toolbar, icon_name='media-playback-start') self._control_toolbar.show() toolbar_box.toolbar.insert(self._control_toolbar_button, -1) self._control_toolbar_button.hide() self.set_toolbar_box(toolbar_box) toolbar_box.show_all() self.connect('key_press_event', self.__key_press_event_cb) self.connect('playlist-finished', self.__playlist_finished_cb) # We want to be notified when the activity gets the focus or # loses it. When it is not active, we don't need to keep # reproducing the video self.connect('notify::active', self.__notify_active_cb) self._video_canvas = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self._playlist_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.playlist_widget = PlayList() self.playlist_widget.connect('play-index', self.__play_index_cb) self.playlist_widget.connect('missing-tracks', self.__missing_tracks_cb) self.playlist_widget.set_size_request( Gdk.Screen.width() * PLAYLIST_WIDTH_PROP, 0) self.playlist_widget.show() self._playlist_box.pack_start(self.playlist_widget, expand=True, fill=True, padding=0) self._playlist_toolbar = Gtk.Toolbar() move_up = ToolButton("go-up") move_up.set_tooltip(_("Move up")) move_up.connect("clicked", self._move_up_cb) self._playlist_toolbar.insert(move_up, 0) move_down = ToolButton("go-down") move_down.set_tooltip(_("Move down")) move_down.connect("clicked", self._move_down_cb) self._playlist_toolbar.insert(move_down, 1) self._playlist_box.pack_end(self._playlist_toolbar, False, False, 0) self._video_canvas.pack_start(self._playlist_box, False, False, 0) # Create the player just once logging.debug('Instantiating GstPlayer') self.player = GstPlayer() self.player.connect('eos', self.__player_eos_cb) self.player.connect('error', self.__player_error_cb) self.player.connect('play', self.__player_play_cb) self.control = Controls(self, toolbar_box.toolbar, self._control_toolbar) self._separator = Gtk.SeparatorToolItem() self._separator.props.draw = False self._separator.set_expand(True) self._separator.show() toolbar_box.toolbar.insert(self._separator, -1) self._stop = StopButton(self) toolbar_box.toolbar.insert(self._stop, -1) self._empty_widget = Gtk.Label(label="") self._empty_widget.show() self.videowidget = VideoWidget() self.set_canvas(self._video_canvas) self._init_view_area() self.show_all() # need hide the playlist by default self._playlist_box.hide() self._configure_cb() self.player.init_view_area(self.videowidget) self._volume_monitor = Gio.VolumeMonitor.get() self._volume_monitor.connect('mount-added', self.__mount_added_cb) self._volume_monitor.connect('mount-removed', self.__mount_removed_cb) if handle.object_id is None: # The activity was launched from scratch. We need to show # the Empty Widget self.playlist_widget.hide() emptypanel.show(self, 'activity-jukebox', _('No media'), _('Choose media files'), self.control.show_picker_cb) self.control.check_if_next_prev() Gdk.Screen.get_default().connect('size-changed', self._configure_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) self._logger = logging.getLogger('poll-activity') self._logger.debug('Starting Poll activity') self._polls = set() self.current_vote = None # This property allows result viewing while voting self._view_answer = True # This property allows use image in answer self._use_image = False # This property allows play a sound when click in # the button to make a vote self._play_vote_sound = False # This property allows remember in the radio button options # the last vote self._remember_last_vote = True # This property has the image size self._image_size = {'height': 100, 'width': 100} # the active poll self._poll = None # get the Presence Service self.pservice = presenceservice.get_instance() self.initiating = False # Buddy object for you owner = self.pservice.get_owner() self.owner = owner self.nick = owner.props.nick self.nick_sha1 = sha1(self.nick.encode()).hexdigest() toolbar = Toolbar(self) toolbar.create_button.connect('clicked', self.__button_new_clicked) toolbar.choose_button.connect('clicked', self.__button_select_clicked) toolbar.export_data_bt.connect('clicked', self.__save_data_cb) toolbar.export_image_bt.connect('clicked', self.__save_image_cb) toolbar.pie_chart_button.connect('clicked', self.__chart_type_clicked_cb, CHART_TYPE_PIE) toolbar.vbar_chart_button.connect('clicked', self.__chart_type_clicked_cb, CHART_TYPE_VERTICAL_BARS) self._chart_type_selected = CHART_TYPE_PIE self.set_toolbar_box(toolbar) emptypanel.show(self, 'new-poll', _('Create a new poll'), _('Create'), self.__button_new_clicked) self.show_all() self.poll_session = None self.connect('shared', self.__shared_cb) self.connect('joined', self.__joined_cb)