コード例 #1
0
ファイル: editor.py プロジェクト: jjjesus/kivy_contest_2014
    def __init__(self, **kwargs):
        super(LSystemsEdit, self).__init__(**kwargs)
        self.name = "edit"
        self.main_layout = BoxLayout(orientation='horizontal')

        self.edit_layout = BoxLayout(orientation='vertical', size_hint_x=.4)
        #Text boxes
        self.name_input = TextInput(multiline=False,
                                    size_hint_y=None,
                                    height=sp(30))
        self.name_input.bind(text=self.on_text)
        self.angle = TextInput(multiline=False,
                               size_hint_y=None,
                               height=sp(30))
        self.angle.bind(text=self.on_text)
        self.axiom = TextInput(multiline=False,
                               size_hint_y=None,
                               height=sp(30))
        self.axiom.bind(text=self.on_text)
        self.rules = TextInput(multiline=True, size_hint=(1, .4))
        self.rules.bind(text=self.on_text)
        self.rule_chooser = GridLayout(cols=6, size_hint=(1, .2))
        #buttons for changing number of iterations
        self.iterations_buttons = BoxLayout(orientation='horizontal',
                                            size_hint_y=None,
                                            height=sp(30))
        self.minus = Button(text="-")
        self.iter_label = Label(text="1")
        self.plus = Button(text="+")
        self.minus.bind(on_press=self.iter_press)
        self.plus.bind(on_press=self.iter_press)
        self.iterations_buttons.add_widget(self.minus)
        self.iterations_buttons.add_widget(self.iter_label)
        self.iterations_buttons.add_widget(self.plus)

        self.image = LSystemImage()

        self.edit_layout.add_widget(
            Label(text="[b]Name[/b]",
                  markup=True,
                  size_hint_y=None,
                  height=sp(30)))
        self.edit_layout.add_widget(self.name_input)
        self.edit_layout.add_widget(
            Label(text="[b]Angle[/b]",
                  markup=True,
                  size_hint_y=None,
                  height=sp(30)))
        self.edit_layout.add_widget(self.angle)
        self.edit_layout.add_widget(
            Label(text="[b]Axiom[/b]",
                  markup=True,
                  size_hint_y=None,
                  height=sp(30)))
        self.edit_layout.add_widget(self.axiom)
        self.edit_layout.add_widget(
            Label(text="[b]Rules[/b]",
                  markup=True,
                  size_hint_y=None,
                  height=sp(30)))
        self.edit_layout.add_widget(self.rules)
        self.edit_layout.add_widget(
            (Label(text="[b]Choose rule to visualise[/b]",
                   markup=True,
                   size_hint_y=None,
                   height=sp(30))))
        self.edit_layout.add_widget(self.rule_chooser)
        self.edit_layout.add_widget(
            (Label(text="[b]Change number of iterations[/b]",
                   markup=True,
                   size_hint_y=None,
                   height=sp(30))))
        self.edit_layout.add_widget(self.iterations_buttons)
        self.edit_layout.add_widget((Label(text="[b]L-systems syntax[/b]",
                                           markup=True,
                                           size_hint_y=None,
                                           height=sp(30))))
        syntax_label = ScrollableLabel()
        syntax_label.text = syntax
        #        def f(*args,**kwargs): syntax_label.text_size = syntax_label.size
        #        syntax_label.bind(size = f)

        self.edit_layout.add_widget(syntax_label)
        self.main_layout.add_widget(self.edit_layout)
        self.main_layout.add_widget(self.image)

        #self.load_lsystem(('quartet', ('fb', {'a': 'fbfa+hfa+fb-fa', 'h': '-', 'b': 'fb+fa-fb-jfbfa', 'j': '+', 'f': ''}, 90.0)))

        self.add_widget(self.main_layout)
コード例 #2
0
ファイル: main.py プロジェクト: jjjesus/kivy_contest_2014
    def __init__(self, **kwargs):
        #TODO KV!!!!!!
        self.register_event_type('on_edit')
        super(LSystemsView, self).__init__(**kwargs)
        self.name = "view"
        self.main_layout = BoxLayout(orientation='vertical')
        self.buttons_layout = BoxLayout(orientation='horizontal',
                                        size_hint=(1, .05))
        self.labels_layout = BoxLayout(orientation='horizontal',
                                       size_hint=(1, .05))
        self.image = LSystemImage()
        self.image.bind(on_update=self.image_update)

        self.width_choice = DropDown()
        self.width_choice.bind(on_select=self.choose_width)
        self.width_choice_button = Button(text="Line width")
        self.width_choice_button.bind(on_release=self.width_choice.open)

        for i in range(1, 10):
            btn = ToggleButton(text=str(i),
                               group='width_values',
                               size_hint_y=None,
                               height=sp(30))
            if i == 1: btn.state = 'down'
            btn.bind(on_press=lambda btn: self.width_choice.select(btn.text))
            self.width_choice.add_widget(btn)
        self.fractal_choice = DropDown()
        self.fractal_choice.bind(on_select=self.choose_fractal)
        self.file_choice_button = Button(text="File")
        self.choice_button = Button(text="L-System")
        self.file_choice_button.bind(
            on_release=self.on_file_choose)  #self.file_choice.open)
        self.choice_button.bind(on_release=self.fractal_choice.open)
        self.next_button = Button(text="Next")
        self.ls_name = Label(text="")
        self.cur_file = Label(text="")
        self.plus_button = Button(text="+")
        self.minus_button = Button(text="-")
        self.background_button = Button(text="Background")
        self.background_button.bind(on_press=self.choose_background_color)
        self.plus_button.bind(on_press=self.plus)
        self.minus_button.bind(on_press=self.minus)
        self.next_button.bind(on_press=self.next)
        self.edit_button = Button(text="Edit")
        self.edit_button.bind(on_press=self.edit)
        self.segments = Label(text="")
        self.iterations = Label()
        self.buttons_layout.add_widget(self.file_choice_button)
        self.buttons_layout.add_widget(self.choice_button)
        self.buttons_layout.add_widget(self.next_button)
        self.buttons_layout.add_widget(self.plus_button)
        self.buttons_layout.add_widget(self.minus_button)
        self.buttons_layout.add_widget(self.edit_button)
        self.buttons_layout.add_widget(self.background_button)
        self.buttons_layout.add_widget(self.width_choice_button)
        self.labels_layout.add_widget(
            Label(text="[b]File name:[/b]", markup=True))
        self.labels_layout.add_widget(self.cur_file)
        self.labels_layout.add_widget(
            Label(text="[b]L-system name:[/b]", markup=True))
        self.labels_layout.add_widget(self.ls_name)
        self.labels_layout.add_widget(
            Label(text="[b]Number of iterations:[/b]", markup=True))
        self.labels_layout.add_widget(self.iterations)
        self.labels_layout.add_widget(
            Label(text="[b]Number of segments:[/b]", markup=True))
        self.labels_layout.add_widget(self.segments)
        self.main_layout.add_widget(self.image)
        self.main_layout.add_widget(self.buttons_layout)
        self.main_layout.add_widget(self.labels_layout)

        self.file_chooser = LFileChooser()
        self.file_chooser.bind(on_choose=self.choose_file)
        self.popup = Popup(title='Load L-Systems',
                           content=self.file_chooser,
                           size_hint=(None, None),
                           size=(500, 500))

        self.color_picker = BackgroundColorPicker()
        self.color_picker.bind(on_choose=self.change_background_color)
        self.color_picker_popup = Popup(title="Pick color",
                                        content=self.color_picker,
                                        size_hint=(None, None),
                                        size=(500, 500))

        self.add_widget(self.main_layout)