Ejemplo n.º 1
0
    def _floater_open(self, parent, *args):
        if not self._floater:
            self._floater = Floater(parent, parent)
            self._floater.size_min_set(
                self._floater_min_w, self._floater_min_h)

            self._floater_title_init()
            self._floater_actions_init()
            self._floater_content_init()

        self._floater_update()

        self._floater.show()
Ejemplo n.º 2
0
def mouse_click(x, y):
    global object
    if object == 'Ball':
        balls.add(Ball(x, y, random_angle()))
    elif object == "Floater":
        balls.add(Floater(x, y, random_angle()))
    elif object == "Black_Hole":
        simu.add(Black_Hole(x, y))
    elif object == "Pulsator":
        simu.add(Pulsator(x, y))
    elif object == "Remove":
        g = balls
        h = set()
        k = set()
        for f in g:
            if f.contains((x, y)):
                h.add(f)
        for s in simu:
            if s.contains((x, y)):
                k.add(s)
        for l in h:
            remove(l)
        for b in k:
            simu.remove(b)
        pass
    elif object == "Hunter":
        simu.add(Hunter(x, y, random_angle()))
 def update(self, model):
     if len(Black_Hole.update(self, model)) != 0:
         for i in range(len(Black_Hole.update(self, model))):
             for a in range(10):
                 choice = randint(1, 2)
                 dx = randint(-10, 10)
                 dy = randint(-10, 10)
                 if choice == 1:
                     model.simuls.add(Ball(self._x + dx, self._y + dy))
                 elif choice == 2:
                     model.simuls.add(Floater(self._x + dx, self._y + dy))
         self.eaten = set()
         model.remove(self)
Ejemplo n.º 4
0
    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()
Ejemplo n.º 5
0
def mouse_click(x, y):
    if button == 'Ball':
        simulation.add(Ball(x, y))
    elif button == 'Floater':
        simulation.add(Floater(x, y))
    elif button == 'Black_Hole':
        simulation.add(Black_Hole(x, y))
    elif button == 'Pulsator':
        simulation.add(Pulsator(x, y))
    elif button == 'Hunter':
        simulation.add(Hunter(x, y))
    elif button == 'Special':
        simulation.add(Special(x, y))
    elif button == 'Remove':
        for i in simulation.copy():
            if i.distance((x, y)) < i.radius:
                remove(i)
Ejemplo n.º 6
0
def mouse_click(x,y):
    global selection, simultons
    if selection == 'Remove': #Need to finish
        for sim in simultons.copy():
            if sim.contains( (x,y) ):
                remove(sim)
    elif selection == 'Ball':
        add( Ball(x,y,5,5,0,5) )
    elif selection == 'Floater':
        add( Floater(x,y,5,5,0,5) )
    elif selection == 'Black_Hole':
        add( Black_Hole(x,y,20,20) )
    elif selection == 'Pulsator':
        add( Pulsator(x,y,20,20) )
    elif selection == 'Hunter':
        add( Hunter(x,y,20,20,0,5) )
    elif selection == 'Special':
        add( Special(x,y,5,5,0,10) )
Ejemplo n.º 7
0
def mouse_click(x,y):
    try:
        if object_name == 'Ball':
            balls.add(Ball(x,y))
        elif object_name == 'Floater':
            balls.add(Floater(x,y))
        elif object_name == 'Black_Hole':
            balls.add(Black_Hole(x,y))
        elif object_name == 'Pulsator':
            balls.add(Pulsator(x,y))
        elif object_name == 'Hunter':
            balls.add(Hunter(x,y))  
        elif object_name == 'Special':
            balls.add(Special(x,y))
  
        elif object_name == 'Remove':
            for i in find(lambda a: a.contains((x,y))):
                balls.remove(i)      
        
    except:
        pass
Ejemplo n.º 8
0
def mouse_click(x, y):
    global balls
    if select_kind == 'Remove':
        for b in balls:
            coor = b.get_location()
            if coor[0] - 5 < x and x < coor[0] + 5 and coor[
                    1] - 5 < y and y < coor[1] + 5:
                remove(b)
                break
    elif select_kind == 'Ball':
        add(Ball(x, y))
    elif select_kind == 'Floater':
        add(Floater(x, y))
    elif select_kind == 'Black_Hole':
        add(Black_Hole(x, y))
    elif select_kind == 'Pulsator':
        add(Pulsator(x, y))
    elif select_kind == 'Hunter':
        add(Hunter(x, y))
    elif select_kind == 'Special':
        add(Special(x, y))
