Python PySide.QtGui.QFileDialog() Examples

The following are 15 code examples of PySide.QtGui.QFileDialog(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PySide.QtGui , or try the search function .
Example #1
Source File: eagleCmd.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def brdIn():
  board=qg.QFileDialog().getOpenFileName() [0]
  try:
		radice=et.parse(board).getroot()
		el=[]
		pos=[]
		for ramo in radice.iter('element'):
			el.append(ramo)
		for e in el:
			x=float(e.attrib['x'])
			y=float(e.attrib['y'])
			if ('rot' in e.attrib) and (e.attrib['rot'].lstrip('R').isdigit()):
				rot=float(e.attrib['rot'].lstrip('R'))
			else:
				rot=0.0
			pos.append([e.attrib['name'],[x,y,rot]])
		dpos=dict(pos)
		for k in dpos.keys():
			App.Console.PrintMessage(str(k)+'\t'+str(dpos[k])+'\n')
		return dpos
  except:
		App.Console.PrintMessage('no such file\n') 
Example #2
Source File: vfpfunc.py    From vfp2py with MIT License 6 votes vote down vote up
def getfile(file_ext='', text='', button_caption='', button_type=0, title=''):
    filter = {
        '': '',
        'txt': 'File (*.txt)',
        'dbf': 'Table/DBF (*.dbf)',
    }.get(file_ext, '*.' + file_ext)
    t = QtGui.QFileDialog()
    t.setFilter('All Files (*.*);;' + filter)
    t.selectFilter(filter or 'All Files (*.*);;')
    if text:
        (next(x for x in t.findChildren(QtGui.QLabel) if x.text() == 'File &name:')).setText(text)
    if button_caption:
        t.setLabelText(QtGui.QFileDialog.Accept, button_caption)
    if title:
        t.setWindowTitle(title)
    t.exec_()
    return t.selectedFiles()[0] 
Example #3
Source File: utils.py    From Satori with Artistic License 2.0 6 votes vote down vote up
def download_button_clicked(self):

        directory = QtGui.QFileDialog().getExistingDirectory()
        if not directory or len(directory) == 0 or not os.path.exists(directory):
            return
        self.download_button.setVisible(False)
        self.download_progress.setVisible(True)
        filename = os.path.basename(self.link())
        self.full_filename = os.path.join(directory, filename)

        url = QtCore.QUrl(self.link())
        request = QtNetwork.QNetworkRequest(url)
        self.current_download = self.manager.get(request)
        self.current_download.setReadBufferSize(1048576)
        self.connect(self.current_download, QtCore.SIGNAL("downloadProgress(qint64, qint64)"),
                     self.download_hook)
        self.current_download.downloadProgress.connect(self.download_hook)
        self.current_download.finished.connect(self.download_finished)
        self.current_download.readyRead.connect(self.download_ready_read)
        self.current_f = open(self.full_filename, 'wb')
        self.parent.exiting.connect(self.closing) 
Example #4
Source File: __init__.py    From FreeCAD_assembly2 with GNU Lesser General Public License v2.1 6 votes vote down vote up
def Activated(self):
        selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
        obj = selection[0]
        filename, filetype = QtGui.QFileDialog.getSaveFileName(
            QtGui.QApplication.activeWindow(),
            "Specify the filename for the fork of '%s'" % obj.Label[:obj.Label.find('_import')],
            os.path.dirname(FreeCAD.ActiveDocument.FileName),
            "FreeCAD Document (*.fcstd)"
            )
        if filename == '':
            return
        if not os.path.exists(filename):
            debugPrint(2, 'copying %s -> %s' % (obj.sourceFile, filename))
            shutil.copyfile(obj.sourceFile, filename)
            obj.sourceFile = filename
            FreeCAD.open(obj.sourceFile)
        else:
            QtGui.QMessageBox.critical(  QtGui.QApplication.activeWindow(), "Bad filename", "Specify a new filename!") 
Example #5
Source File: polarUtilsCmd.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def getFromFile():
  '''Input polar coord. from .csv: returns a list of (x,y,0).
  The file must be ";" separated: column A = radius, column B = angle'''
  from PySide import QtGui
  fileIn=open(QtGui.QFileDialog().getOpenFileName()[0],'r')
  lines=fileIn.readlines()
  fileIn.close()
  xyCoord=[]
  for line in lines:
    polarCoord=line.split(';')
    xyCoord.append(polar2xy(float(polarCoord[0]),float(polarCoord[1])*math.pi/180))
  return xyCoord 
Example #6
Source File: vfpfunc.py    From vfp2py with MIT License 5 votes vote down vote up
def getdir(dir='.', text='', caption='Select Text', flags=0, root_only=False):
    return QtGui.QFileDialog.getExistingDirectory(parent=S['_screen'], caption=caption, dir=dir) 
Example #7
Source File: mainform.py    From Satori with Artistic License 2.0 5 votes vote down vote up
def select_folder_button_clicked(self):
        directory = QtGui.QFileDialog().getExistingDirectory()
        if not directory or len(directory) == 0 or not os.path.exists(directory):
            return
        file_list = list(filter(lambda x: os.path.isfile(x), map(lambda x: os.path.join(directory, x), os.listdir(directory))))
        if len(file_list) > 0:
            self.check_sha_sums(file_list) 
Example #8
Source File: mainform.py    From Satori with Artistic License 2.0 5 votes vote down vote up
def select_file_button_clicked(self):
        file_path = QtGui.QFileDialog().getOpenFileName()[0]
        if not file_path or len(file_path) == 0 or not os.path.exists(file_path):
            return
        self.check_sha_sums([file_path]) 
Example #9
Source File: __init__.py    From FreeCAD_assembly2 with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        if FreeCADGui.ActiveDocument == None:
            FreeCAD.newDocument()
        view = FreeCADGui.activeDocument().activeView()
        #filename, filetype = QtGui.QFileDialog.getOpenFileName(
        #    QtGui.QApplication.activeWindow(),
        #    "Select FreeCAD document to import part from",
        #    "",# "" is the default, os.path.dirname(FreeCAD.ActiveDocument.FileName),
        #    "FreeCAD Document (*.fcstd)"
        #    )
        dialog = QtGui.QFileDialog(
            QtGui.QApplication.activeWindow(),
            "Select FreeCAD document to import part from"
            )
        dialog.setNameFilter("Supported Formats (*.FCStd *.brep *.brp *.imp *.iges *.igs *.obj *.step *.stp);;All files (*.*)")
        if dialog.exec_():
            filename = dialog.selectedFiles()[0]
        else:
            return
        importedObject = importPart( filename )
        FreeCAD.ActiveDocument.recompute()
        if not importedObject.fixedPosition: #will be true for the first imported part
            PartMover( view, importedObject )
        else:
            from PySide import QtCore
            self.timer = QtCore.QTimer()
            QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.GuiViewFit)
            self.timer.start( 200 ) #0.2 seconds 
