So I wanted a textBox to only let hexadecimals be typed.
And now I want it to put leading zeroes to the entered hex.
This is my code:
--------------------------------------------------------------------------------------------------
class tbNumber(dabo.ui.dTextBox):
''' Only allows typing Hexadecimal fills with 0 up to TextLength'''
def afterInit(self):
self.ForceCase = 'Upper'
self.bindEvent(dEvents.KeyChar, self.soloNumerosHex)
self.bindEvent(dEvents.ValueChanged, self.FormatValue)
def soloNumerosHex(self, evt):
if not (evt.keyCode in (9, 8, 13, 127, 314, 316)
# Tab, BackTab, BackSpace, Enter, Delete,
# flecha izquierda y flecha derecha
# están permitidos
or evt.keyChar in string.hexdigits):
evt.stop()
def FormatValue(self, evt):
''' Fills with 0 up to TextLength'''
self.Value = self.Value.rjust(self.TextLength, '0')
--------------------------------------------------------------------------------------------------------
It works partially.
If the user changes the value of the control (click or tab to the
textbox and put some hex) leading zeroes are put on exiting the control.
But if I have a "delete" button (all it does is
self.Form.myTextBox.Value = '0') the first time I click on it I will see
"0000000" in the textbox, but if I click it a second time then I will
see "0" in the textbox. If I click on the textbox, put a number and
leave the textbox it will put leading zeroes and clicking on the
"delete" button will work ok the first time.
I can see a problem in my code, and that is that it should enter an
endless loop as the ValueChanged event will call self.FormatValue() that
will change the value again. But I can't imagine how else to do it.
I'll thank any help and any code corrections.
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[email protected]