def update_file_layout(self): auth_token='S2_xUq0_iNAAAAAAAAAACYNG1zf1GAzKpVWVfmLcZLA-FIiSlGxMvmxBkAtspuWQ' client = dropbox.client.DropboxClient(auth_token) self.clear_widgets() b=BoxLayout(orientation='vertical') file_system = FileSystemLocal() root_dir= App.get_running_app().user_data_dir+'/';result_dir=root_dir+'results' file_list=file_system.listdir(root_dir) # this returns a list of files in dir if os.path.exists(result_dir):file_list.extend(file_system.listdir(App.get_running_app().user_data_dir+'/'+'results'+'/')) file_list=[x for x in file_list if x[-4:]=='.csv'] b.add_widget(Label(text='Select Files to Upload',bold=True,font_size=sp(25),size_hint_y= 0.1)) file_system = FileSystemLocal() file_list=file_system.listdir(App.get_running_app().user_data_dir+'/') # this returns a list of files in dir file_list=[x for x in file_list if x[-4:]=='.csv'] s=ScrollView(size_hint_y=0.75) g=GridLayout(cols=2,size_hint_y=None) for file_1 in file_list: c=CheckBox(active=False) l=Label(bold= True,font_size=sp(20),text=file_1,size_hint_y= None,height=70) self.check_boxes[c]=file_1 g.add_widget(l);g.add_widget(c) g.bind(minimum_height=g.setter('height')) s.add_widget(g) b.add_widget(s) g_options=GridLayout(cols=2,size_hint_y= 0.1,orientation='horizontal') g_options.add_widget(Button(text="Send",on_press=self.upload,font_size=sp(25))) g_options.add_widget(Button(text="Back",on_press=self.return_back,font_size=sp(25))) b.add_widget(g_options) self.add_widget(b)
def findPictures(self, path): file_system = FileSystemLocal() files = file_system.listdir( path + '/' + self.first_name ) # this returns a list of files in dir of each member #adding all .jpg or png files to the pictures array for file in files: #checking filetype if file[-4:] == '.jpg' or file[-4:] == '.png': complete_filepath = path + '/' + self.first_name + '/' + file self.pictures.append(complete_filepath)
def findFile(self): if self.root.ids["ViewPreProcess"].ids["Explorer"].ids["icon_view_tab"].show_hidden: path = self.root.ids["ViewPreProcess"].ids["Explorer"].ids["list_view_tab"].path else: path = self.root.ids["ViewPreProcess"].ids["Explorer"].ids["icon_view_tab"].path file_system = FileSystemLocal() print "Path : " + str(path) for i in file_system.listdir(path): if re.search(".CR2",i): print "I : " + str(i) filename = [] filename.append(i) self.update_list_data(path,filename)
def __init__(self, **kwargs): # ao iniciar procura pelos arquivos MP3 super(MusicPlayer, self).__init__( **kwargs) # disponíveis no mesmo diretório do programa file_system = FileSystemLocal() self.listaMusicas = [ ] # cria uma lista para inserir os nomes dos arquivos for arquivoMusica in file_system.listdir( './' ): # preenche a lista com todos os nomes de arquivos que contenham if '.mp3' in arquivoMusica: # mp3 no nome self.listaMusicas.append(arquivoMusica) self.indexMusicaAtual = 0 # inicia tocando o arquivo de index 0 na lista
def __init__(self, **kwargs): super(MusicPlayer, self).__init__(**kwargs) self.file_system = FileSystemLocal() self.listaMusicas = [] self.path_musica = str() self.musicaPath = str() self.musica = SoundLoader.load('F:/marcilinho/PythonP/Player/musicas/') self.indexMusicaAtual = 0 # F:/marcilinho/PythonP/Player/musicas/ Sound.volume = 1
def set_image(self, p): """设置图片""" self.image.source = p # 添加图片至列表 self.list.clear() idx = 0 for f in self.manager.get_screen( 'selection').file_chooser.files: # 获取当前图片路径 if not FileSystemLocal().is_dir(f): if f == p: # 记录当前图片在文件中的位置 self.current = idx self.list.append(f) idx += 1
def update_file_layout(self): self.clear_widgets() self.check_boxes={} b=BoxLayout(orientation='vertical') file_system = FileSystemLocal() file_list=file_system.listdir(App.get_running_app().user_data_dir+'/') # this returns a list of files in dir file_list=[x for x in file_list if x[-4:]=='.csv'] b.add_widget(Label(text='Select files to be deleted',bold=True,font_size=sp(25),size_hint_y= 0.1)) s=ScrollView(size_hint_y=0.75) g=GridLayout(cols=2,size_hint_y=None) for file_1 in file_list: c=CheckBox() l=Label(bold= True,font_size=sp(20),text=file_1,size_hint_y= None,height=70) self.check_boxes[c]=file_1 g.add_widget(l);g.add_widget(c) g.bind(minimum_height=g.setter('height')) s.add_widget(g) b.add_widget(s) g_options=GridLayout(cols=2,size_hint_y= 0.10) g_options.add_widget(Button(text="Delete",on_press=self.create_result,font_size=sp(25))) g_options.add_widget(Button(text="Back",on_press=self.return_back,font_size=sp(25))) b.add_widget(g_options) self.add_widget(b)
def select_experiment(self): file_system = FileSystemLocal() file_list=file_system.listdir(App.get_running_app().user_data_dir+'/') # this returns a list of files in dir file_list=[x for x in file_list if x[-4:]=='.csv'] if len(file_list)>0: box = BoxLayout(orientation= 'vertical') s=ScrollView(size_hint_y=0.80) g=GridLayout(cols=1,size_hint_y=None) for exp_file in file_list: g.add_widget(ToggleButton(text=exp_file, group='experiment',size_hint_y= None,height=90)) g.bind(minimum_height=g.setter('height')) s.add_widget(g) box.add_widget(s) close_button=Button(text='Ok',size_hint=(.25,.15),pos_hint={'right': (0.75+0.5)/2}) box.add_widget(close_button) close_button.bind(on_release=self.file_button_clicked) self.select_exp=Popup(title='Select Experiment',content=box,size_hint=(.75,.75),auto_dismiss=True) self.select_exp.open() else: error_popup=Popup(title='Error',content=Label(text="Please create a experiment before.")\ ,size_hint=(.80,.40),auto_dismiss=True) error_popup.open() Clock.schedule_interval(error_popup.dismiss, 3)
def getGroupPictures(self): #creating an array holding all the paths self.group_pictures = [] file_system = FileSystemLocal() try: # this returns a list of files in dir files = file_system.listdir(self.current_selected_path + '/' + GROUP_FOLDER) except: # returnung an empty array files = [] #DEBUG: print("no folder") #adding all .jpg or png files to the pictures array for file in files: #checking filetype if file[-4:] == '.jpg' or file[-4:] == '.png': complete_filepath = (self.current_selected_path + '/' + GROUP_FOLDER + '/' + file) self.group_pictures.append(complete_filepath)
def refresh_folder(self, *_): fileslayout = self.ids['files'] fileslayout.selects = [] fileslayout.selected = {} data = [] files = [] dirs = [] walk = os.walk for root, list_dirs, list_files in walk(self.folder, topdown=True): dirs = list_dirs[:] list_dirs.clear() files = list_files self.folder_files = files if dirs or files: self.can_delete_folder = False else: self.can_delete_folder = True dirs = sorted(dirs, key=lambda s: s.lower()) #Sort directory list for directory in dirs: fullpath = os.path.join(self.folder, directory) data.append({ 'text': directory, 'fullpath': fullpath, 'type': 'folder', 'file': '', 'owner': self, 'is_folder': True, 'selected': False, 'multi_select': self.multi_select, 'selectable': True, 'file_size': '', 'modified': '' }) #Sort file list if self.show_files: if self.filetypes_filter: filtered_files = [] for item in self.filetypes_filter: filtered_files += fnmatch.filter(files, item) files = filtered_files #files = sorted(files, key=lambda s: s.lower()) files = sort_nicely(files) if self.autoselect_files and self.multi_select: file_selected = True else: file_selected = False filesystem = FileSystemLocal() for file in files: fullpath = os.path.join(self.folder, file) if not self.show_hidden: if filesystem.is_hidden(fullpath): continue file_size = int(os.path.getsize(fullpath)) modified = int(os.path.getmtime(fullpath)) file_data = { 'text': file, 'fullpath': fullpath, 'type': 'file', 'file': file, 'owner': self, 'is_folder': False, 'selected': file_selected, 'multi_select': self.multi_select, 'selectable': self.file_select, 'file_size': format_size(file_size), 'modified': datetime.datetime.fromtimestamp(modified).strftime( '%Y-%m-%d, %I:%M%p') } data.append(file_data) if file_selected: fileslayout.selects.append(file_data) if file_selected: Clock.schedule_once(self.update_selected_files) self.file_list_data = data self.reset_folder_scroll()
class MusicPlayer(FloatLayout): # Função que é executada ao iniciar def __init__(self, **kwargs): super(MusicPlayer, self).__init__(**kwargs) self.file_system = FileSystemLocal() self.listaMusicas = [] self.path_musica = str() self.musicaPath = str() self.musica = SoundLoader.load('F:/marcilinho/PythonP/Player/musicas/') self.indexMusicaAtual = 0 # F:/marcilinho/PythonP/Player/musicas/ Sound.volume = 1 ############### Funções Adicionais ############### # Verifica se o index for maior que o numero de musicas def verificarIndex(self): """ Se o index da música for maior que a quantidade de de musicas ele volta o index a zero """ if self.indexMusicaAtual > len(self.listaMusicas) - 1: self.indexMusicaAtual = 0 def mostraNomeMusica(self): # Mostra no console print("Tocando: " + self.listaMusicas[self.indexMusicaAtual]) # Mostra na interface self.ids.musica_text.text = self.listaMusicas[self.indexMusicaAtual] def salvaPathMusica(self): self.path_musica = self.ids.musica_source.text # Verifica cada .mp3 que estiver na pasta escrita e coloca na lista 'listaMusicas' for arquivoMusica in self.file_system.listdir(self.path_musica): if '.mp3' in arquivoMusica: self.listaMusicas.append(arquivoMusica) self.ids.musica_text.text = 'Salvo' print(self.path_musica) print('') print(self.listaMusicas) def carregaMusica(self): self.musicaPath = self.path_musica + self.listaMusicas[ self.indexMusicaAtual] self.musica = SoundLoader.load(self.musicaPath) ############### Funções Principais ############## # Função que é chamada ao clicar no botão "Reproduzir" def play_music(self): self.carregaMusica() self.musica.play() self.mostraNomeMusica() self.verificarIndex() # Função que ao clicar em 'proxima' diminui em 1 no index def proxima(self): self.musica.stop() self.indexMusicaAtual += 1 self.carregaMusica() self.musica.play() self.mostraNomeMusica() self.verificarIndex() # Função que ao clicar em 'anterior' adiciona em 1 no index def anterior(self): self.musica.stop() self.indexMusicaAtual -= 1 self.carregaMusica() self.musica.play() self.mostraNomeMusica() self.verificarIndex() # Função que ao clicar em 'anterior' diminui em 1 no index def stop_music(self): self.musica.stop() self.indexMusicaAtual = 0 self.ids.musica_text.text = "Nenhuma musica tocando no momento"