Example #10
Source File: PySimulator.py    From PySimulator with GNU Lesser General Public License v3.0 5 votes vote down vote up
def saveFigure(self):
        ''' Exports the current window to an image '''
        if self.activePlotContainer and self.activePlot:
            rast = "Rasterized Images (*.png *.tiff *.bmp *.jpg *.jpeg *.gif)"
            pdf = "Portable Document Format (*.pdf)"
            svg = "Scalable Vector Graphics (*.svg *.html)"
            # (fileName, extension) = QtGui.QFileDialog().getSaveFileName(self, 'Save Plot as image', os.getcwd(), rast + ";;" + pdf + ";;" + svg)
            (fileName, extension) = QtGui.QFileDialog().getSaveFileName(self, 'Save Plot as Image', os.getcwd(), rast)
            if not fileName:
                return
            if extension == rast:
                gc = chaco.plot_graphics_context.PlotGraphicsContext((self.activePlotContainer.activeWidget.width(), self.activePlotContainer.activeWidget.height()))
                gc.render_component(self.activePlotContainer.activeWidget.component)
                gc.save(fileName)
                print "Saved rasterized image to: ", fileName
                '''
                elif extension == pdf:
                    print "PDF rendering is currently in a unfinished state!"
                    __import__("chaco.pdf_graphics_context", globals(), locals(), [], -1)
                    gc = chaco.pdf_graphics_context.PdfPlotGraphicsContext(None, fileName, "A4")
                    gc.render_component(self.activePlotContainer.activeWidget.component)
                    gc.save()
                    print "Saved PDF to: ", fileName
                elif extension == svg:
                    __import__("chaco.svg_graphics_context", globals(), locals(), [], -1)
                    gc = chaco.svg_graphics_context.SVGGraphicsContext((self.activePlotContainer.activeWidget.width(), self.activePlotContainer.activeWidget.height()))
                    gc.render_component(self.activePlotContainer.activeWidget.component)
                    gc.save(fileName)
                    print "Saved SVG to: ", fileName
                '''
            else:
                print "File extension error. Unable to save image."
        else:
            print "Error saving plot. Plot type unknown or invalid" 
