예제 #1
0
파일: after.py 프로젝트: tanayz/kivyapp
    def build(self):
        f = FloatLayout()
        b = Button(pos_hint={'x': 0.5, 'center_y': .5},text='Hello world', font_size=14)
        s = Scatter()
        l = Label(text="Hello!",font_size=150)
        
        def select_to(*args):
            try:
                print args[1][0]
            except:
                pass
    
        fi = FileChooserIconView()

        f.add_widget(s)        
        s.add_widget(l)
        l.add_widget(b)
        
        def callback(instance):
            print('The button <%s> is being pressed' % instance.text)
            
            f.add_widget(fi)
        b.bind(on_press=callback)
        fi.bind(on_selection=select_to)
        return f
예제 #2
0
    def on_triple_tap(self):

        filechoser_layout = AnchorLayout()

        #filechoser = FileChooserIconView( size_hint = (0.75,0.85), path=settings['kraken_path'] +'/picture') #, multiselect = True)
        filechoser = FileChooserIconView(size_hint=(0.75, 0.85),
                                         path='/home')  #, multiselect = True)
        filechoser_list_layout = AnchorLayout(anchor_x='left', anchor_y='top')
        filechoser_list_layout.add_widget(filechoser)

        button_layout = AnchorLayout(anchor_x='left', anchor_y='bottom')

        box = BoxLayout(orientation='vertical',
                        size_hint=(0.75, None),
                        height=96)

        bli = BoxLayout(orientation='horizontal')
        ok_button = Button(text='Ok')
        cancel_button = Button(text='Cancel')

        bli2 = BoxLayout(orientation='horizontal')
        ti = TextInput(size_hint=(1, None), height=48)
        bli2.add_widget(Label(text='Enter File Name : '))
        bli2.add_widget(ti)

        bli.add_widget(ok_button)
        bli.add_widget(cancel_button)
        box.add_widget(bli2)
        box.add_widget(bli)
        button_layout.add_widget(box)

        image_layout = AnchorLayout(anchor_x='right', anchor_y='center')
        wimg = Image(source=settings['kraken_path'] + '/picture/girl.jpg',
                     size_hint=(0.25, None),
                     size=(200, Window.size[1]))
        image_layout.add_widget(wimg)

        filechoser_layout.add_widget(filechoser_list_layout)
        filechoser_layout.add_widget(button_layout)
        filechoser_layout.add_widget(image_layout)

        popup_browser = Popup(title='Select File')
        popup_browser.add_widget(filechoser_layout)

        def save_path(instance):
            if ti.text != '':
                self.text = filechoser.path + '/' + ti.text
            else:
                self.text = filechoser.selection[0]
            popup_browser.dismiss()

        def file_select(self, file):
            if file:
                wimg.source = file[0]

        cancel_button.bind(on_press=popup_browser.dismiss)
        ok_button.bind(on_press=save_path)
        filechoser.bind(selection=file_select)

        popup_browser.open()
예제 #3
0
파일: main.py 프로젝트: imbi7py/Server
 def ad(self, instance):
     chos = FileChooserIconView(path="./", )
     chos.bind(selection=self.aded)
     popup = Popup(title='Test popup',
                   content=chos,
                   size_hint=(None, None),
                   size=(400, 400))
     popup.open()
    def choose_file(self, instances):
        filechooser = FileChooserIconView()
        filechooser.bind(
            on_selection=lambda x: self.selected(filechooser.selection))
        self.main_layout.add_widget(filechooser)

        btn2 = Button(text='Add', size_hint=(1, .2))
        x = btn2.bind(on_release=lambda x: self.open(filechooser.path,
                                                     filechooser.selection))
        self.main_layout.add_widget(btn2)
        return x
예제 #5
0
class FileBrowserIconView(SettingPath):
    def _create_popup(self, instance):

        #Main Container
        content = BoxLayout(orientation='vertical')

        self.popup = popup = Popup(content=content,
                                   title=self.title,
                                   size_hint=(0.7, 0.9),
                                   auto_dismiss=True)
        popup.open()

        #Header with Current Path - enter a new value and press return
        header = BoxLayout(size_hint_y=None, height='35dp', spacing='5dp')
        btn1 = Button(text="Path: ", size_hint=(.1, 1))
        btn1.bind(on_release=self._updatePath)
        header.add_widget(btn1)
        #TODO: Uncomment for production
        #header.add_widget(Label(text="Current Path: ", size_hint=(.1,1)))

        #Current Path Input
        self.pathInput = TextInput(text=self.value,
                                   size_hint=(.9, 1),
                                   multiline=False)
        self.pathInput.bind(on_text_validate=self._updatePath)
        header.add_widget(self.pathInput)
        content.add_widget(header)

        content.add_widget(SettingSpacer())
        self.textinput = FileChooserIconView(path=self.value,
                                             size_hint=(1, 1),
                                             dirselect=True,
                                             show_hidden=False)
        self.textinput.bind(on_path=self.val)
        content.add_widget(self.textinput)

        # 2 buttons are created for accept or cancel the current value
        btnlayout = BoxLayout(size_hint_y=None, height='50dp', spacing='5dp')
        btn = Button(text='Ok')
        btn.bind(on_release=self._validate)
        btnlayout.add_widget(btn)
        btn = Button(text='Cancel')
        btn.bind(on_release=self._dismiss)
        btnlayout.add_widget(btn)
        content.add_widget(btnlayout)

    def val(self):
        self.value = self.textinput
        self._validate()

    def _updatePath(self, instance):
        print(self.pathInput.text)
        self.textinput.path = self.pathInput.text
예제 #6
0
파일: panels.py 프로젝트: jma22/backfire
class LoadPopup(Popup):
    def __init__(self, load_callback, pex_error_callback, error_callback,
                 on_new_config):
        super(LoadPopup, self).__init__()

        self.load_callback = load_callback
        self.pex_error_callback = pex_error_callback
        self.error_callback = error_callback
        self.on_new_config = on_new_config

        self.content_holder = BoxLayout()
        self.filechooser = FileChooserIconView(path=os.getcwd(),
                                               size_hint=(.8, .8))
        self.load_bt = Button(text='Select',
                              size_hint=(.1, .1),
                              background_normal='button6.png',
                              background_down='button6down.png')

        self.filechooser.bind(on_entry_added=self.update_path)
        self.load_bt.bind(on_release=self.load)

        self.content_holder.add_widget(self.filechooser)
        self.content_holder.add_widget(self.load_bt)

        self.title = 'load file from {}'.format(self.filechooser.path)
        self.content = self.content_holder
        self.size_hint = (.7, .7)
        self.pos_hint = {'center_x': .5, 'center_y': .5}

    def load(self, *kwargs):
        if self.filechooser.selection != []:
            config_path = self.filechooser.selection[0]

            if not config_path.endswith('.pex'):
                self.pex_error_callback()
                return
            try:
                # hand off config path to particle.load_config
                self.load_callback(config_path)

                # call App to update slider defaults and emitter type
                self.on_new_config()

                # close popup window
                self.dismiss()

            except:
                # config file cannot be loaded
                self.error_callback()

    def update_path(self, *kwargs):
        self.title = 'load file from {}'.format(self.filechooser.path)
예제 #7
0
파일: app.py 프로젝트: RobertJaskolski/ANN
    def __init__(self, **kwargs):
        super(FileSelect, self).__init__(**kwargs)

        container = BoxLayout(orientation='vertical')

        file_chooser = FileChooserIconView()
        file_chooser.bind(
            on_selection=lambda x: self.selected(file_chooser.selection))

        open_btn = Button(text='Open selected file', size_hint=(1, .2))
        open_btn.bind(on_release=lambda x: open_file(file_chooser.path,
                                                     file_chooser.selection))

        container.add_widget(file_chooser)
        container.add_widget(open_btn)
        self.add_widget(container)
예제 #8
0
class HackApp(App):
    def update(self, select, instance, value):
        file = self.chooser.selection
        self.imagebox.clear_widgets()
        selected = Image(source=file[0])
        self.imagebox.add_widget(selected)

        class_found, pourc = predict(file[0])
        self.resultlabel.text = f'Classe : {class_found}\nPourcentage : {pourc}'

    def build(self):
        self.title = "HackApp"
        mainwindow = BoxLayout(orientation="vertical")
        imagelayout = BoxLayout(orientation="vertical")
        resultlayout = BoxLayout()
        self.imagebox = BoxLayout()
        popupbutton = Button(text="Choose the photo to analyse",
                             size_hint=(0.5, 0.2),
                             pos_hint={'x': 0.25},
                             background_color=color_button)
        launchbutton = Button(text="Launch Analysis",
                              size_hint=(0.5, 0.2),
                              pos_hint={'x': 0.25},
                              background_color=color_button)
        popup = Popup(size_hint=(0.5, 0.5))

        ospath = os.path.abspath(os.getcwd())
        self.chooser = FileChooserIconView(path=ospath)

        self.resultlabel = Label(text="", color=color_text)

        ledimage = Image(source="led-sunlight-300x230.jpg")

        popupbutton.bind(on_press=popup.open)
        self.chooser.bind(on_submit=self.update)

        popup.add_widget(self.chooser)
        imagelayout.add_widget(self.imagebox)
        imagelayout.add_widget(popupbutton)
        imagelayout.add_widget(launchbutton)
        resultlayout.add_widget(self.resultlabel)
        resultlayout.add_widget(ledimage)
        mainwindow.add_widget(imagelayout)
        mainwindow.add_widget(resultlayout)

        return mainwindow
