Example #1
0
def menu():
    hello = Text(
        "Приветствую! Для продолжения настройте параметры лабиринта.\n" +
        "Если карта лабиринта будет некорректно отображаться, " +
        "попробуйте уменьшить значение ширины или развернуть окно.")
    height_enter = IntEdit("Высота лабиринта: ", 30)
    width_enter = IntEdit("Ширина лабиринта: ", 45)
    done = Button("Готово")
    done_pad = Padding(done, align="center", width=10)

    back = AttrMap(SolidFill("\u25E6"), "blueprint")
    pile = Pile(
        [hello, Divider("\u2500"), height_enter, width_enter, done_pad])
    menu = Filler(LineBox(pile))
    main_widget = Overlay(menu,
                          back,
                          align="center",
                          width=35,
                          height=12,
                          valign="middle")
    loop = MainLoop(main_widget, palette)
    connect_signal(done, 'click', start_game)
    loop.run()

    return MazeGame(height_enter.value(), width_enter.value())
Example #2
0
class AddCharmDialog(Overlay):
    """ Adding charm dialog """

    def __init__(self, underlying, juju_state, destroy, command_runner=None):
        import cloudinstall.charms
        charm_modules = [import_module('cloudinstall.charms.' + mname)
                         for (_, mname, _) in
                         pkgutil.iter_modules(cloudinstall.charms.__path__)]
        charm_classes = [m.__charm_class__ for m in charm_modules
                         if m.__charm_class__.allow_multi_units]

        self.cr = command_runner
        self.underlying = underlying
        self.destroy = destroy

        self.boxes = []
        self.bgroup = []
        first_index = 0
        for i, charm_class in enumerate(charm_classes):
            charm = charm_class(juju_state=juju_state)
            if charm.name() and not first_index:
                first_index = i
            r = RadioButton(self.bgroup, charm.name())
            r.text_label = charm.name()
            self.boxes.append(r)

        self.count_editor = IntEdit("Number of units to add: ", 1)
        self.boxes.append(self.count_editor)
        wrapped_boxes = _wrap_focus(self.boxes)

        bs = [Button("Ok", self.yes), Button("Cancel", self.no)]
        wrapped_buttons = _wrap_focus(bs)
        self.buttons = Columns(wrapped_buttons)
        self.items = ListBox(wrapped_boxes)
        self.items.set_focus(first_index)
        ba = BoxAdapter(self.items, height=len(wrapped_boxes))
        self.lb = ListBox([ba, Text(""), self.buttons])
        self.w = LineBox(self.lb, title="Add unit")
        self.w = AttrMap(self.w, "dialog")
        Overlay.__init__(self, self.w, self.underlying,
                         'center', 45, 'middle', len(wrapped_boxes) + 4)

    def yes(self, button):
        selected = [r for r in self.boxes if
                    r is not self.count_editor
                    and r.get_state()][0]
        _charm_to_deploy = selected.label
        n = self.count_editor.value()
        log.info("Adding {n} units of {charm}".format(
            n=n, charm=_charm_to_deploy))
        self.cr.add_unit(_charm_to_deploy, count=int(n))
        self.destroy()

    def no(self, button):
        self.destroy()
Example #3
0
class IntegerEditor(WidgetWrap):
    """ IntEdit input class
    """
    def __init__(self, default=0):
        self._edit = IntEdit(default=default)
        super().__init__(self._edit)

    @property
    def value(self):
        return self._edit.value()

    @value.setter
    def value(self, val):
        return self._edit.set_edit_text(str(val))