Changeset 10462:f615f9bb8348 in orange


Ignore:
Timestamp:
03/07/12 20:34:41 (2 years ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
rebase_source:
e0e81317be7e94777360a2a0373960fc9889a2ac
Message:

Added unicode filename support for save/load widgets.

Location:
Orange/OrangeWidgets
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeWidgets/Data/OWFile.py

    r9671 r10462  
    1616 
    1717warnings.filterwarnings("error", ".*" , orange.KernelWarning, "OWFile", 11) 
    18  
    1918 
    2019class FileNameContextHandler(ContextHandler): 
     
    200199                startfile = self.recentFiles[0] 
    201200 
    202         filename = str(QFileDialog.getOpenFileName(self, 'Open Orange Data File', startfile, self.dlgFormats)) 
    203  
     201        filename = QFileDialog.getOpenFileName(self, 'Open Orange Data File', startfile, self.dlgFormats) 
     202        filename = unicode(filename) 
     203         
    204204        if filename == "": 
    205205            return 
  • Orange/OrangeWidgets/Data/OWPythonScript.py

    r9671 r10462  
    1313 
    1414import code 
     15 
    1516 
    1617class PythonSyntaxHighlighter(QSyntaxHighlighter): 
     
    431432    def onAddScriptFromFile(self, *args): 
    432433        file = QFileDialog.getOpenFileName(self, 'Open Python Script', self.codeFile, 'Python files (*.py)\nAll files(*.*)') 
     434        file = unicode(file) 
    433435        if file: 
    434             file = str(file) 
    435436            name = os.path.basename(file) 
    436437            self.libraryList.append(Script(name, open(file, "rb").read(), 0, file)) 
     
    493494    def openScript(self, filename=None): 
    494495        if filename == None: 
    495             self.codeFile = str(QFileDialog.getOpenFileName(self, 'Open Python Script', self.codeFile, 'Python files (*.py)\nAll files(*.*)'))     
     496            filename = unicode(QFileDialog.getOpenFileName(self, 'Open Python Script', 
     497                               self.codeFile, 'Python files (*.py)\nAll files(*.*)')) 
     498            self.codeFile = filename 
    496499        else: 
    497500            self.codeFile = filename 
     
    517520        else: 
    518521            filename = self.codeFile 
    519              
    520         self.codeFile = QFileDialog.getSaveFileName(self, 'Save Python Script', filename, 'Python files (*.py)\nAll files(*.*)') 
     522        filename = QFileDialog.getSaveFileName(self, 'Save Python Script', 
     523                            filename, 'Python files (*.py)\nAll files(*.*)')  
     524        self.codeFile = unicode(filename) 
    521525         
    522526        if self.codeFile: 
    523527            fn = "" 
    524             head, tail = os.path.splitext(str(self.codeFile)) 
     528            head, tail = os.path.splitext(self.codeFile) 
    525529            if not tail: 
    526530                fn = head + ".py" 
    527531            else: 
    528                 fn = str(self.codeFile) 
     532                fn = self.codeFile 
    529533             
    530534            f = open(fn, 'w') 
  • Orange/OrangeWidgets/Data/OWSave.py

    r9671 r10462  
    77""" 
    88 
    9 # 
    10 # OWFile.py 
    11 # The File Widget 
    12 # A widget for opening orange data files 
    13 # 
    149from OWWidget import * 
    1510import OWGUI 
     
    9186#       The following is a workaround. 
    9287#       (As a consequence, filter selection is not taken into account when appending a default extension.) 
    93         filename, selectedFilter = str(QFileDialog.getSaveFileName(self, 'Save Orange Data File', startfile, 
    94                          self.dlgFormats)), self.dlgFormats.split("\n")[0] 
    95  
     88        filename, selectedFilter = QFileDialog.getSaveFileName(self, 'Save Orange Data File', startfile, 
     89                         self.dlgFormats), self.dlgFormats.split("\n")[0] 
     90        filename = unicode(filename) 
    9691        if not filename or not os.path.split(filename)[1]: 
    9792            return 
     
    9994        ext = lower(os.path.splitext(filename)[1]) 
    10095        if not ext in self.savers: 
    101             filt_ext = self.re_filterExtension.search(str(str(selectedFilter))).group("ext") 
     96            filt_ext = self.re_filterExtension.search(str(selectedFilter)).group("ext") 
    10297            if filt_ext == ".*": 
    10398                filt_ext = ".tab" 
     
    105100 
    106101 
    107         self.addFileToList(str(filename)) 
     102        self.addFileToList(filename) 
    108103        self.saveFile() 
    109104 
     
    111106        self.error() 
    112107        if self.data is not None: 
    113             combotext = str(self.filecombo.currentText()) 
     108            combotext = unicode(self.filecombo.currentText()) 
    114109            if combotext == "(none)": 
    115110                QMessageBox.information( None, "Error saving data", "Unable to save data. Select first a file name by clicking the '...' button.", QMessageBox.Ok + QMessageBox.Default) 
     
    125120                return 
    126121            self.error() 
    127  
    128  
    129122 
    130123    def addFileToList(self,fn): 
  • Orange/OrangeWidgets/OWReport.py

    r9873 r10462  
    229229    def saveReport(self): 
    230230        filename = QFileDialog.getSaveFileName(self, "Save Report", self.saveDir, "Web page (*.html *.htm)") 
     231        filename = unicode(filename) 
     232         
    231233        if not filename: 
    232234            return 
    233  
    234         filename = str(filename) 
     235         
    235236        path, fname = os.path.split(filename) 
    236237        self.saveDir = path 
     
    287288    def saveXML(self): 
    288289        filename = QFileDialog.getSaveFileName(self, "Export Report", self.saveDir, "XML file (*.xml)") 
     290        filename = unicode(filename) 
    289291        if not filename: 
    290292            return 
    291293 
    292         outf = file(str(filename), "wt") 
     294        outf = file(filename, "wt") 
    293295        outf.write('<?xml version="1.0" encoding="ascii"?>\n<report version="1.0">\n') 
    294296         
     
    319321    def loadXML(self): 
    320322        filename = QFileDialog.getOpenFileName(self, "Import Report", self.saveDir, "XML file (*.xml)") 
     323        filename = unicode(filename) 
     324         
    321325        if not filename: 
    322326            return 
  • Orange/OrangeWidgets/Prototypes/OWLoadAssocRules.py

    r9671 r10462  
    6161        filename = QFileDialog.getOpenFileName(self, "Load Rules From File", 
    6262                        self.last_file, "Pickle files (*.pickle *.pck)\nAll files (*.*)") 
    63         filename = str(filename) 
     63        filename = unicode(filename) 
    6464        if filename: 
    6565            if filename in self.filename_history: 
  • Orange/OrangeWidgets/Prototypes/OWLoadClassifier.py

    r9671 r10462  
    77 
    88from OWWidget import * 
     9 
    910import OWGUI 
    1011import orange 
     
    6465        filename = QFileDialog.getOpenFileName(self, "Load Classifier From File", 
    6566                        self.lastFile, "Pickle files (*.pickle *.pck)\nAll files (*.*)") 
    66         filename = str(filename) 
     67        filename = unicode(filename) 
    6768        if filename: 
    6869            if filename in self.filenameHistory: 
  • Orange/OrangeWidgets/Prototypes/OWPickle.py

    r9671 r10462  
    6666        filename = QFileDialog.getSaveFileName(self, "Save Object As ...", 
    6767                    self.last_save_file, "Pickle files (*.pickle *.pck);; All files (*.*)") 
    68         filename = str(filename) 
     68        filename = unicode(filename) 
    6969        if filename: 
    7070            if filename in self.filename_history: 
  • Orange/OrangeWidgets/Prototypes/OWRScript.py

    r9671 r10462  
    66 
    77from OWWidget import * 
     8 
    89from OWPythonScript import OWPythonScript, Script, ScriptItemDelegate, PythonConsole 
    910from OWItemModels import PyListModel, ModelActionsWidget 
     
    304305         
    305306    def onAddScriptFromFile(self): 
    306         filename = str(QFileDialog.getOpenFileName(self, "Open script", self.lastDir)) 
     307        filename = QFileDialog.getOpenFileName(self, "Open script", self.lastDir) 
     308        filename = unicode(filename) 
    307309        if filename: 
    308310            script = open(filename, "rb").read() 
     
    315317        if row is not None: 
    316318            script = self.libraryModel[row] 
    317             filename = str(QFileDialog.getSaveFileName(self, "Save Script As", script.sourceFileName or self.lastDir)) 
     319            filename = QFileDialog.getSaveFileName(self, "Save Script As", script.sourceFileName or self.lastDir) 
     320            filename = unicode(filename) 
    318321            if filename: 
    319322                self.lastDir, name = os.path.split(filename) 
  • Orange/OrangeWidgets/Prototypes/OWSaveAssocRules.py

    r9671 r10462  
    6464        filename = QFileDialog.getSaveFileName(self, "Save Rules As ...", 
    6565                    self.last_save_file, "Pickle files (*.pickle *.pck);; All files (*.*)") 
    66         filename = str(filename) 
     66        filename = unicode(filename) 
    6767        if filename: 
    6868            if filename in self.filename_history: 
  • Orange/OrangeWidgets/Prototypes/OWSaveClassifier.py

    r9671 r10462  
    6969        filename = QFileDialog.getSaveFileName(self, "Save Classifier As ...", 
    7070                    self.lastSaveFile, "Pickle files (*.pickle *.pck);; All files (*.*)") 
    71         filename = str(filename) 
     71        filename = unicode(filename) 
    7272        if filename: 
    7373            if filename in self.filenameHistory: 
  • Orange/OrangeWidgets/Prototypes/OWUnpickle.py

    r9671 r10462  
    99from OWWidget import * 
    1010import OWGUI 
    11  
    1211 
    1312class OWUnpickle(OWWidget): 
     
    6463        filename = QFileDialog.getOpenFileName(self, "Load Object From File", 
    6564                        self.last_file, "Pickle files (*.pickle *.pck)\nAll files (*.*)") 
    66         filename = str(filename) 
     65        filename = unicode(filename) 
    6766        if filename: 
    6867            if filename in self.filename_history: 
Note: See TracChangeset for help on using the changeset viewer.