Created
February 23, 2015 17:03
-
-
Save maiamcc/4ebaa1b27de9531cabf3 to your computer and use it in GitHub Desktop.
trying to resolve one notification before initing another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### IN WINDOW.PY | |
@log | |
def dismiss_previous_notification(self): | |
try: | |
self.notification.dismiss() | |
except AttributeError: | |
pass | |
@log | |
def _init_playlist_removal_notification(self): | |
self.dismiss_previous_notification() | |
self.notification = Gd.Notification() | |
self.notification.set_timeout(20) | |
grid = Gtk.Grid(valign=Gtk.Align.CENTER, margin_right=8) | |
grid.set_column_spacing(8) | |
self.notification.add(grid) | |
undo_button = Gtk.Button.new_with_mnemonic(_("_Undo")) | |
label = _("Playlist %s removed" %( | |
self.views[3].current_playlist.get_title())) | |
grid.add(Gtk.Label.new(label)) | |
grid.add(undo_button) | |
self.notification.show_all() | |
self._overlay.add_overlay(self.notification) | |
self.notification.deletion_index = self.views[3].current_playlist_index | |
self.notification.connect("dismissed", self._playlist_removal_notification_dismissed) | |
undo_button.connect("clicked", self._undo_deletion) | |
@log | |
def _playlist_removal_notification_dismissed(self, widget): | |
if self.views[3].really_delete: | |
Views.playlists.delete_playlist(self.views[3].pl_todelete) | |
else: | |
self.views[3].really_delete = True | |
@log | |
def _undo_deletion(self, widget): | |
self.views[3].really_delete = False | |
self.notification.dismiss() | |
self.views[3].undo_playlist_deletion(self.notification.deletion_index) | |
### IN VIEW.PY | |
@log | |
def current_playlist_is_protected(self): | |
current_playlist_id = self.current_playlist.get_id() | |
if current_playlist_id in StaticPlaylists.get_protected_ids(): | |
return True | |
else: | |
return False | |
@log | |
def stage_playlist_for_deletion(self): | |
self._model.clear() | |
_iter = self.playlists_sidebar.get_generic_view().get_selection().get_selected()[1] | |
if not _iter: | |
return | |
iter_next = self.playlists_model.iter_next(_iter)\ | |
or self.playlists_model.iter_previous(_iter) | |
if iter_next: | |
selection = self.playlists_sidebar.get_generic_view().get_selection() | |
selection.select_iter(iter_next) | |
self.playlists_sidebar.emit('item-activated', '0', | |
self.playlists_model.get_path(iter_next)) | |
playlist = self.playlists_model.get_value(_iter, 5) | |
self.pl_todelete = playlist | |
self.playlists_model.remove(_iter) | |
@log | |
def undo_playlist_deletion(self, deletion_index): | |
self._add_playlist_item_to_model(self.pl_todelete, index=deletion_index) | |
@log | |
def _on_delete_activate(self, menuitem, data=None): | |
if not self.current_playlist_is_protected(): | |
self.window._init_playlist_removal_notification() | |
self.stage_playlist_for_deletion() | |
else: | |
self.window._init_protected_playlist_notification() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment