コード例 #1
0
ファイル: xconfigwidget.py プロジェクト: zengjunfeng/projexui
 def __init__( self, parent, uifile = '' ):
     super(XConfigWidget, self).__init__(parent)
     
     # load the ui if specified
     if ( uifile ):
         curr_dir = QDir.currentPath()
         QDir.setCurrent(os.path.dirname(uifile))
         uic.loadUi(uifile, self)
         QDir.setCurrent(curr_dir)
     
     self._plugin  = None
コード例 #2
0
    def loadFile(self, filename):
        # creates the new XdkItem
        filename = nativestring(filename)
        basename = os.path.basename(filename)
        name = os.path.splitext(basename)[0]

        temp_dir = nativestring(QDir.tempPath())
        temp_path = os.path.join(temp_dir, 'xdk/%s' % name)

        # remove existing files from the location
        if os.path.exists(temp_path):
            try:
                shutil.rmtree(temp_path, True)
            except:
                pass

        # make sure we have the temp location available
        if not os.path.exists(temp_path):
            try:
                os.makedirs(temp_path)
            except:
                pass

        # extract the zip files to the temp location
        zfile = zipfile.ZipFile(filename, 'r')
        zfile.extractall(temp_path)
        zfile.close()

        # load the table of contents
        self.loadingFinished.emit(filename)
コード例 #3
0
    def loadFilename(self, filename=''):
        """
        Loads a new XDK file into the system.
        
        :param      filename | <str>
        
        :return     <bool> | success
        """
        if (not (filename and isinstance(filename, basestring))):
            filename = QFileDialog.getOpenFileName(self, 'Open XDK File',
                                                   QDir.currentPath(),
                                                   'XDK Files (*.xdk)')

            if type(filename) == tuple:
                filename = nativestring(filename[0])

            if not filename:
                return False

        if not (filename and os.path.exists(filename)):
            return False

        elif filename in self.loadedFilenames():
            return False

        self.loadFileRequested.emit(filename)
        self.setCursor(Qt.WaitCursor)

        return True
コード例 #4
0
ファイル: xdkitem.py プロジェクト: zengjunfeng/projexui
    def __init__(self, xdk_filename):
        # create the new XdkItem
        super(XdkItem, self).__init__(None, xdk_filename)

        # creates the new XdkItem
        basename = os.path.basename(nativestring(xdk_filename))
        name = os.path.splitext(basename)[0]

        temppath = nativestring(QDir.tempPath())
        temp_path = os.path.join(temppath, 'xdk/%s' % name)

        # define custom properties
        self._tempFilepath = temp_path
        self._searchurls = {}

        # set the options
        self.setChildIndicatorPolicy(self.ShowIndicator)
        self.setIcon(0, QIcon(projexui.resources.find('img/sdk.png')))

        toc_file = os.path.join(temp_path, 'toc.xml')
        toc_xml = None
        if toc_file:
            try:
                toc_xml = ElementTree.parse(toc_file).getroot()[0]
            except:
                pass

        if toc_xml is not None:
            self._url = 'file:///%s/index.html' % temp_path.strip('/')
            self.setText(0, toc_xml.get('title', self.text(0)))
            self.loadFromXml(toc_xml, temp_path)
        else:
            # load the url information for this entry
            for name in sorted(os.listdir(temp_path)):
                # ignore 'hidden' folders
                if name.startswith('_') and not name.startswith('__'):
                    continue

                # ignore special cases (only want modules for this)
                if '-' in name or name == 'toc.xml':
                    continue

                # use the index or __init__ information
                if name == '__init__.html':
                    self._url = 'file:///%s/%s' % (temp_path, name)
                    continue

                elif name == 'index.html':
                    self._url = 'file:///%s/%s' % (temp_path, name)

                # otherwise, load a childitem
                filepath = os.path.join(temp_path, name)
                folder = os.path.isdir(filepath)
                XdkEntryItem(self, filepath, folder=folder)
コード例 #5
0
ファイル: xdkitem.py プロジェクト: bitesofcode/projexui
 def __init__(self, xdk_filename):
     # create the new XdkItem
     super(XdkItem, self).__init__(None, xdk_filename)
     
     # creates the new XdkItem
     basename = os.path.basename(nativestring(xdk_filename))
     name     = os.path.splitext(basename)[0]
     
     temppath  = nativestring(QDir.tempPath())
     temp_path = os.path.join(temppath, 'xdk/%s' % name)
     
     # define custom properties
     self._tempFilepath  = temp_path
     self._searchurls    = {}
     
     # set the options
     self.setChildIndicatorPolicy(self.ShowIndicator)
     self.setIcon(0, QIcon(projexui.resources.find('img/sdk.png')))
     
     toc_file = os.path.join(temp_path, 'toc.xml')
     toc_xml = None
     if toc_file:
         try:
             toc_xml = ElementTree.parse(toc_file).getroot()[0]
         except:
             pass
     
     if toc_xml is not None:
         self._url = 'file:///%s/index.html' % temp_path.strip('/')
         self.setText(0, toc_xml.get('title', self.text(0)))
         self.loadFromXml(toc_xml, temp_path)
     else:
         # load the url information for this entry
         for name in sorted(os.listdir(temp_path)):
             # ignore 'hidden' folders
             if name.startswith('_') and not name.startswith('__'):
                 continue
             
             # ignore special cases (only want modules for this)
             if '-' in name or name == 'toc.xml':
                 continue
             
             # use the index or __init__ information
             if name == '__init__.html':
                 self._url = 'file:///%s/%s' % (temp_path, name)
                 continue
             
             elif name == 'index.html':
                 self._url = 'file:///%s/%s' % (temp_path, name)
             
             # otherwise, load a childitem
             filepath = os.path.join(temp_path, name)
             folder = os.path.isdir(filepath)
             XdkEntryItem(self, filepath, folder=folder)
