Exemplo n.º 1
0
def _qfiledialog_wrapper(attr, parent=None, caption='', basedir='',
                         filters='', selectedfilter='', options=None):
    if options is None:
        options = QFileDialog.Options(0)
    try:
        # PyQt <v4.6 (API #1)
        from winpython.qt.QtCore import QString
    except ImportError:
        # PySide or PyQt >=v4.6
        QString = None  # analysis:ignore
    tuple_returned = True
    try:
        # PyQt >=v4.6
        func = getattr(QFileDialog, attr+'AndFilter')
    except AttributeError:
        # PySide or PyQt <v4.6
        func = getattr(QFileDialog, attr)
        if QString is not None:
            selectedfilter = QString()
            tuple_returned = False
    
    # Calling QFileDialog static method
    if sys.platform == "win32":
        # On Windows platforms: redirect standard outputs
        _temp1, _temp2 = sys.stdout, sys.stderr
        sys.stdout, sys.stderr = None, None
    try:
        result = func(parent, caption, basedir,
                      filters, selectedfilter, options)
    except TypeError:
        # The selectedfilter option (`initialFilter` in Qt) has only been 
        # introduced in Jan. 2010 for PyQt v4.7, that's why we handle here 
        # the TypeError exception which will be raised with PyQt v4.6
        # (see Issue 960 for more details)
        result = func(parent, caption, basedir, filters, options)
    finally:
        if sys.platform == "win32":
            # On Windows platforms: restore standard outputs
            sys.stdout, sys.stderr = _temp1, _temp2
            
    # Processing output
    if tuple_returned:
        # PySide or PyQt >=v4.6
        output, selectedfilter = result
    else:
        # PyQt <v4.6 (API #1)
        output = result
    if QString is not None:
        # PyQt API #1: conversions needed from QString/QStringList
        selectedfilter = to_text_string(selectedfilter)
        if isinstance(output, QString):
            # Single filename
            output = to_text_string(output)
        else:
            # List of filenames
            output = [to_text_string(fname) for fname in output]
            
    # Always returns the tuple (output, selectedfilter)
    return output, selectedfilter
Exemplo n.º 2
0
 def process_packages(self, action):
     """Install/uninstall packages"""
     if action == 'install':
         text, table = 'Installing', self.table
         if not self.get_packages_to_be_installed():
             return
     elif action == 'uninstall':
         text, table = 'Uninstalling', self.untable
     else:
         raise AssertionError
     packages = table.get_selected_packages()
     if not packages:
         return
     func = getattr(self.distribution, action)
     thread = Thread(self)
     for widget in self.children():
         if isinstance(widget, QWidget):
             widget.setEnabled(False)
     try:
         status = self.statusBar()
     except AttributeError:
         status = self.parent().statusBar()
     progress = QProgressDialog(self, Qt.FramelessWindowHint)
     progress.setMaximum(len(packages))  #  old vicious bug:len(packages)-1
     for index, package in enumerate(packages):
         progress.setValue(index)
         progress.setLabelText("%s %s %s..." %
                               (text, package.name, package.version))
         QApplication.processEvents()
         if progress.wasCanceled():
             break
         if package in table.model.actions:
             try:
                 thread.callback = lambda: func(package)
                 thread.start()
                 while thread.isRunning():
                     QApplication.processEvents()
                     if progress.wasCanceled():
                         status.setEnabled(True)
                         status.showMessage("Cancelling operation...")
                 table.remove_package(package)
                 error = thread.error
             except Exception as error:
                 error = to_text_string(error)
             if error is not None:
                 pstr = (package.name + ' ' + package.version)
                 QMessageBox.critical(
                     self,
                     "Error",
                     "<b>Unable to %s <i>%s</i></b>"
                     "<br><br>Error message:<br>%s" % (action, pstr, error),
                 )
     progress.setValue(progress.maximum())
     status.clearMessage()
     for widget in self.children():
         if isinstance(widget, QWidget):
             widget.setEnabled(True)
     thread = None
     for table in (self.table, self.untable):
         table.refresh_distribution(self.distribution)
