本文整理汇总了Python中PySide.QtCore.QDir类的典型用法代码示例。如果您正苦于以下问题:Python QDir类的具体用法?Python QDir怎么用?Python QDir使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDir类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getProjectFile
def getProjectFile(filename=None):
d = QDir()
d.cd(app.manifest.get('gendir',"bin")) # cd into the directory we generate to
if filename is None: # we want just the generation directory
return d.absolutePath() # so return the absolute path
else: # the only other option is a file in the gendir
return d.absoluteFilePath(filename) # so give the absolute path to that file
示例2: render
def render(self, fileName, width, height):
self.setViewportSize(QSize(width, height))
fileInfo = QFileInfo(fileName)
dir = QDir()
dir.mkpath(fileInfo.absolutePath())
viewportSize = self.viewportSize()
pageSize = self.mainFrame().contentsSize()
if pageSize.isEmpty():
return False
buffer = QImage(pageSize, QImage.Format_ARGB32)
buffer.fill(qRgba(255, 255, 255, 0))
p = QPainter(buffer)
p.setRenderHint( QPainter.Antialiasing, True)
p.setRenderHint( QPainter.TextAntialiasing, True)
p.setRenderHint( QPainter.SmoothPixmapTransform, True)
self.setViewportSize(pageSize)
self.mainFrame().render(p)
p.end()
self.setViewportSize(viewportSize)
return buffer.save(fileName)
示例3: __init__
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.setupUi(self)
self.settings = QSettings(QSettings.IniFormat, QSettings.UserScope, COMPANY, APPNAME)
self.restoreGeometry(self.settings.value(self.__class__.__name__))
self.images = []
if len(sys.argv) > 1:
d = QDir(path=sys.argv[1])
else:
d = QDir(path=QFileDialog.getExistingDirectory())
d.setNameFilters(['*.png'])
d.setFilter(QDir.Files or QDir.NoDotAndDotDot)
d = QDirIterator(d)
images = []
while d.hasNext():
images.append(d.next())
for i in images:
print i
self.images = [QImage(i) for i in images]
self.images += [crop_image_from_file(i, 50)[0] for i in images]
示例4: __init__
def __init__(self, parent=None, common_name=None, image=None):
QtGui.QDialog.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
types = controller.get_types()
self.directory = QDir.root()
self.display = QGraphicsView()
self.ui.scrollArea.setWidget(self.display)
for tipo in types:
self.ui.typeBox.addItem(tipo["nombre"], tipo["id_tipo"])
if common_name is None:
self.ui.btn_done.clicked.connect(self.add)
if image is None:
self.ui.image.setPlainText(image)
else:
self.setWindowTitle(u"Editar animal")
self.common = common_name
animal_data = controller.get_animal(common_name)
self.ui.common_name.setPlainText(animal_data["nombre_comun"])
self.ui.cientific_name.setText(animal_data["nombre_cientifico"])
self.ui.data.setText(animal_data["datos"])
tipo = self.ui.typeBox.currentText()
id_type = controller_form.get_id_type(tipo)
id_animal = controller_form.get_id_animal(common_name)
self.image = controller_form.get_image(id_animal)
if self.image:
self.path = QDir.currentPath() + "/images/" + self.image[0] + self.image[1]
self.ui.image.setPlainText(self.path)
Ifile = QFileInfo(self.path)
pixImage = controller_form.get_root_image(self.path)
item = QGraphicsPixmapItem(pixImage.scaled(100,100))
scene = QGraphicsScene()
scene.addItem(item)
self.display.setScene(scene)
self.ui.image.setPlainText(self.path)
else:
noimage = controller_form.no_image()
item = QGraphicsPixmapItem(noimage.scaled(100,100))
scene = QGraphicsScene()
scene.addItem(item)
self.display.setScene(scene)
scene = QGraphicsScene()
scene.addItem(item)
self.display.setScene(scene)
self.path = ""
self.ui.image.setPlainText(self.path)
self.ui.btn_done.clicked.connect(self.edit)
self.ui.btn_delete.clicked.connect(self.delete)
self.ui.btn_open.clicked.connect(self.open)
self.ui.btn_cancel.clicked.connect(self.cancel)
示例5: parse_interface
def parse_interface(interfacename):
tree = xmlparse("views" + QDir.separator() + interfacename + ".xml").getroot() # get the tree
Compiler.current_interfacename = interfacename # set the current interfacename
imported = [] # this is the list of interfaces to parse after this one
Compiler.code += "from PySide.QtGui import *\nfrom PySide.QtCore import *\n" # import PySide
Compiler.code += "from oxide.widgets.all import *\n" # import Oxide
if interfacename == Compiler.start: # if this is the start interface, create a QApplication
Compiler.code += "import sys\n" # using sys.argv,
Compiler.code += "app = OxideApplication(sys.argv)\n" # create a QApplication
add_util_funcs() # add the utility functions
add_model(interfacename,"__main__") # now add the model code to the output file
for element in tree: # iterate through the elements in the tree
if element.tag.lower() == "animations": # here we handle the special 'animations' tag
Compiler.to_be_own_class = False # there is no way that we're in the resources tag here
for animation in element: # go through each animation
parse_animation(animation) # and parse it
elif element.tag.lower() == "window": # here we handle the window
Compiler.to_be_own_class = False # there is no way that we're in the resources tag here
parse_toplevel(element) # using parse_window
elif element.tag.lower() == "resources":
Compiler.to_be_own_class = True
for child in element:
Compiler.direct_resources_child = True
parse_abstract_element(child)
Compiler.direct_resources_child = False
Compiler.direct_resources_child = False
elif element.tag.lower() == "import":
Compiler.code += "import " + element.get('interface') + "\n"
imported.append(element.get('interface'))
if interfacename == Compiler.start: # to finish up, if this is the start file
Compiler.code += "sys.exit(app.exec_())\n" # run the application
# now it has come time to put the code on the filesystem
if not QDir("bin").exists(): # if the 'bin' folder doesn't exist
QDir().mkdir("bin") # create it
interfacefile = open(Compiler.gendir + QDir.separator() + interfacename + ".py", 'w')
interfacefile.write(Compiler.code) # write Compiler.code to the file
Compiler.code = "" # reset Compiler.code
for interface in imported:
parse_interface(interface)
示例6: onBrowseClicked
def onBrowseClicked(self):
"""Slot. Called when the user clicks on the `browseButton` button"""
# Presents the user with a native directory selector window
localdir = QFileDialog.getExistingDirectory()
localdir = QDir.fromNativeSeparators(localdir)
if len(localdir) > 0:
# If `localdir`'s value is good, store it using a `QSettings` object
# and triggers a sync request.
# Careful with '\' separators on Windows.
localdir = QDir.toNativeSeparators(localdir)
get_settings().setValue(SettingsKeys['localdir'], localdir)
self.localdirEdit.setText(localdir)
示例7: processModels
def processModels():
for filename in QDir("models").entryList(QDir.Files):
out = ""
for line in open("models" + QDir.separator() + filename).readlines():
try:
if not line.strip()[0] == "#":
if line[:8] == "from " + app.manifest.get('gendir',"bin"): out += "# " + line;
else: out += line
else: out += line
except IndexError: # it must have just been a newline (lstrip makes it ""), so there is no index 0
out += "\n"
f = open("models" + QDir.separator() + filename, 'w')
f.write(out)
f.close()
示例8: on_change_root_path
def on_change_root_path(self, current_path):
if current_path == SOURCEIMAGES_TAG:
current_path = os.path.join(
cmds.workspace(query=True, rootDirectory=True),
cmds.workspace(fileRuleEntry='sourceImages')
)
self.files_model.setRootPath(current_path)
self.files_list.setRootIndex(self.files_model.index(current_path))
if self.path_edit:
self.path_edit.setText(current_path)
if self.parent_folder_btn:
current_dir = QDir(current_path)
self.parent_folder_btn.setEnabled(current_dir.cdUp())
示例9: getConfigStyleDict
def getConfigStyleDict():
styledict = {} #initialize the new styledict
# get the tree from the style.xml file
tree = xmlparse("config" + QDir.separator() + "style.xml").getroot()
for styletype in tree: # iterate over the types of widget
styletype_key = styletype.tag.lower() if styletype.tag.lower().startswith("default-") else styletype.tag
styledict[styletype_key] = {} # create a new dictionary for the style-type
for state in States:
styledict[styletype_key][state] = {}
styledict[styletype_key]['normal'] = {}
styledict[styletype_key]['durations'] = {}
for styledef_or_statedef in styletype:
if styledef_or_statedef.tag.lower() in States:
for styledef in styledef_or_statedef:
styledict[styletype_key][styledef_or_statedef.tag.lower()][styledef.tag.lower()] = getValue(styledef)
elif styledef_or_statedef.tag.lower() in StateTransitions:
if styledef_or_statedef.get('time') is None:
raise StyleError(styletype.tag + " => " + styledef_or_statedef.tag + " must have 'time' attribute")
styledict[styletype_key]['durations'][styledef_or_statedef.tag.lower()] = int(styledef_or_statedef.get('time'))
else:
for state in States:
styledict[styletype_key][state][styledef_or_statedef.tag.lower()] = getValue(styledef_or_statedef)
styledict[styletype_key]['normal'][styledef_or_statedef.tag.lower()] = getValue(styledef_or_statedef)
return styledict
示例10: create_folder
def create_folder(self):
"""
Crea carpeta de imagenes si no existe
"""
self.directory = QDir.root()
if not os.path.exists(self.directory.currentPath()+"/images"):
os.makedirs(self.directory.currentPath()+"/images")
示例11: fileOpen
def fileOpen(self, lineEdit, filters):
openFile = QFileDialog.getOpenFileName(self, "Find Files", QDir.currentPath(), filters="*." + filters)
uiDebug(openFile)
if openFile != None :
lineEdit.setText(openFile[0])
self.setUserConfig()
self.showConfig()
示例12: no_image
def no_image():
"""
Si no existe imagen carga una por defecto
"""
path = QDir.currentPath() + "/images/noimage.jpg"
pixMap = QPixmap(path)
return pixMap
示例13: localFromServer
def localFromServer(self, serverpath):
# Removing leading '/' so `os.path.join` doesn't treat
# `localpath` as an absolute path
localpath = serverpath[1:] if serverpath.startswith('/') else serverpath
localpath = QDir.toNativeSeparators(localpath)
localpath = os.path.join(self.localdir, localpath)
return localpath
示例14: _fetchChildren
def _fetchChildren(self):
'''Fetch and return new child items.'''
children = []
for entry in QDir.drives():
path = os.path.normpath(entry.canonicalFilePath())
children.append(Mount(path))
return children
示例15: loadConfig
def loadConfig(self):
'''加载配置文件'''
configfile = QFileDialog.getOpenFileName(self, "Load Config File", QDir.currentPath(), filter="*.cfg")
uiDebug(configfile)
if configfile != None :
self.readConfig(configfile)
self.stopServer()
self.startServer()
self.showConfig()
uiDebug("loadConfig")