dabo Commit
Revision 5775
Date: 2010-04-04 09:42:33 -0700 (Sun, 04 Apr 2010)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5775
Changed:
U trunk/ide/CxnEditor.py
A trunk/ide/HomeDirectoryStatusBar.py
Log:
Improved the handling of encryption by creating the Crypto property, which will
use the recent changes to the SimpleCrypt script.
Added the HomeDirectoryStatusBar class, which will be used in all the visual
tools.
Diff:
Modified: trunk/ide/CxnEditor.py
===================================================================
--- trunk/ide/CxnEditor.py 2010-04-04 13:49:19 UTC (rev 5774)
+++ trunk/ide/CxnEditor.py 2010-04-04 16:42:33 UTC (rev 5775)
@@ -12,12 +12,17 @@
from dabo.lib.connParser import importConnections
import dabo.lib.utils as utils
dui.loadUI("wx")
+from HomeDirectoryStatusBar import HomeDirectoryStatusBar
class EditorForm(dui.dForm):
def afterSetMenuBar(self):
self.createMenu()
+
+
+ def beforeInit(self):
+ self.StatusBarClass = HomeDirectoryStatusBar
def afterInit(self):
@@ -33,7 +38,6 @@
self.connDict = dict.fromkeys(connKeys)
self._origConnDict = dict.fromkeys(connKeys)
self.currentConn = None
- self.crypt = dabo.db.dConnectInfo()
self.createControls()
# temp hack to be polymorphic with dEditor (dIDE):
@@ -312,13 +316,13 @@
for fld in dd.keys():
val = eval("self.%s" % fld)
if fld == "password":
- origVal = self.crypt.decrypt(dd[fld])
+ origVal = self.Crypto.decrypt(dd[fld])
else:
origVal = dd[fld]
if val == origVal:
continue
if fld == "password":
- dd[fld] = self.crypt.encrypt(val)
+ dd[fld] = self.Crypto.encrypt(val)
else:
dd[fld] = val
@@ -332,7 +336,7 @@
for fld in dd.keys():
val = dd[fld]
if fld == "password":
- val = self.crypt.decrypt(dd[fld])
+ val = self.Crypto.decrypt(dd[fld])
else:
val = dd[fld]
if isinstance(val, basestring):
@@ -405,8 +409,8 @@
try:
dd = self.connDict[self.currentConn]
if fld == "password":
- if val != self.crypt.decrypt(dd["password"]):
- dd[fld] = self.crypt.encrypt(val)
+ if val != self.Crypto.decrypt(dd["password"]):
+ dd[fld] = self.Crypto.encrypt(val)
else:
dd[fld] = val
except StandardError, e:
@@ -494,6 +498,11 @@
# Get the values from the connDict, and adjust any pathing
# to be relative
vals = self.relPaths(self.connDict.values())
+ v0 = vals[0]
+ if self.isFileBasedBackend(v0["dbtype"]):
+ # Previous values from the form might still be in the
dict.
+ # Blank them out, as they are not valid for file-based
backends.
+ v0["host"] = v0["user"] = v0["password"] = v0["port"] =
""
xml = createXML(vals)
file(self.connFile, "w").write(xml)
dabo.ui.callAfter(self.bringToFront)
@@ -504,14 +513,24 @@
if self.isFileBasedBackend(val["dbtype"]):
db = val["database"]
if os.path.exists(db):
- val["database"] =
utils.relativePath(db, self.connFile)
+ val["database"] =
self.connDict["database"] = utils.relativePath(db,
self.Application.HomeDirectory)
return vals
+ def _getCrypto(self):
+ try:
+ return self.Application.Crypto
+ except:
+ pass
+
+ Crypto = property(_getCrypto, None, None,
+ _("A reference to the application-supplied encryption
object (dabo.lib.SimpleCrypt)"))
+
+
def main():
files = sys.argv[1:]
- app = dabo.dApp()
+ app = dabo.dApp(ignoreScriptDir=True)
app.BasePrefKey = "CxnEditor"
app.MainFormClass = None
app.setup()
Added: trunk/ide/HomeDirectoryStatusBar.py
===================================================================
--- trunk/ide/HomeDirectoryStatusBar.py (rev 0)
+++ trunk/ide/HomeDirectoryStatusBar.py 2010-04-04 16:42:33 UTC (rev 5775)
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import dabo
+from dabo.dLocalize import _
+dabo.ui.loadUI("wx")
+
+
+class HomeDirectoryStatusBar(dabo.ui.dStatusBar):
+ """This class is designed to be used in the visual tools to replace the
regular StatusBar
+ in the main form. The idea is that when using the tools, it is
important to know the
+ HomeDirectory that Dabo is using, as pathing is calculated relative to
that for all
+ values that contain paths. It also provides a convenient way to change
the HomeDirectory
+ by clicking on the hyperlink.
+ """
+ def afterInit(self):
+ # The target we are setting the HomeDirectory is usually the
Application, but can also
+ # be the form itself. If the form sets the target, use that.
Otherwise, default
+ # to the Application.
+ try:
+ self._target = self.Form.getHomeDirectoryTarget()
+ except AttributeError:
+ self._target = self.Application
+ link = self.linkChangeHD = dabo.ui.dHyperLink(self,
Caption=_("Home Directory: "),
+ ShowInBrowser=False, OnHit=self._changeHD)
+ link.VisitedColor = link.LinkColor = "blue"
+ txt = self.txtHD = dabo.ui.dTextBox(self, Enabled=False,
DataSource=self._target,
+ DataField="HomeDirectory")
+ sz = self.Sizer = dabo.ui.dSizer("H")
+ sz.appendSpacer(4)
+ sz.append(link)
+ sz.append(txt, 1)
+ dabo.ui.callAfter(self.update)
+ dabo.ui.callAfter(self.layout)
+ # Necessary so that this works in the Class Designer
+ txt._designerMode = False
+
+
+ def _changeHD(self, evt):
+ dirname = dabo.ui.getDirectory(_("Select Home Directory"),
self._target.HomeDirectory)
+ if dirname:
+ self._target.HomeDirectory = dirname
+ self.update()
+
+
+ def SetStatusText(self, val, fld=0):
+ # Don't allow status text
+ pass
+
+
+if __name__ == "__main__":
+ class HDForm(dabo.ui.dForm):
+ def beforeInit(self):
+ self.StatusBarClass = HomeDirectoryStatusBar
+
+
+ app = dabo.dApp(MainFormClass=HDForm)
+ app.start()
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]