コード例 #1
0
ファイル: Manager.py プロジェクト: Sergey271195/kivy_tertis
class Application(ScreenManager):
    def __init__(self, **kwargs):
        super(Application, self).__init__(**kwargs)

        #Starting Screen
        self.db = BdManager("Tetris.db", "Players")
        self.reg_form = RegisterForm()
        self.start = Screen(name="Start")
        self.start.add_widget(self.reg_form)
        self.reg_form.submit.bind(on_press=self.to_login_screen)

        #Game Screen
        self.sound = SoundLoader.load("Main_theme.mp3")
        self.game = Screen(name="Game")
        self.add_widget(self.start)
        self.add_widget(self.game)

        self.create_game_screen()

    def create_game_screen(self):
        self.main = MainWindow()
        self.left_border = ScoreWindow()
        self.right_border = RightWindow()
        self.game_screen = GameWindow(size_hint_x=1.4,
                                      left=self.left_border,
                                      right=self.right_border)
        self.game_screen.proper_colors = proper_colors
        self.main.add_widget(self.left_border)
        self.main.add_widget(self.game_screen)
        self.main.add_widget(self.right_border)
        self.game.add_widget(self.main)
        self.game_screen.sound_btn.bind(on_press=self.play_music)
        self.game_screen.back_btn.bind(on_press=self.back)

    def play_music(self, instance):
        if instance.text == "Music off":
            instance.text = "Music on"
            self.sound.stop()
        else:
            instance.text = "Music off"
            self.sound.play()
            self.sound.loop = True

    def back(self, instance, *args):
        self.game.clear_widgets()
        self.switch_screen(instance)
        self.create_game_screen()
        if self.sound.state == "play":
            self.sound.stop()

    def switch_screen(self, instance):
        if self.current == "Start":
            self.current = "Game"
            #self.game_screen.define_next_figure()
            self.game_screen.create_figure()
        elif self.current == "Game":
            self.current = "Start"

    def to_login_screen(self, instance):
        self.firstname = self.reg_form.firstname_input.text.strip()
        self.lastname = self.reg_form.lastname_input.text.strip()
        if (self.lastname == "" or self.firstname == ""):
            pass
        else:
            self.img_source = self.reg_form.img.source
            self.popup = MyPopup(self.img_source, self)
            self.db.add_player(self.firstname, self.lastname)
            self.db.login(self.firstname, self.lastname)
            self.popup.lbl.text = f"Welcome {self.firstname} {self.lastname}"
            self.game_screen.img.source = self.img_source
            self.game_screen.firstname_label.text = f"{self.firstname}"
            self.game_screen.lastname_label.text = f"{self.lastname}"
            self.popup.open()

    def create_leaderboard(self):
        self.game_screen.pos_box.clear_widgets()
        self.game_screen.name_box.clear_widgets()
        self.game_screen.score_box.clear_widgets()
        for i in range(0, len(self.db.get_leaderboard_names()[:10])):
            self.game_screen.pos_box.add_widget(Label(text=f"{i+1}"))
        for name, lastname in self.db.get_leaderboard_names()[:10]:
            self.game_screen.name_box.add_widget(
                Label(text=f"{name} {lastname}"))
        for score in self.db.get_leaderboard_score()[:10]:
            self.game_screen.score_box.add_widget(Label(text=f"{score}"))