Example #11
Source File: PySimulator.py    From PySimulator with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _openFileMenu(self, loaderplugin):
        extensionStr = ''
        for ex in loaderplugin.modelExtension:
            extensionStr += u'*.' + ex + u';'
        if len(extensionStr) > 0:
            extensionStr = extensionStr[:-1]
        ''' Load a model '''
        (fileName, trash) = QtGui.QFileDialog().getOpenFileName(self, 'Open Model', os.getcwd(), extensionStr)
        if fileName == '':
            return
        split = unicode.rsplit(fileName, '.', 1)
        if len(split) > 1:
            suffix = split[1]
        else:
            suffix = u''
        modelName = None
        if suffix in [u'mo', u'moe']:
            if len(split[0]) > 0:
                split = unicode.rsplit(split[0], u'/', 1)
                defaultModelName = split[1]
            else:
                defaultModelName = u''
            modelName, ok = QtGui.QInputDialog().getText(self, 'Modelica model', 'Full Modelica model name / ident, e.g. Modelica.Blocks.Examples.PID_Controller', text=defaultModelName)
            if not ok:
                return


        self.setEnabled(False)
        self._loadingFileInfo()
        self.openModelFile(loaderplugin, fileName, modelName)
        self.setEnabled(True) 
Example #12
Source File: PySimulator.py    From PySimulator with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _openResultFileMenu(self):
        ''' Load a Result file '''
        formats = 'All formats ('
        formats2 = ''
        for i, ext in enumerate(Plugins.SimulationResult.fileExtension):
            formats += ' *.' + ext
            formats2 += Plugins.SimulationResult.description[i] + ' (*.' + ext + ')'
            if i + 1 < len(Plugins.SimulationResult.fileExtension):
                formats2 += ';;'
        formats += ');;' + formats2
        (fileNames, trash) = QtGui.QFileDialog().getOpenFileNames(self, 'Open Result File', os.getcwd(), formats)
        import locale
        for fileName in fileNames:
            self.openResultFile(unicode(fileName.encode(locale.getpreferredencoding()), locale.getpreferredencoding()).replace(u'\\', u'/')) 
Example #13
Source File: PySimulator.py    From PySimulator with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _convertResultFileMenu(self):
        ''' Select a result file '''
        (fileName, trash) = QtGui.QFileDialog().getOpenFileName(self, 'Select Result File', os.getcwd(), 'Dymola Result File (*.mat)')
        if fileName == '':
            return
        print("Convert " + fileName + " ...")
        mtsfFileName = Plugins.SimulationResult.Mtsf.Mtsf.convertFromDymolaMatFile(fileName)
        print(" done: " + mtsfFileName + "\n") 
Example #14
Source File: PySimulator.py    From PySimulator with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _changeDirectoryMenu(self):
        ''' Select a working directory '''
        dirName = QtGui.QFileDialog().getExistingDirectory(self, 'Select Working Directory', os.getcwd())
        if dirName == '':
            return
        self._chDir(dirName) 
Example #15
Source File: Wolfram.py    From PySimulator with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, modelName, modelFileName, config):

        SimulatorBase.Model.__init__(self, modelName, modelFileName, config)
        self.modelType = 'Modelica model in Wolfram'

        self.onlyResultFile = False
        self.integrationSettings.resultFileExtension = 'mat'

        self._availableIntegrationAlgorithms = ['DASSL', 'CVODES', 'Euler', 'RungeKutta', 'Heun']
        self.integrationSettings.algorithmName = self._availableIntegrationAlgorithms[0]

        self._IntegrationAlgorithmHasFixedStepSize = [False, False, True, True, True]
        self._IntegrationAlgorithmCanProvideStepSizeResults = [False, False, True, True, True]

        if not config['Plugins']['Wolfram'].has_key('mathLinkPath'):
            config['Plugins']['Wolfram']['mathLinkPath'] = ''
        mathLinkPath = config['Plugins']['Wolfram']['mathLinkPath']

        if mathLinkPath == '' or not os.path.exists(mathLinkPath):
            ''' Ask for MathLink executable '''
            print "No MathLink executable (math.exe or MathKernel.exe) found to run Wolfram. Please select one ..."
            (mathLinkPath, trash) = QtGui.QFileDialog().getOpenFileName(None, 'Select MathLink executable file', os.getcwd(), 'Executable file (*.exe)')
        if mathLinkPath == '':
            print "failed. No MathLink executable (math.exe or MathKernel.exe) specified."
            return None
        else:
            config['Plugins']['Wolfram']['mathLinkPath'] = mathLinkPath
            config.write()

        #Creates a link to a Mathematica Kernel and stores information needed for communication
        self.mathLink = pythonica.Pythonica(path= "" + mathLinkPath + "" )
        self.compileModel()

        self._initialResult = loadResultFileInit(os.path.join(os.getcwd(), self.name + ".sim"))