Пример #1
0
    def _notify_err(self, err, **kargs):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

        self._notification = ErrorNotify(self)

        if isinstance(err, IOError) and err.errno == errno.EEXIST:
            self._notification.title = "Swap file already exists"
            lb = elementary.Label(self._notification)
            lb.text_set("Another program may be editing the same file<br>" +
                        "or a previous edition session for this file crashed.")
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ignore Swap", self._open_forced)
            self._notification.action_add("Recover", self._open_recovery)
            self._notification.action_add("Abort", self._notify_abort)
        elif isinstance(err, swapfile.CompileError):
            self._notification.title = "Compiler Error"
            lb = elementary.Label(self._notification)
            lb.text_set(str(err.message).replace('\n', '<br>'))
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ok", self._notify_abort)
        else:
            self._notification.title = str(err).replace(':', '<br>')
            self._notification.action_add("Ok", self._notify_abort)

        self._notification.show()
Пример #2
0
    def _check_changed_cb(self, obj, part):
        if obj.state:
            self._part_add(part, self._edit_grp.animation.name)

            op = Operation("part (%s) addition into animation (%s)" % \
                                (part, self._edit_grp.animation.name))
            op.redo_callback_add(self._part_add, part,
                                 self._edit_grp.animation.name)
            op.undo_callback_add(self._part_remove, part,
                                 self._edit_grp.animation.name)
            self._operation_stack_cb(op)
        else:
            # FIXME: Take the confirmation out of this function
            self._notification = ErrorNotify(
                self, elementary.ELM_NOTIFY_ORIENT_CENTER)
            self._notification.title = "Part Removal"
            lb = elementary.Label(self._notification)
            lb.text_set("Are you sure you want to remove<br>"
                        "this part from the animation?")
            lb.show()
            self._notification.pack_end(lb)
            self._notification.action_add("Remove",
                                          self._confirm_remove_cb,
                                          data=part)
            self._notification.action_add("Cancel",
                                          self._cancel_remove_cb,
                                          data=obj)
            self._notification.show()
Пример #3
0
    def _check_changed_cb(self, obj, part):
        if obj.state:
            self._part_add(part, self._edit_grp.animation.name)

            op = Operation("part (%s) addition into animation (%s)" % \
                                (part, self._edit_grp.animation.name))
            op.redo_callback_add(self._part_add, part,
                                 self._edit_grp.animation.name)
            op.undo_callback_add(self._part_remove, part,
                                 self._edit_grp.animation.name)
            self._operation_stack_cb(op)
        else:
            # FIXME: Take the confirmation out of this function
            self._notification = ErrorNotify(
                self, elementary.ELM_NOTIFY_ORIENT_CENTER)
            self._notification.title = "Part Removal"
            lb = elementary.Label(self._notification)
            lb.text_set("Are you sure you want to remove<br>"
                         "this part from the animation?")
            lb.show()
            self._notification.pack_end(lb)
            self._notification.action_add("Remove",
                                          self._confirm_remove_cb, data=part)
            self._notification.action_add("Cancel",
                                          self._cancel_remove_cb, data=obj)
            self._notification.show()
Пример #4
0
    def _notify_err(self, err, **kargs):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

        self._notification = ErrorNotify(self)

        if isinstance(err, IOError) and err.errno == errno.EEXIST:
            self._notification.title = "Swap file already exists"
            lb = elementary.Label(self._notification)
            lb.text_set(
                "Another program may be editing the same file<br>" +
                "or a previous edition session for this file crashed.")
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ignore Swap", self._open_forced)
            self._notification.action_add("Recover", self._open_recovery)
            self._notification.action_add("Abort", self._notify_abort)
        elif isinstance(err, swapfile.CompileError):
            self._notification.title = "Compiler Error"
            lb = elementary.Label(self._notification)
            lb.text_set(str(err.message).replace('\n', '<br>'))
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ok", self._notify_abort)
        else:
            self._notification.title = str(err).replace(':', '<br>')
            self._notification.action_add("Ok", self._notify_abort)

        self._notification.show()
