This repository has been archived by the owner on Jan 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyview.py
executable file
·94 lines (70 loc) · 2.12 KB
/
pyview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# pyview Image Viewer
# Main entry point
import sys
from PyQt4 import QtGui, QtCore
from gui.MainWindow import MainWindow
from CommandLine import CommandLine
from FolderHelper import FolderHelper
import Version
import ImageFormats
# Translates a string
def tr(string):
"""
This helper function is used to translates strings in the pyview scope.
"""
translated = QtCore.QCoreApplication.translate("pyview", string)
return str(translated)
# Version
class LocalizedVersion:
APPNAME = Version.APP_NAME
APPTITLE = tr("Image Viewer")
APPVERSION = Version.APP_VERSION
DESCRIPTION = tr(Version.DESCRIPTION)
# Main Entry point
def main():
"""The pyview main entry point"""
global folderHelper, window
# Build command line parser
cmdLine = CommandLine(LocalizedVersion())
options = cmdLine.getOptions()
# Load image format plugins
ImageFormats.loadImageFormatPlugins()
# Get initial directory
folderHelper = FolderHelper(options)
folderHelper.setLastOpenedFile(options.initialFile)
startDir = folderHelper.getFileDialogInitialDirectory()
# Get and configure App object
app = QtGui.QApplication(sys.argv)
#QtGui.QApplication.setStyle(QtGui.QStyleFactory.create("Cleanlooks"))
# Create and set window
window = MainWindow()
window.setFileDialogDirectory(startDir)
window.centerWindow()
# Connections
window.connect(window, QtCore.SIGNAL("openFileFinished(char*, bool)"), onFileLoaded)
# Show the window
window.show()
# Load initial file
if options.initialFile:
window.openFile(options.initialFile)
# Start the application
return app.exec_()
# Callback to set the dialog startup path whenever an image is loaded
def onFileLoaded(filepath, success):
"""
Is invoked through the event system and sets the
startup path for file dialogs whenever and image was loaded
"""
global folderHelper, window
# Set the last path
folderHelper.setLastOpenedFile(filepath)
# Get and set the new path
path = folderHelper.getFileDialogInitialDirectory()
window.setFileDialogDirectory(path)
return
# System entry point
if __name__ == "__main__":
# Spank me
sys.exit(main())