コード例 #6
0
ファイル: xiconbutton.py プロジェクト: zengjunfeng/projexui
 def pickFilepath( self ):
     """
     Picks the image file to use for this icon path.
     """
     filepath = QFileDialog.getOpenFileName( self,
                                             'Select Image File',
                                             QDir.currentPath(),
                                             self.fileTypes())
     
     if type(filepath) == tuple:
         filepath = nativestring(filepath[0])
     
     if ( filepath ):
         self.setFilepath(filepath)
コード例 #7
0
 def saveAs( self, filename = '' ):
     """
     Saves the current document to the inputed filename.  If no filename \
     is supplied, then the user will be prompted to supply a filename.
     
     :param      filename | <str>
     
     :return     <bool> | success
     """
     if ( not (filename and isinstance(filename, basestring)) ):
         langTypes = XLanguage.pluginFileTypes()
         filename = QFileDialog.getSaveFileName( None,
                                                 'Save File As...',
                                                 QDir.currentPath(),
                                                 langTypes)
         
         if type(filename) == tuple:
             filename = nativestring(filename[0])
     
     if ( not filename ):
         return False
     
     docfile = QFile(filename)
     if ( not docfile.open(QFile.WriteOnly) ):
         logger.warning('Could not open %s for writing.' % filename)
         return False
     
     success = self.write(docfile)
     docfile.close()
     
     if success:
         filename = nativestring(filename)
         self._filename = filename
         
         self.setModified(False)
         
         # set the language
         lang = XLanguage.byFileType(os.path.splitext(filename)[1])
         if ( lang != self.language() ):
             self.setLanguage(lang)
     
     return success
コード例 #8
0
 def pickFilepath( self ):
     """
     Prompts the user to select a filepath from the system based on the \
     current filepath mode.
     """
     mode = self.filepathMode()
     
     filepath = ''
     filepaths = []
     curr_dir = nativestring(self._filepathEdit.text())
     if ( not curr_dir ):
         curr_dir = QDir.currentPath()
     
     if mode == XFilepathEdit.Mode.SaveFile:
         filepath = QFileDialog.getSaveFileName( self,
                                                 self.windowTitle(),
                                                 curr_dir,
                                                 self.filepathTypes() )
                                                 
     elif mode == XFilepathEdit.Mode.OpenFile:
         filepath = QFileDialog.getOpenFileName( self,
                                                 self.windowTitle(),
                                                 curr_dir,
                                                 self.filepathTypes() )
     
     elif mode == XFilepathEdit.Mode.OpenFiles:
         filepaths = QFileDialog.getOpenFileNames( self,
                                                   self.windowTitle(),
                                                   curr_dir,
                                                   self.filepathTypes() )
     
     else:
         filepath = QFileDialog.getExistingDirectory( self,
                                                      self.windowTitle(),
                                                      curr_dir )
     
     if filepath:
         if type(filepath) == tuple:
             filepath = filepath[0]
         self.setFilepath(nativestring(filepath))
     elif filepaths:
         self.setFilepaths(map(str, filepaths))
コード例 #9
0
ファイル: xiconbutton.py プロジェクト: zengjunfeng/projexui
 def dropEvent( self, event ):
     """
     Handles a drop event.
     """
     url  = event.mimeData().urls()[0]
     url_path = nativestring(url.toString())
     
     # download an icon from the web
     if ( not url_path.startswith('file:') ):
         filename = os.path.basename(url_path)
         temp_path = os.path.join(nativestring(QDir.tempPath()), filename)
         
         try:
             urllib.urlretrieve(url_path, temp_path)
         except IOError:
             return
         
         self.setFilepath(temp_path)
     else:
         self.setFilepath(url_path.replace('file://', ''))
コード例 #10
0
    def saveAs(self, filename=''):
        """
        Saves the current document to the inputed filename.  If no filename \
        is supplied, then the user will be prompted to supply a filename.
        
        :param      filename | <str>
        
        :return     <bool> | success
        """
        if (not (filename and isinstance(filename, basestring))):
            langTypes = XLanguage.pluginFileTypes()
            filename = QFileDialog.getSaveFileName(None, 'Save File As...',
                                                   QDir.currentPath(),
                                                   langTypes)

            if type(filename) == tuple:
                filename = nativestring(filename[0])

        if (not filename):
            return False

        docfile = QFile(filename)
        if (not docfile.open(QFile.WriteOnly)):
            logger.warning('Could not open %s for writing.' % filename)
            return False

        success = self.write(docfile)
        docfile.close()

        if success:
            filename = nativestring(filename)
            self._filename = filename

            self.setModified(False)

            # set the language
            lang = XLanguage.byFileType(os.path.splitext(filename)[1])
            if (lang != self.language()):
                self.setLanguage(lang)

        return success