Пример #5
0
    def _timeremove_cb(self, obj, emission, source):
        t = float(source)
        anim_name = self.e.animation.name
        anim_frame = self.e.animation.state
        prog = "@%s@%.2f" % (anim_name, t)

        saved_states = []
        for part_name in self.e.animation.parts:
            part = self.e.part_get(part_name)
            st_obj = part.state_get(prog)
            st_class = objects_data.state_class_from_part_type_get(part)
            state_save = st_class(st_obj)
            saved_states.append([part.name, state_save])

        trans = self.e.animation.program.transition

        def agree(bt, notification):
            self._remove_time_point(t, anim_name, anim_frame)
            notification.hide()
            notification.delete()
            op = Operation("animation (%s) frame (%s) deletion" % \
                               (anim_name, t))
            op.redo_callback_add(self._remove_time_point, t, anim_name,
                                 anim_frame)
            op.undo_callback_add(self._frame_readd, t, anim_name, saved_states,
                                 trans)
            self._operation_stack_cb(op)

        def disagree(bt, notification):
            notification.hide()
            notification.delete()

        if t in self.e.animation.timestops:
            notification = ErrorNotify(
                self._parent, orient=elementary.ELM_NOTIFY_ORIENT_CENTER)
            notification.title = "Do you really want to delete this " \
                "animation frame?"
            notification.action_add("Yes", agree, None, notification)
            notification.action_add("No", disagree, None, notification)
            notification.show()
Пример #6
0
    def _timeremove_cb(self, obj, emission, source):
        t = float(source)
        anim_name = self.e.animation.name
        anim_frame = self.e.animation.state
        prog = "@%s@%.2f" % (anim_name, t)

        saved_states = []
        for part_name in self.e.animation.parts:
            part = self.e.part_get(part_name)
            st_obj = part.state_get(prog)
            st_class = objects_data.state_class_from_part_type_get(part)
            state_save = st_class(st_obj)
            saved_states.append([part.name, state_save])

        trans = self.e.animation.program.transition

        def agree(bt, notification):
            self._remove_time_point(t, anim_name, anim_frame)
            notification.hide()
            notification.delete()
            op = Operation("animation (%s) frame (%s) deletion" % \
                               (anim_name, t))
            op.redo_callback_add(self._remove_time_point, t, anim_name,
                                 anim_frame)
            op.undo_callback_add(
                self._frame_readd, t, anim_name, saved_states, trans)
            self._operation_stack_cb(op)

        def disagree(bt, notification):
            notification.hide()
            notification.delete()

        if t in self.e.animation.timestops:
            notification = ErrorNotify(
                self._parent, orient=elementary.ELM_NOTIFY_ORIENT_CENTER)
            notification.title = "Do you really want to delete this " \
                "animation frame?"
            notification.action_add("Yes", agree, None, notification)
            notification.action_add("No", disagree, None,  notification)
            notification.show()