Ejemplo n.º 9
0
def mouse_click(x,y):
    global balls, click, remove_set
    if str(click) == "Remove":
        try:
            for ele in balls:
                if ele.contains((x,y)):
                    remove(ele) 
        except:
            pass
    else:
        if str(click) == "Ball":
            add(Ball(x,y))
        elif str(click) == 'Black_Hole':
            add(Black_Hole(x,y))
        elif str(click) == 'Floater':
            add(Floater(x,y))
        elif str(click) == 'Hunter':
            add(Hunter(x,y))
        elif str(click) == 'Pulsator':
            add(Pulsator(x,y))
        elif str(click) == "Special":
            add(Special(x,y))
Ejemplo n.º 10
0
class FloaterOpener(object):
    _floater_min_w = 200
    _floater_min_h = 300

    def __init__(self, popup_hide_object_signal_list=[]):
        self._floater = None

        if not popup_hide_object_signal_list:
            return

        for obj, sig in popup_hide_object_signal_list:
            obj.callback_add(sig, self._floater_cancel)

    def _floater_title_init(self):
        self._floater.title_set("")

    def _floater_actions_init(self):
        self._floater.action_add("Cancel", self._floater_cancel)

    def _floater_content_init(self):
        return

    def _floater_open(self, parent, *args):
        if not self._floater:
            self._floater = Floater(parent, parent)
            self._floater.size_min_set(
                self._floater_min_w, self._floater_min_h)

            self._floater_title_init()
            self._floater_actions_init()
            self._floater_content_init()

        self._floater_update()

        self._floater.show()

    def _floater_update(self):
        return

    def _floater_cancel(self, *args):
        if not self._floater:
            return

        self._floater.hide()
Ejemplo n.º 11
0
 def update(self, model):
     self.time_count += 1
     target_simu = model.find(
         lambda x: isinstance(x, Prey) == False and self.distance(
             x.get_location()) <= Special.safe_distance)
     if target_simu != set():
         for target in target_simu:
             position_target = target.get_location()
             position_hunter = self.get_location()
             self.set_angle(pi -
                            atan2(position_target[1] -
                                  position_hunter[1], position_target[0] -
                                  position_hunter[0]))
         self.rs = self.get_speed() + random()
         self.set_speed(self.rs)
     if self.time_count > 30:
         model.simulton_module.add(
             Floater(self.get_location()[0],
                     self.get_location()[1]))
         model.simulton_module.add(
             Ball(self.get_location()[0],
                  self.get_location()[1]))
         self.time_count = 0
     self.move()
    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()
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)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
    def loadFloaters(self, config, allowedSections):
        """Load objects floating in the water.

        Args:
            config:          Parsed level config object.
                             configparser.ConfigParser object.
            allowedSections: List or tuple of names used in configuration
                             files to specify configuration for a track
                             section.
        """
        riverTracks = []
        floatingObjects = []
        for trackSection in allowedSections:

            if not config[trackSection].getboolean('enabled'):
                continue

            cfg = config[trackSection]

            gaps = []
            for amount in cfg.get('gaps').replace(' ', '').split(','):
                gaps.append(int(amount))

            track = {
                'top': cfg.getint('top'),
                'bottom': cfg.getint('bottom'),
                'direction': cfg.get('direction'),
                'speed': cfg.getint('speed'),
                'gaps': gaps,
            }
            riverTracks.append(track)

            # Get names of config files for the floaters for the level.
            configFilenames = cfg.get('floaters').replace(' ', '').split(',')

            # Load specified water objects.
            waterObjects = []
            for idx, configName in enumerate(configFilenames):
                configPath = os.path.join(self.configDir, configName)
                if idx == len(gaps):
                    msg = (f"No gap defined for floater '{configPath}' in "
                           f"section '{trackSection}'.")
                    print(msg)
                    raise ValueError(msg)
                stuff = Floater(configPath,
                                roadDirection=track['direction'],
                                screenWidth=self.screenWidth,
                                screenHeight=self.screenHeight,
                                roadTop=track['top'],
                                roadBottom=track['bottom'],
                                gapInFront=gaps[idx],
                                speed=track['speed'])

                # Calculate and set starting position of the floater.
                if idx == 0:
                    carWidth = stuff.carWidth

                    if stuff.direction == 'to_left':
                        initPos = stuff.initPos = stuff.gap
                    else:
                        initPos = stuff.initPos = self.screenWidth - stuff.gap

                    stuff.gap = 0
                    stuff.calcPositions()

                else:
                    if stuff.direction == 'to_left':
                        stuff.initPos = initPos + carWidth + stuff.gap
                    else:
                        stuff.initPos = initPos - stuff.carWidth - stuff.gap
                    stuff.calcPositions()

                    initPos = stuff.initPos
                    carWidth = stuff.carWidth

                waterObjects.append(stuff)

            floatingObjects += waterObjects

        return (riverTracks, floatingObjects)