dabo Commit
Revision 4418
Date: 2008-08-16 17:16:45 -0700 (Sat, 16 Aug 2008)
Author: Nate
Trac: http://svn.dabodev.com/trac/dabo/changeset/4418
Changed:
U branches/Nate/dabo/__version__.py
U branches/Nate/dabo/ui/uiwx/dEditor.py
U branches/Nate/dabo/ui/uiwx/dSpinner.py
U branches/Nate/ide/Editor.py
Log:
Merged trunk changes with my branch.
Diff:
Modified: branches/Nate/dabo/__version__.py
===================================================================
--- branches/Nate/dabo/__version__.py 2008-08-16 19:40:35 UTC (rev 4417)
+++ branches/Nate/dabo/__version__.py 2008-08-17 00:16:45 UTC (rev 4418)
@@ -3,7 +3,7 @@
# Everything else is boilerplate copied also to other dabo repositories.
package_name = "dabo"
_version = "0.8.4"
-_approximateRevision = "~4400"
+_approximateRevision = "~4414"
import os
import lib
Modified: branches/Nate/dabo/ui/uiwx/dEditor.py
===================================================================
--- branches/Nate/dabo/ui/uiwx/dEditor.py 2008-08-16 19:40:35 UTC (rev
4417)
+++ branches/Nate/dabo/ui/uiwx/dEditor.py 2008-08-17 00:16:45 UTC (rev
4418)
@@ -446,9 +446,9 @@
### NOT WORKING! GOTTA FIGURE OUT THE MASK STUFF! ###
if line is None:
line = self.LineNumber
- print "START LN", line
+# print "START LN", line
nxtLine = self.MarkerNext(line, self._bmkPos)
- print "NEXT", nxtLine
+# print "NEXT LN", nxtLine
if nxtLine > -1:
self.moveToEnd()
self.LineNumber = nxtLine
@@ -577,7 +577,7 @@
"t": seltxt.title}[newcase]
self.ReplaceSelection(fnc())
except KeyError:
- raise ValueError, "Case must be either upper,
lower, capitalize, or invert."
+ raise ValueError, _("Case must be either upper,
lower, capitalize, or invert.")
self.SelectionPosition = pos
@@ -1334,9 +1334,10 @@
return dabo.ui.areYouSure(s)
- def promptForFileName(self, prompt="Select a file", saveAs=False,
- path=None):
+ def promptForFileName(self, prompt=None, saveAs=False, path=None):
"""Prompt the user for a file name."""
+ if prompt is None:
+ prompt = _("Select a file")
if path is None:
try:
drct = self._curdir
@@ -1359,13 +1360,13 @@
If the file exists, confirm with the user that they really want
to
overwrite.
"""
+ prompt = _("Save As")
while True:
- fname = self.promptForFileName(prompt="Save As",
saveAs=True)
+ fname = self.promptForFileName(prompt=prompt,
saveAs=True)
if fname is None:
break
if os.path.exists(fname):
- r = dabo.ui.areYouSure("File '%s' already
exists. "
- "Do you want to overwrite it?" % fname,
defaultNo=True)
+ r = dabo.ui.areYouSure(_("File '%s' already
exists. Do you want to overwrite it?") % fname, defaultNo=True)
if r is None:
# user canceled.
fname = None
@@ -1401,16 +1402,16 @@
else:
try:
fModTime = os.stat(fname).st_mtime
- if fModTime > self._fileModTime:
- if not dabo.ui.areYouSure(_("""The file
has been modified on the disk since you opened it.
- Do you want to overwrite it?"""), _("File Conflict"), defaultNo=True,
cancelButton=False):
- return
- except StandardError:
- pass
+ except OSError:
+ fModTime = None
+ if fModTime > self._fileModTime:
+ if not dabo.ui.areYouSure(_("""The file has
been modified on the disk since you opened it.
+Do you want to overwrite it?"""), _("File Conflict"), defaultNo=True,
cancelButton=False):
+ return
try:
open(fname,
"wb").write(self.GetText().encode(self.Encoding))
except OSError:
- dabo.ui.stop("Could not save %s. Please check your
write permissions." % fname)
+ dabo.ui.stop(_("Could not save file '%s'. Please check
your write permissions.") % fname)
return False
# set self._fileName, in case it was changed with a Save As
self._fileName = fname
@@ -1520,7 +1521,7 @@
cc = self.checkChangesAndContinue()
if cc:
if fileSpec is None:
- fileSpec = self.promptForFileName("Open")
+ fileSpec = self.promptForFileName(_("Open"))
if fileSpec is None:
return False
try:
@@ -1529,10 +1530,9 @@
f.close()
except IOError:
if os.path.exists(fileSpec):
- dabo.ui.stop("Could not open %s.
Please check that you have read permissions." % fileSpec)
+ dabo.ui.stop(_("Could not open %s.
Please check that you have read permissions.") % fileSpec)
return False
- if dabo.ui.areYouSure("File '%s' does not
exist."
- " Would you like to create it?"
% fileSpec):
+ if dabo.ui.areYouSure(_("File '%s' does not
exist. Would you like to create it?") % fileSpec):
text = ""
self.saveFile(fileSpec)
else:
Modified: branches/Nate/dabo/ui/uiwx/dSpinner.py
===================================================================
--- branches/Nate/dabo/ui/uiwx/dSpinner.py 2008-08-16 19:40:35 UTC (rev
4417)
+++ branches/Nate/dabo/ui/uiwx/dSpinner.py 2008-08-17 00:16:45 UTC (rev
4418)
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-
import locale
-try:
- from decimal import Decimal as decimal
-except ImportError:
- decimal = float
+from decimal import Decimal as decimal
import wx
import dabo
@@ -18,16 +15,31 @@
from dabo.ui import makeProxyProperty
-class dSpinButton(dcm.dDataControlMixin, wx.SpinButton):
+class _dSpinButton(dcm.dDataControlMixin, wx.SpinButton):
+ """Simple wrapper around the base wx.SpinButton."""
def __init__(self, parent, properties=None, attProperties=None, *args,
**kwargs):
- self._baseClass = dSpinButton
+ self._baseClass = _dSpinButton
preClass = wx.PreSpinButton
kwargs["style"] = kwargs.get("style", 0) | wx.SP_ARROW_KEYS
dcm.dDataControlMixin.__init__(self, preClass, parent,
properties, attProperties,
*args, **kwargs)
+ def __onWxSpinUp(self, evt):
+ self.raiseEvent(dEvents.SpinUp, spinType="button")
+ self.raiseEvent(dEvents.Spinner, spinType="button")
+
+
+ def __onWxSpinDown(self, evt):
+ self.raiseEvent(dEvents.SpinDown, spinType="button")
+ self.raiseEvent(dEvents.Spinner, spinType="button")
+
+
+
class dSpinner(dabo.ui.dDataPanel):
+ """Control for allowing a user to increment a value by discreet steps
across a range
+ of valid values.
+ """
def __init__(self, parent, properties=None, attProperties=None, *args,
**kwargs):
self.__constructed = False
self._spinWrap = False
@@ -45,7 +57,7 @@
# Create the child controls
self._proxy_textbox = dabo.ui.dTextBox(self, Value=val,
Width=32,
StrictNumericEntry=False, _EventTarget=self)
- self._proxy_spinner = dSpinButton(parent=self,
_EventTarget=self)
+ self._proxy_spinner = _dSpinButton(parent=self,
_EventTarget=self)
self.__constructed = True
self.Sizer = dabo.ui.dSizer("h")
self.Sizer.append(self._proxy_textbox, 1, valign="middle")
@@ -59,6 +71,10 @@
self.autoBindEvents()
ps = self._proxy_spinner
pt = self._proxy_textbox
+ # Set an essentially infinite range. We'll handle the range
ourselves.
+ ps.SetRange(-2**30, 2**30)
+ # We'll also control wrapping ourselves
+ self._proxy_spinner._addWindowStyleFlag(wx.SP_WRAP)
ps.Bind(wx.EVT_SPIN_UP, self.__onWxSpinUp)
ps.Bind(wx.EVT_SPIN_DOWN, self.__onWxSpinDown)
ps.Bind(wx.EVT_SPIN, self._onWxHit)
@@ -72,56 +88,86 @@
return self.__constructed
- def __onWxSpinUp(self, evt):
- if self._spinUp():
- self.raiseEvent(dEvents.SpinUp, spinType="button")
- self.raiseEvent(dEvents.Spinner, spinType="button")
+ def _coerceTypes(self, newVal, minn, maxx, margin):
+ """Handle the problems when min/max/increment values are
+ of one type, and the edited value another.
+ """
+ typN = type(newVal)
+ # Only problem here is Decimal and float combinations
+ if typN == decimal:
+ def toDec(val):
+ return decimal(str(val))
+ margin = toDec(margin)
+ if type(maxx) == float:
+ maxx = toDec(maxx)
+ if type(minn) == float:
+ minn = toDec(minn)
+ elif typN == float:
+ if type(maxx) == decimal:
+ maxx = float(maxx)
+ if type(minn) == decimal:
+ minn = float(minn)
+ return minn, maxx, margin
- def __onWxSpinDown(self, evt):
- if self._spinDown():
- self.raiseEvent(dEvents.SpinDown, spinType="button")
- self.raiseEvent(dEvents.Spinner, spinType="button")
-
-
- def _spinUp(self):
+ def _spinUp(self, evt=None):
+ """Handles a user request to increment the value."""
ret = True
curr = self._proxy_textbox.Value
- new = curr + self.Increment
- if new <= self.Max:
- self._proxy_textbox.Value = new
+ newVal = curr + self.Increment
+ minn, maxx, margin = self._coerceTypes(newVal, self.Min,
self.Max, 0.0001)
+ diff = newVal - maxx
+ if diff < margin:
+ self._proxy_textbox.Value = newVal
elif self._spinWrap:
- xs = new - self.Max
- self._proxy_textbox.Value = self.Min + xs
+ self._proxy_textbox.Value = minn + diff
else:
ret = False
self._checkBounds()
self.flushValue()
+ self.raiseEvent(dEvents.Hit, hitType="button")
return ret
- def _spinDown(self):
+ def _spinDown(self, evt=None):
+ """Handles a user request to decrement the value."""
ret = True
curr = self._proxy_textbox.Value
- new = curr - self.Increment
- if new >= self.Min:
- self._proxy_textbox.Value = new
+ newVal = curr - self.Increment
+ minn, maxx, margin = self._coerceTypes(newVal, self.Min,
self.Max, -0.0001)
+ diff = newVal - minn
+ if diff > margin:
+ self._proxy_textbox.Value = newVal
elif self._spinWrap:
- xs = self.Min - new
- self._proxy_textbox.Value = self.Max - xs
+ self._proxy_textbox.Value = maxx + diff
else:
ret = False
self._checkBounds()
self.flushValue()
+ self.raiseEvent(dEvents.Hit, hitType="button")
return ret
+ def __onWxSpinUp(self, evt):
+ """Respond to the wx event by raising the Dabo event."""
+ if self._spinUp():
+ self.raiseEvent(dEvents.SpinUp, spinType="button")
+ self.raiseEvent(dEvents.Spinner, spinType="button")
+
+
+ def __onWxSpinDown(self, evt):
+ """Respond to the wx event by raising the Dabo event."""
+ if self._spinDown():
+ self.raiseEvent(dEvents.SpinDown, spinType="button")
+ self.raiseEvent(dEvents.Spinner, spinType="button")
+
+
def _checkBounds(self):
"""Make sure that the value is within the current Min/Max"""
if self._proxy_textbox.Value < self.Min:
- self._proxy_textbox.Value = self.Min
+ self._proxy_textbox.Value = self._proxy_spinner.Value =
self.Min
elif self._proxy_textbox.Value > self.Max:
- self._proxy_textbox.Value = self.Max
+ self._proxy_textbox.Value = self._proxy_spinner.Value =
self.Max
def _onWxHit(self, evt):
@@ -138,6 +184,9 @@
def _onChar(self, evt):
+ """Handle the case where the user presses the up/down arrows to
+ activate the spinner.
+ """
keys = dabo.ui.dKeys
kc = evt.keyCode
if kc in (keys.key_Up, keys.key_Numpad_up):
@@ -153,6 +202,9 @@
def _onLostFocus(self, evt):
+ """We need to handle the case where the user types an invalid
value
+ into the textbox and then tabs/clicks away.
+ """
val = self.Value
pt = self._proxy_textbox
if (val > self.Max) or (val < self.Min):
@@ -219,7 +271,6 @@
def _setMax(self, val):
if self._constructed():
self._max = val
- self._proxy_spinner.SetRange(self.Min, val)
self._checkBounds()
else:
self._properties["Max"] = val
@@ -231,24 +282,17 @@
def _setMin(self, val):
if self._constructed():
self._min = val
- self._proxy_spinner.SetRange(val, self.Max)
self._checkBounds()
else:
self._properties["Min"] = val
def _getSpinnerWrap(self):
- try:
- return
self._proxy_spinner._hasWindowStyleFlag(wx.SP_WRAP)
- except AttributeError:
- return self._spinWrap
+ return self._spinWrap
def _setSpinnerWrap(self, val):
if self._constructed():
self._spinWrap = val
- self._proxy_spinner._delWindowStyleFlag(wx.SP_WRAP)
- if val:
-
self._proxy_spinner._addWindowStyleFlag(wx.SP_WRAP)
else:
self._properties["SpinnerWrap"] = val
Modified: branches/Nate/ide/Editor.py
===================================================================
--- branches/Nate/ide/Editor.py 2008-08-16 19:40:35 UTC (rev 4417)
+++ branches/Nate/ide/Editor.py 2008-08-17 00:16:45 UTC (rev 4418)
@@ -369,7 +369,9 @@
for pg in self.pgfEditor.Pages:
ed = pg.editor
if not ed.isChanged() and ed.checkForDiskUpdate():
+ selpos = ed.SelectionPosition
ed.openFile(ed._fileName)
+ ed.SelectionPosition = selpos
def onLexSelect(self, evt):
_______________________________________________
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]