|
@@ -1,9 +1,11 @@
|
|
#!/usr/bin/env python
|
|
#!/usr/bin/env python
|
|
# -*- coding: utf8 -*-
|
|
# -*- coding: utf8 -*-
|
|
|
|
|
|
|
|
+import os.path
|
|
import re
|
|
import re
|
|
import sys
|
|
import sys
|
|
|
|
|
|
|
|
+from functools import partial
|
|
from collections import defaultdict
|
|
from collections import defaultdict
|
|
|
|
|
|
from PyQt4.QtGui import *
|
|
from PyQt4.QtGui import *
|
|
@@ -60,7 +62,7 @@ class WindowMixin(object):
|
|
|
|
|
|
|
|
|
|
class MainWindow(QMainWindow, WindowMixin):
|
|
class MainWindow(QMainWindow, WindowMixin):
|
|
- def __init__(self):
|
|
|
|
|
|
+ def __init__(self, filename=None):
|
|
super(MainWindow, self).__init__()
|
|
super(MainWindow, self).__init__()
|
|
self.setWindowTitle(__appname__)
|
|
self.setWindowTitle(__appname__)
|
|
|
|
|
|
@@ -91,7 +93,8 @@ class MainWindow(QMainWindow, WindowMixin):
|
|
self.statusBar().show()
|
|
self.statusBar().show()
|
|
|
|
|
|
# Application state.
|
|
# Application state.
|
|
- self.filename = ''
|
|
|
|
|
|
+ self.image = QImage()
|
|
|
|
+ self.filename = filename
|
|
self.recent_files = []
|
|
self.recent_files = []
|
|
|
|
|
|
# TODO: Could be completely declarative.
|
|
# TODO: Could be completely declarative.
|
|
@@ -118,7 +121,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|
# The file menu has default dynamically generated entries.
|
|
# The file menu has default dynamically generated entries.
|
|
self.updateFileMenu()
|
|
self.updateFileMenu()
|
|
# Since loading the file may take some time, make sure it runs in the background.
|
|
# Since loading the file may take some time, make sure it runs in the background.
|
|
- self.queueEvent(self.loadFile)
|
|
|
|
|
|
+ self.queueEvent(partial(self.loadFile, self.filename))
|
|
|
|
|
|
def queueEvent(self, function):
|
|
def queueEvent(self, function):
|
|
QTimer.singleShot(0, function)
|
|
QTimer.singleShot(0, function)
|
|
@@ -135,15 +138,16 @@ class MainWindow(QMainWindow, WindowMixin):
|
|
message = "Failed to read %s" % filename
|
|
message = "Failed to read %s" % filename
|
|
else:
|
|
else:
|
|
message = "Loaded %s" % os.path.basename(unicode(filename))
|
|
message = "Loaded %s" % os.path.basename(unicode(filename))
|
|
- self.showImage()
|
|
|
|
self.image = image
|
|
self.image = image
|
|
self.filename = filename
|
|
self.filename = filename
|
|
|
|
+ self.showImage()
|
|
self.statusBar().showMessage(message)
|
|
self.statusBar().showMessage(message)
|
|
|
|
|
|
def showImage(self):
|
|
def showImage(self):
|
|
if self.image.isNull():
|
|
if self.image.isNull():
|
|
return
|
|
return
|
|
self.imageWidget.setPixmap(QPixmap.fromImage(self.image))
|
|
self.imageWidget.setPixmap(QPixmap.fromImage(self.image))
|
|
|
|
+ self.imageWidget.show()
|
|
|
|
|
|
def closeEvent(self, event):
|
|
def closeEvent(self, event):
|
|
# TODO: Make sure changes are saved.
|
|
# TODO: Make sure changes are saved.
|
|
@@ -190,7 +194,7 @@ def main(argv):
|
|
"""Standard boilerplate Qt application code."""
|
|
"""Standard boilerplate Qt application code."""
|
|
app = QApplication(argv)
|
|
app = QApplication(argv)
|
|
app.setApplicationName(__appname__)
|
|
app.setApplicationName(__appname__)
|
|
- win = MainWindow()
|
|
|
|
|
|
+ win = MainWindow(argv[1] if len(argv) == 2 else None)
|
|
win.show()
|
|
win.show()
|
|
return app.exec_()
|
|
return app.exec_()
|
|
|
|
|