def __init__(self, parent, new_sig_cb=None, sigs_list_cb=None): if not new_sig_cb or not sigs_list_cb: raise TypeError("You must set callbacks for signals retrieval and" " creation on NewSignalWizard objects.") Wizard.__init__(self, parent) self._type = None self.page_add( "default", "New Signal", "Name the new signal to be created and choose its type.") self._sig_name_entry = NameEntry(self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)) self.content_add("default", self._sig_name_entry) self._sig_name_entry.show() self._types_btns = SignalTypesButtons(self, self._type_select) self._types_btns.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._types_btns.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) self.content_add("default", self._types_btns) self._types_btns.show() self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._add, key="Return") self.action_disabled_set("default", "Add", True) self._new_sig_cb = new_sig_cb self._sigs_list_cb = sigs_list_cb
def _state_add_new_cb(self, popup, data): self.newstate_entry = NameEntry(self._pop) self.newstate_entry.entry = self._state_newname() self.newstate_entry.show() self.pager.item_simple_push(self.newstate_entry) self._pop.actions_clear() self._pop.action_add("Add", self._states_added_cb) self._pop.action_add("Close", self._cancel_clicked)
def __init__(self, parent, editable_grp, operation_stack_cb, img_new_img_cb=None, img_list_get_cb=None, img_id_get_cb=None, workfile_name_get_cb=None): Wizard.__init__(self, parent) self._parent = parent self._edit_grp = editable_grp self._operation_stack_cb = operation_stack_cb self._new_img_cb = img_new_img_cb self._img_list_get_cb = img_list_get_cb self._img_id_get_cb = img_id_get_cb self._workfile_name_get_cb = workfile_name_get_cb self._part_name = None self._type = None self.page_add("default", "New Part", "Name the new part to be inserted and choose its type.") self._part_name_entry = NameEntry( self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)) self.content_add("default", self._part_name_entry) self._part_name_entry.show() self._types_list = TypesList(self, self._type_select) self.content_add("default", self._types_list) self._types_list.show() self._ext_list = ExternalSelector(self, self._default_name_set) self._ext_list.size_hint_weight_set(0.0, 0.0) self.content_add("default", self._ext_list) self._ext_list.show() self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._sizing_go, key="Return") self.action_disabled_set("default", "Add", True) edje.message_signal_process() self._name_changed = False self.page_add("sizing", "New Part", "Position and size of new part.") self._partsetup = PartSetup(self) self._partsetup.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._partsetup.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) self._partsetup.show() self.action_add("sizing", "Cancel", self._default_go, key="Escape") self.action_add("sizing", "Add", self._add, key="Return") self.content_add("sizing", self._partsetup) self.goto("default")
def __init__(self, parent, new_anim_cb=None, anims_list_cb=None, parts_list_cb=None): if not new_anim_cb or not anims_list_cb: raise TypeError("You must set callbacks for animations retrieval" " and creation on NewAnimationWizard objects.") Wizard.__init__(self, parent) self.page_add("default", "New Animation", "Name the new animation to be created.", separator=True) self._anim_name_entry = NameEntry(self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, 0.5)) self.content_add("default", self._anim_name_entry) self._anim_name_entry.show() lbl = elementary.Label(self) lbl.text_set("Select the parts to use in the animation." " An empty selection will use all parts.") self.content_add("default", lbl) lbl.show() self._parts_list = elementary.List(self) self._parts_list.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._parts_list.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) if parts_list_cb: for p in parts_list_cb(): self._parts_list.item_append(p) self._parts_list.multi_select = True self._parts_list.go() self.content_add("default", self._parts_list) self._parts_list.show() self.alternate_background_set(True) self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._add, key="Return") self.action_disabled_set("default", "Add", True) self._new_anim_cb = new_anim_cb self._anims_list_cb = anims_list_cb
def __init__(self, parent, new_sig_cb=None, sigs_list_cb=None): if not new_sig_cb or not sigs_list_cb: raise TypeError("You must set callbacks for signals retrieval and" " creation on NewSignalWizard objects.") Wizard.__init__(self, parent) self._type = None self.page_add("default", "New Signal", "Name the new signal to be created and choose its type.") self._sig_name_entry = NameEntry( self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL), ) self.content_add("default", self._sig_name_entry) self._sig_name_entry.show() self._types_btns = SignalTypesButtons(self, self._type_select) self._types_btns.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._types_btns.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) self.content_add("default", self._types_btns) self._types_btns.show() self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._add, key="Return") self.action_disabled_set("default", "Add", True) self._new_sig_cb = new_sig_cb self._sigs_list_cb = sigs_list_cb
def _state_add_new_cb(self, popup, data): self.newstate_entry = NameEntry(self._pop) self.newstate_entry.entry = self._state_newname() self.newstate_entry.show() self.pager.content_push(self.newstate_entry) self._pop.actions_clear() self._pop.action_add("Add", self._states_added_cb) self._pop.action_add("Close", self._cancel_clicked)
def __init__(self, parent, new_anim_cb=None, anims_list_cb=None, parts_list_cb=None): if not new_anim_cb or not anims_list_cb: raise TypeError("You must set callbacks for animations retrieval" " and creation on NewAnimationWizard objects.") Wizard.__init__(self, parent) self.page_add("default", "New Animation", "Name the new animation to be created.", separator=True) self._anim_name_entry = NameEntry( self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, 0.5)) self.content_add("default", self._anim_name_entry) self._anim_name_entry.show() lbl = elementary.Label(self) lbl.text_set("Select the parts to use in the animation." " An empty selection will use all parts.") self.content_add("default", lbl) lbl.show() self._parts_list = elementary.List(self) self._parts_list.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._parts_list.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) if parts_list_cb: for p in parts_list_cb(): self._parts_list.item_append(p) self._parts_list.multi_select = True self._parts_list.go() self.content_add("default", self._parts_list) self._parts_list.show() self.alternate_background_set(True) self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._add, key="Return") self.action_disabled_set("default", "Add", True) self._new_anim_cb = new_anim_cb self._anims_list_cb = anims_list_cb
class NewSignalWizard(Wizard): def __init__(self, parent, new_sig_cb=None, sigs_list_cb=None): if not new_sig_cb or not sigs_list_cb: raise TypeError("You must set callbacks for signals retrieval and" " creation on NewSignalWizard objects.") Wizard.__init__(self, parent) self._type = None self.page_add( "default", "New Signal", "Name the new signal to be created and choose its type.") self._sig_name_entry = NameEntry(self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)) self.content_add("default", self._sig_name_entry) self._sig_name_entry.show() self._types_btns = SignalTypesButtons(self, self._type_select) self._types_btns.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._types_btns.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) self.content_add("default", self._types_btns) self._types_btns.show() self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._add, key="Return") self.action_disabled_set("default", "Add", True) self._new_sig_cb = new_sig_cb self._sigs_list_cb = sigs_list_cb def _name_changed_cb(self, obj): self._check_name_and_type() def _type_select(self, type_): self._type = type_ self._check_name_and_type() def _check_name_and_type(self): error_msg = "This signal name is already used in this group" def good(): self._sig_name_entry.status_label = "" self.action_disabled_set("default", "Add", False) def bad(): self._sig_name_entry.status_label = error_msg self.action_disabled_set("default", "Add", True) def incomplete(): self._sig_name_entry.status_label = "" self.action_disabled_set("default", "Add", True) name = self._sig_name_entry.entry if name in self._sigs_list_cb(): bad() return if not name or self._type is None: incomplete() return good() def _add(self): name = self._sig_name_entry.entry success = self._new_sig_cb(name, self._type) if success: ecore.idler_add(self.close) else: self.notify("Error creating new signal.") def _cancel(self): self.close()
class NewAnimationWizard(Wizard): def __init__(self, parent, new_anim_cb=None, anims_list_cb=None, parts_list_cb=None): if not new_anim_cb or not anims_list_cb: raise TypeError("You must set callbacks for animations retrieval" " and creation on NewAnimationWizard objects.") Wizard.__init__(self, parent) self.page_add("default", "New Animation", "Name the new animation to be created.", separator=True) self._anim_name_entry = NameEntry( self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, 0.5)) self.content_add("default", self._anim_name_entry) self._anim_name_entry.show() lbl = elementary.Label(self) lbl.text_set("Select the parts to use in the animation." " An empty selection will use all parts.") self.content_add("default", lbl) lbl.show() self._parts_list = elementary.List(self) self._parts_list.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._parts_list.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) if parts_list_cb: for p in parts_list_cb(): self._parts_list.item_append(p) self._parts_list.multi_select = True self._parts_list.go() self.content_add("default", self._parts_list) self._parts_list.show() self.alternate_background_set(True) self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._add, key="Return") self.action_disabled_set("default", "Add", True) self._new_anim_cb = new_anim_cb self._anims_list_cb = anims_list_cb def _name_changed_cb(self, obj): error_msg = "This animation name already exists in this group" def good(): self._anim_name_entry.status_label = "" self.action_disabled_set("default", "Add", False) def bad(): self._anim_name_entry.status_label = error_msg self.action_disabled_set("default", "Add", True) def ugly(): self._anim_name_entry.status_label = "" self.action_disabled_set("default", "Add", True) name = self._anim_name_entry.entry if not name: ugly() return if name in self._anims_list_cb(): bad() return good() def _add(self): name = self._anim_name_entry.entry its = self._parts_list.selected_items_get() if not its: parts = None else: parts = [] for it in its: parts.append(it.label_get()) success = self._new_anim_cb(name, parts) if success: self.close() else: self.notify("Error creating new animation.") def _cancel(self): self.close()
class WidgetStates(WidgetEntryButton): pop_min_w = 200 pop_min_h = 300 def __init__(self, parent, editable, operation_stack_cb): WidgetEntryButton.__init__(self, parent, "editje/icon/options") self._operation_stack_cb = operation_stack_cb self._edit_grp = editable self._selstate = None self._pop = None self._edit_grp.part.callback_add("part.unselected", self._close_cb) self._edit_grp.part.callback_add("part.changed", self._close_cb) def _open(self, bt, *args): self.open() def _list_populate(self, *args): self.states.clear() for s in self._edit_grp.part.states: ico = None if s == self._edit_grp.part.state.name: ico = Icon(self.states) ico.file_set(self.theme_file, "editje/icon/confirm") ico.scale_set(0, 0) lbl = "%s %.2f" % s self.states.item_append(lbl, None, ico, self._show_actions, s) self.states.go() def _state_add_new_cb(self, popup, data): self.newstate_entry = NameEntry(self._pop) self.newstate_entry.entry = self._state_newname() self.newstate_entry.show() self.pager.content_push(self.newstate_entry) self._pop.actions_clear() self._pop.action_add("Add", self._states_added_cb) self._pop.action_add("Close", self._cancel_clicked) def _state_newname(self): max = 0 cur_state = self._edit_grp.part.state.name if re.match("[a-zA-Z]*\d{2,}", cur_state[0]): cur = cur_state[0][:-2] else: cur = cur_state[0] for state in self._edit_grp.part.states: if re.match("%s\d{2,}" % cur, state[0]): num = int(state[0][len(cur):]) if num > max: max = num nst = cur + "%.2d" % (max + 1) return nst # if st_to state does not exist for the part, it is created def _part_state_copy_from(self, part_name, st_from, st_to): self._edit_grp.part.name = part_name pt = self._edit_grp.part_get(part_name) existed = pt.state_exist(*st_to) # FIXME: totally don't know why state_copy was not working for the # latter case, return here when things change underneath. also fix # the ugly event emitions if not existed: pt.state_copy(st_from[0], st_from[1], st_to[0], st_to[1]) self._edit_grp.part.event_emit("state.added", st_to) self._edit_grp.part.state.name = st_to else: st = pt.state_get(*st_to) st.copy_from(*st_from) self._edit_grp.part.state.event_emit("state.changed", st_to) def _remove_state_internal(self, state): if self._is_default(state): # FIXME: notify the user of it somehow return False if state == self._edit_grp.part.state.name: self._edit_grp.part.state.name = ("default", 0.00) return self._edit_grp.part.state_del(*state) def _states_added_cb(self, popup, data): new_state = self.newstate_entry.entry tmp = new_state.split(None, 1) if len(tmp) == 1: new_state = (tmp[0], 0.0) else: new_state = (tmp[0], float(tmp[1])) part_name = self._edit_grp.part.name part = self._edit_grp.part_get(part_name) curr_state = self._edit_grp.part.state.name if part.state_exist(*new_state): # FIXME: notify the user of it somehow return self._part_state_copy_from(part_name, curr_state, new_state) op = Operation("state addition") op.redo_callback_add( self._part_state_copy_from, part_name, curr_state, new_state) op.undo_callback_add(self._remove_state_internal, new_state) self._operation_stack_cb(op) self.close() def _is_default(self, state): if type(state) == str: return state == "default 0.00" return state == ("default", 0.00) def _state_restore(self, part_name, state_save, readd=False): self._edit_grp.part.name = part_name st_name = (state_save.name, state_save.value) if readd: if not self._edit_grp.part.state_add(*st_name): return state = self._edit_grp.part_get(part_name).state_get(*st_name) state_save.apply_to(state) # FIXME: ugly hacks if readd: # 2nd time for this sig self._edit_grp.part.event_emit("state.added", st_name) else: self._edit_grp.part.state.event_emit("state.changed", st_name) self._edit_grp.part.state.name = st_name def _remove_state_cb(self, btn, state_name): part_name = self._edit_grp.part.name part = self._edit_grp.part_get(part_name) st_obj = part.state_get(*state_name) st_class = objects_data.state_class_from_part_type_get(part) state_save = st_class(st_obj) if self._remove_state_internal(state_name): op = Operation("state deletion") op.redo_callback_add(self._remove_state_internal, state_name) op.undo_callback_add( self._state_restore, part_name, state_save, readd=True) self._operation_stack_cb(op) else: del state_save self._pop.actions_clear() self._pop.action_add("New", self._state_add_new_cb) self._pop.action_add("Close", self._cancel_clicked) self.pager.content_pop() def _reset_state_to_cb(self, it, st_from): part_name = self._edit_grp.part.name curr_state = self._edit_grp.part.state.name part = self._edit_grp.part_get(part_name) st_obj = part.state_get(*curr_state) st_class = objects_data.state_class_from_part_type_get(part) state_save = st_class(st_obj) self._part_state_copy_from(part_name, st_from, curr_state) op = Operation( "state copying (%s into %s)" % (st_from[0], curr_state[0])) op.redo_callback_add( self._part_state_copy_from, part_name, st_from, curr_state) op.undo_callback_add(self._state_restore, part_name, state_save) self._operation_stack_cb(op) self.close() def _cancel_clicked(self, popup, data): self.close() def _states_select_cb(self, it, state): self._selstate = state self._edit_grp.part.state.name = state self.close() def _action_button_add(self, label, callback, state): btn = Button(self._pop) btn.text_set(label) btn.callback_clicked_add(callback, state) btn.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) btn.size_hint_weight_set(0.0, 0.0) self.actions_box.pack_end(btn) btn.show() return btn def _show_actions(self, it, ti, state): strstate = "%s %.2f" % state self.actions_box = Box(self._pop) name_box = Box(self._pop) lb_state = Label(self._pop) lb_state.text_set("<b>State: ") lb_name = Label(self._pop) lb_name.text_set(strstate) name_box.horizontal_set(True) name_box.pack_end(lb_state) lb_state.show() name_box.pack_end(lb_name) lb_name.show() self.actions_box.pack_end(name_box) name_box.show() space = Label(self._pop) space.text_set(" ") self.actions_box.pack_end(space) space.show() self._action_button_add("Change to", self._states_select_cb, state) self._action_button_add("Reset to", self._reset_state_to_cb, state) btn_delete = self._action_button_add( "Delete", self._remove_state_cb, state) if self._is_default(state): btn_delete.disabled_set(True) lb_name.style_set("editje.statedefault") else: lb_name.style_set("editje.statenormal") self.pager.content_push(self.actions_box) self._pop.actions_clear() self._pop.action_add("Back", self._back_to_list_cb) self._pop.action_add("Close", self._cancel_clicked) def _back_to_list_cb(self, it, ti): self.pager.content_pop() self._pop.actions_clear() self._pop.action_add("New", self._state_add_new_cb) self._pop.action_add("Close", self._cancel_clicked) self.states.selected_item_get().selected_set(False) def open(self): if not self._pop: self._pop = Floater(self.button, self.obj) self.pager = Pager(self._pop) self.pager.style_set("editje.rightwards") self.states = List(self._pop) self.states.size_hint_weight_set( evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self.states.size_hint_align_set(-1.0, -1.0) self.states.show() self.pager.content_push(self.states) self._pop.content_set(self.pager) self._pop.size_min_set(self.pop_min_w, self.pop_min_h) self._pop.title_set("States selection") self._pop.action_add("New", self._state_add_new_cb) self._pop.action_add("Close", self._cancel_clicked) self._edit_grp.part.callback_add( "states.changed", self._list_populate) self._edit_grp.part.state.callback_add( "state.changed", self._list_populate) self._list_populate() self._pop.show() def _close_cb(self, *args): self.close() def close(self): if not self._pop: return self._edit_grp.part.callback_del("states.changed", self._list_populate) self._edit_grp.part.state.callback_del( "state.changed", self._list_populate) self._pop.hide() self._pop = None def _internal_value_set(self, val): WidgetEntryButton._internal_value_set(self, val) if self._is_default(val): self.entry.disabled_set(True) else: self.entry.disabled_set(False)
class NewPartWizard(Wizard): def __init__(self, parent, editable_grp, operation_stack_cb, img_new_img_cb=None, img_list_get_cb=None, img_id_get_cb=None, workfile_name_get_cb=None): Wizard.__init__(self, parent) self._parent = parent self._edit_grp = editable_grp self._operation_stack_cb = operation_stack_cb self._new_img_cb = img_new_img_cb self._img_list_get_cb = img_list_get_cb self._img_id_get_cb = img_id_get_cb self._workfile_name_get_cb = workfile_name_get_cb self._part_name = None self._type = None self.page_add("default", "New Part", "Name the new part to be inserted and choose its type.") self._part_name_entry = NameEntry( self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)) self.content_add("default", self._part_name_entry) self._part_name_entry.show() self._types_list = TypesList(self, self._type_select) self.content_add("default", self._types_list) self._types_list.show() self._ext_list = ExternalSelector(self, self._default_name_set) self._ext_list.size_hint_weight_set(0.0, 0.0) self.content_add("default", self._ext_list) self._ext_list.show() self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._sizing_go, key="Return") self.action_disabled_set("default", "Add", True) edje.message_signal_process() self._name_changed = False self.page_add("sizing", "New Part", "Position and size of new part.") self._partsetup = PartSetup(self) self._partsetup.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._partsetup.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) self._partsetup.show() self.action_add("sizing", "Cancel", self._default_go, key="Escape") self.action_add("sizing", "Add", self._add, key="Return") self.content_add("sizing", self._partsetup) self.goto("default") def _name_changed_cb(self, obj): self._name_changed = True self._check_name_and_type() def _type_select(self, list_, item, label, *args, **kwargs): self._type = label if self._type == edje.EDJE_PART_TYPE_EXTERNAL: self._external_selector_toggle(True) else: self._external_selector_toggle(False) self._default_name_set(item.label_get()) self._check_name_and_type() def _check_name_and_type(self): error_msg = "This part name is already used in this group" def good(): self._part_name_entry.status_label = "" self.action_disabled_set("default", "Add", False) def bad(): self._part_name_entry.status_label = error_msg self.action_disabled_set("default", "Add", True) def incomplete(): self._part_name_entry.status_label = "" self.action_disabled_set("default", "Add", True) name = self._part_name_entry.entry if name in self._edit_grp.parts: bad() return if not name or not self._type: incomplete() return external_type = self._ext_list.type if self._type == edje.EDJE_PART_TYPE_EXTERNAL and not external_type: incomplete() return good() def _default_name_set(self, label): if self._name_changed and self._part_name_entry.entry or not label: self._check_name_and_type() return max_num = 0 for p in self._edit_grp.parts: name = re.match("^%s(\d{2,})$" % label, p) if name: num = int(name.group(1)) if num > max_num: max_num = num self._part_name_entry.entry = label + "%.2d" % (max_num + 1) edje.message_signal_process() self._name_changed = False def _add(self): def add_internal(name, edje_type, ext_name=""): if not self._edit_grp.part_add(name, edje_type, ext_name, init=self._partsetup.apply_to): self.notify("Error adding new part.") return False return True self._part_name = self._part_name_entry.entry if self._type == edje.EDJE_PART_TYPE_EXTERNAL: ext_name = self._ext_list.type else: ext_name = "" if self._type == edje.EDJE_PART_TYPE_IMAGE: ImageSelectionWizard(self._parent, self._image_set, self._new_img_cb, self._img_list_get_cb, self._img_id_get_cb, self._workfile_name_get_cb).show() else: if add_internal(self._part_name, self._type, ext_name): op = Operation("part addition") op.redo_callback_add( add_internal, self._part_name, self._type, ext_name) op.undo_callback_add(self._edit_grp.part_del, self._part_name) self._operation_stack_cb(op) self.close() def _image_set(self, selection): def part_add(name, edje_type, selection): if not self._edit_grp.part_add(name, edje_type, ""): return False self._edit_grp.part.state.image = selection return True if part_add(self._part_name, self._type, selection): op = Operation("part addition") op.redo_callback_add(part_add, self._part_name, self._type, selection) op.undo_callback_add(self._edit_grp.part_del, self._part_name) self._operation_stack_cb(op) def _external_selector_toggle(self, show): if show: self._ext_list.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._ext_list._modules_first.selected_set(True) else: self._ext_list.size_hint_weight_set(0, 0) external_type = self._ext_list._types.selected_item_get() if external_type: external_type.selected_set(False) self._ext_list.type = "" def _cancel(self): self.close() def _sizing_go(self): self.goto("sizing") def _default_go(self): self.goto("default")
class NewAnimationWizard(Wizard): def __init__(self, parent, new_anim_cb=None, anims_list_cb=None, parts_list_cb=None): if not new_anim_cb or not anims_list_cb: raise TypeError("You must set callbacks for animations retrieval" " and creation on NewAnimationWizard objects.") Wizard.__init__(self, parent) self.page_add("default", "New Animation", "Name the new animation to be created.", separator=True) self._anim_name_entry = NameEntry(self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, 0.5)) self.content_add("default", self._anim_name_entry) self._anim_name_entry.show() lbl = elementary.Label(self) lbl.text_set("Select the parts to use in the animation." " An empty selection will use all parts.") self.content_add("default", lbl) lbl.show() self._parts_list = elementary.List(self) self._parts_list.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._parts_list.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) if parts_list_cb: for p in parts_list_cb(): self._parts_list.item_append(p) self._parts_list.multi_select = True self._parts_list.go() self.content_add("default", self._parts_list) self._parts_list.show() self.alternate_background_set(True) self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._add, key="Return") self.action_disabled_set("default", "Add", True) self._new_anim_cb = new_anim_cb self._anims_list_cb = anims_list_cb def _name_changed_cb(self, obj): error_msg = "This animation name already exists in this group" def good(): self._anim_name_entry.status_label = "" self.action_disabled_set("default", "Add", False) def bad(): self._anim_name_entry.status_label = error_msg self.action_disabled_set("default", "Add", True) def ugly(): self._anim_name_entry.status_label = "" self.action_disabled_set("default", "Add", True) name = self._anim_name_entry.entry if not name: ugly() return if name in self._anims_list_cb(): bad() return good() def _add(self): name = self._anim_name_entry.entry its = self._parts_list.selected_items_get() if not its: parts = None else: parts = [] for it in its: parts.append(it.label_get()) success = self._new_anim_cb(name, parts) if success: self.close() else: self.notify("Error creating new animation.") def _cancel(self): self.close()
class WidgetStates(WidgetEntryButton): pop_min_w = 200 pop_min_h = 300 def __init__(self, parent, editable, operation_stack_cb): WidgetEntryButton.__init__(self, parent, "editje/icon/options") self._operation_stack_cb = operation_stack_cb self._edit_grp = editable self._selstate = None self._pop = None self._edit_grp.part.callback_add("part.unselected", self._close_cb) self._edit_grp.part.callback_add("part.changed", self._close_cb) def _open(self, bt, *args): self.open() def _list_populate(self, *args): self.states.clear() for s in self._edit_grp.part.states: ico = None if s == self._edit_grp.part.state.name: ico = Icon(self.states) ico.file_set(self.theme_file, "editje/icon/confirm") ico.resizable_set(0, 0) lbl = "%s %.2f" % s self.states.item_append(lbl, None, ico, self._show_actions, s) self.states.go() def _state_add_new_cb(self, popup, data): self.newstate_entry = NameEntry(self._pop) self.newstate_entry.entry = self._state_newname() self.newstate_entry.show() self.pager.item_simple_push(self.newstate_entry) self._pop.actions_clear() self._pop.action_add("Add", self._states_added_cb) self._pop.action_add("Close", self._cancel_clicked) def _state_newname(self): max = 0 cur_state = self._edit_grp.part.state.name if re.match("[a-zA-Z]*\d{2,}", cur_state[0]): cur = cur_state[0][:-2] else: cur = cur_state[0] for state in self._edit_grp.part.states: if re.match("%s\d{2,}" % cur, state[0]): num = int(state[0][len(cur):]) if num > max: max = num nst = cur + "%.2d" % (max + 1) return nst # if st_to state does not exist for the part, it is created def _part_state_copy_from(self, part_name, st_from, st_to): self._edit_grp.part.name = part_name pt = self._edit_grp.part_get(part_name) existed = pt.state_exist(*st_to) # FIXME: totally don't know why state_copy was not working for the # latter case, return here when things change underneath. also fix # the ugly event emitions if not existed: pt.state_copy(st_from[0], st_from[1], st_to[0], st_to[1]) self._edit_grp.part.event_emit("state.added", st_to) self._edit_grp.part.state.name = st_to else: st = pt.state_get(*st_to) st.copy_from(*st_from) self._edit_grp.part.state.event_emit("state.changed", st_to) def _remove_state_internal(self, state): if self._is_default(state): # FIXME: notify the user of it somehow return False if state == self._edit_grp.part.state.name: self._edit_grp.part.state.name = ("default", 0.00) return self._edit_grp.part.state_del(*state) def _states_added_cb(self, popup, data): new_state = self.newstate_entry.entry tmp = new_state.split(None, 1) if len(tmp) == 1: new_state = (tmp[0], 0.0) else: new_state = (tmp[0], float(tmp[1])) part_name = self._edit_grp.part.name part = self._edit_grp.part_get(part_name) curr_state = self._edit_grp.part.state.name if part.state_exist(*new_state): # FIXME: notify the user of it somehow return self._part_state_copy_from(part_name, curr_state, new_state) op = Operation("state addition") op.redo_callback_add(self._part_state_copy_from, part_name, curr_state, new_state) op.undo_callback_add(self._remove_state_internal, new_state) self._operation_stack_cb(op) self.close() def _is_default(self, state): if type(state) == str: return state == "default 0.00" return state == ("default", 0.00) def _state_restore(self, part_name, state_save, readd=False): self._edit_grp.part.name = part_name st_name = (state_save.name, state_save.value) if readd: if not self._edit_grp.part.state_add(*st_name): return state = self._edit_grp.part_get(part_name).state_get(*st_name) state_save.apply_to(state) # FIXME: ugly hacks if readd: # 2nd time for this sig self._edit_grp.part.event_emit("state.added", st_name) else: self._edit_grp.part.state.event_emit("state.changed", st_name) self._edit_grp.part.state.name = st_name def _remove_state_cb(self, btn, state_name): part_name = self._edit_grp.part.name part = self._edit_grp.part_get(part_name) st_obj = part.state_get(*state_name) st_class = objects_data.state_class_from_part_type_get(part) state_save = st_class(st_obj) if self._remove_state_internal(state_name): op = Operation("state deletion") op.redo_callback_add(self._remove_state_internal, state_name) op.undo_callback_add(self._state_restore, part_name, state_save, readd=True) self._operation_stack_cb(op) else: del state_save self._pop.actions_clear() self._pop.action_add("New", self._state_add_new_cb) self._pop.action_add("Close", self._cancel_clicked) self.pager.item_pop() def _reset_state_to_cb(self, it, st_from): part_name = self._edit_grp.part.name curr_state = self._edit_grp.part.state.name part = self._edit_grp.part_get(part_name) st_obj = part.state_get(*curr_state) st_class = objects_data.state_class_from_part_type_get(part) state_save = st_class(st_obj) self._part_state_copy_from(part_name, st_from, curr_state) op = Operation("state copying (%s into %s)" % (st_from[0], curr_state[0])) op.redo_callback_add(self._part_state_copy_from, part_name, st_from, curr_state) op.undo_callback_add(self._state_restore, part_name, state_save) self._operation_stack_cb(op) self.close() def _cancel_clicked(self, popup, data): self.close() def _states_select_cb(self, it, state): self._selstate = state self._edit_grp.part.state.name = state self.close() def _action_button_add(self, label, callback, state): btn = Button(self._pop) btn.text_set(label) btn.callback_clicked_add(callback, state) btn.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) btn.size_hint_weight_set(0.0, 0.0) self.actions_box.pack_end(btn) btn.show() return btn def _show_actions(self, it, ti, state): strstate = "%s %.2f" % state self.actions_box = Box(self._pop) name_box = Box(self._pop) lb_state = Label(self._pop) lb_state.text_set("<b>State: ") lb_name = Label(self._pop) lb_name.text_set(strstate) name_box.horizontal_set(True) name_box.pack_end(lb_state) lb_state.show() name_box.pack_end(lb_name) lb_name.show() self.actions_box.pack_end(name_box) name_box.show() space = Label(self._pop) space.text_set(" ") self.actions_box.pack_end(space) space.show() self._action_button_add("Change to", self._states_select_cb, state) self._action_button_add("Reset to", self._reset_state_to_cb, state) btn_delete = self._action_button_add("Delete", self._remove_state_cb, state) if self._is_default(state): btn_delete.disabled_set(True) lb_name.style_set("editje.statedefault") else: lb_name.style_set("editje.statenormal") self.pager.item_simple_push(self.actions_box) self._pop.actions_clear() self._pop.action_add("Back", self._back_to_list_cb) self._pop.action_add("Close", self._cancel_clicked) def _back_to_list_cb(self, it, ti): self.pager.item_pop() self._pop.actions_clear() self._pop.action_add("New", self._state_add_new_cb) self._pop.action_add("Close", self._cancel_clicked) self.states.selected_item_get().selected_set(False) def open(self): if not self._pop: self._pop = Floater(self.button, self.obj) self.pager = Naviframe(self._pop) self.pager.style_set("editje.rightwards") self.states = List(self._pop) self.states.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self.states.size_hint_align_set(-1.0, -1.0) self.states.show() self.pager.item_simple_push(self.states) self._pop.content_set(self.pager) self._pop.size_min_set(self.pop_min_w, self.pop_min_h) self._pop.title_set("States selection") self._pop.action_add("New", self._state_add_new_cb) self._pop.action_add("Close", self._cancel_clicked) self._edit_grp.part.callback_add("states.changed", self._list_populate) self._edit_grp.part.state.callback_add("state.changed", self._list_populate) self._list_populate() self._pop.show() def _close_cb(self, *args): self.close() def close(self): if not self._pop: return self._edit_grp.part.callback_del("states.changed", self._list_populate) self._edit_grp.part.state.callback_del("state.changed", self._list_populate) self._pop.hide() self._pop = None def _internal_value_set(self, val): WidgetEntryButton._internal_value_set(self, val) if self._is_default(val): self.entry.disabled_set(True) else: self.entry.disabled_set(False)
class NewSignalWizard(Wizard): def __init__(self, parent, new_sig_cb=None, sigs_list_cb=None): if not new_sig_cb or not sigs_list_cb: raise TypeError("You must set callbacks for signals retrieval and" " creation on NewSignalWizard objects.") Wizard.__init__(self, parent) self._type = None self.page_add("default", "New Signal", "Name the new signal to be created and choose its type.") self._sig_name_entry = NameEntry( self, changed_cb=self._name_changed_cb, weight_hints=(evas.EVAS_HINT_EXPAND, 0.0), align_hints=(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL), ) self.content_add("default", self._sig_name_entry) self._sig_name_entry.show() self._types_btns = SignalTypesButtons(self, self._type_select) self._types_btns.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND) self._types_btns.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) self.content_add("default", self._types_btns) self._types_btns.show() self.action_add("default", "Cancel", self._cancel, key="Escape") self.action_add("default", "Add", self._add, key="Return") self.action_disabled_set("default", "Add", True) self._new_sig_cb = new_sig_cb self._sigs_list_cb = sigs_list_cb def _name_changed_cb(self, obj): self._check_name_and_type() def _type_select(self, type_): self._type = type_ self._check_name_and_type() def _check_name_and_type(self): error_msg = "This signal name is already used in this group" def good(): self._sig_name_entry.status_label = "" self.action_disabled_set("default", "Add", False) def bad(): self._sig_name_entry.status_label = error_msg self.action_disabled_set("default", "Add", True) def incomplete(): self._sig_name_entry.status_label = "" self.action_disabled_set("default", "Add", True) name = self._sig_name_entry.entry if name in self._sigs_list_cb(): bad() return if not name or self._type is None: incomplete() return good() def _add(self): name = self._sig_name_entry.entry success = self._new_sig_cb(name, self._type) if success: ecore.idler_add(self.close) else: self.notify("Error creating new signal.") def _cancel(self): self.close()