def onButtonPress2(self, button): user_path = dirname('Documents') layout = FileBrowser(select_string='select', favorites=[(user_path, 'Documents')]) layout.bind(on_success=self._fbroswer_success2, on_canceled=self._fbroswer_canceled) closeButton = Button(text="Return to Main") layout.add_widget(closeButton) #intsntiate the modal popup and display popup = Popup(title='Application', content=layout) #content = (Lablel(text='This is a demo popup'))) popup.open() #attach close button press with popup.dismiss action closeButton.bind(on_press=popup.dismiss)
class SelectFile(App): def __init__(self, **kwargs): ''' Creates a browser that uses the Kivy Garden FileBrowser add-on to allow the user to select a .png file to pixelate. ''' super(SelectFile, self).__init__(**kwargs) if platform == 'win': user_path = dirname(expanduser('~')) + sep + 'Documents' else: user_path = expanduser('~') + sep + 'Documents' self.browser = FileBrowser(select_string='Select', favorites=[(user_path, 'Documents')]) self.browser.bind(on_success=self._fbrowser_success, on_canceled=self._fbrowser_canceled) def build(self): ''' Builds file browser. ''' return (self.browser) def _fbrowser_canceled(self, instance): ''' Runs if the cancel button in the FileBrowser is pressed. Clears widgets in FileBroswer and runs the main program again, taking the user back to the initial screen. ''' self.browser.clear_widgets() self.stop() from GUI import Leggo_Mosiaac, AppBody Leggo_Mosiaac().run() def _fbrowser_success(self, instance): ''' Checks to see whether the selected image is a .png or not. Outputs a pop up if it is not. Copies selected image into the current working directory (aka the teamLEGGO folder). Displays the selected image and the pixelated image with a back button to take the user back to the initial interface. ''' self.selected_image = str(instance.selection) i = len(instance.selection) self.selected_image = self.selected_image[2:i - 3] self.file_name = self.selected_image.rsplit('/', 1)[-1] n = len(self.file_name) if self.file_name[n - 4:n] == ".png": cwd = os.getcwd() shutil.copy(self.selected_image, cwd + '/teamLEGGO.png') self.browser.clear_widgets() self.drawLabelImage() self.drawImage2() else: pngpls = PngPls() return pngpls.popup() def drawLabelImage(self): ''' Displays label for selected image. ''' self.browser.add_widget( Label(text='[b]Here is your image!:[/b]', markup=True, size_hint=(.1, .1), pos_hint={ 'x': .1, 'y': .8 }, font_size='20sp')) def drawImage2(self): ''' Displays the pixelated image. ''' pixelationProgram = vectorStuff() pixelationProgram.input_mat_size = input_mat_size pixelationProgram.runPixel() self.wimg = Image(source='teamLEGGO_pix.png', size_hint=(1, 1.5), pos_hint={ 'x': .05, 'y': .01 }) self.browser.add_widget(self.wimg) bricksUsed, cost = pixelationProgram.get_price( pixelationProgram.lego_nums, pixelationProgram.input_mat_size) self.browser.add_widget( Label(text=bricksUsed, size_hint=(.1, .1), pos_hint={ 'x': .45, 'y': 0.6 })) self.browser.add_widget( Label(text=cost, size_hint=(.1, .1), pos_hint={ 'x': .45, 'y': .5 })) self.button1 = Button(text='LEGOs Needed', size_hint=(.2, .05), pos_hint={ 'x': .4, 'y': .2 }) self.browser.add_widget(self.button1) self.button1.bind(on_press=self.call) def call(self, instance): ''' Outputs LEGOs needed popup ''' if instance.text == 'LEGOs Needed': numlego = NumLego() numlego.popup()