|
From: <dom...@us...> - 2010-08-04 15:47:30
|
Revision: 58
http://kbarcode.svn.sourceforge.net/kbarcode/?rev=58&view=rev
Author: domseichter
Date: 2010-08-04 15:47:24 +0000 (Wed, 04 Aug 2010)
Log Message:
-----------
Minor fixes
Modified Paths:
--------------
kbarcode4-light/trunk/src/ghostscript.py
kbarcode4-light/trunk/src/kbarcode.py
kbarcode4-light/trunk/src/purepostscript.py
Modified: kbarcode4-light/trunk/src/ghostscript.py
===================================================================
--- kbarcode4-light/trunk/src/ghostscript.py 2010-08-04 15:23:04 UTC (rev 57)
+++ kbarcode4-light/trunk/src/ghostscript.py 2010-08-04 15:47:24 UTC (rev 58)
@@ -23,7 +23,7 @@
def ghostscriptGetBoundingBox(postscript):
name = writeToTempFile(postscript)
- args = [ "gs", "-sDEVICE=bbox", "-sNOPAUSE", "-q" , name, "-c", "showpage", "quit"]
+ args = [ "gs", "-dSAFER", "-sDEVICE=bbox", "-sNOPAUSE", "-q" , name, "-c", "showpage", "quit"]
p = subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
data = p.communicate()[0]
if p.wait() != 0:
@@ -33,8 +33,8 @@
os.unlink(name)
for line in data.splitlines():
- if line.startswith("%%BoundingBox:"):
- values = map(int, line[15:].split())
+ if line.startswith("%%HiResBoundingBox:"):
+ values = map(float, line[20:].split())
return values
return [0, 0, 0, 0]
@@ -59,13 +59,13 @@
def ghostscriptCreatePixmap(postscript, scalex, scaley, resx, resy):
size = ghostscriptGetBoundingBox(postscript)
width = (getXFromArray(size) + getWidthFromArray(size)) / 72.0 * resx
- height= (getYFromArray(size) + getHeightFromArray(size)) / 72.0 * resy
-
+ height= (getHeightFromArray(size)) / 72.0 * resy
+
print size
name = writeToTempFile(postscript)
args = [ "gs", "-g" + str(int(width * scalex)) + "x" + str(int(height * scaley)),
"-r" + str(resx * scalex) + "x" + str(resy * scaley),
- "-sOutputFile=-", "-sDEVICE=ppm",
+ "-sOutputFile=-", "-sDEVICE=ppm", "-dSAFER",
"-sNOPAUSE", "-q", name, "-c", "showpage", "quit" ]
p = subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
data = p.communicate()[0]
Modified: kbarcode4-light/trunk/src/kbarcode.py
===================================================================
--- kbarcode4-light/trunk/src/kbarcode.py 2010-08-04 15:23:04 UTC (rev 57)
+++ kbarcode4-light/trunk/src/kbarcode.py 2010-08-04 15:47:24 UTC (rev 58)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+ #!/usr/bin/python
# kbarcode.py
#
Modified: kbarcode4-light/trunk/src/purepostscript.py
===================================================================
--- kbarcode4-light/trunk/src/purepostscript.py 2010-08-04 15:23:04 UTC (rev 57)
+++ kbarcode4-light/trunk/src/purepostscript.py 2010-08-04 15:47:24 UTC (rev 58)
@@ -79,14 +79,16 @@
program = program + str(rotation) + " rotate\n"
program = program +" gsave\n"
if textVisible:
- program = program + "0 10 moveto\n"
+ # Ghostscripts bbox device cannot work with negative coordinates
+ # so we have to move the text to positives coordinates
+ program = program + " 0 11 moveto\n"
else:
- program = program + "0 0 moveto\n"
+ program = program + " 0 0 moveto\n"
program = program + "(" + value + ") (" + options + ") " + encoding + " barcode grestore\n"
- #tmp = open("/home/dominik/latest.ps", 'w')
- #tmp.write(program)
- #tmp.close()
+ tmp = open("/home/dominik/latest.ps", 'w')
+ tmp.write(program)
+ tmp.close()
picture = ghostscript.ghostscriptCreatePixmap(program, 1.0, 1.0, 96, 96)
return picture
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dom...@us...> - 2010-08-07 16:15:57
|
Revision: 60
http://kbarcode.svn.sourceforge.net/kbarcode/?rev=60&view=rev
Author: domseichter
Date: 2010-08-07 16:15:50 +0000 (Sat, 07 Aug 2010)
Log Message:
-----------
Barcode is now a class
Support for rotation and setting the resolution
Modified Paths:
--------------
kbarcode4-light/trunk/src/Ui_barcodedialog.py
kbarcode4-light/trunk/src/barcode.py
kbarcode4-light/trunk/src/kbarcode.py
kbarcode4-light/trunk/src/purepostscript.py
Modified: kbarcode4-light/trunk/src/Ui_barcodedialog.py
===================================================================
--- kbarcode4-light/trunk/src/Ui_barcodedialog.py 2010-08-07 16:08:27 UTC (rev 59)
+++ kbarcode4-light/trunk/src/Ui_barcodedialog.py 2010-08-07 16:15:50 UTC (rev 60)
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file '/home/dominik/Desktop/Programming/kbarcode/kbarcode4-light/src/barcodedialog.ui'
#
-# Created: Wed Aug 4 15:59:39 2010
+# Created: Sat Aug 7 17:07:10 2010
# by: PyQt4 UI code generator 4.6
#
# WARNING! All changes made in this file will be lost!
@@ -12,7 +12,7 @@
class Ui_BarcodeDialog(object):
def setupUi(self, BarcodeDialog):
BarcodeDialog.setObjectName("BarcodeDialog")
- BarcodeDialog.resize(546, 574)
+ BarcodeDialog.resize(552, 474)
self.horizontalLayout = QtGui.QHBoxLayout(BarcodeDialog)
self.horizontalLayout.setObjectName("horizontalLayout")
self.verticalLayout = QtGui.QVBoxLayout()
@@ -65,10 +65,11 @@
self.label_5 = QtGui.QLabel(BarcodeDialog)
self.label_5.setObjectName("label_5")
self.grid.addWidget(self.label_5, 6, 0, 1, 1)
- self.spinHeight = QtGui.QSpinBox(BarcodeDialog)
- self.spinHeight.setMaximum(100)
- self.spinHeight.setObjectName("spinHeight")
- self.grid.addWidget(self.spinHeight, 6, 1, 1, 1)
+ self.spinResolution = QtGui.QSpinBox(BarcodeDialog)
+ self.spinResolution.setMinimum(72)
+ self.spinResolution.setMaximum(2400)
+ self.spinResolution.setObjectName("spinResolution")
+ self.grid.addWidget(self.spinResolution, 6, 1, 1, 1)
self.checkChecksum = QtGui.QCheckBox(BarcodeDialog)
self.checkChecksum.setObjectName("checkChecksum")
self.grid.addWidget(self.checkChecksum, 3, 1, 1, 1)
@@ -81,7 +82,7 @@
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea)
- self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 420, 120))
+ self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 426, 191))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_3 = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_3.setObjectName("verticalLayout_3")
@@ -91,8 +92,6 @@
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout_2.addWidget(self.scrollArea)
self.verticalLayout.addWidget(self.groupBox)
- spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
- self.verticalLayout.addItem(spacerItem)
self.horizontalLayout.addLayout(self.verticalLayout)
self.buttonBox = QtGui.QDialogButtonBox(BarcodeDialog)
self.buttonBox.setOrientation(QtCore.Qt.Vertical)
@@ -104,7 +103,7 @@
self.label_2.setBuddy(self.value)
self.label_3.setBuddy(self.spinBorder)
self.label_4.setBuddy(self.spinRotation)
- self.label_5.setBuddy(self.spinHeight)
+ self.label_5.setBuddy(self.spinResolution)
self.retranslateUi(BarcodeDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), BarcodeDialog.reject)
@@ -120,8 +119,8 @@
self.label_4.setText(QtGui.QApplication.translate("BarcodeDialog", "&Rotation:", None, QtGui.QApplication.UnicodeUTF8))
self.labelExample.setText(QtGui.QApplication.translate("BarcodeDialog", "Example:", None, QtGui.QApplication.UnicodeUTF8))
self.exampleValue.setText(QtGui.QApplication.translate("BarcodeDialog", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
- self.label_5.setText(QtGui.QApplication.translate("BarcodeDialog", "&Height:", None, QtGui.QApplication.UnicodeUTF8))
- self.spinHeight.setSuffix(QtGui.QApplication.translate("BarcodeDialog", "%", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_5.setText(QtGui.QApplication.translate("BarcodeDialog", "&Resolution:", None, QtGui.QApplication.UnicodeUTF8))
+ self.spinResolution.setSuffix(QtGui.QApplication.translate("BarcodeDialog", "dpi", None, QtGui.QApplication.UnicodeUTF8))
self.checkChecksum.setText(QtGui.QApplication.translate("BarcodeDialog", "&Include check sum", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox.setTitle(QtGui.QApplication.translate("BarcodeDialog", "&Barcode", None, QtGui.QApplication.UnicodeUTF8))
Modified: kbarcode4-light/trunk/src/barcode.py
===================================================================
--- kbarcode4-light/trunk/src/barcode.py 2010-08-07 16:08:27 UTC (rev 59)
+++ kbarcode4-light/trunk/src/barcode.py 2010-08-07 16:15:50 UTC (rev 60)
@@ -1,19 +1,50 @@
#!/usr/bin/python
# barcode.py
-#
-# Barcode generation routines
import sys
from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+import purepostscript
class Barcode:
+
def __init__(self, parent=None):
- self.encodings = [ "code39", "code128", "ean" ]
self.value = ""
- self.encoding = ""
+ self.textVisible = True
+ self.checksumVisible = True
+ self.rotation = 0
+ self.dpi = 72
+ self.encoding = None
+ self.imageData = None
+
+ self._valid = False
+
+ """Generate a barcode from the values that have been set"""
+ def generate(self):
+ e = self.encoding['encoding']
+ self.imageData = purepostscript.createPurePostscriptBarcode(self.value, e, self.textVisible, self.checksumVisible, self.dpi)
+ self._valid = self.imageData != None
+
+
+ """Returns True if this object contains a valid barcode at the moment."""
+ def isValid(self):
+ return self._valid
+
+ """Return the generated barcode as a QImage"""
+ def image(self):
+ if self._valid == False:
+ return QImage()
+
+ image = QImage()
+ if image.loadFromData(self.imageData) == False:
+ return QImage()
- def generateBarcode(self):
- print "Generating : ", self.value, " ", self.encoding
-
- return "GNU Barcode not found"
+ if self.rotation != 0:
+ matrix = QMatrix()
+ matrix.rotate(self.rotation)
+ image = image.transformed(matrix, Qt.SmoothTransformation)
+
+ return image
+
+
Modified: kbarcode4-light/trunk/src/kbarcode.py
===================================================================
--- kbarcode4-light/trunk/src/kbarcode.py 2010-08-07 16:08:27 UTC (rev 59)
+++ kbarcode4-light/trunk/src/kbarcode.py 2010-08-07 16:15:50 UTC (rev 60)
@@ -16,22 +16,26 @@
def __init__(self, parent=None):
QDialog.__init__(self, parent)
-
+
+ self.barcode = Barcode()
+
self.setupUi(self)
self.setWindowTitle(self.tr("KBarcode"))
self.setWindowIcon(QIcon('pics/hi64-app-kbarcode.png'))
self.generateButton = self.buttonBox.addButton("&Generate", QDialogButtonBox.ActionRole)
+ self.copyButton = self.buttonBox.addButton("&Copy", QDialogButtonBox.ActionRole)
self.saveButton = self.buttonBox.button(QDialogButtonBox.Save)
self.connect(self.generateButton, SIGNAL("clicked()"), self.slotGenerate)
+ self.connect(self.copyButton, SIGNAL("clicked()"), self.slotCopy)
self.connect(self.saveButton, SIGNAL("clicked()"), self.slotSave)
self.connect(self.comboEncoding, SIGNAL("currentIndexChanged(int)"), self.slotUpdateExample)
for e in self.encodings:
self.comboEncoding.addItem(e['description'], e['encoding'])
- self.saveButton.setEnabled(False)
+ self.enableButtons(False)
self.slotUpdateExample(self.comboEncoding.currentIndex())
self.value.selectAll()
@@ -51,24 +55,22 @@
e = str(self.comboEncoding.itemData(self.comboEncoding.currentIndex()).toString())
encoding = filter(lambda enc: enc['encoding'] == e, self.encodings)[0]
- value = self.value.text()
- textVisible = self.checkText.isEnabled() and self.checkText.isChecked()
- checksumVisible = self.checkChecksum.isEnabled() and self.checkChecksum.isChecked()
- rotation = self.spinRotation.value()
- height = self.spinHeight.value()
+ self.barcode.value = self.value.text()
+ self.barcode.encoding = encoding
+ self.barcode.textVisible = self.checkText.isEnabled() and self.checkText.isChecked()
+ self.barcode.checksumVisible = self.checkChecksum.isEnabled() and self.checkChecksum.isChecked()
+ self.barcode.rotation = self.spinRotation.value()
+ self.barcode.dpi = self.spinResolution.value()
- imageData = purepostscript.createPurePostscriptBarcode(value, e, textVisible, checksumVisible, rotation, height)
- self.saveButton.setEnabled(False)
- if imageData != None:
- image = QImage()
- if image.loadFromData(imageData):
- self.display.setPixmap(QPixmap(image))
- self.saveButton.setEnabled(True)
- else:
- QMessageBox.critical(self, self.tr("KBarcode"),
- self.tr("Error during image loading.") )
+ self.barcode.generate()
+ self.enableButtons(self.barcode.isValid())
+
+ if self.barcode.isValid() != False:
+ image = self.barcode.image()
+ self.display.setPixmap(QPixmap(image))
+ self.enableButtons(True)
else:
- QMessageBox.critical(self, self.tr("KBarcode"),
+ QMessageBox.critical(self, self.tr("KBarcode"),
self.tr("Error during barcode generation.") )
def slotSave(self):
@@ -88,9 +90,16 @@
else:
QMessageBox.information(self, self.tr("KBarcode"),
filename + " " + filter)
+
+ """Copy the generated barcode to the clipboard"""
+ def slotCopy(self):
+ QApplication.clipboard().setImage(self.barcode.image())
+ """Enable or disable all buttons that are only allowed to be enabled if there is a valid barcode"""
+ def enableButtons(self, state):
+ self.saveButton.setEnabled(state)
+ self.copyButton.setEnabled(state)
-
#
# main
#
Modified: kbarcode4-light/trunk/src/purepostscript.py
===================================================================
--- kbarcode4-light/trunk/src/purepostscript.py 2010-08-07 16:08:27 UTC (rev 59)
+++ kbarcode4-light/trunk/src/purepostscript.py 2010-08-07 16:15:50 UTC (rev 60)
@@ -55,7 +55,7 @@
def hasChecksum(encoding):
return (encoding['extra'].find("includecheck") != -1)
-def createPurePostscriptBarcode(value, encoding, textVisible, checksumVisible, rotation, height):
+def createPurePostscriptBarcode(value, encoding, textVisible, checksumVisible, resolution):
showText= ""
showCheck= ""
foreground = [0, 0, 0]
@@ -76,7 +76,6 @@
program = "%!PS-Adobe-2.0 EPSF-2.0\n%%EndComments\n%%EndProlog\n"
program = program + getBarcodeWriterInPurePostscript() + "\n"
- program = program + str(rotation) + " rotate\n"
program = program +" gsave\n"
if textVisible:
# Ghostscripts bbox device cannot work with negative coordinates
@@ -90,7 +89,7 @@
tmp.write(program)
tmp.close()
- picture = ghostscript.ghostscriptCreatePixmap(program, 1.0, 1.0, 96, 96)
+ picture = ghostscript.ghostscriptCreatePixmap(program, 1.0, 1.0, resolution, resolution)
return picture
# TODO
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dom...@us...> - 2010-08-07 16:56:29
|
Revision: 61
http://kbarcode.svn.sourceforge.net/kbarcode/?rev=61&view=rev
Author: domseichter
Date: 2010-08-07 16:56:22 +0000 (Sat, 07 Aug 2010)
Log Message:
-----------
ADDED: Color support
Modified Paths:
--------------
kbarcode4-light/trunk/src/Ui_barcodedialog.py
kbarcode4-light/trunk/src/barcode.py
kbarcode4-light/trunk/src/barcodedialog.ui
kbarcode4-light/trunk/src/kbarcode.py
kbarcode4-light/trunk/src/purepostscript.py
Modified: kbarcode4-light/trunk/src/Ui_barcodedialog.py
===================================================================
--- kbarcode4-light/trunk/src/Ui_barcodedialog.py 2010-08-07 16:15:50 UTC (rev 60)
+++ kbarcode4-light/trunk/src/Ui_barcodedialog.py 2010-08-07 16:56:22 UTC (rev 61)
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file '/home/dominik/Desktop/Programming/kbarcode/kbarcode4-light/src/barcodedialog.ui'
#
-# Created: Sat Aug 7 17:07:10 2010
+# Created: Sat Aug 7 17:35:41 2010
# by: PyQt4 UI code generator 4.6
#
# WARNING! All changes made in this file will be lost!
@@ -31,26 +31,9 @@
self.value = QtGui.QLineEdit(BarcodeDialog)
self.value.setObjectName("value")
self.grid.addWidget(self.value, 1, 1, 1, 1)
- self.checkText = QtGui.QCheckBox(BarcodeDialog)
- self.checkText.setObjectName("checkText")
- self.grid.addWidget(self.checkText, 2, 1, 1, 1)
- self.spinBorder = QtGui.QSpinBox(BarcodeDialog)
- self.spinBorder.setMaximum(1000)
- self.spinBorder.setObjectName("spinBorder")
- self.grid.addWidget(self.spinBorder, 4, 1, 1, 1)
- self.spinRotation = QtGui.QSpinBox(BarcodeDialog)
- self.spinRotation.setMaximum(359)
- self.spinRotation.setObjectName("spinRotation")
- self.grid.addWidget(self.spinRotation, 5, 1, 1, 1)
- self.label_3 = QtGui.QLabel(BarcodeDialog)
- self.label_3.setObjectName("label_3")
- self.grid.addWidget(self.label_3, 4, 0, 1, 1)
- self.label_4 = QtGui.QLabel(BarcodeDialog)
- self.label_4.setObjectName("label_4")
- self.grid.addWidget(self.label_4, 5, 0, 1, 1)
self.labelExample = QtGui.QLabel(BarcodeDialog)
self.labelExample.setObjectName("labelExample")
- self.grid.addWidget(self.labelExample, 7, 0, 1, 1)
+ self.grid.addWidget(self.labelExample, 6, 0, 1, 1)
self.exampleValue = QtGui.QLabel(BarcodeDialog)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
@@ -61,19 +44,77 @@
self.exampleValue.setWordWrap(True)
self.exampleValue.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse)
self.exampleValue.setObjectName("exampleValue")
- self.grid.addWidget(self.exampleValue, 7, 1, 1, 1)
- self.label_5 = QtGui.QLabel(BarcodeDialog)
+ self.grid.addWidget(self.exampleValue, 6, 1, 1, 1)
+ self.verticalLayout.addLayout(self.grid)
+ self.tabWidget = QtGui.QTabWidget(BarcodeDialog)
+ self.tabWidget.setObjectName("tabWidget")
+ self.tab = QtGui.QWidget()
+ self.tab.setObjectName("tab")
+ self.horizontalLayout_2 = QtGui.QHBoxLayout(self.tab)
+ self.horizontalLayout_2.setObjectName("horizontalLayout_2")
+ self.gridLayout = QtGui.QGridLayout()
+ self.gridLayout.setObjectName("gridLayout")
+ self.checkText = QtGui.QCheckBox(self.tab)
+ self.checkText.setObjectName("checkText")
+ self.gridLayout.addWidget(self.checkText, 0, 1, 1, 1)
+ self.checkChecksum = QtGui.QCheckBox(self.tab)
+ self.checkChecksum.setObjectName("checkChecksum")
+ self.gridLayout.addWidget(self.checkChecksum, 1, 1, 1, 1)
+ self.label_3 = QtGui.QLabel(self.tab)
+ self.label_3.setObjectName("label_3")
+ self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1)
+ self.spinBorder = QtGui.QSpinBox(self.tab)
+ self.spinBorder.setMaximum(1000)
+ self.spinBorder.setObjectName("spinBorder")
+ self.gridLayout.addWidget(self.spinBorder, 2, 1, 1, 1)
+ self.label_4 = QtGui.QLabel(self.tab)
+ self.label_4.setObjectName("label_4")
+ self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1)
+ self.spinRotation = QtGui.QSpinBox(self.tab)
+ self.spinRotation.setMaximum(359)
+ self.spinRotation.setObjectName("spinRotation")
+ self.gridLayout.addWidget(self.spinRotation, 3, 1, 1, 1)
+ self.label_5 = QtGui.QLabel(self.tab)
self.label_5.setObjectName("label_5")
- self.grid.addWidget(self.label_5, 6, 0, 1, 1)
- self.spinResolution = QtGui.QSpinBox(BarcodeDialog)
+ self.gridLayout.addWidget(self.label_5, 4, 0, 1, 1)
+ self.spinResolution = QtGui.QSpinBox(self.tab)
self.spinResolution.setMinimum(72)
self.spinResolution.setMaximum(2400)
self.spinResolution.setObjectName("spinResolution")
- self.grid.addWidget(self.spinResolution, 6, 1, 1, 1)
- self.checkChecksum = QtGui.QCheckBox(BarcodeDialog)
- self.checkChecksum.setObjectName("checkChecksum")
- self.grid.addWidget(self.checkChecksum, 3, 1, 1, 1)
- self.verticalLayout.addLayout(self.grid)
+ self.gridLayout.addWidget(self.spinResolution, 4, 1, 1, 1)
+ self.horizontalLayout_2.addLayout(self.gridLayout)
+ spacerItem = QtGui.QSpacerItem(209, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
+ self.horizontalLayout_2.addItem(spacerItem)
+ self.tabWidget.addTab(self.tab, "")
+ self.tab_2 = QtGui.QWidget()
+ self.tab_2.setObjectName("tab_2")
+ self.horizontalLayout_3 = QtGui.QHBoxLayout(self.tab_2)
+ self.horizontalLayout_3.setObjectName("horizontalLayout_3")
+ self.gridLayout_2 = QtGui.QGridLayout()
+ self.gridLayout_2.setObjectName("gridLayout_2")
+ self.label_6 = QtGui.QLabel(self.tab_2)
+ self.label_6.setObjectName("label_6")
+ self.gridLayout_2.addWidget(self.label_6, 0, 0, 1, 1)
+ self.buttonForeground = ColorButton(self.tab_2)
+ self.buttonForeground.setObjectName("buttonForeground")
+ self.gridLayout_2.addWidget(self.buttonForeground, 0, 1, 1, 1)
+ self.label_7 = QtGui.QLabel(self.tab_2)
+ self.label_7.setObjectName("label_7")
+ self.gridLayout_2.addWidget(self.label_7, 1, 0, 1, 1)
+ self.buttonBackground = ColorButton(self.tab_2)
+ self.buttonBackground.setObjectName("buttonBackground")
+ self.gridLayout_2.addWidget(self.buttonBackground, 1, 1, 1, 1)
+ self.label_8 = QtGui.QLabel(self.tab_2)
+ self.label_8.setObjectName("label_8")
+ self.gridLayout_2.addWidget(self.label_8, 2, 0, 1, 1)
+ self.buttonText = ColorButton(self.tab_2)
+ self.buttonText.setObjectName("buttonText")
+ self.gridLayout_2.addWidget(self.buttonText, 2, 1, 1, 1)
+ self.horizontalLayout_3.addLayout(self.gridLayout_2)
+ spacerItem1 = QtGui.QSpacerItem(191, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
+ self.horizontalLayout_3.addItem(spacerItem1)
+ self.tabWidget.addTab(self.tab_2, "")
+ self.verticalLayout.addWidget(self.tabWidget)
self.groupBox = QtGui.QGroupBox(BarcodeDialog)
self.groupBox.setObjectName("groupBox")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox)
@@ -82,7 +123,7 @@
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea)
- self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 426, 191))
+ self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 426, 141))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_3 = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_3.setObjectName("verticalLayout_3")
@@ -104,8 +145,12 @@
self.label_3.setBuddy(self.spinBorder)
self.label_4.setBuddy(self.spinRotation)
self.label_5.setBuddy(self.spinResolution)
+ self.label_6.setBuddy(self.buttonForeground)
+ self.label_7.setBuddy(self.buttonBackground)
+ self.label_8.setBuddy(self.buttonText)
self.retranslateUi(BarcodeDialog)
+ self.tabWidget.setCurrentIndex(1)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), BarcodeDialog.reject)
QtCore.QMetaObject.connectSlotsByName(BarcodeDialog)
@@ -113,17 +158,23 @@
BarcodeDialog.setWindowTitle(QtGui.QApplication.translate("BarcodeDialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("BarcodeDialog", "&Encoding:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("BarcodeDialog", "&Value:", None, QtGui.QApplication.UnicodeUTF8))
+ self.labelExample.setText(QtGui.QApplication.translate("BarcodeDialog", "Example:", None, QtGui.QApplication.UnicodeUTF8))
+ self.exampleValue.setText(QtGui.QApplication.translate("BarcodeDialog", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
self.checkText.setText(QtGui.QApplication.translate("BarcodeDialog", "&Show text", None, QtGui.QApplication.UnicodeUTF8))
+ self.checkChecksum.setText(QtGui.QApplication.translate("BarcodeDialog", "&Include check sum", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_3.setText(QtGui.QApplication.translate("BarcodeDialog", "&Border:", None, QtGui.QApplication.UnicodeUTF8))
self.spinBorder.setSuffix(QtGui.QApplication.translate("BarcodeDialog", "mm", None, QtGui.QApplication.UnicodeUTF8))
- self.label_3.setText(QtGui.QApplication.translate("BarcodeDialog", "&Border:", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("BarcodeDialog", "&Rotation:", None, QtGui.QApplication.UnicodeUTF8))
- self.labelExample.setText(QtGui.QApplication.translate("BarcodeDialog", "Example:", None, QtGui.QApplication.UnicodeUTF8))
- self.exampleValue.setText(QtGui.QApplication.translate("BarcodeDialog", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
self.label_5.setText(QtGui.QApplication.translate("BarcodeDialog", "&Resolution:", None, QtGui.QApplication.UnicodeUTF8))
self.spinResolution.setSuffix(QtGui.QApplication.translate("BarcodeDialog", "dpi", None, QtGui.QApplication.UnicodeUTF8))
- self.checkChecksum.setText(QtGui.QApplication.translate("BarcodeDialog", "&Include check sum", None, QtGui.QApplication.UnicodeUTF8))
+ self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("BarcodeDialog", "&Basic Options", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_6.setText(QtGui.QApplication.translate("BarcodeDialog", "&Foreground Color:", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_7.setText(QtGui.QApplication.translate("BarcodeDialog", "&Background Color:", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_8.setText(QtGui.QApplication.translate("BarcodeDialog", "&Text Color:", None, QtGui.QApplication.UnicodeUTF8))
+ self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("BarcodeDialog", "&Extra Options", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox.setTitle(QtGui.QApplication.translate("BarcodeDialog", "&Barcode", None, QtGui.QApplication.UnicodeUTF8))
+from colorbutton import ColorButton
if __name__ == "__main__":
import sys
Modified: kbarcode4-light/trunk/src/barcode.py
===================================================================
--- kbarcode4-light/trunk/src/barcode.py 2010-08-07 16:15:50 UTC (rev 60)
+++ kbarcode4-light/trunk/src/barcode.py 2010-08-07 16:56:22 UTC (rev 61)
@@ -17,13 +17,17 @@
self.dpi = 72
self.encoding = None
self.imageData = None
+ self.foreground = QColor(0, 0, 0)
+ self.background = QColor(255, 255, 255)
+ self.textcolor = QColor(0, 0, 0)
self._valid = False
"""Generate a barcode from the values that have been set"""
def generate(self):
e = self.encoding['encoding']
- self.imageData = purepostscript.createPurePostscriptBarcode(self.value, e, self.textVisible, self.checksumVisible, self.dpi)
+ self.imageData = purepostscript.createPurePostscriptBarcode(self.value, e, self.textVisible, self.checksumVisible,
+ self.dpi, self.foreground, self.background, self.textcolor)
self._valid = self.imageData != None
Modified: kbarcode4-light/trunk/src/barcodedialog.ui
===================================================================
--- kbarcode4-light/trunk/src/barcodedialog.ui 2010-08-07 16:15:50 UTC (rev 60)
+++ kbarcode4-light/trunk/src/barcodedialog.ui 2010-08-07 16:56:22 UTC (rev 61)
@@ -44,58 +44,14 @@
<item row="1" column="1">
<widget class="QLineEdit" name="value"/>
</item>
- <item row="2" column="1">
- <widget class="QCheckBox" name="checkText">
- <property name="text">
- <string>&Show text</string>
- </property>
- </widget>
- </item>
- <item row="4" column="1">
- <widget class="QSpinBox" name="spinBorder">
- <property name="suffix">
- <string>mm</string>
- </property>
- <property name="maximum">
- <number>1000</number>
- </property>
- </widget>
- </item>
- <item row="5" column="1">
- <widget class="QSpinBox" name="spinRotation">
- <property name="maximum">
- <number>359</number>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>&Border:</string>
- </property>
- <property name="buddy">
- <cstring>spinBorder</cstring>
- </property>
- </widget>
- </item>
- <item row="5" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>&Rotation:</string>
- </property>
- <property name="buddy">
- <cstring>spinRotation</cstring>
- </property>
- </widget>
- </item>
- <item row="7" column="0">
+ <item row="6" column="0">
<widget class="QLabel" name="labelExample">
<property name="text">
<string>Example:</string>
</property>
</widget>
</item>
- <item row="7" column="1">
+ <item row="6" column="1">
<widget class="QLabel" name="exampleValue">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
@@ -117,39 +73,192 @@
</property>
</widget>
</item>
- <item row="6" column="0">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>&Resolution:</string>
- </property>
- <property name="buddy">
- <cstring>spinResolution</cstring>
- </property>
- </widget>
- </item>
- <item row="6" column="1">
- <widget class="QSpinBox" name="spinResolution">
- <property name="suffix">
- <string>dpi</string>
- </property>
- <property name="minimum">
- <number>72</number>
- </property>
- <property name="maximum">
- <number>2400</number>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QCheckBox" name="checkChecksum">
- <property name="text">
- <string>&Include check sum</string>
- </property>
- </widget>
- </item>
</layout>
</item>
<item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>1</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>&Basic Options</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="1">
+ <widget class="QCheckBox" name="checkText">
+ <property name="text">
+ <string>&Show text</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QCheckBox" name="checkChecksum">
+ <property name="text">
+ <string>&Include check sum</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>&Border:</string>
+ </property>
+ <property name="buddy">
+ <cstring>spinBorder</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QSpinBox" name="spinBorder">
+ <property name="suffix">
+ <string>mm</string>
+ </property>
+ <property name="maximum">
+ <number>1000</number>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>&Rotation:</string>
+ </property>
+ <property name="buddy">
+ <cstring>spinRotation</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="spinRotation">
+ <property name="maximum">
+ <number>359</number>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>&Resolution:</string>
+ </property>
+ <property name="buddy">
+ <cstring>spinResolution</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QSpinBox" name="spinResolution">
+ <property name="suffix">
+ <string>dpi</string>
+ </property>
+ <property name="minimum">
+ <number>72</number>
+ </property>
+ <property name="maximum">
+ <number>2400</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>209</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>&Extra Options</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>&Foreground Color:</string>
+ </property>
+ <property name="buddy">
+ <cstring>buttonForeground</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="ColorButton" name="buttonForeground">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>&Background Color:</string>
+ </property>
+ <property name="buddy">
+ <cstring>buttonBackground</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="ColorButton" name="buttonBackground">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>&Text Color:</string>
+ </property>
+ <property name="buddy">
+ <cstring>buttonText</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="ColorButton" name="buttonText">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>191</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>&Barcode</string>
@@ -166,7 +275,7 @@
<x>0</x>
<y>0</y>
<width>426</width>
- <height>191</height>
+ <height>141</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -201,6 +310,13 @@
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>ColorButton</class>
+ <extends>QPushButton</extends>
+ <header>colorbutton.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections>
<connection>
Modified: kbarcode4-light/trunk/src/kbarcode.py
===================================================================
--- kbarcode4-light/trunk/src/kbarcode.py 2010-08-07 16:15:50 UTC (rev 60)
+++ kbarcode4-light/trunk/src/kbarcode.py 2010-08-07 16:56:22 UTC (rev 61)
@@ -1,4 +1,4 @@
- #!/usr/bin/python
+#!/usr/bin/python
# kbarcode.py
#
@@ -11,6 +11,10 @@
from barcode import Barcode
import purepostscript
+# TODO
+# PDF Export
+# Colors
+
class KBarcode(QDialog, Ui_BarcodeDialog):
encodings = purepostscript.getEncodings()
@@ -32,6 +36,11 @@
self.connect(self.saveButton, SIGNAL("clicked()"), self.slotSave)
self.connect(self.comboEncoding, SIGNAL("currentIndexChanged(int)"), self.slotUpdateExample)
+ self.buttonForeground.setColor( self.barcode.foreground )
+ self.buttonBackground.setColor( self.barcode.background )
+ self.buttonText.setColor( self.barcode.textcolor)
+ self.checkText.setChecked(True)
+ self.spinResolution.setValue(self.physicalDpiX())
for e in self.encodings:
self.comboEncoding.addItem(e['description'], e['encoding'])
@@ -61,6 +70,9 @@
self.barcode.checksumVisible = self.checkChecksum.isEnabled() and self.checkChecksum.isChecked()
self.barcode.rotation = self.spinRotation.value()
self.barcode.dpi = self.spinResolution.value()
+ self.barcode.foreground = self.buttonForeground.color()
+ self.barcode.background = self.buttonBackground.color()
+ self.barcode.textcolor = self.buttonText.color()
self.barcode.generate()
self.enableButtons(self.barcode.isValid())
Modified: kbarcode4-light/trunk/src/purepostscript.py
===================================================================
--- kbarcode4-light/trunk/src/purepostscript.py 2010-08-07 16:15:50 UTC (rev 60)
+++ kbarcode4-light/trunk/src/purepostscript.py 2010-08-07 16:56:22 UTC (rev 61)
@@ -55,12 +55,9 @@
def hasChecksum(encoding):
return (encoding['extra'].find("includecheck") != -1)
-def createPurePostscriptBarcode(value, encoding, textVisible, checksumVisible, resolution):
+def createPurePostscriptBarcode(value, encoding, textVisible, checksumVisible, resolution, foreground, background, textcolor):
showText= ""
showCheck= ""
- foreground = [0, 0, 0]
- background = [255, 255, 255]
- textcolor = [0, 0, 0]
if textVisible:
showText = "includetext"
@@ -70,9 +67,9 @@
options = "%s %s barcolor=%02X%02X%02X showbackground backgroundcolor=%02X%02X%02X textcolor=%02X%02X%02X" % \
(showText, showCheck,
- foreground[0], foreground[1], foreground[2],
- background[0], background[1], background[2],
- textcolor[0], textcolor[1], textcolor[2] )
+ foreground.red(), foreground.green(), foreground.blue(),
+ background.red(), background.green(), background.blue(),
+ textcolor.red(), textcolor.green(), textcolor.blue() )
program = "%!PS-Adobe-2.0 EPSF-2.0\n%%EndComments\n%%EndProlog\n"
program = program + getBarcodeWriterInPurePostscript() + "\n"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dom...@us...> - 2010-08-07 16:59:42
|
Revision: 62
http://kbarcode.svn.sourceforge.net/kbarcode/?rev=62&view=rev
Author: domseichter
Date: 2010-08-07 16:59:34 +0000 (Sat, 07 Aug 2010)
Log Message:
-----------
FIXED: Default tab
Modified Paths:
--------------
kbarcode4-light/trunk/src/Ui_barcodedialog.py
kbarcode4-light/trunk/src/barcodedialog.ui
kbarcode4-light/trunk/src/kbarcode.py
Modified: kbarcode4-light/trunk/src/Ui_barcodedialog.py
===================================================================
--- kbarcode4-light/trunk/src/Ui_barcodedialog.py 2010-08-07 16:56:22 UTC (rev 61)
+++ kbarcode4-light/trunk/src/Ui_barcodedialog.py 2010-08-07 16:59:34 UTC (rev 62)
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file '/home/dominik/Desktop/Programming/kbarcode/kbarcode4-light/src/barcodedialog.ui'
#
-# Created: Sat Aug 7 17:35:41 2010
+# Created: Sat Aug 7 17:59:16 2010
# by: PyQt4 UI code generator 4.6
#
# WARNING! All changes made in this file will be lost!
@@ -150,7 +150,7 @@
self.label_8.setBuddy(self.buttonText)
self.retranslateUi(BarcodeDialog)
- self.tabWidget.setCurrentIndex(1)
+ self.tabWidget.setCurrentIndex(0)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), BarcodeDialog.reject)
QtCore.QMetaObject.connectSlotsByName(BarcodeDialog)
Modified: kbarcode4-light/trunk/src/barcodedialog.ui
===================================================================
--- kbarcode4-light/trunk/src/barcodedialog.ui 2010-08-07 16:56:22 UTC (rev 61)
+++ kbarcode4-light/trunk/src/barcodedialog.ui 2010-08-07 16:59:34 UTC (rev 62)
@@ -78,7 +78,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
- <number>1</number>
+ <number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
Modified: kbarcode4-light/trunk/src/kbarcode.py
===================================================================
--- kbarcode4-light/trunk/src/kbarcode.py 2010-08-07 16:56:22 UTC (rev 61)
+++ kbarcode4-light/trunk/src/kbarcode.py 2010-08-07 16:59:34 UTC (rev 62)
@@ -13,7 +13,6 @@
# TODO
# PDF Export
-# Colors
class KBarcode(QDialog, Ui_BarcodeDialog):
encodings = purepostscript.getEncodings()
@@ -46,6 +45,7 @@
self.enableButtons(False)
self.slotUpdateExample(self.comboEncoding.currentIndex())
+ self.value.setFocus(True)
self.value.selectAll()
def slotUpdateExample(self, index):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dom...@us...> - 2010-08-09 14:48:04
|
Revision: 63
http://kbarcode.svn.sourceforge.net/kbarcode/?rev=63&view=rev
Author: domseichter
Date: 2010-08-09 14:47:57 +0000 (Mon, 09 Aug 2010)
Log Message:
-----------
ADDED: PDF Export
Modified Paths:
--------------
kbarcode4-light/trunk/src/barcode.py
kbarcode4-light/trunk/src/ghostscript.py
kbarcode4-light/trunk/src/kbarcode.py
kbarcode4-light/trunk/src/purepostscript.py
Modified: kbarcode4-light/trunk/src/barcode.py
===================================================================
--- kbarcode4-light/trunk/src/barcode.py 2010-08-07 16:59:34 UTC (rev 62)
+++ kbarcode4-light/trunk/src/barcode.py 2010-08-09 14:47:57 UTC (rev 63)
@@ -6,6 +6,7 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import purepostscript
+import ghostscript
class Barcode:
@@ -26,7 +27,7 @@
"""Generate a barcode from the values that have been set"""
def generate(self):
e = self.encoding['encoding']
- self.imageData = purepostscript.createPurePostscriptBarcode(self.value, e, self.textVisible, self.checksumVisible,
+ self.imageData = purepostscript.createPurePostscriptBarcodePixmap(self.value, e, self.textVisible, self.checksumVisible,
self.dpi, self.foreground, self.background, self.textcolor)
self._valid = self.imageData != None
@@ -51,4 +52,15 @@
return image
-
+
+ """Returns the generated barcode as a PDF document"""
+ def pdf(self):
+ if self._valid == False:
+ return None
+
+ e = self.encoding['encoding']
+ postscript = purepostscript.createPurePostscriptBarcode(self.value, e, self.textVisible, self.checksumVisible,
+ self.dpi, self.foreground, self.background, self.textcolor)
+
+ pdf = ghostscript.convertToPdf(postscript)
+ return pdf
Modified: kbarcode4-light/trunk/src/ghostscript.py
===================================================================
--- kbarcode4-light/trunk/src/ghostscript.py 2010-08-07 16:59:34 UTC (rev 62)
+++ kbarcode4-light/trunk/src/ghostscript.py 2010-08-09 14:47:57 UTC (rev 63)
@@ -61,7 +61,6 @@
width = (getXFromArray(size) + getWidthFromArray(size)) / 72.0 * resx
height= (getHeightFromArray(size)) / 72.0 * resy
- print size
name = writeToTempFile(postscript)
args = [ "gs", "-g" + str(int(width * scalex)) + "x" + str(int(height * scaley)),
"-r" + str(resx * scalex) + "x" + str(resy * scaley),
@@ -78,6 +77,23 @@
return data
-#tmp = open("/tmp/tmpij2vCv", "r")
-#data = tmp.read()
-#print ghostscriptGetBoundingBox(data)
+def convertToPdf(postscript):
+ size = ghostscriptGetBoundingBox(postscript)
+ width = (getXFromArray(size) + getWidthFromArray(size))
+ height= (getHeightFromArray(size))
+
+ name = writeToTempFile(postscript)
+ args = [ "gs", "-g" + str(int(width)) + "x" + str(int(height)),
+ "-r72x72",
+ "-sOutputFile=-", "-sDEVICE=pdfwrite", "-dSAFER",
+ "-sNOPAUSE", "-q", name, "-c", "quit" ]
+ print args
+ p = subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+ data = p.communicate()[0]
+ if p.wait() != 0:
+ os.unlink(name)
+ print "convertToPdf: Error in Ghostscript communication"
+ return None
+
+ os.unlink(name)
+ return data
Modified: kbarcode4-light/trunk/src/kbarcode.py
===================================================================
--- kbarcode4-light/trunk/src/kbarcode.py 2010-08-07 16:59:34 UTC (rev 62)
+++ kbarcode4-light/trunk/src/kbarcode.py 2010-08-09 14:47:57 UTC (rev 63)
@@ -29,10 +29,12 @@
self.generateButton = self.buttonBox.addButton("&Generate", QDialogButtonBox.ActionRole)
self.copyButton = self.buttonBox.addButton("&Copy", QDialogButtonBox.ActionRole)
self.saveButton = self.buttonBox.button(QDialogButtonBox.Save)
+ self.savePdfButton = self.buttonBox.addButton("&Save as PDF", QDialogButtonBox.ActionRole)
self.connect(self.generateButton, SIGNAL("clicked()"), self.slotGenerate)
self.connect(self.copyButton, SIGNAL("clicked()"), self.slotCopy)
self.connect(self.saveButton, SIGNAL("clicked()"), self.slotSave)
+ self.connect(self.savePdfButton, SIGNAL("clicked()"), self.slotSavePdf)
self.connect(self.comboEncoding, SIGNAL("currentIndexChanged(int)"), self.slotUpdateExample)
self.buttonForeground.setColor( self.barcode.foreground )
@@ -100,9 +102,21 @@
if self.display.pixmap().save(filename, format) == False:
QMessageBox.critical(self, self.tr("KBarcode"), self.tr("Error during saving the barcode."))
else:
- QMessageBox.information(self, self.tr("KBarcode"),
- filename + " " + filter)
-
+ QMessageBox.information(self, self.tr("KBarcode"), self.tr("Wrote file: ") + filename )
+
+ """Save current barcode as a PDF file"""
+ def slotSavePdf(self):
+ filter = "PDF File (*.pdf);;"
+ filename = QFileDialog.getSaveFileName(self, self.tr("Save Barcode"),
+ "kbarcodelight:", filter)
+
+ pdf = self.barcode.pdf()
+ f = open(filename, "w")
+ f.write(pdf)
+ f.close
+
+ QMessageBox.information(self, self.tr("KBarcode"), self.tr("Wrote file: ") + filename )
+
"""Copy the generated barcode to the clipboard"""
def slotCopy(self):
QApplication.clipboard().setImage(self.barcode.image())
Modified: kbarcode4-light/trunk/src/purepostscript.py
===================================================================
--- kbarcode4-light/trunk/src/purepostscript.py 2010-08-07 16:59:34 UTC (rev 62)
+++ kbarcode4-light/trunk/src/purepostscript.py 2010-08-09 14:47:57 UTC (rev 63)
@@ -55,6 +55,11 @@
def hasChecksum(encoding):
return (encoding['extra'].find("includecheck") != -1)
+def createPurePostscriptBarcodePixmap(value, encoding, textVisible, checksumVisible, resolution, foreground, background, textcolor):
+ program = createPurePostscriptBarcode(value, encoding, textVisible, checksumVisible, resolution, foreground, background, textcolor)
+ picture = ghostscript.ghostscriptCreatePixmap(program, 1.0, 1.0, resolution, resolution)
+ return picture
+
def createPurePostscriptBarcode(value, encoding, textVisible, checksumVisible, resolution, foreground, background, textcolor):
showText= ""
showCheck= ""
@@ -82,12 +87,11 @@
program = program + " 0 0 moveto\n"
program = program + "(" + value + ") (" + options + ") " + encoding + " barcode grestore\n"
- tmp = open("/home/dominik/latest.ps", 'w')
- tmp.write(program)
- tmp.close()
+ #tmp = open("/home/dominik/latest.ps", 'w')
+ #tmp.write(program)
+ #tmp.close()
- picture = ghostscript.ghostscriptCreatePixmap(program, 1.0, 1.0, resolution, resolution)
- return picture
+ return program
# TODO
# Maxicode
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|