mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 01:58:41 -05:00
hide output of cml apps, make icon prettier
This commit is contained in:
parent
94e66e9972
commit
d7cd915655
4 changed files with 31 additions and 15 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 542 B After Width: | Height: | Size: 486 B |
3
todo
3
todo
|
|
@ -25,7 +25,8 @@ optipng for png and gif, jpegoptim for jpeg. both are available in ubuntu as dep
|
||||||
todo app wise
|
todo app wise
|
||||||
- implement threading
|
- implement threading
|
||||||
- errors need to go to standarderror
|
- errors need to go to standarderror
|
||||||
- make icon
|
- add file icon to table view
|
||||||
|
- hide jpegoptim from commandline
|
||||||
|
|
||||||
todo else
|
todo else
|
||||||
- figure out dependencies for a .deb/how to make a .deb
|
- figure out dependencies for a .deb/how to make a .deb
|
||||||
|
|
|
||||||
BIN
trimage-icon.png
BIN
trimage-icon.png
Binary file not shown.
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.4 KiB |
43
trimage.py
43
trimage.py
|
|
@ -2,6 +2,7 @@ import sys
|
||||||
from os import system
|
from os import system
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os import path
|
from os import path
|
||||||
|
from subprocess import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from hurry.filesize import *
|
from hurry.filesize import *
|
||||||
|
|
@ -49,9 +50,9 @@ class StartQT4(QMainWindow):
|
||||||
description="GUI front-end to compress png and jpg images via "
|
description="GUI front-end to compress png and jpg images via "
|
||||||
"optipng, advpng and jpegoptim")
|
"optipng, advpng and jpegoptim")
|
||||||
parser.add_option("-f", "--file", action="store", type="string",
|
parser.add_option("-f", "--file", action="store", type="string",
|
||||||
dest="filename", help="image to compress")
|
dest="filename", help="compresses image and exit")
|
||||||
parser.add_option("-d", "--directory", action="store", type="string",
|
parser.add_option("-d", "--directory", action="store", type="string",
|
||||||
dest="directory", help="directory of images to compress", )
|
dest="directory", help="compresses images in directory and exit", )
|
||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
|
|
@ -124,19 +125,26 @@ class StartQT4(QMainWindow):
|
||||||
|
|
||||||
#decide with tool to use
|
#decide with tool to use
|
||||||
if path.splitext(str(filename))[1].lower() in [".jpg", ".jpeg"]:
|
if path.splitext(str(filename))[1].lower() in [".jpg", ".jpeg"]:
|
||||||
runstr = 'jpegoptim --strip-all -f -q"' + str(filename) + '"'
|
runstr = 'jpegoptim -f --strip-all "' + str(filename) + '"'
|
||||||
runfile = system(runstr)
|
try:
|
||||||
|
retcode = call(runstr, shell=True, stdout=PIPE)
|
||||||
|
runfile = retcode
|
||||||
|
except OSError, e:
|
||||||
|
runfile = e
|
||||||
elif path.splitext(str(filename))[1].lower() in [".png"]:
|
elif path.splitext(str(filename))[1].lower() in [".png"]:
|
||||||
# don't do advpng yet
|
runstr = ('optipng -force -o7 "' + str(filename)
|
||||||
runstr = ('optipng -q -force -o7 "' + str(filename)
|
+ '"; advpng -z4 "' + str(filename) + '"')
|
||||||
+ '"; advpng -z4 -q "' + str(filename) + '"')
|
try:
|
||||||
#runstr = 'optipng -force -o7 "' + str(filename) + '"'
|
retcode = call(runstr, shell=True, stdout=PIPE)
|
||||||
runfile = system(runstr)
|
runfile = retcode
|
||||||
|
except OSError, e:
|
||||||
|
runfile = e
|
||||||
|
|
||||||
if runfile == 0:
|
if runfile == 0:
|
||||||
#gather new file data
|
#gather new file data
|
||||||
newfile = QFile(filename)
|
newfile = QFile(filename)
|
||||||
|
provider = QFileIconProvider()
|
||||||
|
newfileicon = provider.icon(QFileInfo(filename))
|
||||||
newfilesize = newfile.size()
|
newfilesize = newfile.size()
|
||||||
newfilesizestr = size(newfilesize, system=alternative)
|
newfilesizestr = size(newfilesize, system=alternative)
|
||||||
|
|
||||||
|
|
@ -146,9 +154,15 @@ class StartQT4(QMainWindow):
|
||||||
|
|
||||||
# append current image to list
|
# append current image to list
|
||||||
self.imagelist.append(
|
self.imagelist.append(
|
||||||
(name, oldfilesizestr, newfilesizestr, ratiostr, filename))
|
(newfileicon, name, oldfilesizestr, newfilesizestr, ratiostr,
|
||||||
|
filename))
|
||||||
self.update_table()
|
self.update_table()
|
||||||
|
|
||||||
|
if self.showapp != True:
|
||||||
|
# we work via the commandline
|
||||||
|
print("File:" + filename + ", Old Size:" + oldfilesizestr +
|
||||||
|
", New Size:" + newfilesizestr + ", Ratio:" + ratiostr)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# TODO nice error recovery
|
# TODO nice error recovery
|
||||||
print("uh. not good")
|
print("uh. not good")
|
||||||
|
|
@ -159,7 +173,7 @@ class StartQT4(QMainWindow):
|
||||||
|
|
||||||
# set table model
|
# set table model
|
||||||
tmodel = TriTableModel(self, self.imagelist,
|
tmodel = TriTableModel(self, self.imagelist,
|
||||||
["Filename", "Old Size", "New Size", "Compressed"])
|
["", "Filename", "Old Size", "New Size", "Compressed"])
|
||||||
tview.setModel(tmodel)
|
tview.setModel(tmodel)
|
||||||
|
|
||||||
# set minimum size of table
|
# set minimum size of table
|
||||||
|
|
@ -175,8 +189,9 @@ class StartQT4(QMainWindow):
|
||||||
for row in range(nrows):
|
for row in range(nrows):
|
||||||
tview.setRowHeight(row, 25)
|
tview.setRowHeight(row, 25)
|
||||||
|
|
||||||
# set the first column to be longest
|
# set the second column to be longest
|
||||||
tview.setColumnWidth(0, 300)
|
tview.setColumnWidth(0, 30)
|
||||||
|
tview.setColumnWidth(1, 280)
|
||||||
|
|
||||||
# enable recompress button
|
# enable recompress button
|
||||||
self.enable_recompress()
|
self.enable_recompress()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue