| 1 |
# -*- coding: utf-8 -*- |
|---|
| 2 |
|
|---|
| 3 |
"""Dabo: A Framework for developing data-driven business applications |
|---|
| 4 |
|
|---|
| 5 |
Dabo is for developing multi-platform database business applications - |
|---|
| 6 |
you know, applications that need to connect to a database server (MySQL, |
|---|
| 7 |
Oracle, MS-SQL, whatever), get recordsets of data based on criteria |
|---|
| 8 |
set by the user, provide easy ways to edit and commit changes to the |
|---|
| 9 |
data, and to report on the data. |
|---|
| 10 |
|
|---|
| 11 |
You either program using Python, importing the dabo library, or you |
|---|
| 12 |
use the Dabo Class Designer to create xml files to define your classes. |
|---|
| 13 |
These xml files can contain embedded python code for the best of all worlds. |
|---|
| 14 |
|
|---|
| 15 |
So, the basic idea is that you have a functional, working, albeit basic |
|---|
| 16 |
application up and running very quickly, and you can then spend time |
|---|
| 17 |
getting all the fancy bells and whistles implemented. Keep things as |
|---|
| 18 |
simple as possible though, while still fulfilling your customer's |
|---|
| 19 |
specifications. Simplicity is the better part of elegance. |
|---|
| 20 |
|
|---|
| 21 |
Beyond the wizards and xml definition files, Dabo exposes a nice |
|---|
| 22 |
API in Python for manually creating your own class definitions. IOW, |
|---|
| 23 |
we let you have as much control as you need. You aren't required to |
|---|
| 24 |
take advantage of our xml definition formats at all. |
|---|
| 25 |
|
|---|
| 26 |
Dabo has three main submodules, representing the three tiers common |
|---|
| 27 |
in modern database application design: |
|---|
| 28 |
|
|---|
| 29 |
dabo.db : database |
|---|
| 30 |
dabo.biz : business objects |
|---|
| 31 |
dabo.ui : user interface |
|---|
| 32 |
|
|---|
| 33 |
dabo.db and dabo.biz are completely ui-free, while dabo.ui (currently) |
|---|
| 34 |
requires wxPython. We have allowed for possible future support for other |
|---|
| 35 |
ui libraries, such as PyQt, tk, and curses. |
|---|
| 36 |
|
|---|
| 37 |
The Dabo framework will have to be distributed to your client's machine(s), |
|---|
| 38 |
along with your project-specific data definitions and (if applicable), your |
|---|
| 39 |
subclasses of the Dabo classes and additional Python scripts, if any. There |
|---|
| 40 |
are ways to do runtime deployment via installers that take the complexity |
|---|
| 41 |
out of this, but that is outside the scope of Dabo itself, and you'll use |
|---|
| 42 |
a different method for each target platform. |
|---|
| 43 |
|
|---|
| 44 |
To run Dabo, and apps based on Dabo, you need: |
|---|
| 45 |
+ Python 2.4 or higher (2.5 or higher recommended) |
|---|
| 46 |
|
|---|
| 47 |
+ wxPython 2.8 or higher (2.8.8 or higher highly recommended) |
|---|
| 48 |
(only necessary for apps with a ui: because of the modular |
|---|
| 49 |
nature of Dabo's design, it is possible to use just the |
|---|
| 50 |
db layer, or the db layer in conjunction with the biz |
|---|
| 51 |
layer, with no ui at all.) |
|---|
| 52 |
|
|---|
| 53 |
+ pysqlite2: The Python dbapi module for SQLite. (Not needed in |
|---|
| 54 |
Python 2.5 and higher) |
|---|
| 55 |
|
|---|
| 56 |
+ Windows 98SE or higher |
|---|
| 57 |
+ Macintosh OSX 10.2 or higher (*much* nicer in Tiger - 10.4) |
|---|
| 58 |
+ Linux 2.4 with X11 running and Gtk2 |
|---|
| 59 |
|
|---|
| 60 |
+ Access to some sort of database server, along with the |
|---|
| 61 |
appropriate Python driver(s) installed. For example, for |
|---|
| 62 |
MySQL you'll need to have the MySQL client libraries |
|---|
| 63 |
installed, as well as the MySQLDb Python module. (Dabo |
|---|
| 64 |
does not use ODBC: it connects directly using the Python |
|---|
| 65 |
DB API coupled with the individual database drivers. This |
|---|
| 66 |
is, at the same time, less flexible, tougher to get started |
|---|
| 67 |
with, but more capable, more multi-platform, and better |
|---|
| 68 |
performing, than ODBC is.) (we recommend starting with MySQL |
|---|
| 69 |
installed, because all of the demo code has the best support |
|---|
| 70 |
for MySQL). |
|---|
| 71 |
|
|---|
| 72 |
How you get started is pretty much up to you. Run DaboDemo.py which |
|---|
| 73 |
is in demo/DaboDemo. Run AppWizard.py which is in ide/wizards. |
|---|
| 74 |
Run ClassDesigner.py or ReportDesigner.py in the ide directory. |
|---|
| 75 |
|
|---|
| 76 |
For some quick eye-candy, once you've installed Dabo using the standard |
|---|
| 77 |
'python setup.py install' method, do this from your Python interpreter: |
|---|
| 78 |
|
|---|
| 79 |
import dabo |
|---|
| 80 |
dabo.dApp().start() |
|---|
| 81 |
|
|---|
| 82 |
press Ctrl+D and type the following into the command window that appears: |
|---|
| 83 |
|
|---|
| 84 |
tb = dabo.ui.dTextBox(self) |
|---|
| 85 |
|
|---|
| 86 |
Notice the textbox in the upper left hand corner? |
|---|
| 87 |
|
|---|
| 88 |
tb.Value = "yippee!" |
|---|
| 89 |
tb.FontBold = True |
|---|
| 90 |
print tb.Value |
|---|
| 91 |
|
|---|
| 92 |
Now, use the ui to change the value in the textbox, and switch back to |
|---|
| 93 |
the command window. |
|---|
| 94 |
|
|---|
| 95 |
print tb.Value |
|---|
| 96 |
|
|---|
| 97 |
Have fun in your exploration of Dabo! |
|---|
| 98 |
""" |
|---|
| 99 |
|
|---|
| 100 |
import os |
|---|
| 101 |
import sys |
|---|
| 102 |
import logging |
|---|
| 103 |
try: |
|---|
| 104 |
import pysqlite2 |
|---|
| 105 |
except ImportError: |
|---|
| 106 |
try: |
|---|
| 107 |
import sqlite3 |
|---|
| 108 |
except ImportError: |
|---|
| 109 |
msg = """ |
|---|
| 110 |
|
|---|
| 111 |
Dabo requires SQLite 3 and the pysqlite2 module. You will have to install these |
|---|
| 112 |
free products before running Dabo. You can get them from the following locations: |
|---|
| 113 |
|
|---|
| 114 |
SQLite: http://www.sqlite.org/download.html |
|---|
| 115 |
pysqlite2: http://initd.org/tracker/pysqlite |
|---|
| 116 |
|
|---|
| 117 |
""" |
|---|
| 118 |
sys.exit(msg) |
|---|
| 119 |
|
|---|
| 120 |
# dApp will change the following values upon its __init__: |
|---|
| 121 |
dAppRef = None |
|---|
| 122 |
|
|---|
| 123 |
# Install localization service for dabo. dApp will install localization service |
|---|
| 124 |
# for the user application separately. |
|---|
| 125 |
import dLocalize |
|---|
| 126 |
dLocalize.install("dabo") |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
# Import global settings (do this first, as other imports may rely on it): |
|---|
| 130 |
from settings import * |
|---|
| 131 |
|
|---|
| 132 |
# Instantiate the logger object, which will send messages to user-overridable |
|---|
| 133 |
# locations. Do this before any other imports. |
|---|
| 134 |
from dabo.lib.logger import Log |
|---|
| 135 |
infoLog = Log() |
|---|
| 136 |
infoLog.Caption = "Dabo Info Log" |
|---|
| 137 |
if verboseLogging: |
|---|
| 138 |
infoLog.LogObject = sys.stdout |
|---|
| 139 |
else: |
|---|
| 140 |
class NullWrite(object): |
|---|
| 141 |
def write(self, txt): pass |
|---|
| 142 |
infoLog.LogObject = NullWrite() |
|---|
| 143 |
errorLog = Log() |
|---|
| 144 |
errorLog.Caption = "Dabo Error Log" |
|---|
| 145 |
errorLog.LogObject = sys.stderr |
|---|
| 146 |
# Create a separate log reference for event tracking. |
|---|
| 147 |
eventLog = Log() |
|---|
| 148 |
eventLog.Caption = "Dabo Event Log" |
|---|
| 149 |
eventLog.LogObject = sys.stdout |
|---|
| 150 |
# This log is set to None by default. It must be manually activated |
|---|
| 151 |
# via the Application object. |
|---|
| 152 |
dbActivityLog = Log() |
|---|
| 153 |
dbActivityLog.Caption = "Database Activity Log" |
|---|
| 154 |
dbActivityLog.LogObject = None |
|---|
| 155 |
|
|---|
| 156 |
from __version__ import version |
|---|
| 157 |
import dColors |
|---|
| 158 |
import dEvents |
|---|
| 159 |
|
|---|
| 160 |
from dBug import logPoint |
|---|
| 161 |
import pdb |
|---|
| 162 |
trace = pdb.set_trace |
|---|
| 163 |
|
|---|
| 164 |
from dApp import dApp |
|---|
| 165 |
from dPref import dPref |
|---|
| 166 |
|
|---|
| 167 |
def debugout(*args): |
|---|
| 168 |
txtargs = [unicode(arg) for arg in args] |
|---|
| 169 |
txt = " ".join(txtargs) |
|---|
| 170 |
log = logging.getLogger("Debug") |
|---|
| 171 |
log.debug(txt) |
|---|
| 172 |
# Mangle the namespace so that developers can add lines like: |
|---|
| 173 |
# debugo("Some Message") |
|---|
| 174 |
# or |
|---|
| 175 |
# debugout("Another Message", self.Caption) |
|---|
| 176 |
# to their code for debugging. |
|---|
| 177 |
# (I added 'debugo' as an homage to Whil Hentzen!) |
|---|
| 178 |
import __builtin__ |
|---|
| 179 |
__builtin__.debugo = __builtin__.debugout = debugout |
|---|
| 180 |
|
|---|
| 181 |
# Make sure dabo.db, dabo.biz, and dabo.ui are imported: |
|---|
| 182 |
import dabo.db |
|---|
| 183 |
import dabo.biz |
|---|
| 184 |
import dabo.ui |
|---|
| 185 |
|
|---|
| 186 |
# Store the base path to the framework |
|---|
| 187 |
frameworkPath = os.path.dirname(dabo.__file__) |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
# Define the standard Dabo subdirectory stucture for apps. |
|---|
| 191 |
def _getAppDirectoryNames(): |
|---|
| 192 |
return ("biz", "db", "ui", "resources", "reports", "test") |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
# Method to create a standard Dabo directory structure layout |
|---|
| 196 |
def makeDaboDirectories(homedir=None): |
|---|
| 197 |
"""If homedir is passed, the directories will be created off of that |
|---|
| 198 |
directory. Otherwise, it is assumed that they should be created |
|---|
| 199 |
in the current directory location. |
|---|
| 200 |
""" |
|---|
| 201 |
currLoc = os.getcwd() |
|---|
| 202 |
if homedir is not None: |
|---|
| 203 |
os.chdir(homedir) |
|---|
| 204 |
for d in _getAppDirectoryNames(): |
|---|
| 205 |
if not os.path.exists(d): |
|---|
| 206 |
os.mkdir(d) |
|---|
| 207 |
os.chdir(currLoc) |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
def quickStart(homedir=None): |
|---|
| 211 |
"""This creates a bare-bones application in either the specified |
|---|
| 212 |
directory, or the current one if none is specified. |
|---|
| 213 |
""" |
|---|
| 214 |
currLoc = os.getcwd() |
|---|
| 215 |
if homedir is not None: |
|---|
| 216 |
if not os.path.exists(homedir): |
|---|
| 217 |
os.makedirs(homedir) |
|---|
| 218 |
os.chdir(homedir) |
|---|
| 219 |
makeDaboDirectories() |
|---|
| 220 |
open("main.py", "w").write("""#!/usr/bin/env python |
|---|
| 221 |
# -*- coding: utf-8 -*- |
|---|
| 222 |
import dabo |
|---|
| 223 |
dabo.ui.loadUI("wx") |
|---|
| 224 |
|
|---|
| 225 |
app = dabo.dApp() |
|---|
| 226 |
|
|---|
| 227 |
# IMPORTANT! Change app.MainFormClass value to the name |
|---|
| 228 |
# of the form class that you want to run when your |
|---|
| 229 |
# application starts up. |
|---|
| 230 |
app.MainFormClass = dabo.ui.dFormMain |
|---|
| 231 |
|
|---|
| 232 |
app.start() |
|---|
| 233 |
""") |
|---|
| 234 |
|
|---|
| 235 |
template = """#!/usr/bin/env python |
|---|
| 236 |
# -*- coding: utf-8 -*- |
|---|
| 237 |
###### |
|---|
| 238 |
# In order for Dabo to 'see' classes in your %(dd)s directory, add an |
|---|
| 239 |
# import statement here for each class. E.g., if you have a file named |
|---|
| 240 |
# 'MyClasses.py' in this directory, and it defines two classes named 'FirstClass' |
|---|
| 241 |
# and 'SecondClass', add these lines: |
|---|
| 242 |
# |
|---|
| 243 |
# from MyClass import FirstClass |
|---|
| 244 |
# from MyClass import SecondClass |
|---|
| 245 |
# |
|---|
| 246 |
# Now you can refer to these classes as: self.Application.%(dd)s.FirstClass and |
|---|
| 247 |
# self.Application.%(dd)s.SecondClass |
|---|
| 248 |
###### |
|---|
| 249 |
|
|---|
| 250 |
""" |
|---|
| 251 |
for dd in dabo._getAppDirectoryNames(): |
|---|
| 252 |
fname = "%s/__init__.py" % dd |
|---|
| 253 |
txt = template % locals() |
|---|
| 254 |
open(fname, "w").write(txt) |
|---|
| 255 |
os.chmod("main.py", 0744) |
|---|
| 256 |
os.chdir(currLoc) |
|---|