Changeset 11522:425d83b20b96 in orange


Ignore:
Timestamp:
05/15/13 16:58:00 (11 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Handle QFileOpenEvent request events.

Location:
Orange/OrangeCanvas
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/application/application.py

    r11125 r11522  
    66from PyQt4.QtGui import QApplication 
    77 
    8 from PyQt4.QtCore import Qt 
     8from PyQt4.QtCore import Qt, QUrl, QEvent, pyqtSignal as Signal 
    99 
    1010 
    1111class CanvasApplication(QApplication): 
     12    fileOpenRequest = Signal(QUrl) 
     13 
    1214    def __init__(self, argv): 
    1315        QApplication.__init__(self, argv) 
    1416        self.setAttribute(Qt.AA_DontShowIconsInMenus, True) 
     17 
     18    def event(self, event): 
     19        if event.type() == QEvent.FileOpen: 
     20            self.fileOpenRequest.emit(event.url()) 
     21 
     22        return QApplication.event(self, event) 
  • Orange/OrangeCanvas/application/canvasmain.py

    r11518 r11522  
    880880        else: 
    881881            return QDialog.Rejected 
     882 
     883    def open_scheme_file(self, filename): 
     884        """ 
     885        Open and load a scheme file. 
     886        """ 
     887        if isinstance(filename, QUrl): 
     888            filename = filename.toLocalFile() 
     889 
     890        document = self.current_document() 
     891        if document.isModifiedStrict(): 
     892            if self.ask_save_changes() == QDialog.Rejected: 
     893                return QDialog.Rejected 
     894 
     895        self.load_scheme(filename) 
     896        return QDialog.Accepted 
    882897 
    883898    def load_scheme(self, filename): 
  • Orange/OrangeCanvas/main.py

    r11518 r11522  
    121121    log.debug("Starting CanvasApplicaiton with argv = %r.", qt_argv) 
    122122    app = CanvasApplication(qt_argv) 
     123 
     124    # intercept any QFileOpenEvent requests until the main window is 
     125    # fully initialized 
     126    open_requests = [] 
     127    app.fileOpenRequest.connect(open_requests.append) 
    123128 
    124129    # Note: config.init must be called after the QApplication constructor 
     
    231236    canvas_window.raise_() 
    232237 
    233     if want_welcome and not args: 
     238    if want_welcome and not args and not open_requests: 
    234239        # Process events to make sure the canvas_window layout has 
    235240        # a chance to activate (the welcome dialog is modal and will 
     
    242247                 args[0]) 
    243248        canvas_window.load_scheme(args[0]) 
     249    elif open_requests: 
     250        log.info("Loading a scheme from an `QFileOpenEvent` for %r", 
     251                 open_requests[-1]) 
     252        canvas_window.load_scheme(open_requests[-1].toLocalFile()) 
     253 
     254    app.fileOpenRequest.connect(canvas_window.open_scheme_file) 
    244255 
    245256    stdout_redirect = \ 
Note: See TracChangeset for help on using the changeset viewer.