-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshrinkypic
More file actions
executable file
·162 lines (121 loc) · 5.62 KB
/
shrinkypic
File metadata and controls
executable file
·162 lines (121 loc) · 5.62 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2014, Dennis Drescher
# All rights reserved.
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should also have received a copy of the GNU Lesser General Public
# License along with this library in the file named "LICENSE".
# If not, write to the Free Software Foundation, 51 Franklin Street,
# suite 500, Boston, MA 02110-1335, USA or visit their web page on the
# internet at http://www.fsf.org/licenses/lgpl.html.
# Import modules
import sys, os, argparse
from PySide import QtGui
from PySide.QtGui import QDialog, QMessageBox, QApplication
from shrinkypic.dialog import main
from shrinkypic.process import im_process
from shrinkypic.icon.pyresources import qInitResources, qCleanupResources
# Set some global vars
systemName = 'ShrinkyPic'
systemVersion = '0.1.r26'
class ShrinkyPicMainForm (QDialog, main.Ui_MainWindow) :
def __init__ (self, parent=None) :
'''Initialize and start up the UI'''
super(ShrinkyPicMainForm, self).__init__(parent)
# Init app resources
qInitResources()
appicon = QtGui.QIcon(':/shrinkypic_256.png')
appicon.addFile(':/shrinkypic_96.png')
appicon.addFile(':/shrinkypic_48.png')
appicon.addFile(':/shrinkypic_32.png')
appicon.addFile(':/shrinkypic_16.png')
appicon.addFile(':/shrinkypic.svg')
self.setWindowIcon(appicon)
self.imProcess = im_process.ImProcess()
self.setupUi(self)
self.connectionActions()
def main (self) :
'''This function shows the main dialog'''
self.show()
def connectionActions (self) :
'''Connect to form buttons.'''
self.OkButton.clicked.connect(self.okClicked)
self.GetPictureButton.clicked.connect(self.getPictureFile)
def okClicked (self) :
'''Execute the OK button.'''
view = self.ViewCheckBox.isChecked()
outline = self.OutlineCheckBox.isChecked()
inFile = self.FileNameEdit.text()
caption = self.CaptionEdit.text()
size = self.SizeSelect.currentText()
rotate = self.RotationBox.text()
outFile = getOutfileName(inFile, size, str(rotate))
if os.path.exists(inFile) and os.path.splitext(inFile)[1].lower() in ['.jpg', '.png'] :
# Call the main class to do the work with the data we collected
self.imProcess.processPicFile(inFile, outFile, rotate, size, caption, outline, view)
else :
QMessageBox.warning(self, "Warning", 'Not valid intput file: ' + inFile)
def getPictureFile (self) :
'''Call a basic find file widget to get the file we want to process.'''
fileName = None
dialog = QtGui.QFileDialog(self, "Find a Picture")
dialog.setViewMode(QtGui.QFileDialog.Detail)
dialog.setAcceptMode(QtGui.QFileDialog.AcceptOpen)
dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
if dialog.exec_():
fileName = dialog.selectedFiles()[0]
# When the file is found, change the FileNameEdit text
self.FileNameEdit.setText(fileName)
# Global functions
def getOutfileName (inFile, size, rotate) :
(path, ext) = os.path.splitext(inFile)
(thisDir, fileName) = os.path.split(path)
return os.path.join(thisDir, fileName + '-' + size.capitalize() + '_' + str(rotate) + '.jpg')
###############################################################################
############################### Argparser Setup ###############################
###############################################################################
# The argument handler
def processUserArguments (args) :
'''Process incoming command arguments.'''
# Give a welcome message
print '\n\t\tWelcome to ' + systemName
print '\n\t\tVersion ' + systemVersion + '\n'
inFile = args.filename
rotate = args.rotate
size = args.size
caption = args.caption
outline = args.outline
view = True
outFile = getOutfileName(inFile, size, rotate)
im_process.ImProcess().processPicFile(inFile, outFile, rotate, size, caption, outline, view)
# Script starts running from here
if __name__ == '__main__' :
# Setup the arg parser
parser = argparse.ArgumentParser(description=systemName)
# Argument choices
trueFalse = ['True', 'true', 'False', 'false']
sizes = ['small', 'Small', 'medium', 'Medium', 'large', 'Large']
# Add main arguments (first postion options)
parser.add_argument('filename', help='The file to process (a positional argument required for all actions with this process)')
parser.add_argument('-c', '--caption', default='', help='A caption to add to the output files.')
parser.add_argument('-r', '--rotate', default=0, help='Degrees to rotate the output. Default is none.')
parser.add_argument('-s', '--size', default='small', choices=sizes, help='Size of the output, small, medium, or large.')
parser.add_argument('-o', '--outline', default=True, choices=trueFalse, help='Add a thin outline around the base picture.')
app = QApplication(sys.argv)
if len(sys.argv) == 1 :
window = ShrinkyPicMainForm()
window.main()
sys.exit(app.exec_())
else :
# Send the collected arguments to the handler
processUserArguments(parser.parse_args())