#!/usr/bin/env python

import kivy
kivy.require('1.7.1')

from kivy.app import App
from kivy.base import stopTouchApp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.dropdown import DropDown
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.label import Label


txt = ObjectProperty(None)


class Algebra(BoxLayout):
    '''This class provides the logic
       behind the whole application.'''

    def show_menu(self):
        '''Method for displaying menu.
           The needed class lies in ./menu.py

           In order to make it work as we want,
           we have to pass the position, the size
           and the font-size of the menu to it.'''
        import menu
        menu_position = self.ids.file_menu.pos
        m = menu.Menu( menu_position, self.ids.file_menu.size, self.ids.file_menu.font_size, self.ids.input,  self.ids.input.text )
        m.show_menu()


    def clear(self):
        '''Clearing input text-field
           and setting focus on True'''
        self.txt.text = ''
        self.txt.focus = True

    def open_matrix_assistant(self):
        '''Opens matrix assistant'''
        import assistants.matrix_assistant
        m = assistants.matrix_assistant.MatrixAssistant( self.ids.input )
        m.matrix()

    def close_window(self):
        '''Method for exiting application'''
        stopTouchApp()


class AlgebraApp(App):
    '''Main app-class'''
    def build(self):
        '''Building application window.'''
        return Algebra()


if __name__ == '__main__':
    AlgebraApp().run()