Exemplo n.º 3
0
 def process_packages(self, action):
     """Install/uninstall packages"""
     if action == "install":
         text, table = "Installing", self.table
         if not self.get_packages_to_be_installed():
             return
     elif action == "uninstall":
         text, table = "Uninstalling", self.untable
     else:
         raise AssertionError
     packages = table.get_selected_packages()
     if not packages:
         return
     func = getattr(self.distribution, action)
     thread = Thread(self)
     for widget in self.children():
         if isinstance(widget, QWidget):
             widget.setEnabled(False)
     try:
         status = self.statusBar()
     except AttributeError:
         status = self.parent().statusBar()
     progress = QProgressDialog(self, Qt.FramelessWindowHint)
     progress.setMaximum(len(packages))  #  old vicious bug:len(packages)-1
     for index, package in enumerate(packages):
         progress.setValue(index)
         progress.setLabelText("%s %s %s..." % (text, package.name, package.version))
         QApplication.processEvents()
         if progress.wasCanceled():
             break
         if package in table.model.actions:
             try:
                 thread.callback = lambda: func(package)
                 thread.start()
                 while thread.isRunning():
                     QApplication.processEvents()
                     if progress.wasCanceled():
                         status.setEnabled(True)
                         status.showMessage("Cancelling operation...")
                 table.remove_package(package)
                 error = thread.error
             except Exception as error:
                 error = to_text_string(error)
             if error is not None:
                 pstr = package.name + " " + package.version
                 QMessageBox.critical(
                     self,
                     "Error",
                     "<b>Unable to %s <i>%s</i></b>" "<br><br>Error message:<br>%s" % (action, pstr, error),
                 )
     progress.setValue(progress.maximum())
     status.clearMessage()
     for widget in self.children():
         if isinstance(widget, QWidget):
             widget.setEnabled(True)
     thread = None
     for table in (self.table, self.untable):
         table.refresh_distribution(self.distribution)
Exemplo n.º 4
0
def mimedata2url(source, extlist=None):
    """
    Extract url list from MIME data
    extlist: for example ('.py', '.pyw')
    """
    pathlist = []
    if source.hasUrls():
        for url in source.urls():
            path = _process_mime_path(to_text_string(url.toString()), extlist)
            if path is not None:
                pathlist.append(path)
    elif source.hasText():
        for rawpath in to_text_string(source.text()).splitlines():
            path = _process_mime_path(rawpath, extlist)
            if path is not None:
                pathlist.append(path)
    if pathlist:
        return pathlist
Exemplo n.º 5
0
 def distribution_changed(self, path):
     """Distribution path has just changed"""
     for package in self.table.model.packages:
         self.table.remove_package(package)
     dist = wppm.Distribution(to_text_string(path))
     self.table.refresh_distribution(dist)
     self.untable.refresh_distribution(dist)
     self.distribution = dist
     self.selector.label.setText("Python %s %dbit:" % (dist.version, dist.architecture))
Exemplo n.º 6
0
def mimedata2url(source, extlist=None):
    """
    Extract url list from MIME data
    extlist: for example ('.py', '.pyw')
    """
    pathlist = []
    if source.hasUrls():
        for url in source.urls():
            path = _process_mime_path(to_text_string(url.toString()), extlist)
            if path is not None:
                pathlist.append(path)
    elif source.hasText():
        for rawpath in to_text_string(source.text()).splitlines():
            path = _process_mime_path(rawpath, extlist)
            if path is not None:
                pathlist.append(path)
    if pathlist:
        return pathlist
Exemplo n.º 7
0
 def distribution_changed(self, path):
     """Distribution path has just changed"""
     for package in self.table.model.packages:
         self.table.remove_package(package)
     dist = wppm.Distribution(to_text_string(path))
     self.table.refresh_distribution(dist)
     self.untable.refresh_distribution(dist)
     self.distribution = dist
     self.selector.label.setText('Python %s %dbit:' %
                                 (dist.version, dist.architecture))