예제 #9
0
파일: panels.py 프로젝트: jma22/backfire
class SavePopup(Popup):
    def __init__(self, save_callback, pex_error_callback):
        super(SavePopup, self).__init__()

        self.save_callback = save_callback
        self.pex_error_callback = pex_error_callback

        self.content_holder = BoxLayout(orientation='vertical')
        self.filechooser = FileChooserIconView(path=os.getcwd(),
                                               size_hint=(1, .8))
        self.config_name = TextInput(hint_text='config.pex',
                                     multiline=False,
                                     size_hint=(.3, .1))
        self.save_bt = Button(text='Save',
                              size_hint=(.1, .1),
                              background_normal='button6.png',
                              background_down='button6down.png')

        self.filechooser.bind(on_entry_added=self.update_path)
        self.config_name.bind(on_text_validate=self.save)
        self.save_bt.bind(on_release=self.save)

        self.content_holder.add_widget(self.filechooser)
        self.content_holder.add_widget(self.config_name)
        self.content_holder.add_widget(self.save_bt)

        self.title = 'save file to {}'.format(self.filechooser.path)
        self.content = self.content_holder
        self.size_hint = (.7, .7)
        self.pos_hint = {'center_x': .5, 'center_y': .5}

    def save(self, *kwargs):
        if self.config_name.text == '':
            config_name = 'config.pex'
        else:
            config_name = self.config_name.text
        if not config_name.endswith('.pex'):
            self.pex_error_callback()
        else:
            self.save_callback(config_name, self.filechooser.path)
            self.dismiss()

    def update_path(self, *kwargs):
        self.title = 'save file to {}'.format(self.filechooser.path)
예제 #10
0
    def build(self):
        self.main_box = BoxLayout(orientation='vertical', spacing=10)
        self.files_box = BoxLayout(orientation='horizontal', spacing=20)
        self.button_box = BoxLayout(orientation='horizontal', spacing=20)

        filechooser = FileChooserIconView(
            filters=[lambda folder, filename: not filename.endswith('.sys')])
        filechooser.bind(
            on_selection=lambda x: self.selected(filechooser.selection))

        open_btn = Button(text='Open',
                          size_hint=(1, .2),
                          background_color=get_color_from_hex("#1890ff"),
                          background_normal='',
                          color=get_color_from_hex("#F2F2F2"))
        open_btn.bind(on_release=lambda x: self.open(filechooser.selection))

        self.main_box.add_widget(filechooser)
        self.main_box.add_widget(open_btn)
        return self.main_box
예제 #11
0
 def __init__(self, **kwargs):
     super(FilePopup, self).__init__()
     titleText = kwargs['titleText']
     dirTrue = kwargs['canBeDir']
     buttonText = kwargs['buttonText']
     if buttonText == "Select Folder":
         self.choice = "saveDir"
     elif buttonText == "Select Configuration File":
         self.choice = "configFile"
     content = BoxLayout(orientation='vertical')
     chooseButton = Button(text=buttonText, size_hint=(1, 0.2))
     fileChooser = FileChooserIconView()
     fileChooser.dirselect = BooleanProperty(dirTrue)
     fileChooser.bind(selection=self.selectingFolder)
     chooseButton.bind(on_release=self.chooseFile)
     content.add_widget(fileChooser)
     content.add_widget(chooseButton)
     self.title = titleText
     self.canvas.opacity = 0.8
     self.background_color = 1, 1, 1, 1
     self.content = content
     self.size_hint = (0.8, 0.8)
