Ejemplo n.º 1
0
 def __init__(self, **kwargs):
     super(Container, self).__init__(**kwargs)
     self.previous_text = open(self.kv_file).read()
     parser = Parser(content=self.previous_text)
     widget = Factory.get(parser.root.name)()
     Builder._apply_rule(widget, parser.root, parser.root)
     self.add_widget(widget)
Ejemplo n.º 2
0
    def change_kv(self, *largs):
        '''Called when the update button is clicked. Needs to update the
        interface for the currently active kv widget, if there is one based
        on the kv file the user entered. If there is an error in their kv
        syntax, show a nice popup.'''

        kv_container = self.screen_manager.current_screen.content.children[0]
        try:
            parser = Parser(content=self.language_box.text.encode('utf8'))
            kv_container.clear_widgets()
            widget = Factory.get(parser.root.name)()
            Builder._apply_rule(widget, parser.root, parser.root)
            kv_container.add_widget(widget)
        except (SyntaxError, ParserException) as e:
            self.info_label.text = str(e)
            self.anim = Animation(top=190.0, opacity=1, d=2, t='in_back') +\
                Animation(top=190.0, d=2) +\
                Animation(top=0, opacity=0, d=2)
            self.anim.start(self.info_label)
        except:
            import traceback
            traceback.print_exc()
            popup = Popup(
                title="Boom",
                content=Label(
                    text='Something horrible happened while parsing' +
                    'your Kivy Language',
                    text_size=(350, None),
                    size_hint=(None, None),
                    size=(400, 400)))
            popup.open()
Ejemplo n.º 3
0
    def change_kv(self, *largs):
        '''Called when the update button is clicked. Needs to update the
        interface for the currently active kv widget, if there is one based
        on the kv file the user entered. If there is an error in their kv
        syntax, show a nice popup.'''

        txt = self.language_box.text
        kv_container = self.screen_manager.current_screen.children[0]
        try:
            parser = Parser(content=txt)
            kv_container.clear_widgets()
            widget = Factory.get(parser.root.name)()
            Builder._apply_rule(widget, parser.root, parser.root)
            kv_container.add_widget(widget)
        except (SyntaxError, ParserException) as e:
            self.show_error(e)
        except Exception as e:
            self.show_error(e)
Ejemplo n.º 4
0
 def change_kv(self, *largs):
     kv_container = self.screen_manager.current_screen.content.children[0]
     try:
         parser = Parser(content=self._kv_text.encode('utf8'))
         kv_container.clear_widgets()
         widget = Factory.get(parser.root.name)()
         Builder._apply_rule(widget, parser.root, parser.root)
         kv_container.add_widget(widget)
     except (SyntaxError, ParserException) as e:
         self.info_label.text = str(e)
         self.anim = Animation(top=190.0, opacity=1, d=2, t='in_back') +\
             Animation(top=190.0, d=2) +\
             Animation(top=0, opacity=0, d=2)
         self.anim.start(self.info_label)
     except:
         import traceback
         traceback.print_exc()
         popup = Popup(title="Boom",
             content=Label(text='Something horrible happened while parsing'
                     + 'your Kivy Language', text_size=(350, None),
             size_hint=(None, None), size=(400, 400)))
         popup.open()
Ejemplo n.º 5
0
    def change_kv_open_file(self, *largs):
        txt = self.language_box.text
        kv_container = self.screen_manager.current_screen.children[0]
        try:
            parser = Parser(content=txt)
            kv_container.clear_widgets()
            widget = Factory.get(parser.root.name)()
            Builder._apply_rule(widget, parser.root, parser.root)
            kv_container.add_widget(widget)

            name = self.ids.ui_name.text
            save_path = name
            dump = pickle.dumps(save_path)
            all = self.db.get_kvs()
            kvs = [x[0] for x in all]

            if dump not in kvs:
                self.db.add_kv(dump)

            with open(save_path, 'w') as f:
                f.write(txt)
        except:
            pass
Ejemplo n.º 6
0
 def run(self):
     self.parser = Parser(content=Builder._loadedStr)
     self._build()
     KT.APP.mainloop()
Ejemplo n.º 7
0
    def change_kv(self, *largs):
        '''Called when the update button is clicked. Needs to update the
        interface for the currently active kv widget, if there is one based
        on the kv file the user entered. If there is an error in their kv
        syntax, show a nice popup.'''

        txt = self.language_box.text
        kv_container = self.screen_manager.current_screen.children[0]
        try:
            parser = Parser(content=txt)
            kv_container.clear_widgets()
            widget = Factory.get(parser.root.name)()
            Builder._apply_rule(widget, parser.root, parser.root)
            kv_container.add_widget(widget)

            name = self.ids.ui_name.text
            print(f'The whatever name is {name}')
            if name == 'Untitled*':
                m = ModalView(size_hint=[.6, .7])
                box = BoxLayout(orientation='vertical')
                m.add_widget(box)

                # Function to get user's current home directory
                from os.path import expanduser
                users_home = expanduser('~')
                user_home_dir = os.path.join(users_home, 'Desktop')
                try:
                    os.mkdir(os.path.join(user_home_dir, 'KivyEditor'))
                    user_home_dir = os.path.join(user_home_dir, 'KivyEditor')
                except FileExistsError:
                    # user_home_dir = os.path.join(user_home_dir, 'KivyEditor')
                    pass

                name_box = BoxLayout(size_hint_y=.1)
                fc = FileChooserListView(size_hint_y=.9,
                                         filters=['*kv'],
                                         rootpath=user_home_dir)

                box.add_widget(name_box)
                box.add_widget(fc)

                tinput = TextInput(multiline=False, size_hint_x=.8)
                submit = Button(text='Save',
                                background_color=[1, 1, 1, 1],
                                background_normal='',
                                color=[0, 0, 0, 1],
                                size_hint_x=.2)

                tinput.bind(on_text_validate=lambda x: self.update_name(
                    os.path.join(fc.path, tinput.text), m))
                submit.bind(on_release=lambda x: self.update_name(
                    os.path.join(fc.path, tinput.text), m))

                name_box.add_widget(tinput)
                name_box.add_widget(submit)
                m.open()

            else:
                save_path = name
                dump = pickle.dumps(save_path)
                all = self.db.get_kvs()
                kvs = [x[0] for x in all]

                if dump not in kvs:
                    self.db.add_kv(dump)

                with open(save_path, 'w') as f:
                    f.write(txt)

        except (SyntaxError, ParserException) as e:
            self.show_error(e)
        except Exception as e:
            self.show_error(e)
Ejemplo n.º 8
0
Archivo: main.py Proyecto: dpkm95/DSApp
DS_ROOT = os.path.dirname(__file__)

DS_KVS = os.path.join(DS_ROOT,'ds_kvs')
DS_CLASSES = [c[:-3] for c in os.listdir(DS_KVS)

class Root(FloatLayout):
	screen_manager = ObjectProperty(None)	
	child = ObjectProperty(None) 

	def change_kv(self,*largs):
		child = self.screen_manager.current_screen.children[0]
		with open(child.kv_file, 'rb') as file:
			text = file.read().decode('utf8')
		kv_container = self.screen_manager.current_screen
		try:
			parser = Parser(content = txt)
			kv_container.clear_widgets()
			widget = Factory.get(parser.root.name)()
			Builder._apply_rule(widget,parser.root,parser.root)
			kv_container.add_widget(widget)
		except (SyntaxError, ParserException) as e:
			self.show_error(e)
		except Exception as e:
			self.show_error(e)	 

class DS(App):
	pass

Factory.register('Root', cls=Root)
	
if __name__=='__main__':