Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 2437 → Rev 2438

/trunk/Scribus/scribus/plugins/scriptplugin/samples/ReadMe
16,6 → 16,7
quote.py = French quotation marks
trait_de_coupe.py
wordcount.py = Counts the count of the words :)
sample_db_usage.py = An example of the Scribus cooperating DB.
 
Copy these Examples to any location you like and play with them.
Each script contains Docstring in the file header - this is a common Python
/trunk/Scribus/scribus/plugins/scriptplugin/samples/sample_db_usage.py
0,0 → 1,90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
"""OK. This is a sample Scribus database connection with Python HOWTO.
 
DESCRIPTION:
I've got questions about DB and Scribus in my personal mailbox 3-4
times in a month. So this is an common answer for asking people.
 
Even through I'm an Oracle user/developer I choose MySQL for this
example, because of its presence in the Linux distributions and
hosting availability too.
But the DB server doesn't matter due the PEP 249 - standard DB interface
(http://www.python.org/peps/pep-0249.html).
There are various modules for database accessing:
http://www.python.org/topics/database/modules.html
 
Anyway - this script provides connection to the database server by the
specified values in the hostname, dbname, username, and password variables.
Then it checks the system for table names in the specified databases
and it displays it in the new document finally. Easy and understandable.
 
 
CONTACT:
email : petr@yarpen.cz
 
 
LICENSE:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the 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 General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
 
import sys
 
# environment checking
try:
import scribus
except ImportError:
print "This script only runs from within Scribus."
sys.exit(1)
 
try:
import MySQLdb
except ImportError:
print "You must have 'MySQLdb' installed."
sys.exit(1)
 
 
# connection parameters
hostname = 'server.foo.org'
dbname = 'name'
username = 'username'
password = 'password'
 
# connection to the network wide server would be time consuming. So get the hint to the user.
scribus.statusMessage('Connecting to the ' + hostname + ' server. Be patient, please...')
 
# Database related issues
try:
conn = MySQLdb.connect(passwd=password, db=dbname, host=hostname, user=username)
except:
scribus.messageBox('DB connection example', 'Connection error. You should specify your login in the script')
sys.exit(1)
 
cur = conn.cursor()
# get the list of the databases
# it's like 'select * from dba_tables' in Oracle
count = cur.execute('show tables')
# formating the output
result = str(count) + ' table(s) in the ' + dbname + ' database.\n\n'
for i in cur.fetchall():
result = result + i[0] + '\n'
 
# Scribus presentation part
scribus.newDoc(scribus.PAPER_A5, (10, 10, 20, 20), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT)
txtName = scribus.createText(10, 10, 200, 200)
scribus.setText(result, txtName)
 
scribus.statusMessage('Script done.')
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: Scribus/scribus/plugins/scriptplugin/samples/Makefile.am
===================================================================
--- Scribus/scribus/plugins/scriptplugin/samples/Makefile.am (revision 2437)
+++ Scribus/scribus/plugins/scriptplugin/samples/Makefile.am (revision 2438)
@@ -7,32 +7,20 @@
$(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/golden-mean.py $(prefix)/share/scribus/samples/golden-mean.py
$(INSTALL_DATA) $(srcdir)/quote.py $(prefix)/share/scribus/samples/quote.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/wordcount.py $(prefix)/share/scribus/samples/wordcount.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/Sample1.py $(prefix)/share/scribus/samples/Sample1.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/trait_de_coupe.py $(prefix)/share/scribus/samples/trait_de_coupe.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/Calender.py $(prefix)/share/scribus/samples/Calendar.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/pochette_cd.py $(prefix)/share/scribus/samples/pochette_cd.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/htmlimport.py $(prefix)/share/scribus/samples/htmlimport.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/3columnUSLTR.py $(prefix)/share/scribus/samples/3columnUSLTR.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/3columnA4.py $(prefix)/share/scribus/samples/3columnA4.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/legende.py $(prefix)/share/scribus/samples/legende.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/moins_10_pourcent_group.py $(prefix)/share/scribus/samples/moins_10_pourcent_group.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/plus_10_pourcent_group.py $(prefix)/share/scribus/samples/plus_10_pourcent_group.py
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/ReadMe $(prefix)/share/scribus/samples/ReadMe
- $(mkinstalldirs) $(prefix)/share/scribus/samples/
$(INSTALL_DATA) $(srcdir)/boilerplate.py $(prefix)/share/scribus/samples/boilerplate.py
+ $(INSTALL_DATA) $(srcdir)/sample_db_usage.py $(prefix)/share/scribus/samples/sample_db_usage.py
uninstall-local:
-rm -f $(prefix)/share/scribus/samples/quote.py
@@ -50,5 +38,6 @@
-rm -f $(prefix)/share/scribus/samples/golden-mean.py
-rm -f $(prefix)/share/scribus/samples/ReadMe
-rm -f $(prefix)/share/scribus/samples/boilerplate.py
+ -rm -f $(prefix)/share/scribus/samples/sample_db_usage.py
####### kdevelop will overwrite this part!!! (end)############