コード例 #2
0
class Application(ScreenManager):
    def __init__(self, **kwargs):
        super(Application, self).__init__(**kwargs)
        """Main Screen image"""
        self.screen_image = kivy.resources.resource_find("padariacentral.png")
        """Main screen"""
        self.main_screen = Screen(name='Padaria Central')
        self.layout = BoxLayout(orientation='vertical')
        self.logo = Image(source=self.screen_image,
                          allow_stretch=True,
                          size_hint_y=1)
        self.layout_down = GridLayout(cols=2, rows=1, size_hint_y=0.2)
        self.layout.add_widget(self.logo)
        self.layout.add_widget(self.layout_down)
        self.main_screen.add_widget(self.layout)
        """Define os and default path"""
        self.os = platform
        self.path = ""
        if self.os == 'win':
            self.path = dirname(expanduser("~"))
        else:
            self.path = expanduser("~")
        """ Main screen buttons"""
        self.generate_payments = Button(text='Tirar contas do mês',
                                        size_hint_y=0.1)
        self.generate_payments.bind(
            on_press=lambda x: self.file_chooser("pay"))

        self.send_warnings = Button(text='Enviar aviso para Clientes',
                                    size_hint_y=0.1)
        self.send_warnings.bind(on_press=lambda x: self.file_chooser("info"))

        self.layout_down.add_widget(self.generate_payments)
        self.layout_down.add_widget(self.send_warnings)

        # init default popup
        self.popup = Popup()
        """Screen Manager"""
        self.s_open_file = Screen(name='Selecionar Ficheiro')
        self.add_widget(self.main_screen)
        self.add_widget(self.s_open_file)

        self.s_save_file = Screen(name='Gravar Ficheiro')
        self.add_widget(self.s_save_file)

        # self.s_select_clients = Screen(name='Selecionar Clientes')
        # self.add_widget(self.s_select_clients)
        """Init"""
        self.text_input = TextInput()
        self.text = ""

    def file_chooser(self, op):
        mp_layout = GridLayout(cols=1)

        info = Label(text="Selecionar ficheiro excel!")
        confirm = Button(text="Ok")

        mp_layout.add_widget(info)
        mp_layout.add_widget(confirm)

        confirm.bind(on_press=lambda x: self.browser(op))
        self.popup = Popup(title="Gerar ficheiro",
                           separator_height=0,
                           content=mp_layout,
                           size_hint=(None, None),
                           size=(300, 150))
        self.popup.open()

    def browser(self, op):
        """ This function creates the file chooser to select image"""
        # Create Layout for popup
        try:
            self.popup.dismiss()
        except PopupException:
            pass
        self.current = 'Selecionar Ficheiro'
        b_main_lay = GridLayout(rows=2)
        action_layout = BoxLayout(orientation='horizontal', size_hint_y=0.1)
        file = FileChooserIconView(path=self.path,
                                   size_hint_y=0.9,
                                   multiselect=False)
        # this popup buttons and actions
        select = Button(text='Selecionar')
        select.bind(on_press=lambda x: self.open(file.selection, op))
        cancel = Button(text='Cancelar')

        cancel.bind(on_press=self.cancel_callback)
        action_layout.add_widget(select)
        action_layout.add_widget(cancel)
        b_main_lay.add_widget(file)
        b_main_lay.add_widget(action_layout)

        self.s_open_file.add_widget(b_main_lay)

    # def select_clients(self, clients):
    #     # Create Layout for popup
    #     # try:
    #     #     self.popup.dismiss()
    #     # except PopupException:
    #     #     pass
    #     # self.current = 'Selecionar Clientes'
    #     # self.s_open_file.clear_widgets()
    #     #
    #     # clients_layout = GridLayout(cols=2)
    #     # action_layout = BoxLayout(orientation='horizontal', size_hint_y=0.1)
    #     #
    #     # select = Button(text='Selecionar')
    #     # select.bind(on_press=lambda x: self.cancel_callback())
    #     # cancel = Button(text='Cancelar')
    #     # cancel.bind(on_press=self.cancel_callback)
    #     #
    #     # action_layout.add_widget(select)
    #     # action_layout.add_widget(cancel)
    #     #
    #     # for client in clients:
    #     #     clients_layout.add_widget(Label(text=client.nome))
    #     #     clients_layout.active = CheckBox(active=True)
    #     #     clients_layout.add_widget(clients_layout.active)
    #     #
    #     # clients_layout.add_widget(action_layout)
    #     # self.s_select_clients.add_widget(clients_layout)
    #
    #     """Try like a popup"""
    #     self.current = 'Padaria Central'
    #     grid = GridLayout(cols=2, padding=10, spacing=20, size_hint=(None, None), size=(500, 500))
    #     grid.bind(minimum_height=grid.setter('height'))
    #     dismiss = Button(text='Sair', size_hint=(None, None), size=(50, 30))
    #     create = Button(text='Ok', size_hint=(None, None), size=(50, 30))
    #     for client in clients:
    #         grid.add_widget(Label(text=client.nome))
    #         grid.active = CheckBox(active=True)
    #         grid.add_widget(grid.active)
    #     grid.add_widget(dismiss)
    #     grid.add_widget(create)
    #     root = ScrollView(size_hint=(None, None), size=(500, 500),
    #                       pos_hint={'center_x': .5, 'center_y': .5}, do_scroll_x=False)
    #     root.add_widget(grid)
    #     self.popup = Popup(title="Padaria Central", separator_height=0, content=root)
    #     self.popup.open()
    #     dismiss.bind(on_press=self.popup.dismiss)

    def cancel_callback(self, instance):
        self.current = 'Padaria Central'
        self.s_open_file.clear_widgets()

    def open(self, filename, op):
        self.current = 'Padaria Central'
        self.s_open_file.clear_widgets()
        if op == "pay":
            try:
                grid_s = GridLayout(rows=2)

                confirm = Button(text="Selecionar")

                spinner = Spinner(
                    # default value shown
                    text='Selecione o mês',
                    text_autoupdate=True,
                    # available values
                    values=('Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio',
                            'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro',
                            'Novembro', 'Dezembro'),
                    # just for positioning in our example
                    size_hint=(None, None),
                    size=(275, 40),
                    pos_hint={
                        'center_x': .5,
                        'center_y': .5
                    })

                confirm.bind(on_press=lambda x: self.generate(
                    spinner.text, filename, op, None))

                grid_s.add_widget(spinner)
                grid_s.add_widget(confirm)

                self.popup = Popup(title="Escolher Mês",
                                   separator_height=0,
                                   content=grid_s,
                                   size_hint=(None, None),
                                   size=(300, 150))
                self.popup.open()

            except FileExistsError as e:
                self.end_action(
                    "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                )
        elif op == "info":
            try:
                grid_s = GridLayout(cols=1, rows=4)
                label = Label(text="Mensagem a enviar para clientes:",
                              size_hint=(.5, .3))
                self.text_input = TextInput(text="",
                                            multiline=True,
                                            size_hint=(.5, .8))
                self.text_input.bind(text=self.set_text)
                confirm = Button(text="Seguinte", size_hint=(.5, .2))
                cancel = Button(text="Cancelar", size_hint=(.5, .2))

                cancel.bind(on_press=lambda x: self.popup.dismiss())
                confirm.bind(on_press=lambda x: self.generate(
                    None, filename, op, self.text_input.text))

                grid_s.add_widget(label)
                grid_s.add_widget(self.text_input)
                grid_s.add_widget(confirm)
                grid_s.add_widget(cancel)

                self.popup = Popup(title="Mensagem",
                                   separator_height=0,
                                   content=grid_s,
                                   size_hint=(None, None),
                                   size=(400, 350))
                self.popup.open()
            except Exception as e:
                self.end_action("Erro, tente novamente!")
                print(e)

        else:
            self.end_action(
                "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
            )

    def end_action(self, text):
        self.current = 'Padaria Central'
        grid = GridLayout(rows=2)
        label = Label(text=text)
        dismiss = Button(text='OK', size_hint_y=None, size=(50, 30))
        grid.add_widget(label)
        grid.add_widget(dismiss)
        self.popup = Popup(title="Padaria Central",
                           separator_height=0,
                           content=grid,
                           size_hint=(None, None),
                           size=(300, 200))
        self.popup.open()
        dismiss.bind(on_press=self.popup.dismiss)

    def show_selected_value(self, instance, text):
        """ Get current value from spinner """
        if text is not "Tipo de ficheiro" and not '':
            return text
        else:
            print("Invalid file extension")

    def generate(self, month, filename, op, infotext):
        try:
            self.popup.dismiss()

            mp_layout = GridLayout(cols=1)

            info = Label(text="Selecionar pasta e nome do ficheiro Word")
            confirm = Button(text="Ok")

            mp_layout.add_widget(info)
            mp_layout.add_widget(confirm)

            confirm.bind(on_press=lambda x: self.popup.dismiss())
            self.popup = Popup(title="Guardar Ficheiro",
                               separator_height=0,
                               content=mp_layout,
                               size_hint=(None, None),
                               size=(400, 150))
            self.popup.open()
        except PopupException:
            pass

        try:
            self.current = 'Gravar Ficheiro'
            grid_s = GridLayout(rows=3)
            action_layout = BoxLayout(orientation='horizontal',
                                      size_hint_y=0.1)
            file_name_type_layout = BoxLayout(orientation='horizontal',
                                              size_hint_y=0.1)

            self.text_input = TextInput(text="", multiline=False)
            file_name_type_layout.add_widget(self.text_input)
            self.text_input.bind(text=self.set_text)

            save = Button(text="Guardar")
            cancel = Button(text="Cancelar")
            action_layout.add_widget(save)
            action_layout.add_widget(cancel)
            file = FileChooserIconView(path=self.path, )
            grid_s.add_widget(file)

            grid_s.add_widget(file_name_type_layout)
            grid_s.add_widget(action_layout)
            self.s_save_file.add_widget(grid_s)

            cancel.bind(on_press=self.cancel_callback)

            save.bind(on_press=lambda x: self.proc(
                month, filename, file.path, self.text_input, op, infotext))
        except:
            self.end_action("Algo correu mal, tente novamente!")

    def proc(self, month, input_file_path, output_file_path, output_file_name,
             op, infotext):

        filename = output_file_name.text

        if not filename and op == "pay":
            filename = "Contas" + month

        if not filename and op == "info":
            filename = "InfoClientes"

        if self.os == 'win':
            output_path = output_file_path + "\\" + filename + ".docx"
        else:
            output_path = output_file_path + "/" + filename + ".docx"

        try:
            if op == 'pay':
                try:
                    clients = ExcelInfo(input_file_path[0]).get()
                    for x in clients:
                        print(x)
                    # """try"""
                    # self.select_clients(clients)
                    #
                    Word3Cols(clients, INVERSE_MONTH[month], output_path,
                              "pay", None).create()
                except Exception as e:
                    print(e)
                    self.end_action(
                        "Erro, guarde o ficheiro no formato \n Excel97-2003 (.xls)"
                    )
                else:
                    self.end_action("Ficheiro guardado com sucesso!")
            else:
                clients = ExcelInfo(input_file_path[0]).get()
                Word3Cols(clients, None, output_path, op, infotext).create()
                self.end_action("Ficheiro guardado com sucesso!")
        except Exception as e:
            self.end_action("ERRO, tente novamente!")
            print(e)

    def set_text(self, instance, input):
        """ Workaround to save input from textInput """
        self.text = input
コード例 #3
0
class Menu(ScreenManager):
    def __init__(self, **kwargs):
        """ Create all the default gui elements  """
        super(Menu, self).__init__(**kwargs)
        self.fcv = fire_cv.FireCv()
        self.imT = im_transform.Image_Transform()

        # main screen config
        self.main_screen = Screen(name='Most-g4')
        self.layout = BoxLayout(orientation='vertical')
        self.logo = Image(source='static/logo.png',
                          allow_stretch=True,
                          size_hint_y=1)
        self.layout_down = GridLayout(cols=2, rows=2, size_hint_y=0.2)
        self.layout.add_widget(self.logo)
        self.layout.add_widget(self.layout_down)
        self.main_screen.add_widget(self.layout)
        # self.cols = 1

        # define os and default path
        self.os = platform
        self.path = ""
        if self.os == 'win':
            self.path = dirname(expanduser("~"))
        else:
            self.path = expanduser("~")

        # Define and add buttons to main Screen
        self.vid = Button(text='Dividir Video', size_hint_y=0.1)
        self.vid.bind(on_press=lambda x: (self.browser('vid')))
        self.im = Button(text='Processar Frames', size_hint_y=0.1)
        self.im.bind(on_press=lambda x: (self.browser('frame')))
        self.seg = Button(text='Contornos de Interesse ', size_hint_y=0.1)
        self.seg.bind(on_press=self.seg_workflow)
        self.image_transform = Button(text='Coordenadas Georeferenciadas',
                                      size_hint_y=0.1)
        self.image_transform.bind(on_press=self.image_transformation_workflow)

        self.layout_down.add_widget(self.vid)
        self.layout_down.add_widget(self.im)
        self.layout_down.add_widget(self.seg)
        self.layout_down.add_widget(self.image_transform)

        # init default popup
        self.popup = Popup()

        # Screen Manager
        self.s_open_file = Screen(name='Abrir Ficheiro')
        self.s_save_frame = Screen(name='Gravar Frames')
        self.s_save_area = Screen(name='Gravar Area')
        self.s_coords = Screen(name='Coords')
        self.s_wait = Screen(name='Wait')
        self.add_widget(self.main_screen)
        self.add_widget(self.s_open_file)
        self.add_widget(self.s_save_frame)
        self.add_widget(self.s_save_area)
        self.add_widget(self.s_wait)
        self.add_widget(self.s_coords)

        # filename
        self.text_input = TextInput()
        self.text = ""

        # watershed original fg and bg arrays
        self.ws_original = ""
        self.fg = []
        self.bg = []

        # Image transformation
        self.img_t_og = ""
        self.img_t_map = ""
        self.img_t_cntr = ""

        self.georef_x_min_text = ""
        self.georef_x_max_text = ""
        self.georef_y_min_text = ""
        self.georef_y_max_text = ""

    def browser(self, op):
        """ This function creates the file chooser to select image"""
        # Create Layout for popup
        try:
            self.popup.dismiss()
        except PopupException:
            pass

        self.current = 'Abrir Ficheiro'
        b_main_lay = GridLayout(rows=3)
        if op is 'seg_fg':
            file = FileChooserIconView(path=self.path,
                                       size_hint_y=0.9,
                                       multiselect=True)
        elif op is 'seg_bg':
            file = FileChooserIconView(path=self.path,
                                       size_hint_y=0.9,
                                       multiselect=True)
        else:
            file = FileChooserIconView(path=self.path,
                                       size_hint_y=0.9,
                                       multiselect=False)
        # this popup buttons and actions
        select = Button(text='Abrir', size_hint_y=0.1)
        select.bind(on_press=lambda x: self.open(file.selection, op))

        cancel = Button(text='Cancelar', size_hint_y=0.1)
        cancel.bind(on_press=self.cancel_callback)

        b_main_lay.add_widget(file)
        b_main_lay.add_widget(select)
        b_main_lay.add_widget(cancel)

        self.s_open_file.add_widget(b_main_lay)

    def cancel_callback(self, instance):
        self.current = 'Most-g4'
        self.s_open_file.clear_widgets()
        self.s_save_frame.clear_widgets()
        self.s_save_area.clear_widgets()

    def open(self, filename, op):
        """ Selects the according action bases on operation type (op) and file size"""
        if len(filename) is 1:
            if op is 'frame':
                self.current = 'Most-g4'
                self.s_open_file.clear_widgets()
                try:
                    im = cv2.imread(filename[0])
                    if im is not None:
                        self.analize_frame(im)
                    else:
                        cv2.imshow('img', im)
                except cv2.error as e:
                    cv2.destroyAllWindows()
                    self.end_action(
                        "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                    )
            elif op is 'vid':
                self.current = 'Most-g4'
                self.s_open_file.clear_widgets()
                try:
                    vid = cv2.VideoCapture(filename[0])
                    print(vid)
                    self.save_frame(
                        vid,
                        str(os.path.basename(filename[0])).split(".")[0])
                except cv2.error as e:
                    self.end_action(
                        "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                    )
            elif op is 'original':
                self.current = 'Most-g4'
                self.s_open_file.clear_widgets()
                try:
                    self.ws_original = cv2.imread(filename[0])
                    cntr, ws = self.fcv.watershed(self.ws_original, self.fg,
                                                  self.bg)
                except cv2.error as e:
                    self.end_action(
                        "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                    )
                finally:
                    self.save_builder(ws, cntr)
            elif op is 'img_t_og':
                self.current = 'Most-g4'
                self.s_open_file.clear_widgets()
                try:
                    self.img_t_og = cv2.imread(filename[0])
                    self.image_transformation_workflow(instance="", it=1)
                except cv2.error as e:
                    self.end_action(
                        "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                    )
            elif op is 'img_t_map':
                self.current = 'Most-g4'
                self.s_open_file.clear_widgets()
                try:
                    self.img_t_map = cv2.imread(filename[0])
                    self.image_transformation_workflow(instance="", it=2)
                except cv2.error as e:
                    self.end_action(
                        "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                    )
            elif op is 'img_t_cntr':
                try:
                    self.img_t_cntr = np.load(filename[0], allow_pickle=True)
                    self.georef_coords()
                except IOError as e:
                    self.end_action(
                        "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                    )

        else:
            if op is 'seg_fg':
                self.fg = []
                self.current = 'Most-g4'
                self.s_open_file.clear_widgets()
                for i in filename:
                    try:
                        print(i)
                        aux = cv2.imread(i)
                        self.fg.append(aux)
                        self.seg_workflow(instance="", it=1)
                    except cv2.error as e:
                        self.end_action(
                            "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                        )

            elif op is 'seg_bg':
                self.current = 'Most-g4'
                self.s_open_file.clear_widgets()
                self.bg = []
                for i in filename:
                    try:
                        print(i)
                        aux = cv2.imread(i)
                        self.bg.append(aux)
                        self.seg_workflow(instance="", it=2)
                    except cv2.error as e:
                        self.end_action(
                            "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
                        )

    def save_frame(self, video, folder):
        grid_s = GridLayout(rows=5)

        spinner = Spinner(
            # default value shown
            text='Tipo de ficheiro',
            text_autoupdate=True,
            # available values
            values=('.jpg', '.png'),
            # just for positioning in our example
            size_hint=(None, None),
            size=(100, 44),
            pos_hint={
                'center_x': .5,
                'center_y': .5
            })

        spinner2 = Spinner(
            # default value shown
            text='intervalo(segundos)',
            text_autoupdate=True,
            # available values
            values=('10', '20', '30', '40', '50', '60'),
            # just for positioning in our example
            size_hint=(None, None),
            size=(100, 44),
            pos_hint={
                'center_x': .5,
                'center_y': .5
            })

        spinner.bind(text=self.show_selected_value)
        input_layout = BoxLayout(orientation='horizontal', size_hint_y=0.1)
        input_label = Label(text="Timestamp base",
                            size_hint=(None, None),
                            size=(200, 44))
        self.text_input = TextInput(
            text="",
            hint_text="Ano Mês Dia Hora Minuto Segundo",
            multiline=False,
            size_hint=(None, None),
            size=(300, 44))
        self.text_input.bind(text=self.set_text)

        input_layout.add_widget(self.text_input)
        input_layout.add_widget(input_label)

        # save file
        save = Button(text="Selecionar", size_hint_y=None, size=(100, 44))
        file = FileChooserIconView(path=self.path)
        grid_s.add_widget(file)
        grid_s.add_widget(spinner2)
        grid_s.add_widget(spinner)
        grid_s.add_widget(input_layout)
        grid_s.add_widget(save)
        self.s_save_frame.add_widget(grid_s)
        self.current = 'Gravar Frames'
        save.bind(
            on_release=lambda x: self.video_helper(o=self.os,
                                                   folder=folder,
                                                   path=file.path,
                                                   ext=spinner.text,
                                                   time=int(spinner2.text),
                                                   video=video,
                                                   timestamp=self.text))

    def video_helper(self, o, folder, path, ext, time, video, timestamp):
        """ Call divide_video and report output to user """
        if timestamp is "":
            self.end_action(
                "Timestamp vazio!\nPor favor insira um valor válido")
            self.s_save_frame.clear_widgets()
            return

        self.popup = Popup(title="Divisão de video",
                           separator_height=0,
                           content=Label(text="A processsar video"),
                           size_hint=(None, None),
                           size=(300, 100))

        self.popup.bind(
            on_open=lambda x: self.vid_helper_cont(o=o,
                                                   folder=folder,
                                                   path=path,
                                                   ext=ext,
                                                   time=time,
                                                   video=video,
                                                   timestamp=timestamp))
        self.popup.open()

    def vid_helper_cont(self, o, folder, path, ext, time, video, timestamp):

        result = self.fcv.divide_video(o=o,
                                       folder=folder,
                                       path=path,
                                       ext=ext,
                                       time=time,
                                       video=video,
                                       timestamp=timestamp)
        if result is True:
            self.popup.bind(on_dismiss=lambda x: self.end_action(
                "Video separado com sucesso!\nVer" + path))
        else:
            self.popup.bind(on_dismiss=lambda x: self.end_action(
                "Oops! Algo correu mal!\nVerifique se selecionou o ficheiro correto"
            ))
        self.s_save_frame.clear_widgets()
        self.s_wait.clear_widgets()
        self.popup.dismiss()

    def end_action(self, text):
        """ sucess/error popup """
        self.current = 'Most-g4'
        grid = GridLayout(rows=2)
        label = Label(text=text)
        dismiss = Button(text='OK', size_hint_y=None, size=(50, 30))
        grid.add_widget(label)
        grid.add_widget(dismiss)
        self.popup = Popup(title="Most G4",
                           separator_height=0,
                           content=grid,
                           size_hint=(None, None),
                           size=(300, 200))
        self.popup.open()
        dismiss.bind(on_press=self.popup.dismiss)

    def analize_frame(self, frame):
        """ Auxiliary function to select foreground (relevate areas)
         and background(what to ignore on final segmentation) """

        img = self.fcv.analize_frame(frame=frame)
        self.save_builder(img)

    def save_builder(self, img="", cntr="", converted=""):
        grid_s = GridLayout(rows=5)

        # File extension
        spinner = Spinner(
            # default value shown
            text='Tipo de ficheiro',
            text_autoupdate=True,
            # available values
            values=('.jpg', '.png'),
            # just for positioning in our example
            size_hint=(None, None),
            size=(100, 44),
            pos_hint={
                'center_x': .5,
                'center_y': .5
            })

        spinner.bind(text=self.show_selected_value)

        # filename
        self.text_input = TextInput(text="",
                                    multiline=False,
                                    size_hint=(None, None),
                                    size=(300, 44))
        self.text_input.bind(text=self.set_text)

        # save file
        save = Button(text="Guardar", size_hint_y=None, size=(100, 44))
        cancel = Button(text="Cancelar", size_hint_y=None, size=(100, 44))
        file = FileChooserIconView(path=self.path)
        grid_s.add_widget(file)
        grid_s.add_widget(self.text_input)

        if img is not "":
            grid_s.add_widget(spinner)

        grid_s.add_widget(save)
        grid_s.add_widget(cancel)
        cancel.bind(on_press=self.cancel_callback)
        self.s_save_area.add_widget(grid_s)
        self.current = 'Gravar Area'
        if cntr is not "":
            save.bind(on_press=lambda x: self.save_files(
                path=file.path, extension=spinner.text, img=img, cntr=cntr))
        elif converted is not "":
            save.bind(on_press=lambda x: self.save_files(
                path=file.path, extension=spinner.text, converted=converted))
        else:
            save.bind(on_press=lambda x: self.save_files(
                path=file.path, extension=spinner.text, img=img))

    def seg_workflow(self, instance, it=0):
        """ Workflow control for segmentação button """
        try:
            self.popup.clear_widgets()
            self.popup.dismiss()
        except PopupException:
            pass
        seg_layout = GridLayout(cols=1)
        info = Label(text="Selecionar imagens áreas de interesse")
        info2 = Label(text="Selecionar imagens áreas a omitir")
        info3 = Label(text="Selecionar imagem original")
        confirm = Button(text="OK")

        if it is 0:
            seg_layout.add_widget(info)
            confirm.bind(on_press=lambda x: self.browser('seg_fg'))
        elif it is 1:
            seg_layout.add_widget(info2)
            confirm.bind(on_press=lambda x: self.browser('seg_bg'))
        elif it is 2:
            seg_layout.add_widget(info3)
            confirm.bind(on_press=lambda x: self.browser('original'))
        seg_layout.add_widget(confirm)
        self.popup = Popup(title="Segmentação",
                           separator_height=0,
                           content=seg_layout,
                           size_hint=(None, None),
                           size=(300, 150))
        self.popup.open()
        pass

    def save_files(self, path, extension, img="", cntr="", converted=""):
        self.current = 'Most-g4'

        print(converted)

        if self.os == 'win':
            # Create path with our without folder if saving multiple files
            if cntr is not "":
                path = path + "\\" + self.text
            if os.path.exists(os.path.normpath(path)) is False:
                os.mkdir(path)

            if img is not "":
                cv2.imwrite(path + "\\" + self.text + extension, img)
            if cntr is not "":
                np.save(path + "\\" + self.text, cntr)
            if converted is not "":
                np.save(path + "\\" + self.text, converted)

        else:
            # Create path with our without folder if saving multiple files
            if cntr is not "":
                path = path + "/" + self.text
            if os.path.exists(os.path.normpath(path)) is False:
                os.mkdir(path)

            if img is not "":
                cv2.imwrite(path + "/" + self.text + extension, img)
            if cntr is not "":
                np.save(path + "/" + self.text, cntr)
            if converted is not "":
                np.save(path + "/" + self.text, converted)
        self.s_save_area.clear_widgets()

    def image_transformation_workflow(self, instance, it=0):
        """ Image transformation gui controller """
        try:
            self.popup.clear_widgets()
            self.popup.dismiss()
        except PopupException:
            pass

        imt_layout = GridLayout(cols=1)
        info = Label(text="Selecionar imagem original")
        info2 = Label(text="Selecionar mapa da área")
        info3 = Label(
            text="Selecionar ficheiro dos contorno\n(imagem_original.npy)")
        confirm = Button(text="OK")

        if it is 0:
            imt_layout.add_widget(info)
            confirm.bind(on_press=lambda x: self.browser('img_t_og'))
        elif it is 1:
            imt_layout.add_widget(info2)
            confirm.bind(on_press=lambda x: self.browser('img_t_map'))
        elif it is 2:
            imt_layout.add_widget(info3)
            confirm.bind(on_press=lambda x: self.browser('img_t_cntr'))
        imt_layout.add_widget(confirm)
        self.popup = Popup(title="Transformação",
                           separator_height=0,
                           content=imt_layout,
                           size_hint=(None, None),
                           size=(300, 150))
        self.popup.open()

    def georef_coords(self):
        self.current = 'Coords'
        coods_layout = BoxLayout(orientation="vertical")

        main_in_layout = BoxLayout(orientation="vertical", size_hint_y=0.8)

        input_layout_x_min = BoxLayout(orientation='horizontal',
                                       size_hint_y=0.25)
        input_label_x_min = Label(text="X Mínimo",
                                  size_hint=(None, None),
                                  size=(200, 30))

        input_layout_x_max = BoxLayout(orientation='horizontal',
                                       size_hint_y=0.25)
        input_label_x_max = Label(text="X Máximo",
                                  size_hint=(None, None),
                                  size=(200, 30))

        input_layout_y_min = BoxLayout(orientation='horizontal',
                                       size_hint_y=0.25)
        input_label_y_min = Label(text="Y Mímino",
                                  size_hint=(None, None),
                                  size=(200, 30))

        input_layout_y_max = BoxLayout(orientation='horizontal',
                                       size_hint_y=0.25)
        input_label_y_max = Label(text="Y Máximo",
                                  size_hint=(None, None),
                                  size=(200, 30))

        georef_x_min = TextInput(text="",
                                 multiline=False,
                                 size_hint=(None, None),
                                 size=(300, 30))
        georef_x_max = TextInput(text="",
                                 multiline=False,
                                 size_hint=(None, None),
                                 size=(300, 30))
        georef_y_min = TextInput(text="",
                                 multiline=False,
                                 size_hint=(None, None),
                                 size=(300, 30))
        georef_y_max = TextInput(text="",
                                 multiline=False,
                                 size_hint=(None, None),
                                 size=(300, 30))
        confirm = Button(text="OK", size_hint_y=0.2)

        georef_y_min.bind(text=self.set_y_min)
        georef_y_max.bind(text=self.set_y_max)
        georef_x_min.bind(text=self.set_x_min)
        georef_x_max.bind(text=self.set_x_max)

        input_layout_x_min.add_widget(georef_x_min)
        input_layout_x_min.add_widget(input_label_x_min)

        input_layout_x_max.add_widget(georef_x_max)
        input_layout_x_max.add_widget(input_label_x_max)

        input_layout_y_min.add_widget(georef_y_min)
        input_layout_y_min.add_widget(input_label_y_min)

        input_layout_y_max.add_widget(georef_y_max)
        input_layout_y_max.add_widget(input_label_y_max)

        confirm.bind(on_press=self.coords_helper)

        main_in_layout.add_widget(input_layout_x_min)
        main_in_layout.add_widget(input_layout_x_max)
        main_in_layout.add_widget(input_layout_y_min)
        main_in_layout.add_widget(input_layout_y_max)
        coods_layout.add_widget(main_in_layout)
        coods_layout.add_widget(confirm)

        self.s_coords.add_widget(coods_layout)

    def coords_helper(self, instance):
        result = False
        self.current = 'Most-g4'
        self.s_coords.clear_widgets()
        self.s_open_file.clear_widgets()

        result, converted = self.imT.main(self.img_t_og, self.img_t_map,
                                          self.img_t_cntr,
                                          self.georef_x_min_text,
                                          self.georef_x_max_text,
                                          self.georef_y_min_text,
                                          self.georef_y_max_text)
        if result is True:
            self.save_builder(converted=converted)

    def show_selected_value(self, instance, text):
        """ Get current value from spinner """
        if text is not 'Tipo de ficheiro' and not '':
            return text
        else:
            print("Invalid file extension")

    def set_text(self, instance, input):
        """ Workaround to save input from textInput """
        self.text = input

    def set_x_min(self, instance, input):
        """ Workaround to save x min from textInput """
        self.georef_x_min_text = input

    def set_x_max(self, instance, input):
        """ Workaround to save x max from textInput """
        self.georef_x_max_text = input

    def set_y_min(self, instance, input):
        """ Workaround to save y min from textInput """
        self.georef_y_min_text = input

    def set_y_max(self, instance, input):
        """ Workaround to save x min from textInput """
        self.georef_y_max_text = input