Пример #7
0
class AnimationsPartsList(PartsList):
    def __init__(self, parent, editable_grp, operation_stack_cb):
        PartsList.__init__(self, parent, editable_grp, operation_stack_cb)

        self._remove_confirmation = None

        self._edit_grp.animation.callback_add("animation.changed",
                                              self._animation_changed_cb)
        self._edit_grp.animation.callback_add("animation.unselected",
                                              self._animation_changed_cb)
        self._blocked_parts = []

    def _animation_changed_cb(self, emissor, data):
        # Nasty hack
        self._parts_update_cb(None, self._edit_grp.parts)

    def _parts_update_cb(self, emissor, data):
        if not self._edit_grp.animation.name:
            self.clear()
            self._edit_grp.animation.event_emit("parts.blocked.changed", [])
            return

        parts = data
        self.clear()
        self._blocked_parts = []
        self._edit_grp.part.name = None
        for p in parts[::-1]:
            chk = elementary.Check(self._parent)
            chk.state_set(self._edit_grp.animation.parts.get(p))
            if not chk.state:
                self._blocked_parts.append(p)
            chk.callback_changed_add(self._check_changed_cb, p)
            chk.show()
            self.add_full(p, end=chk)
        self.go()
        self._edit_grp.animation.event_emit("parts.blocked.changed",
                                            self._blocked_parts)

    def _part_added_cb(self, emissor, data):
        if not self._edit_grp.animation.name:
            PartsList._part_added_cb(self, emissor, data)
            return

        chk = elementary.Check(self._parent)
        chk.state_set(False)
        self._blocked_parts.append(data)
        self._edit_grp.animation.event_emit("parts.blocked.changed",
                                            self._blocked_parts)
        chk.callback_changed_add(self._check_changed_cb, data)
        chk.show()
        self.add_full(data, end=chk)
        self.go()

    def _check_changed_cb(self, obj, part):
        if obj.state:
            self._part_add(part, self._edit_grp.animation.name)

            op = Operation("part (%s) addition into animation (%s)" % \
                                (part, self._edit_grp.animation.name))
            op.redo_callback_add(self._part_add, part,
                                 self._edit_grp.animation.name)
            op.undo_callback_add(self._part_remove, part,
                                 self._edit_grp.animation.name)
            self._operation_stack_cb(op)
        else:
            # FIXME: Take the confirmation out of this function
            self._notification = ErrorNotify(
                self, elementary.ELM_NOTIFY_ORIENT_CENTER)
            self._notification.title = "Part Removal"
            lb = elementary.Label(self._notification)
            lb.text_set("Are you sure you want to remove<br>"
                         "this part from the animation?")
            lb.show()
            self._notification.pack_end(lb)
            self._notification.action_add("Remove",
                                          self._confirm_remove_cb, data=part)
            self._notification.action_add("Cancel",
                                          self._cancel_remove_cb, data=obj)
            self._notification.show()

    def _context_recall(self, **kargs):
        if "animation" in kargs:
            self._edit_grp.animation.name = kargs["animation"]
            if "time" in kargs:
                self._edit_grp.animation.state = kargs["time"]
        if "part" in kargs:
            self._edit_grp.part.name = kargs["part"]
            if "state" in kargs:
                self._edit_grp.part.state.name = kargs["state"]

    def _part_add(self, part, anim_name, saved_states=None):

        def frame_readd(part_name, saved_states):
            part = self._edit_grp.part_get(part_name)
            self._edit_grp.part.name = part_name
            for t, state in saved_states:
                if not part.state_exist(state.name):
                    prog = self._edit_grp.program_get(state.name)
                    prog.target_add(part_name)
                    part.state_add(state.name, 0.0)
                st = part.state_get(state.name)
                state.apply_to(st)
            if self._edit_grp.animation.program:
                statename = self._edit_grp.animation.program.name
                part.state_selected_set(statename)

        self._context_recall(animation=anim_name)
        self._edit_grp.animation.part_add(part)
        if saved_states:
            frame_readd(part, saved_states)
        self._parts_update_cb(None, self._edit_grp.parts)

    def _part_remove(self, part, anim_name):
        self._context_recall(animation=anim_name)
        self._edit_grp.animation.part_remove(part)
        self._parts_update_cb(None, self._edit_grp.parts)

    def _confirm_remove_cb(self, btn, part):
        saved_states = []
        p = self._edit_grp.part_get(part)
        for t in self._edit_grp.animation.timestops:
            prog = "@%s@%.2f" % (self._edit_grp.animation.name, t)
            st_obj = p.state_get(prog)
            if not st_obj:
                continue
            st_class = objects_data.state_class_from_part_type_get(p)
            state_save = st_class(st_obj)
            saved_states.append([t, state_save])

        self._part_remove(part, self._edit_grp.animation.name)
        self._notification_delete()
        op = Operation("part (%s) deletion from animation (%s)" % \
                            (part, self._edit_grp.animation.name))
        op.redo_callback_add(self._part_remove, part,
                             self._edit_grp.animation.name)
        op.undo_callback_add(self._part_add, part,
                             self._edit_grp.animation.name,
                             saved_states)
        self._operation_stack_cb(op)

    def _cancel_remove_cb(self, btn, chk):
        self._notification_delete()
        chk.state = True

    def _notification_delete(self):
        self._notification.delete()
        self._notification = None

    def _selected_cb(self, list_, list_item):
        if not self._edit_grp.animation.name:
            return

        part_name = list_item.label_get()
        if self._edit_grp.animation.parts.get(part_name):
            CList._selected_cb(self, list_, list_item)
            self._edit_grp.part.name = part_name
        else:
            self._edit_grp.part.name = None
            CList._unselected_cb(self, list_, list_item)
