如何使用gtk.fileselection(python)过滤对路径的访问?
How to filter the access to path with gtk.fileselection (python)?
我用 gtk.fileselection 工作,它工作得很好。但是如何使用文件选择小部件阻止对给定路径的访问。
如果我不阻止对特定路径的访问,用户可以看到我系统中的敏感信息。
class FileSelection:
# Get the selected filename and print it to the console
def file_ok_sel(self, w):
print "%s" % self.filew.get_filename()
def destroy(self, widget):
gtk.main_quit()
def __init__(self):
#Create a new file selection widget
self.filew = gtk.FileSelection("File selection")
self.filew.hide_fileop_buttons()
self.filew.get_focus()
self.filew.connect("destroy", self.destroy)
# Connect the ok_button to file_ok_sel method
self.filew.ok_button.connect("clicked", self.file_ok_sel)
# Connect the cancel_button to destroy the widget
self.filew.cancel_button.connect("clicked",lambda w: self.filew.destroy())
# Lets set the filename, as if this were a save dialog,
# and we are giving a default filename
self.filew.set_filename("penguin.png")
self.filew.show()
def main(self):
gtk.main()
print "selection"*10
return 0
事实上,我只想允许访问从 "mnt/tnc/" 挂起的路径,不再允许访问。
archivosTNC = os.listdir("/mnt/tnc")
lista = []
for a in archivosTNC:
if a[-2:] == ".H":
lista.append(a)
elif a[-4:] == ".txt":
lista.append(a)
elif a[-4:] == ".png":
lista.append(a)
elif a[-4:] == ".jpg":
lista.append(a)
ventana = gtk.Window()
ventana.set_default_size(-1, 300)
scrolledWindow = gtk.ScrolledWindow()
scrolledWindow.set_policy (hscrollbar_policy=gtk.POLICY_NEVER, vscrollbar_policy=gtk.POLICY_AUTOMATIC)
ventana.add(scrolledWindow)
tabla=table()
vbox = gtk.VBox()
tabla.attachToCell(vbox, col=1, row=1)
scrolledWindow.add_with_viewport(tabla)
#ventana.add(vbox)
for item in lista:
boton = gtk.Button(str(item))
boton.connect('clicked', self.devolverNombreArchivo)
vbox.pack_start(boton)
我用 gtk.fileselection 工作,它工作得很好。但是如何使用文件选择小部件阻止对给定路径的访问。 如果我不阻止对特定路径的访问,用户可以看到我系统中的敏感信息。
class FileSelection:
# Get the selected filename and print it to the console
def file_ok_sel(self, w):
print "%s" % self.filew.get_filename()
def destroy(self, widget):
gtk.main_quit()
def __init__(self):
#Create a new file selection widget
self.filew = gtk.FileSelection("File selection")
self.filew.hide_fileop_buttons()
self.filew.get_focus()
self.filew.connect("destroy", self.destroy)
# Connect the ok_button to file_ok_sel method
self.filew.ok_button.connect("clicked", self.file_ok_sel)
# Connect the cancel_button to destroy the widget
self.filew.cancel_button.connect("clicked",lambda w: self.filew.destroy())
# Lets set the filename, as if this were a save dialog,
# and we are giving a default filename
self.filew.set_filename("penguin.png")
self.filew.show()
def main(self):
gtk.main()
print "selection"*10
return 0
事实上,我只想允许访问从 "mnt/tnc/" 挂起的路径,不再允许访问。
archivosTNC = os.listdir("/mnt/tnc")
lista = []
for a in archivosTNC:
if a[-2:] == ".H":
lista.append(a)
elif a[-4:] == ".txt":
lista.append(a)
elif a[-4:] == ".png":
lista.append(a)
elif a[-4:] == ".jpg":
lista.append(a)
ventana = gtk.Window()
ventana.set_default_size(-1, 300)
scrolledWindow = gtk.ScrolledWindow()
scrolledWindow.set_policy (hscrollbar_policy=gtk.POLICY_NEVER, vscrollbar_policy=gtk.POLICY_AUTOMATIC)
ventana.add(scrolledWindow)
tabla=table()
vbox = gtk.VBox()
tabla.attachToCell(vbox, col=1, row=1)
scrolledWindow.add_with_viewport(tabla)
#ventana.add(vbox)
for item in lista:
boton = gtk.Button(str(item))
boton.connect('clicked', self.devolverNombreArchivo)
vbox.pack_start(boton)