Exemplo n.º 8
0
 def select_directory(self):
     """Select directory"""
     basedir = to_text_string(self.line_edit.text())
     if not osp.isdir(basedir):
         basedir = getcwd()
     while True:
         directory = getexistingdirectory(self, self.TITLE, basedir)
         if not directory:
             break
         if not utils.is_python_distribution(directory):
             QMessageBox.warning(self, self.TITLE,
                 "The following directory is not a Python distribution.",
                 QMessageBox.Ok)
             basedir = directory
             continue
         directory = osp.abspath(osp.normpath(directory))
         self.set_distribution(directory)
         self.emit(SIGNAL('selected_distribution(QString)'), directory)
         break
Exemplo n.º 9
0
def getexistingdirectory(parent=None, caption='', basedir='',
                         options=QFileDialog.ShowDirsOnly):
    """Wrapper around QtGui.QFileDialog.getExistingDirectory static method
    Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0"""
    # Calling QFileDialog static method
    if sys.platform == "win32":
        # On Windows platforms: redirect standard outputs
        _temp1, _temp2 = sys.stdout, sys.stderr
        sys.stdout, sys.stderr = None, None
    try:
        result = QFileDialog.getExistingDirectory(parent, caption, basedir,
                                                  options)
    finally:
        if sys.platform == "win32":
            # On Windows platforms: restore standard outputs
            sys.stdout, sys.stderr = _temp1, _temp2
    if not is_text_string(result):
        # PyQt API #1
        result = to_text_string(result)
    return result
Exemplo n.º 10
0
def getexistingdirectory(parent=None,
                         caption='',
                         basedir='',
                         options=QFileDialog.ShowDirsOnly):
    """Wrapper around QtGui.QFileDialog.getExistingDirectory static method
    Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0"""
    # Calling QFileDialog static method
    if sys.platform == "win32":
        # On Windows platforms: redirect standard outputs
        _temp1, _temp2 = sys.stdout, sys.stderr
        sys.stdout, sys.stderr = None, None
    try:
        result = QFileDialog.getExistingDirectory(parent, caption, basedir,
                                                  options)
    finally:
        if sys.platform == "win32":
            # On Windows platforms: restore standard outputs
            sys.stdout, sys.stderr = _temp1, _temp2
    if not is_text_string(result):
        # PyQt API #1
        result = to_text_string(result)
    return result
Exemplo n.º 11
0
def _qfiledialog_wrapper(attr,
                         parent=None,
                         caption='',
                         basedir='',
                         filters='',
                         selectedfilter='',
                         options=None):
    if options is None:
        options = QFileDialog.Options(0)
    try:
        # PyQt <v4.6 (API #1)
        from winpython.qt.QtCore import QString
    except ImportError:
        # PySide or PyQt >=v4.6
        QString = None  # analysis:ignore
    tuple_returned = True
    try:
        # PyQt >=v4.6
        func = getattr(QFileDialog, attr + 'AndFilter')
    except AttributeError:
        # PySide or PyQt <v4.6
        func = getattr(QFileDialog, attr)
        if QString is not None:
            selectedfilter = QString()
            tuple_returned = False

    # Calling QFileDialog static method
    if sys.platform == "win32":
        # On Windows platforms: redirect standard outputs
        _temp1, _temp2 = sys.stdout, sys.stderr
        sys.stdout, sys.stderr = None, None
    try:
        result = func(parent, caption, basedir, filters, selectedfilter,
                      options)
    except TypeError:
        # The selectedfilter option (`initialFilter` in Qt) has only been
        # introduced in Jan. 2010 for PyQt v4.7, that's why we handle here
        # the TypeError exception which will be raised with PyQt v4.6
        # (see Issue 960 for more details)
        result = func(parent, caption, basedir, filters, options)
    finally:
        if sys.platform == "win32":
            # On Windows platforms: restore standard outputs
            sys.stdout, sys.stderr = _temp1, _temp2

    # Processing output
    if tuple_returned:
        # PySide or PyQt >=v4.6
        output, selectedfilter = result
    else:
        # PyQt <v4.6 (API #1)
        output = result
    if QString is not None:
        # PyQt API #1: conversions needed from QString/QStringList
        selectedfilter = to_text_string(selectedfilter)
        if isinstance(output, QString):
            # Single filename
            output = to_text_string(output)
        else:
            # List of filenames
            output = [to_text_string(fname) for fname in output]

    # Always returns the tuple (output, selectedfilter)
    return output, selectedfilter