Пример #8
0
class OpenFile(elementary.Window):
    _notification = None

    def __init__(self, open_cb, *args, **kargs):
        elementary.Window.__init__(self, "openfile", elementary.ELM_WIN_BASIC)
        self.title_set("Open file")
        self.autodel_set(True)

        self._open_cb = (open_cb, args, kargs)

        bg = elementary.Background(self)
        self.resize_object_add(bg)
        bg.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
        bg.show()

        self._fs = FileSelector(self)
        self._fs.filter = self._filter
        self._fs.action_add("Cancel", self._cancel)
        self._fs.action_add("Ok", self._open)
        self._fs.action_disabled_set("Ok", True)
        self._fs.callback_add("file.clicked", self._file_clicked)
        self._fs.callback_add("file.selected", self._file_selected)
        self._fs.callback_add("file.selection_clear", self._file_unselected)
        self.resize_object_add(self._fs)
        self._fs.show()

        self.resize(600, 480)

    def show(self):
        self.activate()
        elementary.Window.show(self)

    def _file_clicked(self, obj, data):
        self._open(None)

    def _file_selected(self, obj, data):
        self._fs.action_disabled_set("Ok", False)

    def _file_unselected(self, obj, data):
        self._fs.action_disabled_set("Ok", True)

    def _filter(self, file):
        return file.endswith(".edc") or file.endswith(".edj")

    def _path_set(self, value):
        self._fs.path = value

    path = property(fset=_path_set)

    def _open_ok(self, sf, **kargs):
        self.hide()
        open_cb, args, kargs = self._open_cb
        open_cb(sf, *args, **kargs)
        self.delete()

    def _open(self, bt, mode=None):
        swapfile.open(self._fs.file, self._open_ok, self._notify_err, mode)

    def _open_forced(self, bt, data):
        self._open(bt, swapfile.REPLACE)

    def _open_recovery(self, bt, data):
        self._open(bt, swapfile.RESTORE)

    def list_files_on_diretory(self):
        path = os.getenv("PWD")
        list = os.listdir(path)
        list.sort(key=str.lower)
        files = []
        for file in list:
            if not file.startswith("."):
                full = os.path.join(path, file)
                if os.path.isfile(full):
                    if file.endswith(".edj"):
                        files.append(file)
        return files

    def _cancel(self, bt):
        self.delete()

    def _notify_del(self):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

    def _notify(self, message):
        self._notify_del()
        self._notification = elementary.Notify(self)
        self._notification.timeout_set(2)
        self._notification.orient_set(
            elementary.ELM_NOTIFY_ORIENT_BOTTOM_RIGHT)

        bx = elementary.Box(self)
        bx.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
        bx.horizontal_set(True)
        self._notification.content_set(bx)
        bx.show()

        lb = elementary.Label(self)
        lb.text_set(message)
        bx.pack_end(lb)
        lb.show()

        self._notification.show()

    def _notify_err(self, err, **kargs):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

        self._notification = ErrorNotify(self)

        if isinstance(err, IOError) and err.errno == errno.EEXIST:
            self._notification.title = "Swap file already exists"
            lb = elementary.Label(self._notification)
            lb.text_set("Another program may be editing the same file<br>" +
                        "or a previous edition session for this file crashed.")
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ignore Swap", self._open_forced)
            self._notification.action_add("Recover", self._open_recovery)
            self._notification.action_add("Abort", self._notify_abort)
        elif isinstance(err, swapfile.CompileError):
            self._notification.title = "Compiler Error"
            lb = elementary.Label(self._notification)
            lb.text_set(str(err.message).replace('\n', '<br>'))
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ok", self._notify_abort)
        else:
            self._notification.title = str(err).replace(':', '<br>')
            self._notification.action_add("Ok", self._notify_abort)

        self._notification.show()

    def _notify_abort(self, bt, data):
        self._notify_del()