예제 #12
0
class PopU(BoxLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.partitions_caption = os.popen(
            'wmic logicaldisk get caption').read()
        self.partitions_caption = self.partitions_caption.split()
        self.partitions_caption.remove('Caption')
        print(self.partitions_caption)
        self.partitions_btn = GridLayout(cols=10,
                                         rows=1,
                                         size_hint_y=0.1,
                                         spacing=2)
        for partition in self.partitions_caption:
            self.part_btn = Button(text=partition, id=partition + "\\")
            #self.part_btn.bind(on_release=lambda *args: self.change_main_direct(self.part_btn.id, *args))
            self.part_btn.bind(
                on_release=partial(self.change_main_direct, self.part_btn.id))
            #print(self.part_btn.id)
            self.partitions_btn.add_widget(self.part_btn)

        self.add_widget(self.partitions_btn)

        self.text_btn_grid = GridLayout(cols=1,
                                        rows=1,
                                        size_hint=(1, 0.09),
                                        spacing=5,
                                        padding=1)
        self.path_Text = TextInput(multiline=False,
                                   size_hint_x=1,
                                   font_size=11)
        #self.change_design_btn = Button(text="Lists", size_hint_x=0.2)
        #self.change_design_btn.bind(on_release=self.change_design_fn)
        self.text_btn_grid.add_widget(self.path_Text)
        #self.text_btn_grid.add_widget(self.change_design_btn)
        self.add_widget(self.text_btn_grid)

        self.file_chooser_list = FileChooserIconView(size_hint_y=0.8)
        self.file_chooser_list.dirselect = True
        self.file_chooser_list.bind(selection=self.on_select)
        self.file_chooser_list.path = "D:\\"
        self.add_widget(self.file_chooser_list)
        """self.file_chooser_Icon = FileChooserIconView(size_hint_y=0.8)
        self.file_chooser_Icon.dirselect = True
        self.file_chooser_Icon.bind(selection=self.on_select)
        self.file_chooser_Icon.path = "D:\\"
        self.add_widget(self.file_chooser_Icon)"""

        self.buttons_grid = GridLayout(cols=2,
                                       rows=2,
                                       size_hint_y=0.1,
                                       spacing=2)
        self.select_btn = Button(text="Select", size_hint=(0.4, 0.1))
        self.cancel_btn = Button(text="Cancel", size_hint=(0.4, 0.1))

        self.buttons_grid.add_widget(self.select_btn)
        self.buttons_grid.add_widget(self.cancel_btn)

        self.orientation = 'vertical'
        self.add_widget(self.buttons_grid)
        self.path = ""

    def on_select(self, instance, obj):
        try:
            if self.file_chooser_list.selection:
                self.path = self.file_chooser_list.selection[0]
                self.path_Text.text = self.path + "\\"
                print(self.path)
        except Exception as e:
            print(f"Selecting Directory, Error: {e} ")

    def change_main_direct(self, path, *instance):
        print(path)
        try:
            self.file_chooser_list.path = path
            self.path_Text.text = path
        except Exception as e:
            print(f"Changing Path: error:{e}")
예제 #13
0
class CustomizeArt(BoxLayout):

    preview_height_hint = 0.5

    def __init__(self, app, **kwargs):
        super(CustomizeArt, self).__init__(**kwargs)

        self.app = app

        self.orientation = 'vertical'
        self.spacing = round(Window.width * 0.01)

        self.fl = FileChooserIconView()
        self.fl.bind(selection=self.highlight)

        btn1 = Button(text='Select')
        btn1.bind(on_release=self.select)
        btn2 = Button(text='Default')
        btn2.bind(on_release=self.reset_image)
        btn3 = Button(text='Cancel')
        btn3.bind(on_release=self.cancel)

        self.btnlayout=BoxLayout(size_hint_y=0.12,\
                            spacing=round(Window.width*0.01),\
                            orientation='horizontal')
        self.btnlayout.add_widget(btn1)
        self.btnlayout.add_widget(btn2)
        self.btnlayout.add_widget(btn3)

        self.message=Label(text='Preview will be displayed here'+\
                           '\nSupported formats include\n.png\n.jpg\n.jpeg')
        self.message.size_hint_y = self.preview_height_hint
        self.message.valign = 'middle'
        self.message.halign = 'center'

        self.size = (Window.width, Window.height)
        self.add_widget(self.message)
        self.add_widget(self.fl)
        self.add_widget(self.btnlayout)
        self.padding=[Window.width*0.01,Window.height*0.005,\
                      Window.width*0.01,Window.height*0.005]

        self.preview = None

    def select(self, instance):
        if self.preview == None:
            self.invalid_selection()
        else:
            self.app.make_selection(self.fl.selection[0])

    def reset_image(self, instance):
        self.app.make_selection('./imageAssets/puzzles/')

    def cancel(self, instance):
        self.app.turn_off_selection()

    def invalid_selection(self):
        try:
            self.error_message.open()
        except:
            self.error_message = self.error_popUp()
            self.error_message.open()

    def highlight(self, filechooser, selection):
        try:
            path = selection[0]
            file_type = path[-4] + path[-3] + path[-2] + path[-1]

            if file_type == '.png' or file_type == '.jpg' or file_type == 'jpeg':
                self.preview = Image(source=path)
                self.preview.size_hint_y = self.preview_height_hint
                self.clear_widgets()
                self.add_widget(self.preview)
                self.add_widget(self.fl)
                self.add_widget(self.btnlayout)
            elif self.preview != None:
                self.default_display()
        except:
            if self.preview != None:
                self.default_display()

    def default_display(self):
        self.clear_widgets()
        self.add_widget(self.message)
        self.add_widget(self.fl)
        self.add_widget(self.btnlayout)
        self.preview = None

    def error_popUp(self):
        myText = Label(valign='middle', halign='center')
        myText.text='Selected file is not supported\nSupported'+\
                     ' formats include\n.png\n.jpg\n.jpeg'
        myButton = Button(text='Dismiss')
        myButton.bind(on_release=self.error_popUp_dismiss)
        myButton.size_hint_y = 0.3
        myBox = BoxLayout(orientation='vertical')
        myBox.add_widget(myText)
        myBox.add_widget(myButton)
        return Popup(title='Please select again',
                     content=myBox,
                     size_hint=(0.9, 0.5))

    def error_popUp_dismiss(self, instance):
        self.error_message.dismiss()
예제 #14
0
class FIRST(FloatLayout):
    def __init__(self, *args, **kwargs):
        super().__init__(*args)

        with self.canvas:
            Color(0, 0.5, 1, 1)
            Rectangle(pos=(0, h * 0.95), size=(w, h * 0.05))

        self.ti = TextInput(hint_text="Enter yout text here",
                            size_hint=(0.7, 0.5),
                            pos_hint={
                                'x': 0.15,
                                'y': 0.4
                            })
        self.add_widget(self.ti)

        self.bt = Button(font_size=30,
                         text="Generate",
                         size_hint=(0.4, 0.07),
                         pos_hint={
                             'x': 0.15,
                             'y': 0.27
                         },
                         background_normal="Icon/button.png")
        self.add_widget(self.bt)
        self.bt.bind(on_press=self.pop)

        self.btt5 = Button(font_size=30,
                           text="Select",
                           size_hint=(0.4, 0.07),
                           pos_hint={
                               'x': 0.45,
                               'y': 0.27
                           },
                           background_normal="Icon/button.png")
        self.add_widget(self.btt5)

        self.bt3 = Button(size_hint=(0.1, 0.05),
                          pos_hint={
                              'x': 0.9,
                              'y': 0.95
                          },
                          background_normal="Icon/list.png")
        self.add_widget(self.bt3)

        self.img1 = Imag(source="Icon/banner.png",
                         size=(w, h * 0.4),
                         pos=(0, -0.37 * h))
        self.add_widget(self.img1)

        self.bt5 = Button(size_hint=(0.1, 0.05),
                          pos_hint={
                              'x': 0,
                              'y': 0.95
                          },
                          background_normal="Icon/info.png")
        self.add_widget(self.bt5)

        self.bt3.bind(on_press=self.shift)
        self.bt5.bind(on_press=self.popinfo)
        self.btt5.bind(on_press=self.openfile)

    def shift(self, *args):
        s.current = "3"

    def popinfo(self, *args):
        f2 = FloatLayout()

        self.label = Label(markup=True,
                           halign="center",
                           valign="top",
                           font_size=0.0185 * h,
                           text=""" [b][u]To use this application[/u]:-[/b]

-> Copy the text from source and paste in the "enter 
text" window on the home screen.

-> Click on the generate button and name your PDF 
file and save.

-> Your PDF will be generated along with picture of 
every page in your gallery.

-> Or alternatively you can upload a txt file with text 
in it and can get a PDF generated.

[u][b]Created by[/u]:-[/b] 

Rahul Gothwal, Yugam Sachdeva

[b][u] Note[/u]:- [/b]

If you face any issue feel free to report issue at: 
[b]https://bit.ly/T2H-RIS[/b]""",
                           color=(0, 0, 0, 1),
                           size_hint=(1, 1),
                           pos_hint={
                               'x': 0,
                               'y': 0
                           })
        f2.add_widget(self.label)

        pop1 = Popup(title_color=(0, 0.5, 1, 1),
                     background="Icon/white.jpeg",
                     content=f2,
                     title="Information",
                     size_hint=(0.8, 0.8),
                     pos_hint={
                         'x': 0.1,
                         'y': 0.1
                     })

        pop1.open()

    def pop(self, instance):
        global f, pop, d, pop4, pop3
        try:
            self.remove_widget(pop4)
            self.remove_widget(pop3)
        except:
            pass

        d = instance.text
        if d == "Yes":
            if file_text == '':
                try:
                    self.remove_widget(self.llb)
                except:
                    pass

                self.lb = Label(text="File format is wrong or file is empty!",
                                color=(0, 0, 0, 1),
                                size_hint=(1, 0.05),
                                pos_hint={
                                    'x': 0,
                                    'y': 0.33
                                })
                self.add_widget(self.lb)
            else:
                self.naming()
        else:
            try:
                self.remove_widget(self.lb)
            except:
                pass
            if self.ti.text == '':
                self.llb = Label(text="Empty PDF can't be generated!",
                                 color=(0, 0, 0, 1),
                                 size_hint=(1, 0.05),
                                 pos_hint={
                                     'x': 0,
                                     'y': 0.33
                                 })
                self.add_widget(self.llb)
            else:
                self.naming()

    def naming(self, *args):
        global pop, ff
        ff = FloatLayout()

        self.ti1 = TextInput(hint_text="Enter PDF name",
                             size_hint=(0.8, 0.2),
                             pos_hint={
                                 'x': 0.1,
                                 'y': 0.6
                             })
        ff.add_widget(self.ti1)

        self.bt1 = Button(text="Done",
                          size_hint=(0.4, 0.3),
                          pos_hint={
                              'x': 0.3,
                              'y': 0.08
                          },
                          background_normal="Icon/button.png")
        ff.add_widget(self.bt1)
        self.bt1.bind(on_press=self.pdfgene)

        pop = Popup(auto_dismiss=False,
                    title_color=(0, 0.5, 1, 1),
                    background="Icon/white.jpeg",
                    content=ff,
                    title="Save PDF",
                    size_hint=(0.8, 0.3),
                    pos_hint={
                        'x': 0.1,
                        'y': 0.3
                    })

        pop.open()

    def openfile(self, *args):
        global pop3
        self.filechoose = FileChooserIconView(path=".")
        pop3 = Popup(title="File Manager",
                     content=self.filechoose,
                     size_hint=(1, 1),
                     pos_hint={
                         'x': 0,
                         'y': 0
                     })
        self.add_widget(pop3)
        self.filechoose.bind(on_submit=self.pk)

    def pk(self, a, path, b):
        global pop3, file_text, pop4
        f = FloatLayout()
        self.ll = Label(color=(0, 0, 0, 1),
                        text="Do you want to covert this Doc into PDF?",
                        size_hint=(1, 0.5),
                        pos_hint={
                            'x': 0,
                            'y': 0.5
                        })
        f.add_widget(self.ll)

        self.yes = Button(text="Yes",
                          font_size=30,
                          size_hint=(0.4, 0.25),
                          pos_hint={
                              'x': 0.1,
                              'y': 0.2
                          },
                          background_normal="Icon/button.png")
        f.add_widget(self.yes)
        self.yes.bind(on_press=self.pop)

        self.no = Button(text="No",
                         font_size=30,
                         size_hint=(0.4, 0.25),
                         pos_hint={
                             'x': 0.5,
                             'y': 0.2
                         },
                         background_normal="Icon/button.png")
        f.add_widget(self.no)
        self.no.bind(on_press=self.denied)

        pop4 = Popup(background="Icon/white.jpeg",
                     title="Confirmation",
                     title_color=(0, 0.5, 1, 1),
                     content=f,
                     size_hint=(0.8, 0.3),
                     pos_hint={
                         'x': 0.1,
                         'y': 0.35
                     })
        self.add_widget(pop4)

        for i in [".txt"]:
            if path[0].endswith(i):
                files = open(path[0], "r")
                file_text = files.read()
            else:
                file_text = ''

    def denied(self, *args):
        global pop4, name
        self.remove_widget(pop4)

    def pdfgene(self, instance):
        global BG, sizeofSheet, allowedChars, gap, name, sa, d, pop
        c = instance.text
        daty = os.listdir('.')
        pdf = self.ti1.text + ".pdf"
        if len(self.ti1.text) == 0 or pdf in daty:
            self.lb1 = Label(text="Name is empty or already exist!",
                             color=(0, 0, 0, 1),
                             size_hint=(1, 0.05),
                             pos_hint={
                                 'x': 0,
                                 'y': 0.38
                             })
            ff.add_widget(self.lb1)
        else:
            pop.dismiss()
            try:
                self.remove_widget(self.lb)
            except:
                pass

            try:
                if d == "Yes":
                    date = file_text
                else:
                    date = self.ti.text

                data = date.replace('\n', '')
                name = self.ti1.text

                with open(name + ".pdf", 'w') as file:
                    pass

                l = len(data)
                nn = len(data) // 600
                chunks, chunk_size = len(data), len(data) // (nn + 1)
                p = [
                    data[i:i + chunk_size]
                    for i in range(0, chunks, chunk_size)
                ]

                for i in range(0, len(p)):
                    worddd(p[i])
                    writee('\n')
                    BG.save('%doutput.png' % i)
                    BG1 = Image.open("Font/base.png")
                    BG = BG1
                    gap = 0
                    _ = 0

            except ValueError as E:
                print("{}\nTry again".format(E))

            imagelist = []
            for i in range(0, len(p)):
                imagelist.append('%doutput.png' % i)
            try:
                pdf_creation(imagelist.pop(0)[20])

                for PNG_FILE in imagelist:
                    pdf_creation(PNG_FILE, flag=True)
            except:
                pass

            needle()
            self.ti.text = ""
            s.current = "3"
예제 #15
0
def on_pic_change(s):
    """
    This method creates file chooser pop-up for user to upload profile picture as png file.
    :param s: It is for handling class structure.
    :return:
    """

    def on_pic_select(self, widget_name, file_path, mouse_pos):
        """
        This method uploads selected picture to server and updates related widgets on GUI.
        :param self: It is for handling class structure.
        :param widget_name: It is for handling file chooser input.
        :param file_path: It is path of selected file.
        :param mouse_pos: It is for handling file chooser input.
        :return:
        """

        self.popup.dismiss()

        database_api.uploadProfilePic(Cache.get("info", "token"),
                                      Cache.get("info", "nick"),
                                      file_path[0]
                                      )

        if round_image.update_image():
            Cache.append("info",
                         "pict",
                         True
                         )

            pic = [self.ico_user_picture,
                   self.ids["img_user_card"]
                   ]
            for pp in pic:
                pp.source = "data/img/pic_user_current.png"
                pp.reload()

    popup_content = FloatLayout()
    s.popup = Popup(title="Change Profile Picture",
                    content=popup_content,
                    separator_color=[140 / 255., 55 / 255., 95 / 255., 1.],
                    size_hint=(None, None),
                    size=(s.width / 2, s.height / 2)
                    )
    filechooser = FileChooserIconView(path=Cache.get("config", "path"),
                                      filters=["*.png"],
                                      size=(s.width, s.height),
                                      pos_hint={"center_x": .5, "center_y": .5}
                                      )
    filechooser.bind(on_submit=partial(on_pic_select,
                                       s
                                       )
                     )
    popup_content.add_widget(filechooser)
    popup_content.add_widget(Button(text="Upload",
                                    font_name="data/font/LibelSuit.ttf",
                                    font_size=s.height / 40,
                                    background_normal="data/img/widget_green.png",
                                    background_down="data/img/widget_green_select.png",
                                    size_hint_x=.5,
                                    size_hint_y=None,
                                    height=s.height / 20,
                                    pos_hint={"center_x": .25, "y": .0},
                                    on_release=filechooser.on_submit)  # TODO
                             )
    popup_content.add_widget(Button(text="Cancel",
                                    font_name="data/font/LibelSuit.ttf",
                                    font_size=s.height / 40,
                                    background_normal="data/img/widget_red.png",
                                    background_down="data/img/widget_red_select.png",
                                    size_hint_x=.5,
                                    size_hint_y=None,
                                    height=s.height / 20,
                                    pos_hint={"center_x": .75, "y": .0},
                                    on_release=s.popup.dismiss)
                             )
    s.popup.open()
예제 #16
0
class DavChooser(BoxLayout):
    filename = StringProperty("")
    chooser = ObjectProperty(None, allownone=True)
    path = StringProperty(home)

    def __init__(self, **kwargs):
        super(DavChooser, self).__init__(**kwargs)
        self.orientation = "vertical"
        self.spacing = "5dp"
        self.chooser = FileChooserIconView(path=self.path)
        self.chooser.bind(selection=self.on_file_select, path=self.setter("path"))
        self.fileentry = TextInput(size_hint_y=None, height="30dp", text=self.filename, multiline=False)
        self.fileentry.bind(text=self.setter("filename"))
        self.davbar = BoxLayout(orientation="horizontal", size_hint_y=None, height="45dp", spacing="5dp")
        self.levelup = Button(on_press=hide_keyboard, on_release=self.on_levelup, height=40, width=40, size_hint=(None, None), background_normal=os.path.join(curdir, "images/levelup_normal.png"), background_down=os.path.join(curdir, "images/levelup_down.png"))
        self.newdir = Button(on_press=hide_keyboard, on_release=self.on_newdir, height=40, width=40, size_hint=(None, None), background_normal=os.path.join(curdir, "images/newdir_normal.png"), background_down=os.path.join(curdir, "images/newdir_down.png"))
        self.davbar.add_widget(self.levelup)

        scroll = ScrollView(pos_hint={'center_x': .5, 'center_y': .5}, do_scroll_y=False, size_hint=(1, 1))
        self.navbar = GridLayout(cols=1, orientation="horizontal", spacing=5, padding=[5, 0, 0, 0])
        self.navbar.bind(minimum_height=self.navbar.setter('height'))
        scroll.add_widget(self.navbar)

        self.davbar.add_widget(scroll)
        self.davbar.add_widget(self.newdir)

        self.chooser.bind(path=self.on_path)
        self.on_path(None, self.path)

        self.add_widget(self.davbar)
        self.add_widget(self.fileentry)
        self.add_widget(self.chooser)

    def on_path(self, instance, path):

        splitpath = os.path.abspath(path).split(os.sep)
        self.navbar.clear_widgets()
        if splitpath[0] == "":
            splitpath[0] = os.sep
        #print splitpath

        for i in splitpath:
            if i != "":
                btn = Button(text=i, on_press=hide_keyboard, on_release=self.navigate, height=40, size_hint=(None, None))
                btn.path = os.path.normpath(os.sep.join(splitpath[:splitpath.index(i)+1]))
                #print "buttonpath", btn.path, splitpath[:splitpath.index(i)+1], "i:", i, splitpath.index(i)
                self.navbar.cols = len(self.navbar.children) + 1
                self.navbar.add_widget(btn)

    def on_levelup(self, *args):
        #print "levelup", os.sep.join(self.chooser.path.split(os.sep)[:-1]), self.chooser.path
        newpath = os.sep.join(self.chooser.path.split(os.sep)[:-1])
        if newpath == "":
            newpath = os.sep
        self.chooser.path = newpath

    def on_newdir(self, *args):
        content = BoxLayout(orientation="vertical", spacing="5dp")
        self.popup = Popup(size_hint=(.5, .5), content=content, title="New folder")
        buttonbox = BoxLayout(orientation="horizontal", spacing="5dp", height=45)
        ok = Button(text="OK", on_press=hide_keyboard, on_release=self.mkdir, height=40, size_hint_y=None)
        cancel = Button(text="Cancel", on_press=hide_keyboard, on_release=self.popup.dismiss, height=40, size_hint_y=None)
        buttonbox.add_widget(ok)
        buttonbox.add_widget(cancel)
        self.direntry = TextInput(height=30, size_hint_y=None, on_text_validate=self.mkdir, multiline=False)
        content.add_widget(self.direntry)
        content.add_widget(buttonbox)
        self.popup.open()

    def mkdir(self, *args):
        #print "mkdir", os.path.join(self.chooser.path, self.direntry.text)
        os.mkdir(os.path.join(self.chooser.path, self.direntry.text))
        # This should make the view refresh
        self.chooser.path = os.sep + self.chooser.path[:]
        self.popup.dismiss()

    def navigate(self, button):
        #print "navigate", button.path
        self.chooser.path = button.path

    def on_file_select(self, instance, selection):
        try:
            self.fileentry.text = selection and os.path.basename(selection[0]) or ""
        except:
            self.fileentry.text = ""
        self.filename = selection[0]
예제 #17
0
파일: main.py 프로젝트: the-duck/launcher
class TreeViewBlock(Button, TreeViewNode):
    def __init__(self, *args, **kwargs):
        super(TreeViewBlock, self).__init__(*args, **kwargs)
        print args
        self.background_normal = "images/button.png"
        self.background_down = "images/button.png"
        self.background_color = [0, 0, 0, 0]
        self.color = [.2, 0.2, 0.2, 1]
        self.size_hint_y = None
        self.height = 30
        self.bind(on_release=self.click)
        self.color_selected = [.9, .5, .3, 1]
        the_layout = BoxLayout(orientation="vertical")
        b1 = BoxLayout(size_hint_y=None, height=45, padding=5)
        l = Label(text="Title : ", font_size=16)
        t = TextInput(text=self.text, multiline=False, font_size=18)
        t.bind(on_text_validate=self.onTextChange)
        b1.add_widget(l)
        b1.add_widget(t)
        b2 = BoxLayout(padding=8)
        l1 = Label(text="Add ")
        b3 = BoxLayout(orientation="vertical")
        btn1 = Button(text="Application", font_size=14)
        btn1.bind(on_release=self.appsPopupOpen)
        btn2 = Button(text="File", font_size=14)
        btn2.bind(on_release=self.filesPopupOpen)
        btn3 = Button(text="Folder", font_size=14)
        btn3.bind(on_release=self.foldersPopupOpen)
        b3.add_widget(btn1)
        b3.add_widget(btn2)
        b3.add_widget(btn3)
        l2 = Label(text="To Block.")
        b2.add_widget(l1)
        b2.add_widget(b3)
        b2.add_widget(l2)
        rem = Button(text="Remove this block",
                     size_hint_y=None,
                     height=30,
                     background_normal="images/button.png",
                     background_color=[.8, .2, .2, 1])
        rem.bind(on_release=self.removeBlock)
        the_layout.add_widget(b1)
        the_layout.add_widget(Label(text="----", size_hint_y=None, height=20))
        the_layout.add_widget(b2)
        the_layout.add_widget(rem)
        self.popupWindow = Popup(title="Block: '{}'".format(self.text),
                                 size_hint=(None, None),
                                 size=(400, 230),
                                 separator_color=[.9, .4, .2, 1],
                                 background_color=[0, 0, 0, .6],
                                 content=the_layout)
        ###Apps
        b = BoxLayout(orientation="vertical")
        self.app_list = AddAppList()
        a_btn = Button(text="Add This Application",
                       size_hint_y=None,
                       height=40)
        a_btn.bind(on_release=self.addApp)
        b.add_widget(self.app_list)
        b.add_widget(a_btn)
        self.appsPopup = Popup(title="Add Application to '{}'".format(
            self.text),
                               size_hint=(None, None),
                               size=(400, 400),
                               separator_color=[.9, .4, .2, 1],
                               background_color=[0, 0, 0, .6],
                               content=b)
        ##Files
        box = BoxLayout(orientation="vertical")
        self.f = FileChooserIconView(multiselect=False,
                                     path=os.path.expanduser("~"))
        self.f.bind(on_submit=self.addFile)
        l = Label(text="Double click on a file to add it.",
                  size_hint_y=None,
                  height=40)
        box.add_widget(self.f)
        box.add_widget(l)
        self.filesPopup = Popup(title="Add File to '{}'".format(self.text),
                                size_hint=(None, None),
                                size=(500, 500),
                                separator_color=[.9, .4, .2, 1],
                                background_color=[0, 0, 0, .6],
                                content=box)
        ##Folders
        box1 = BoxLayout(orientation="vertical")
        self.f2 = FileChooserIconView(multiselect=False,
                                      path=os.path.expanduser("~"))
        self.f2.bind(on_entry_added=self.updateFolders)
        b = BoxLayout(size_hint_y=None, height=50, padding=5)
        self.folder_label = Label(text=self.f2.path, id="FileLabel")
        btn = Button(text="Add Folder", size_hint_x=None, width=150)
        btn.bind(on_release=self.addFolder)
        b.add_widget(self.folder_label)
        b.add_widget(btn)
        box1.add_widget(self.f2)
        box1.add_widget(b)
        self.foldersPopup = Popup(title="Add Folder to '{}'".format(self.text),
                                  size_hint=(None, None),
                                  size=(500, 500),
                                  separator_color=[.9, .4, .2, 1],
                                  background_color=[0, 0, 0, .6],
                                  content=box1)

    def onTextChange(self, *args):
        for b in pickle.loads(d_cfg.get()['blocks']):
            if b["name"] == self.text:
                b["name"] = args[0].text
                self.text = args[0].text
                blocks = createBlockDicts(self.parentTree.iterate_all_nodes())
                updateConfig({'blocks': blocks})

    def appsPopupOpen(self, *args):
        self.popupWindow.dismiss()
        self.appsPopup.open()

    def filesPopupOpen(self, *args):
        self.popupWindow.dismiss()
        self.filesPopup.open()

    def foldersPopupOpen(self, *args):
        self.popupWindow.dismiss()
        self.foldersPopup.open()

    def addApp(self, *args):
        s = self.app_list.adapter.selection[0].text
        if s != None:
            #Update
            node = self.parentTree.selected_node
            new = TreeViewButton(text=s)
            new.parentTree = self.parentTree
            self.parentTree.add_node(new, node)
            self.appsPopup.dismiss()
            blocks = createBlockDicts(self.parentTree.iterate_all_nodes())
            updateConfig({"blocks": blocks})

    def addFile(self, *args):
        for b in pickle.loads(d_cfg.get()["blocks"]):
            if b["name"] == self.text:
                #Update Tree
                node = self.parentTree.selected_node
                new = TreeViewButton(text=str(args[1][0]))
                new.parentTree = self.parentTree
                self.parentTree.add_node(new, node)
                self.filesPopup.dismiss()
                blocks = createBlockDicts(self.parentTree.iterate_all_nodes())
                updateConfig({"blocks": blocks})

    def addFolder(self, *args):
        p = self.f2.path
        if os.path.exists(p):
            #Update
            node = self.parentTree.selected_node
            new = TreeViewButton(text=p)
            new.parentTree = self.parentTree
            self.parentTree.add_node(new, node)
            self.foldersPopup.dismiss()
            blocks = createBlockDicts(self.parentTree.iterate_all_nodes())
            print blocks
            updateConfig({"blocks": blocks})

    def updateFolders(self, *args):
        self.folder_label.text = self.f2.path

    def removeBlock(self, *args):
        try:
            self.parentTree.remove_node(self)
            blocks = createBlockDicts(self.parentTree.iterate_all_nodes())
            updateConfig({"blocks": blocks})
        except:
            pass
        self.popupWindow.dismiss()

    def click(self, *args):
        self.popupWindow.open()
예제 #18
0
class FTPView(GridLayout):
    #class FTPView(BoxLayout):
    def __init__(self, **kwargs):
        self.listftp = []

        self.first_time = 1

        #1 column for the global grid layout
        kwargs['cols'] = 1
        super(FTPView, self).__init__(**kwargs)

        #show the load button
        self.Load()

    def BuildList(self):
        args_converter = \
            lambda row_index, rec: \
                {'text': rec['text'],
                 'height': 25,
                 'size_hint_y': None,
                 'cls_dicts': [{'cls': ListItemLabel,
                        'kwargs': {'text': rec['text'][3], 'height': 25,}},
                       {'cls': ListItemLabel,
                        'kwargs': {'text': rec['text'][0], 'size_hint_x':.3}},
                       {'cls': ListItemLabel,
                        'kwargs': {'text': rec['text'][1], 'size_hint_x':.02}},
                       {'cls': ListItemLabel,
                        'kwargs': {'text': rec['text'][2], 'size_hint_x':.3}}]}

        #item_strings = [self.listftp[index][3] for index in xrange(len(self.listftp))]
        integers_dict = {
            self.listftp[i][3]: {
                'text': self.listftp[i],
                'is_selected': False
            }
            for i in xrange(len(self.listftp))
        }

        dict_adapter = DictAdapter(  #sorted_keys=item_strings,
            data=integers_dict,
            args_converter=args_converter,
            selection_mode='single',
            allow_empty_selection=False,
            cls=CompositeListItem)

        # Use the adapter in our ListView:
        self.list_view = ListView(adapter=dict_adapter)
        #print "len", len(self.listftp), self.listftp

        #self.list_view = ListView(item_strings = self.listftp)

        self.buttonLoad = Button(text='Load', size_hint_y=.1)
        self.buttonLoad.bind(on_release=self.Load)

        self.buttonDoIt = Button(text='Do it', size_hint_y=.1)
        self.buttonDoIt.bind(on_release=self.DoIt)

        #self.buttonCancel = Button(text = 'Cancel', size_hint_y = .1)#, center_x = 150)
        #self.buttonCancel.bind(on_release = self.Cancel)

        #add the widgets
        self.add_widget(self.buttonLoad)
        self.add_widget(self.list_view)
        self.add_widget(self.buttonDoIt)
        #self.add_widget(self.buttonCancel)

    def ScanFTP(self):
        try:
            self.listftp = []
            #set the title
            self.listftp.append(["LOCAL", " ", "FTP", " "])

            #read the user and password in a file
            fileaccount = open("ftp", "r")
            user = fileaccount.readline()
            mdp = fileaccount.readline()
            fileaccount.close()

            ftp = FTP("ftpperso.free.fr", user, mdp)

            ftp.cwd(self.remotePath)

            #get remote files list
            remoteDir = ftp.nlst()
            #print "remote: ", remoteDir

            #get local files list
            localDir = os.listdir(self.localPath)
            #print " local", localDir

            print

            #check local files in remote
            for localFile in localDir:
                localTime = os.path.getmtime(
                    os.path.join(self.localPath, localFile))
                #localTime = datetime.utcfromtimestamp(localTime) #syncback seems to work in utc #fix utc method 1
                localTime = datetime.fromtimestamp(
                    localTime)  #fix utc method 2

                try:
                    remoteIndex = remoteDir.index(localFile)
                except:
                    remoteIndex = -1

                if remoteIndex != -1:
                    #print localFile, "is present on remote"

                    #get ftp file time
                    remoteTime = ftp.sendcmd('MDTM ' + remoteDir[remoteIndex])
                    #print remoteTime
                    remoteTime = datetime.strptime(
                        remoteTime[4:],
                        "%Y%m%d%H%M%S")  #fix utc method 1 : nothing
                    remoteTime = remoteTime + (
                        datetime.now() - datetime.utcnow())  #fix utc method 2

                    #check time diff
                    if abs(
                        (localTime -
                         remoteTime).total_seconds()) < 10:  #delta 10 seconds
                        #if localTime == remoteTime:
                        #check size diff to test if copy was interrupted : "!!" if error in copy, "=" if size are same too
                        #get distant file size
                        remoteSize = ftp.sendcmd('SIZE ' +
                                                 remoteDir[remoteIndex])
                        #print "remote size :", int(remoteSize[4:])

                        localSize = os.path.getsize(
                            os.path.join(self.localPath, localFile))
                        #print "local size :", localSize

                        #print "local ", localFile, " is same than remote :", localTime, remoteTime #nothing to do
                        if int(remoteSize[4:]) != localSize:
                            self.listftp.append([
                                str(localTime)[:19], "!!",
                                str(remoteTime)[:19], localFile
                            ])
                        else:
                            self.listftp.append([
                                str(localTime)[:19], "=",
                                str(remoteTime)[:19], localFile
                            ])
                    elif localTime > remoteTime:
                        #print "local ", localFile, " is newer than remote :", localTime, remoteTime, localTime - remoteTime # must upload local then touch local file to synchronize time
                        self.listftp.append([
                            str(localTime)[:19], ">",
                            str(remoteTime)[:19], localFile
                        ])
                    else:
                        #print "local ", localFile, " is older than remote :", localTime, remoteTime #must download remote then try to set local time with remote time
                        self.listftp.append([
                            str(localTime)[:19], "<",
                            str(remoteTime)[:19], localFile
                        ])
                else:
                    #print localFile, " is not present on remote" #must upload local
                    self.listftp.append(
                        [str(localTime)[:19], "", "", localFile])

            #check if new remote files must be downloaded (not present at all in local)
            for remoteFile in remoteDir:
                #skip . and ..
                if remoteFile != '.' and remoteFile != '..':
                    try:
                        remoteIndex = localDir.index(remoteFile)
                    except:
                        #error file not found me be downloaded
                        print remoteFile, " is only present on remote"
                        self.listftp.append(
                            ["", "", str(remoteTime)[:19], remoteFile])

            #close the connection
            ftp.quit()
        except Exception as e:
            #show modal message box if error
            content = Button(text=str(e))
            popup = Popup(title='Scanning error',
                          content=content,
                          size_hint=(1, 1))
            content.bind(on_press=popup.dismiss)
            popup.open()

    def Load(self, *l):
        print "Load"

        self.fl = FileChooserIconView(path=".",
                                      rootpath=".",
                                      filters=["*.ftp"],
                                      dirselect=False)  #, size_hint_y = None)
        #self.fl.height = 500
        self.fl.bind(selection=self.on_selected)
        self.add_widget(self.fl)

    def on_selected(self, filechooser, selection):
        print 'on_selected', selection
        self.remove_widget(self.fl)

        if self.first_time != 1:
            self.remove_widget(self.buttonLoad)
            self.remove_widget(self.list_view)
            self.remove_widget(self.buttonDoIt)
            #self.remove_widget(self.buttonCancel)

        self.first_time = 0

        fileRead = open(selection[0], "r")
        self.localPath = fileRead.readline().rstrip('\n').rstrip('\r')
        self.remotePath = fileRead.readline().rstrip('\n').rstrip('\r')
        fileRead.close()
        self.ScanFTP()

        self.BuildList()

    def DoIt(self, *l):
        print "DoIt"

        #read the user and password in a file
        fileaccount = open("ftp", "r")
        user = fileaccount.readline()
        mdp = fileaccount.readline()
        fileaccount.close()

        #connect
        ftp = FTP("ftpperso.free.fr", user, mdp)

        ftp.cwd(self.remotePath)

        for current_file in self.listftp:
            if current_file[1] == ">":
                print "must upload ", current_file[3]
                self.upload(ftp, current_file[3])
            elif current_file[1] == "<":
                print "must download ", current_file[
                    3], "and set time ", current_file[2]
                self.download(ftp, current_file[3], current_file[2])
            elif current_file[1] == "" and current_file[0]:
                print "must upload ", current_file[3]
                self.upload(ftp, current_file[3])
            elif current_file[1] == "" and current_file[2]:
                print "must download ", current_file[
                    3], "and set time ", current_file[2]
                self.download(ftp, current_file[3], current_file[2])

        #close the connection
        ftp.quit()

    '''def Cancel(self, *l):
        print "Cancel"
        self.remove_widget(self.buttonDoIt)
        self.add_widget(self.buttonDoIt)'''

    def upload(self, ftp, filename):
        fileup = open(os.path.join(self.localPath, filename),
                      'rb')  # open the file
        ftp.storbinary('STOR ' + filename, fileup)  # send the file
        fileup.close()  # close the file

        #must set the localtime to the current time, so times are synchronized if allowed
        try:
            os.utime(os.path.join(self.localPath, filename), None)
        except:
            print "os.utime not permitted"

    def download(self, ftp, filename, remotetimestr):
        # download the file
        lf = open(os.path.join(self.localPath, filename), "wb")
        ftp.retrbinary("RETR " + filename, lf.write, 8 * 1024)
        lf.close()

        #set the localtime to the remote time
        # MUST CONVERT REMOTE TIME FROM UTC (add two hours for free)
        dt = datetime.strptime(remotetimestr, "%Y-%m-%d %H:%M:%S")
        print dt.strftime("%Y-%m-%d %H:%M:%S")
        st = time.mktime(dt.timetuple())
        #st = time.mktime(dt.utctimetuple()) #fix utc method 1, 1h problem
        #print dt.timetuple(), dt.utctimetuple(), st
        #os.utime(os.path.join(self.localPath, filename), None) # allowed but useless since it is the actual time
        try:
            os.utime(
                os.path.join(self.localPath, filename),
                (st,
                 st))  #OSError: [Errno 1] Operation not permitted: on android
        except:
            print "os.utime not permitted"
예제 #19
0
    def load_json(self, instance):

        path = ''

        filechoser_layout = AnchorLayout()

        #filechoser = FileChooserIconView( size_hint = (0.75,0.85), path=settings['kraken_path'] +'/picture') #, multiselect = True)
        filechoser = FileChooserIconView(size_hint=(0.75, 0.85),
                                         path='/home')  #, multiselect = True)
        filechoser_list_layout = AnchorLayout(anchor_x='left', anchor_y='top')
        filechoser_list_layout.add_widget(filechoser)

        button_layout = AnchorLayout(anchor_x='left', anchor_y='bottom')

        box = BoxLayout(orientation='vertical',
                        size_hint=(0.75, None),
                        height=96)

        bli = BoxLayout(orientation='horizontal')
        ok_button = Button(text='Ok')
        cancel_button = Button(text='Cancel')

        bli2 = BoxLayout(orientation='horizontal')
        ti = TextInput(size_hint=(1, None), height=48)
        bli2.add_widget(Label(text='Enter File Name : '))
        bli2.add_widget(ti)

        bli.add_widget(ok_button)
        bli.add_widget(cancel_button)
        box.add_widget(bli2)
        box.add_widget(bli)
        button_layout.add_widget(box)

        image_layout = AnchorLayout(anchor_x='right', anchor_y='center')
        wimg = Image(source=settings['kraken_path'] + '/picture/girl.jpg',
                     size_hint=(0.25, None),
                     size=(200, Window.size[1]))
        image_layout.add_widget(wimg)

        filechoser_layout.add_widget(filechoser_list_layout)
        filechoser_layout.add_widget(button_layout)
        filechoser_layout.add_widget(image_layout)

        popup_browser = Popup(title='Open File')
        popup_browser.add_widget(filechoser_layout)

        def save_path(instance):
            if ti.text != '':
                path = filechoser.path + '/' + ti.text
            else:
                path = filechoser.selection[0]

            # Open From File
            ds = self.drawing_space
            self.clear(instance)

            with open(path) as json_file:
                json_data = json.load(json_file)
                funs = json_data['workflow']['cv']
                for fun in funs:
                    if fun['name'] != 'Line':
                        tr = ToolRectangle()
                        tr.redraw(ds, fun['pos']['x'], fun['pos']['y'],
                                  fun['name'], fun['id'], fun['pars'],
                                  fun['in_cv'], fun['out_cv'], fun['level'])
                for fun in funs:
                    if fun['name'] != 'Line':
                        for child in ds.children:
                            if child.id is fun['id']:
                                a = child
                                break
                        for b in fun['out_cv']:
                            for child in ds.children:
                                if child.id == b:
                                    line_widget = self.new_line(a, child)
                                    line_widget.widgetA = a
                                    line_widget.widgetB = child

                                    line_widget.isLine = True
                                    line_widget.name = "Line"
                                    line_widget.id = str(uuid.uuid1())

                                    a.connect.append([child, line_widget])
                                    child.connect.append([a, line_widget])

            popup_browser.dismiss()

        def file_select(self, file):
            if file:
                wimg.source = file[0]

        cancel_button.bind(on_press=popup_browser.dismiss)
        ok_button.bind(on_press=save_path)
        filechoser.bind(selection=file_select)

        popup_browser.open()
예제 #20
0
class ViewOutputDestination(Screen):
    current_directory = "\\"

    def __init__(self, next_screen, previous_screen, secretary, screen_manager, **kwargs):
        super().__init__(**kwargs)
        self.main_layout = RelativeLayout()

        self.label_screen = Label(text="Choose save location", font_size=UiConstants.UiConstants.labe_main_screen,
                                  size_hint=(0.5, 0.2), pos_hint={'x': 0.25, 'y': 0.8}, color=[0, 0, 0, 1],
                                  font_name="fonts/RobotoMono-Bold.ttf",)
        self.file_chooser = FileChooserIconView(size_hint=(0.7, 0.4), pos_hint={'y': 0.4, 'x': 0.15})
        self.current_directory = self.file_chooser.path
        self.file_chooser.bind(path=self.okay)
        self.button_next_screen = Button(text="NEXT",font_size=UiConstants.UiConstants.label_font_size,
                                         size_hint=(0.25, 0.1), pos_hint={'x': 0.5, 'y': 0.0},
                                         background_normal="backgrounds/next-button.jpg",
                                         background_down="backgrounds/next-button-pressed.jpg",
                                         font_name="fonts/RobotoMono-Bold.ttf",
                                         on_release=lambda btn: self.go_to_next_screen(next_screen=next_screen,
                                                                                       secretary=secretary,
                                                                                       screen_manager=screen_manager))
        self.button_previous_screen = Button(text="PREV", size_hint=(0.25, 0.1), pos_hint={'x': 0.25, 'y': 0},
                                             background_normal="backgrounds/back-button.jpg",
                                             font_size=UiConstants.UiConstants.label_font_size,
                                             background_down="backgrounds/back-button-down.jpg",
                                             font_name="fonts/RobotoMono-Bold.ttf",
                                             on_release=lambda btn: self.go_back(previous_screen=previous_screen,
                                                                                 screen_manager=screen_manager))
        self.label_current_directory_field = Label(text="Current Directory: ",
                                                   font_name="fonts/RobotoMono-Regular.ttf",
                                                   size_hint=(0.25, 0.1),
                                                   pos_hint={'x': 0.25, 'y': 0.30}, color=[0, 0, 0, 1])
        self.label_current_directory = TextInput(text=self.current_directory, size_hint=(0.25, 0.1),
                                             font_name="fonts/RobotoMono-Regular.ttf",
                                             pos_hint={'x': 0.5, 'y': 0.3}
                                                 , background_normal="backgrounds/input-background.jpg", disabled="true",
                                                 background_disabled_normal="backgrounds/input-background.jpg")

        self.label_file_name = Label(text="File name:", size_hint=(0.25, 0.1), pos_hint={'y': 0.18, 'x': 0.25},
                                     font_name="fonts/RobotoMono-Regular.ttf",
                                     color=[0, 0, 0, 1])
        self.text_input_file_name = TextInput(size_hint=(0.25, 0.1), pos_hint={'y': 0.18, 'x': 0.5},
                                              font_name="fonts/RobotoMono-Regular.ttf"
                                              , background_normal="backgrounds/input-background.jpg")
        self.text_input_file_name.input_filter = self.filename_text_filter
        self.main_layout.add_widget(self.label_screen)
        self.main_layout.add_widget(self.file_chooser)
        self.main_layout.add_widget(self.label_current_directory_field)
        self.main_layout.add_widget(self.label_current_directory)
        self.main_layout.add_widget(self.label_file_name)
        self.main_layout.add_widget(self.text_input_file_name)
        self.main_layout.add_widget(self.button_next_screen)
        self.main_layout.add_widget(self.button_previous_screen)
        Clock.schedule_once(self.custom_init, 1)

    def custom_init(self, *args):
        self.add_widget(self.main_layout)

    def file_selection(self):
        print("hello")
        print(self.file_chooser.path)

    def filename_text_filter(self, string, undo):
        string = re.sub('[~`!@#$%^&*()_=+;"{|:,<>./?]', '', string)
        return string

    def go_to_next_screen(self, next_screen, secretary, screen_manager):

        if len(self.text_input_file_name.text) > 0:
            secretary.output_file_path = self.label_current_directory.text
            secretary.output_file_name = self.text_input_file_name.text + ".txt"

            screen_manager.current = next_screen
            screen_manager.current_screen.reload_ui(secretary)

        else:
            print("no go")

    def go_back(self, previous_screen, screen_manager):
        screen_manager.current = previous_screen

    def path_changed(self, object, value):
        print('filechooser: ', object, "path changed to: ", value)

    def okay(self, object, value):
        print(object)
        self.label_current_directory.text = value
예제 #21
0
    def to_json(self, instance):

        path = ''

        filechoser_layout = AnchorLayout()

        #filechoser = FileChooserIconView( size_hint = (0.75,0.85), path=settings['kraken_path'] +'/picture') #, multiselect = True)
        filechoser = FileChooserIconView(size_hint=(0.75, 0.85),
                                         path='/home')  #, multiselect = True)
        filechoser_list_layout = AnchorLayout(anchor_x='left', anchor_y='top')
        filechoser_list_layout.add_widget(filechoser)

        button_layout = AnchorLayout(anchor_x='left', anchor_y='bottom')

        box = BoxLayout(orientation='vertical',
                        size_hint=(0.75, None),
                        height=96)

        bli = BoxLayout(orientation='horizontal')
        ok_button = Button(text='Ok')
        cancel_button = Button(text='Cancel')

        bli2 = BoxLayout(orientation='horizontal')
        ti = TextInput(size_hint=(1, None), height=48)
        bli2.add_widget(Label(text='Enter File Name : '))
        bli2.add_widget(ti)

        bli.add_widget(ok_button)
        bli.add_widget(cancel_button)
        box.add_widget(bli2)
        box.add_widget(bli)
        button_layout.add_widget(box)

        image_layout = AnchorLayout(anchor_x='right', anchor_y='center')
        wimg = Image(source=settings['kraken_path'] + '/picture/girl.jpg',
                     size_hint=(0.25, None),
                     size=(200, Window.size[1]))
        image_layout.add_widget(wimg)

        filechoser_layout.add_widget(filechoser_list_layout)
        filechoser_layout.add_widget(button_layout)
        filechoser_layout.add_widget(image_layout)

        popup_browser = Popup(title='Save File')
        popup_browser.add_widget(filechoser_layout)

        def save_path(instance):
            if ti.text != '':
                path = filechoser.path + '/' + ti.text
            else:
                path = filechoser.selection[0]

            # Save JSON

            cv = []
            for child in self.drawing_space.children:
                cv.append(child)

            workflow = dict(cv=cv)

            with open(path, 'w') as f:
                json.dump(dict(workflow=workflow), f, cls=KrakenJsonEncoder)

            popup_browser.dismiss()

        def file_select(self, file):
            if file:
                wimg.source = file[0]

        cancel_button.bind(on_press=popup_browser.dismiss)
        ok_button.bind(on_press=save_path)
        filechoser.bind(selection=file_select)

        popup_browser.open()
예제 #22
0
파일: main.py 프로젝트: descentos/launcher
class TreeViewBlock(Button, TreeViewNode):
	def __init__(self, *args, **kwargs):
		super(TreeViewBlock, self).__init__(*args, **kwargs)
		print args
		self.background_normal="images/button.png"
		self.background_down="images/button.png"
		self.background_color=[0,0,0,0]
		self.color=[.2,0.2,0.2,1]
		self.size_hint_y=None
		self.height=30
		self.bind(on_release=self.click)
		self.color_selected=[.9,.5,.3,1]
		the_layout=BoxLayout(orientation="vertical")
		b1 = BoxLayout(size_hint_y=None, height=45, padding=5)
		l= Label(text="Title : ",font_size=16)
		t = TextInput(text=self.text, multiline=False, font_size=18)
		t.bind(on_text_validate=self.onTextChange)
		b1.add_widget(l)
		b1.add_widget(t)
		b2=BoxLayout(padding=8)
		l1=Label(text="Add ")
		b3=BoxLayout(orientation="vertical")
		btn1=Button(text="Application",font_size=14)
		btn1.bind(on_release=self.appsPopupOpen)
		btn2=Button(text="File",font_size=14)
		btn2.bind(on_release=self.filesPopupOpen)
		btn3=Button(text="Folder",font_size=14)	
		btn3.bind(on_release=self.foldersPopupOpen)
		b3.add_widget(btn1)
		b3.add_widget(btn2)
		b3.add_widget(btn3)
		l2=Label(text="To Block.")	
		b2.add_widget(l1)
		b2.add_widget(b3)	
		b2.add_widget(l2)
		rem = Button(text="Remove this block",
				size_hint_y=None,
				height=30,
				background_normal="images/button.png",
				background_color=[.8,.2,.2,1])
		rem.bind(on_release=self.removeBlock)
		the_layout.add_widget(b1)
		the_layout.add_widget(Label(text="----",size_hint_y=None,height=20))
		the_layout.add_widget(b2)
		the_layout.add_widget(rem)
		self.popupWindow = Popup(title="Block: '{}'".format(self.text),
					size_hint=(None,None),
					size=(400,230),
					separator_color=[.9,.4,.2,1],
					background_color=[0,0,0,.6],
					content=the_layout
					)
		###Apps	
		b = BoxLayout(orientation="vertical")
		self.app_list =AddAppList()
		a_btn=Button(text="Add This Application", size_hint_y=None, height=40)
		a_btn.bind(on_release=self.addApp)
		b.add_widget(self.app_list)
		b.add_widget(a_btn)
		self.appsPopup = Popup(title="Add Application to '{}'".format(self.text),
					size_hint=(None,None),
					size=(400,400),
					separator_color=[.9,.4,.2,1],
					background_color=[0,0,0,.6],
					content=b
					)
		##Files
		box = BoxLayout(orientation="vertical")
		self.f=FileChooserIconView(multiselect=False, path= os.path.expanduser("~"))
		self.f.bind(on_submit=self.addFile)
		l=Label(text="Double click on a file to add it.",size_hint_y=None,height=40)
		box.add_widget(self.f)
		box.add_widget(l)
		self.filesPopup = Popup(title="Add File to '{}'".format(self.text),
					size_hint=(None,None),
					size=(500,500),
					separator_color=[.9,.4,.2,1],
					background_color=[0,0,0,.6],
					content=box
					)
		##Folders	
		box1=BoxLayout(orientation="vertical")
		self.f2=FileChooserIconView(multiselect=False, path= os.path.expanduser("~"))
		self.f2.bind(on_entry_added=self.updateFolders)
		b=BoxLayout(size_hint_y=None, height=50, padding=5)
		self.folder_label = Label(text=self.f2.path,id="FileLabel")
		btn=Button(text="Add Folder", size_hint_x=None,width=150)
		btn.bind(on_release=self.addFolder)
		b.add_widget(self.folder_label)
		b.add_widget(btn)
		box1.add_widget(self.f2)
		box1.add_widget(b)
		self.foldersPopup = Popup(title="Add Folder to '{}'".format(self.text),
					size_hint=(None,None),
					size=(500,500),
					separator_color=[.9,.4,.2,1],
					background_color=[0,0,0,.6],
					content=box1
					)
	def onTextChange(self, *args):
		for b in pickle.loads(d_cfg.get()['blocks']):
			if  b["name"] == self.text:
				b["name"]=args[0].text
				self.text=args[0].text
				blocks=createBlockDicts(self.parentTree.iterate_all_nodes())
				updateConfig({'blocks':blocks})
	def appsPopupOpen(self,*args):
		self.popupWindow.dismiss()
		self.appsPopup.open()
	def filesPopupOpen(self,*args):
		self.popupWindow.dismiss()
		self.filesPopup.open()
	def foldersPopupOpen(self,*args):
		self.popupWindow.dismiss()
		self.foldersPopup.open()
	def addApp(self, *args):
		s =   self.app_list.adapter.selection[0].text
		if s!=None:
			#Update
			node= self.parentTree.selected_node
			new=TreeViewButton(text=s)
			new.parentTree=self.parentTree
			self.parentTree.add_node(new,node)
			self.appsPopup.dismiss()
			blocks= createBlockDicts(self.parentTree.iterate_all_nodes())
			updateConfig({"blocks":blocks})
	def addFile(self,*args):
		for b in pickle.loads(d_cfg.get()["blocks"]):
			if b["name"]==self.text:
				#Update Tree
				node= self.parentTree.selected_node
				new=TreeViewButton(text=str(args[1][0]))
				new.parentTree=self.parentTree
				self.parentTree.add_node(new,node)
				self.filesPopup.dismiss()
				blocks= createBlockDicts(self.parentTree.iterate_all_nodes())
				updateConfig({"blocks":blocks})
	def addFolder(self,*args):
		p = self.f2.path
		if os.path.exists(p):
			#Update
			node= self.parentTree.selected_node
			new=TreeViewButton(text=p)
			new.parentTree=self.parentTree
			self.parentTree.add_node(new,node)
			self.foldersPopup.dismiss()
			blocks= createBlockDicts(self.parentTree.iterate_all_nodes())
			print blocks
			updateConfig({"blocks":blocks})
	def updateFolders(self,*args):
		self.folder_label.text = self.f2.path
	def removeBlock(self,*args):
		try:
			self.parentTree.remove_node(self)
			blocks= createBlockDicts(self.parentTree.iterate_all_nodes())
			updateConfig({"blocks":blocks})
		except:pass
		self.popupWindow.dismiss()
	def click(self,*args):		
		self.popupWindow.open()
예제 #23
0
    def popup_constructor_file(self, title):
        """
        generalized popup constructor for save/load/export and import image commands
        :param title:
        :return:
        """
        changed_dir = True  #set this to false when testing in IDE
        file_browser = FileChooserIconView()
        file_browser_text = TextInput(text="File.txt",
                                      multiline=False,
                                      size=(345, 30),
                                      size_hint=(None, None))
        file_browser.add_widget(file_browser_text)
        file_browser.path = self.backend.working_dir + 'Saved maps'
        file_browser_cancel_btn = Button(text="Cancel",
                                         size=(60, 30),
                                         size_hint=(None, None),
                                         pos=(415, 0))
        file_browser_confirm_btn = Button(text="blank",
                                          size=(60, 30),
                                          size_hint=(None, None),
                                          pos=(350, 0))
        if title == "Save Map":
            file_browser_text.text = file_browser.path + "/Untitled.text"
            file_browser_confirm_btn.text = "Save"
        elif title == "Load Map":
            file_browser_text.text = file_browser.path + "/Untitled.text"
            file_browser_confirm_btn.text = "Load"
        elif title == "Import Image":
            file_browser_text.text = file_browser.path + "/Untitled.png"
            file_browser_confirm_btn.text = "Import"
        else:
            file_browser_text.text = file_browser.path + "/Untitled.png"
            file_browser_confirm_btn.text = "Export"
        file_browser.add_widget(file_browser_cancel_btn)
        file_browser.add_widget(file_browser_confirm_btn)

        def resolve_dialogue(instance):
            try:
                if title == "Save Map":
                    if file_browser_text.text.split("\\")[-1] in [i.split("\\")[-1] for i in file_browser.files] or \
                            file_browser_text.text.split("/")[-1] in [i.split("\\")[-1] for i in file_browser.files]:

                        def overwrite_resolve(instance):
                            self.backend.save_to_file(file_browser_text.text)
                            self.backend.working_file = file_browser_text.text
                            self.backend.last_save = datetime.now()
                            self.update_map_title()
                            pop2.dismiss()
                            pop.dismiss()
                            self.initialize_keyboard()

                        overwrite_okay.bind(on_press=overwrite_resolve)
                        nonlocal overwrite_msg
                        overwrite_msg = Label(
                            text=
                            f"The file: \n{file_browser_text.text}\nwill be Overwritten"
                        )
                        pop2.open()
                    else:
                        self.backend.save_to_file(file_browser_text.text)
                        self.backend.working_file = file_browser_text.text
                        self.backend.last_save = datetime.now()
                        self.update_map_title()
                        pop.dismiss()
                        self.initialize_keyboard()
                elif title == "Load Map":
                    self.backend.load_from_file(file_browser_text.text)
                    self.redraw_map()
                    self.redraw_tileset()
                    self.redraw_active_tile()
                    self.populate_layer_list(self.children[0].children[0])
                    self.backend.working_file = file_browser_text.text
                    self.backend.last_save = datetime.now()
                    self.update_map_title()
                    pop.dismiss()
                    self.initialize_keyboard()
                elif title == "Export Map":
                    if file_browser_text.text.split("\\")[-1] in [i.split("\\")[-1] for i in file_browser.files] or \
                            file_browser_text.text.split("/")[-1] in [i.split("\\")[-1] for i in file_browser.files]:

                        def overwrite_resolve(instance):
                            self.backend.export(file_browser_text.text)
                            pop2.dismiss()
                            pop.dismiss()
                            self.initialize_keyboard()

                        overwrite_okay.bind(on_press=overwrite_resolve)
                        overwrite_msg.text = f"!WARNING!: The file: \n{file_browser_text.text}\nwill be Overwritten"
                        pop2.open()
                    else:
                        self.backend.export(file_browser_text.text)
                        pop.dismiss()
                        self.initialize_keyboard()
                elif title == "Import Image":
                    self.backend.import_img(file_browser_text.text)
                    self.populate_layer_list(self.children[0].children[0])
                    self.redraw_map()
                    pop.dismiss()
                    self.initialize_keyboard()

            except Exception as e:
                error = Popup(title=" An error Occured:",
                              content=(Label(text=e.__str__())),
                              size_hint=(None, None),
                              size=(400, 200),
                              auto_dismiss=True)
                error.open()

        def filecancel(instance):
            pop.dismiss()
            self.initialize_keyboard()

        def update_file_text(instance, path):
            nonlocal changed_dir
            changed_dir = True
            if title == "Save Map" or title == "Load Map":
                file_browser_text.text = file_browser.path + "/Untitled.text"
            else:
                file_browser_text.text = file_browser.path + "/Untitled.png"

        def update_file_text_select(instance, selection, touch):
            path = ""
            for i in selection:
                path = i
                file_browser_text.text = path
            if changed_dir == False:
                segments = path.split("\\")
                del segments[5]
                clean_path = "\\".join(segments)
                file_browser_text.text = clean_path

        file_browser.bind(on_submit=update_file_text_select,
                          path=update_file_text)
        file_browser_cancel_btn.bind(on_press=filecancel)
        file_browser_confirm_btn.bind(on_press=resolve_dialogue)

        pop = Popup(title=title,
                    content=file_browser,
                    size_hint=(None, None),
                    size=(500, 500),
                    auto_dismiss=True)
        pop.open()

        overwrite = GridLayout(rows=2)
        overwrite_msg = Label(
            text=
            f"!WARNING!: The file: \n{file_browser_text.text}\nwill be Overwritten"
        )
        overwrite_buttons = GridLayout(cols=2,
                                       size_hint=(1, None),
                                       size=(100, 40))
        overwrite_okay = Button(text="Overwrite",
                                size_hint=(1, None),
                                size=(100, 40))
        overwrite_cancel = Button(text="Cancel",
                                  size_hint=(1, None),
                                  size=(100, 40))
        overwrite_buttons.add_widget(overwrite_okay)
        overwrite_buttons.add_widget(overwrite_cancel)
        overwrite.add_widget(overwrite_msg)
        overwrite.add_widget(overwrite_buttons)
        overwrite_cancel.bind(on_press=lambda instance: pop2.dismiss())

        pop2 = Popup(title="Confirm File Overwrite",
                     content=overwrite,
                     size_hint=(None, None),
                     size=(500, 300),
                     auto_dismiss=True)
예제 #24
0
class FileDialog(Widget):
    def __init__(self, **kwargs):
        super(FileDialog, self).__init__(**kwargs)
        self._pick_mode = "file"
        self._single_file = True
        self._view_type = "list"
        self._sel_files = list()
        self._sel_path = ""

    def show(self, path, title="", width=400, height=430):
        self._path = os.path.split(path)
        self._old_path = ""

        self.vbox_main = BoxLayout(orientation="vertical")
        self.txt_path = TextInput(size_hint_y=None, height=30)
        self.txt_path.multiline = False
        self.txt_path.text = self._path
        self.txt_path.bind(focus=self.on_focus)
        self.txt_path.bind(on_text_validate=self.validate_path)

        self.fclv = FileChooserIconView()
        self.fclv.path = self._path

        self.fclv.bind(path=self.set_path)
        self.fclv.multiselect = True

        vb_buttons = BoxLayout(orientation="horizontal")
        vb_buttons.size_hint_y = None
        vb_buttons.height = 30
        self.btn_ok = Button(text="Ok")
        self.btn_cancel = Button(text="Cancel")
        vb_buttons.add_widget(self.btn_ok)
        vb_buttons.add_widget(self.btn_cancel)

        self.vbox_main.add_widget(self.txt_path)
        self.vbox_main.add_widget(self.fclv)
        self.vbox_main.add_widget(vb_buttons)

        self.btn_ok.on_release = lambda: self.handle_ok(
            self.txt_path.text, self.fclv)
        self.btn_cancel.on_release = lambda: self.popup.dismiss()

        self.popup = Popup(title=title,
                           content=self.vbox_main,
                           size_hint=(None, None),
                           size=(width, height))
        self.popup.open()

    def handle_ok(self, path, selection):
        if self.pick_mode == "file":
            if len(selection) == 0:
                Gui.message(self, "Select a file")
            else:
                self._sel_files.extend(selection)
                self.popup.dismiss()
        else:
            self._sel_path = path
            self.popup.dismiss()

    @property
    def pick_mode(self):
        return self._pick_mode

    @pick_mode.setter
    def pick_mode(self, value):
        valid_values = ["file", "path"]
        if value in valid_values:
            self._pick_mode = value
        else:
            raise Exception("invalid pick_mode. Valid values:" + valid_values)

    @property
    def view_type(self):
        return self._pick_mode

    @view_type.setter
    def view_type(self, value):
        valid_values = ["list", "icon"]
        if value in valid_values:
            self._view_type = value
        else:
            raise Exception("invalid view type. Valid values:" + valid_values)

    @property
    def single_file(self):
        return self._single_file

    @single_file.setter
    def single_file(self, value):
        self._single_file = value

    @property
    def selected_files(self):
        return self._sel_files

    @property
    def selected_path(self):
        return self._sel_path