Пример #9
0
class AnimationsPartsList(PartsList):
    def __init__(self, parent, editable_grp, operation_stack_cb):
        PartsList.__init__(self, parent, editable_grp, operation_stack_cb)

        self._remove_confirmation = None

        self._edit_grp.animation.callback_add("animation.changed",
                                              self._animation_changed_cb)
        self._edit_grp.animation.callback_add("animation.unselected",
                                              self._animation_changed_cb)
        self._blocked_parts = []

    def _animation_changed_cb(self, emissor, data):
        # Nasty hack
        self._parts_update_cb(None, self._edit_grp.parts)

    def _parts_update_cb(self, emissor, data):
        if not self._edit_grp.animation.name:
            self.clear()
            self._edit_grp.animation.event_emit("parts.blocked.changed", [])
            return

        parts = data
        self.clear()
        self._blocked_parts = []
        self._edit_grp.part.name = None
        for p in parts[::-1]:
            chk = elementary.Check(self._parent)
            chk.state_set(self._edit_grp.animation.parts.get(p))
            if not chk.state:
                self._blocked_parts.append(p)
            chk.callback_changed_add(self._check_changed_cb, p)
            chk.show()
            self.add_full(p, end=chk)
        self.go()
        self._edit_grp.animation.event_emit("parts.blocked.changed",
                                            self._blocked_parts)

    def _part_added_cb(self, emissor, data):
        if not self._edit_grp.animation.name:
            PartsList._part_added_cb(self, emissor, data)
            return

        chk = elementary.Check(self._parent)
        chk.state_set(False)
        self._blocked_parts.append(data)
        self._edit_grp.animation.event_emit("parts.blocked.changed",
                                            self._blocked_parts)
        chk.callback_changed_add(self._check_changed_cb, data)
        chk.show()
        self.add_full(data, end=chk)
        self.go()

    def _check_changed_cb(self, obj, part):
        if obj.state:
            self._part_add(part, self._edit_grp.animation.name)

            op = Operation("part (%s) addition into animation (%s)" % \
                                (part, self._edit_grp.animation.name))
            op.redo_callback_add(self._part_add, part,
                                 self._edit_grp.animation.name)
            op.undo_callback_add(self._part_remove, part,
                                 self._edit_grp.animation.name)
            self._operation_stack_cb(op)
        else:
            # FIXME: Take the confirmation out of this function
            self._notification = ErrorNotify(
                self, elementary.ELM_NOTIFY_ORIENT_CENTER)
            self._notification.title = "Part Removal"
            lb = elementary.Label(self._notification)
            lb.text_set("Are you sure you want to remove<br>"
                        "this part from the animation?")
            lb.show()
            self._notification.pack_end(lb)
            self._notification.action_add("Remove",
                                          self._confirm_remove_cb,
                                          data=part)
            self._notification.action_add("Cancel",
                                          self._cancel_remove_cb,
                                          data=obj)
            self._notification.show()

    def _context_recall(self, **kargs):
        if "animation" in kargs:
            self._edit_grp.animation.name = kargs["animation"]
            if "time" in kargs:
                self._edit_grp.animation.state = kargs["time"]
        if "part" in kargs:
            self._edit_grp.part.name = kargs["part"]
            if "state" in kargs:
                self._edit_grp.part.state.name = kargs["state"]

    def _part_add(self, part, anim_name, saved_states=None):
        def frame_readd(part_name, saved_states):
            part = self._edit_grp.part_get(part_name)
            self._edit_grp.part.name = part_name
            for t, state in saved_states:
                if not part.state_exist(state.name):
                    prog = self._edit_grp.program_get(state.name)
                    prog.target_add(part_name)
                    part.state_add(state.name, 0.0)
                st = part.state_get(state.name)
                state.apply_to(st)
            if self._edit_grp.animation.program:
                statename = self._edit_grp.animation.program.name
                part.state_selected_set(statename)

        self._context_recall(animation=anim_name)
        self._edit_grp.animation.part_add(part)
        if saved_states:
            frame_readd(part, saved_states)
        self._parts_update_cb(None, self._edit_grp.parts)

    def _part_remove(self, part, anim_name):
        self._context_recall(animation=anim_name)
        self._edit_grp.animation.part_remove(part)
        self._parts_update_cb(None, self._edit_grp.parts)

    def _confirm_remove_cb(self, btn, part):
        saved_states = []
        p = self._edit_grp.part_get(part)
        for t in self._edit_grp.animation.timestops:
            prog = "@%s@%.2f" % (self._edit_grp.animation.name, t)
            st_obj = p.state_get(prog)
            if not st_obj:
                continue
            st_class = objects_data.state_class_from_part_type_get(p)
            state_save = st_class(st_obj)
            saved_states.append([t, state_save])

        self._part_remove(part, self._edit_grp.animation.name)
        self._notification_delete()
        op = Operation("part (%s) deletion from animation (%s)" % \
                            (part, self._edit_grp.animation.name))
        op.redo_callback_add(self._part_remove, part,
                             self._edit_grp.animation.name)
        op.undo_callback_add(self._part_add, part,
                             self._edit_grp.animation.name, saved_states)
        self._operation_stack_cb(op)

    def _cancel_remove_cb(self, btn, chk):
        self._notification_delete()
        chk.state = True

    def _notification_delete(self):
        self._notification.delete()
        self._notification = None

    def _selected_cb(self, list_, list_item):
        if not self._edit_grp.animation.name:
            return

        part_name = list_item.label_get()
        if self._edit_grp.animation.parts.get(part_name):
            CList._selected_cb(self, list_, list_item)
            self._edit_grp.part.name = part_name
        else:
            self._edit_grp.part.name = None
            CList._unselected_cb(self, list_, list_item)
Пример #10
0
class OpenFile(elementary.Window):
    _notification = None

    def __init__(self, open_cb, *args, **kargs):
        elementary.Window.__init__(self, "openfile",
                                   elementary.ELM_WIN_BASIC)
        self.title_set("Open file")
        self.autodel_set(True)

        self._open_cb = (open_cb, args, kargs)

        bg = elementary.Background(self)
        self.resize_object_add(bg)
        bg.size_hint_weight_set(evas.EVAS_HINT_EXPAND,
                                evas.EVAS_HINT_EXPAND)
        bg.show()

        self._fs = FileSelector(self)
        self._fs.filter = self._filter
        self._fs.action_add("Cancel", self._cancel)
        self._fs.action_add("Ok", self._open)
        self._fs.action_disabled_set("Ok", True)
        self._fs.callback_add("file.clicked", self._file_clicked)
        self._fs.callback_add("file.selected", self._file_selected)
        self._fs.callback_add("file.selection_clear", self._file_unselected)
        self.resize_object_add(self._fs)
        self._fs.show()

        self.resize(600, 480)

    def show(self):
        self.activate()
        elementary.Window.show(self)

    def _file_clicked(self, obj, data):
        self._open(None)

    def _file_selected(self, obj, data):
        self._fs.action_disabled_set("Ok", False)

    def _file_unselected(self, obj, data):
        self._fs.action_disabled_set("Ok", True)

    def _filter(self, file):
        return file.endswith(".edc") or file.endswith(".edj")

    def _path_set(self, value):
        self._fs.path = value

    path = property(fset=_path_set)

    def _open_ok(self, sf, **kargs):
        self.hide()
        open_cb, args, kargs = self._open_cb
        open_cb(sf, *args, **kargs)
        self.delete()

    def _open(self, bt, mode=None):
        swapfile.open(self._fs.file, self._open_ok, self._notify_err, mode)

    def _open_forced(self, bt, data):
        self._open(bt, swapfile.REPLACE)

    def _open_recovery(self, bt, data):
        self._open(bt, swapfile.RESTORE)

    def list_files_on_diretory(self):
        path = os.getenv("PWD")
        list = os.listdir(path)
        list.sort(key=str.lower)
        files = []
        for file in list:
            if not file.startswith("."):
                full = os.path.join(path, file)
                if os.path.isfile(full):
                    if file.endswith(".edj"):
                        files.append(file)
        return files

    def _cancel(self, bt):
        self.delete()

    def _notify_del(self):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

    def _notify(self, message):
        self._notify_del()
        self._notification = elementary.Notify(self)
        self._notification.timeout_set(2)
        self._notification.orient_set(
            elementary.ELM_NOTIFY_ORIENT_BOTTOM_RIGHT)

        bx = elementary.Box(self)
        bx.size_hint_weight_set(evas.EVAS_HINT_EXPAND,
                                evas.EVAS_HINT_EXPAND)
        bx.horizontal_set(True)
        self._notification.content_set(bx)
        bx.show()

        lb = elementary.Label(self)
        lb.text_set(message)
        bx.pack_end(lb)
        lb.show()

        self._notification.show()

    def _notify_err(self, err, **kargs):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

        self._notification = ErrorNotify(self)

        if isinstance(err, IOError) and err.errno == errno.EEXIST:
            self._notification.title = "Swap file already exists"
            lb = elementary.Label(self._notification)
            lb.text_set(
                "Another program may be editing the same file<br>" +
                "or a previous edition session for this file crashed.")
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ignore Swap", self._open_forced)
            self._notification.action_add("Recover", self._open_recovery)
            self._notification.action_add("Abort", self._notify_abort)
        elif isinstance(err, swapfile.CompileError):
            self._notification.title = "Compiler Error"
            lb = elementary.Label(self._notification)
            lb.text_set(str(err.message).replace('\n', '<br>'))
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ok", self._notify_abort)
        else:
            self._notification.title = str(err).replace(':', '<br>')
            self._notification.action_add("Ok", self._notify_abort)

        self._notification.show()

    def _notify_abort(self, bt, data):
        self._notify_del()