473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

UI Edit Controls

440 256MB
Hi,

I need to enter only float/integer values for the "Edit" controls in my UI.I should allow to enter "alphabets".

How to check this condition?.

Thanks
PSB
Apr 17 '07 #1
11 1488
bartonc
6,596 Expert 4TB
Hi,

I need to enter only float/integer values for the "Edit" controls in my UI.I should allow to enter "alphabets".

How to check this condition?.

Thanks
PSB
??? Tkinter has:
Text
Entry
??? Edit ???
Apr 17 '07 #2
psbasha
440 256MB
??? Tkinter has:
Text
Entry
??? Edit ???
Sorry ,I should not allow user to enter 'Text',user is allowed to enter "float/int" values.

-PSB
Apr 17 '07 #3
bartonc
6,596 Expert 4TB
Sorry ,I should not allow user to enter 'Text',user is allowed to enter "float/int" values.

-PSB
Enter into what kind of widget????

If you are using Tkinter.Entery()s, I can provide subclasses that I wrote.
Apr 17 '07 #4
psbasha
440 256MB
I am using "Tkinter".Is possible help me with sample code?

-PSB
Apr 18 '07 #5
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from dbtools import *
  3. from datetime import date, time
  4. from calendar import monthrange
  5.  
  6. ### I tried using Tk's validatecommand callback, but it works badly.
  7. ### Access and choice of event bindings is much better this way.
  8. ### The creation of the set() method make these widgets looks like Variables.
  9.  
  10. class ValidEntry(Entry):
  11.     """Validate the value of an entry widget; Use escape to go back to
  12.     previous value.
  13.     A callback routine which expects the event
  14.     can optionally be notified of changes to the entry. Set next to
  15.     a widget instance that whould get the focus next on <Return>."""
  16.     def __init__(self, master=None, callback=None, minvalue=None, maxvalue=None,
  17.                  cnf={}, **kw):
  18.         try:
  19.             self.next = kw.pop('next')
  20.         except KeyError:
  21.             self.next = None
  22.         try:
  23.             self.receiver = kw.pop('receiver')
  24.         except KeyError:
  25.             self.receiver = None
  26.         try:
  27.             self.nullProc = kw.pop('nullProc')
  28.         except KeyError:
  29.             self.nullProc = None
  30.         Entry.__init__(self, master, cnf, **kw)
  31.  
  32.         self.callback = callback
  33.         self.minvalue = minvalue
  34.         self.maxvalue = maxvalue
  35.         self.oldvalue = ''
  36.  
  37.         self.bind('<Tab>', self.CheckValue)
  38.         self.bind('<Return>', self.CheckValue)
  39.         self.bind('<FocusOut>', self.CheckValue)    # For clicks outside this widget
  40.         self.bind('<FocusIn>', self.ReFocus)
  41.         self.bind('<Escape>', self.UndoValue)
  42.  
  43.     def set(self, value):
  44.         self.delete(0,END)
  45.         self.insert(0, str(value))
  46.         self.oldvalue = str(value)
  47.  
  48.     def replace(self, value):
  49. ##        print 'replacing %s with %s' %(repr(self.oldvalue), repr(value))
  50.         if self.oldvalue:
  51.             self.oldvalue = ''
  52.         self.delete(0,END)
  53.         self.insert(0, str(value))
  54.  
  55.     def clear(self):
  56.         self.set('')
  57.  
  58.     def convert(self, value=None):
  59.         """Override this method to return an alternate format (or type)"""
  60.         if value is None:
  61.             value = self.get()
  62.         return value
  63.  
  64.     def CheckValue(self, event=None):
  65.         """If the current value is equal to oldvalue, there's nothing to
  66.            check.  Else, validate() may change the the user-entered value,
  67.            so re-get() and store in oldvalue. Callbacks happen for new valid
  68.            values. Events are generated for old values and new valid values."""
  69.         if event is None:
  70.             event = Event()
  71.             event.widget = self
  72.             event.type = '35'
  73. ##        print 'checking %s' %event.widget
  74.         value = self.get()
  75.         isvalid = True
  76.         if value != self.oldvalue:
  77.             if value:
  78.                 isvalid = self.Validate(value)
  79.             if isvalid:
  80.                 if type(isvalid) == bool:
  81.                     newvalue = self.get()
  82.                     self.oldvalue = newvalue
  83.                     self.select_clear()
  84.                     self.icursor(END)
  85.                     if self.callback is not None:
  86. ##                        print 'calling back'
  87.                         self.callback(event)
  88.                 else: self.Invalid(isvalid[0], isvalid[1])
  89.             else:
  90.                 self.Invalid()
  91.         else:
  92.             self.SendEvent(event)
  93.         if isvalid:
  94.             if event.type == '2' or event.type == '35':
  95.                 if self.next is not None:
  96.                     self.next.focus_set()
  97.  
  98.     def Invalid(self, index1=0, index2=END):
  99.         self.bell()
  100.         self.focus_set()
  101.         self.select_range(index1, index2)
  102.         self.icursor(index1)
  103.  
  104.     def Validate(self, value):
  105.         """An override of this method may re-format the string
  106.         and then store it by calling self.replace(newvalue).
  107.         Call this method from inside a try block that catches the
  108.         ValueError exception for min/max checking after converting
  109.         the string to a hashable type"""
  110.  
  111.         minvalue = self.minvalue
  112.         if minvalue is not None and value < minvalue:
  113.             raise ValueError
  114.         maxvalue = self.maxvalue
  115.         if maxvalue is not None and value > maxvalue:
  116.             raise ValueError
  117.         return True
  118.  
  119.     def ReFocus(self, event=None):
  120.         self.select_range(0, END)
  121.         self.icursor(END)
  122.  
  123.     def UndoValue(self, event=None):
  124.         """Pass the <Escape> to the receiver."""
  125.         self.set(self.oldvalue)
  126.         self.ReFocus()
  127.         try:
  128.             self.receiver.event_generate("<<Entry_Escape>>")
  129.         except AttributeError: pass
  130.  
  131.     def ReturnEvent(self):
  132.         """Generate a <Return> event in this widget."""
  133.         event = Event()
  134.         event.widget = self
  135.         event.type = '2'
  136.         self.icursor(END)
  137.         self.CheckValue(event)
  138.  
  139.     def SendEvent(self, event):
  140.         """Pass the <Tab>, <Return>, <FocusOut> up the chain when
  141.            the value didn't change."""
  142.         try:
  143.             self.nullProc(event)
  144.         except TypeError: pass
  145.  
  146.     def SetNextWidget(self, nextWidget):
  147.         self.next = nextWidget
  148.  
  149.     def GetNextWidget(self):
  150.         return self.next
  151.  
  152.     def SetRecWidget(self, receiver):
  153.         self.receiver = receiver
  154.  
  155.     def SetNullProc(self, nullProc):
  156.         self.nullProc = nullProc
  157.  
  158.     def SetCallback(self, callback):
  159.         self.callback = callback
  160.  
  161.     def Close(self):
  162.         self.ReturnEvent()
  163. # Date and Time Entries remove due to post-size limit #
  164.  
  165. class IntegerEntry(ValidEntry):
  166.     def Validate(self, value):
  167.         try:
  168.             a = int(value)
  169.             ValidEntry.Validate(self, a)
  170.             return True
  171.         except ValueError:
  172.             return False
  173.  
  174.     def convert(self, value=None):
  175.         if value is None:
  176.             value = self.get()
  177.         try:
  178.             value = int(value)
  179.         except ValueError:
  180.             pass
  181.         return value
  182.  
  183. class FloatEntry(ValidEntry):
  184.     def Validate(self, value):
  185.         try:
  186.             a = float(value)
  187.             ValidEntry.Validate(self, a)
  188.             return True
  189.         except ValueError:
  190.             return False
  191.  
  192.     def convert(self, value=None):
  193.         if value is None:
  194.             value = self.get()
  195.         try:
  196.             value = float(value)
  197.         except ValueError:
  198.             pass
  199.         return value
  200.  
  201. class HexEntry(ValidEntry):
  202.     def Validate(self, value):
  203.         try:
  204.             a = int(value, 16)
  205.             ValidEntry.Validate(self, a)
  206.             self.replace(value.upper())
  207.             return True
  208.         except ValueError:
  209.             return False
  210.  
  211. class DollarEntry(FloatEntry):
  212.     def __init__(self, master=None, callback=None, minvalue=None, maxvalue=None,
  213.                  cnf={}, **kw):
  214.         ValidEntry.__init__(self, master, callback, minvalue, maxvalue, cnf, **kw)
  215.         self.config(justify=RIGHT)
  216.  
  217.     def Validate(self, value):
  218.         try:        # Allow up to 5 places to the right of dp
  219.             if value[0] == '$':
  220.                 value = value[1:]
  221.             a = float(value)
  222.             ValidEntry.Validate(self, a)
  223.             a = '$%.5f' %a
  224.             self.replace(a[:-3])   # but only keep 2
  225.             return True
  226.         except ValueError:
  227.             return False
  228.  
  229.     def get(self):
  230.         value = Entry.get(self)
  231.         if value:
  232.             if value[0] == '$':
  233.                 value = value[1:]
  234.         return value
  235.  
  236. class StringEntry(ValidEntry):
  237.     """Disable minvalue and maxvalue, allow all text."""
  238.     def Validate(self, value):
  239.         return True
  240.  
  241. class StateEntry(ValidEntry):
  242.     def Validate(self, value):
  243.         if len(value) > 2 or not value.isalpha():
  244.             return False
  245.         self.replace(value.upper())
  246.         return True
  247.  
  248. class NameEntry(ValidEntry):
  249.     def Validate(self, value):
  250.         l = value.split()
  251.         value = ' '.join(value.capitalize() for value in l)
  252.         self.replace(value)
  253.         return True
  254.  
  255. class PhoneEntry(ValidEntry):
  256.     def Validate(self, value):
  257.         for char in set(' -()').intersection(value):
  258.             l = value.split(char)
  259.             value = ''.join(l)
  260.         i = len(value)
  261.         if i >= 7:
  262.             if i == 7 and int(value[0]) > 1:
  263.                 self.replace('%s-%s' %(value[:3], value[3:]))
  264.                 return True
  265.             if i == 8 and value[0] == '1':
  266.                 self.replace('1-%s-%s' %(value[1:4], value[4:]))
  267.                 return True
  268.             if i == 10 and int(value[0]) > 1:
  269.                 self.replace('(%s) %s-%s' %(value[:3], value[3:6], value[6:]))
  270.                 return True
  271.             if i == 11 and value[0] == '1':
  272.                 self.replace('1-(%s) %s-%s' %(value[1:4], value[4:7], value[7:]))
  273.                 return True
  274.         return False
  275.  
  276.  
  277.  
  278. if __name__ == '__main__':
  279.     root = Tk(className='widget test window')
  280.     top = Frame()
  281.     top.pack()
  282.  
  283.     def cb(event):
  284.         print 'Callback called by event type %s' %(event.type)
  285.  
  286.     de = DateEntry(top, width=11, callback=cb)
  287.     pe = PhoneEntry(top, width=15, callback=cb)
  288.     ne = TimeEntry(top, callback=cb)
  289.  
  290.     de.next = pe
  291.     pe.next = ne
  292.     ne.next = de
  293.  
  294.     de.pack()
  295.     pe.pack()
  296.     ne.pack()
  297.     de.setdate('')
  298.     root.mainloop()
Apr 18 '07 #6
psbasha
440 256MB
I dont have dbtools modules
"from dbtools import *"

Expand|Select|Wrap|Line Numbers
  1. Sample
  2. IDLE 1.1.4      
  3. >>> ================================ RESTART ================================
  4. >>> 
  5.  
  6. Traceback (most recent call last):
  7.   File "C:\Validtaion.py", line 2, in -toplevel-
  8.     from dbtools import *
  9. ImportError: No module named dbtools
  10. >>> 
  11.  
Apr 19 '07 #7
bartonc
6,596 Expert 4TB
I dont have dbtools modules
"from dbtools import *"

Expand|Select|Wrap|Line Numbers
  1. Sample
  2. IDLE 1.1.4      
  3. >>> ================================ RESTART ================================
  4. >>> 
  5.  
  6. Traceback (most recent call last):
  7.   File "C:\Validtaion.py", line 2, in -toplevel-
  8.     from dbtools import *
  9. ImportError: No module named dbtools
  10. >>> 
  11.  
The module that I posted is very old. Feel free to simply remove the parts that you need and chuck the rest.
Apr 19 '07 #8
psbasha
440 256MB
I tried commenting the "from dbtools import *" and related methods.But I am not able to see any UI controls.

-PSB
Apr 19 '07 #9
bartonc
6,596 Expert 4TB
I tried commenting the "from dbtools import *" and related methods.But I am not able to see any UI controls.

-PSB
I'm still not clear on whether Tkinter.Entery is what you are looking for...
Apr 20 '07 #10
psbasha
440 256MB
Validation for the Data enetered in UI controls.

I am looking for the data enetr in the "Edit Box"Controls.

Suppose user wants to enter the ineteger values only in the Edit Box,So the code has to check for only integer values entry.If by mistake user enters "alphabets/special characters",the edit box should not allow to take.Otherwise the application crashes or we have to throw error

-PSB
Apr 20 '07 #11
bartonc
6,596 Expert 4TB
Validation for the Data enetered in UI controls.

I am looking for the data enetr in the "Edit Box"Controls.

Suppose user wants to enter the ineteger values only in the Edit Box,So the code has to check for only integer values entry.If by mistake user enters "alphabets/special characters",the edit box should not allow to take.Otherwise the application crashes or we have to throw error

-PSB
The thing is this:
I've never heard of an "Edit Box" Control.
If you can
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import EditBox
then you need to show what you are doing.
Apr 20 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Kevin Myers | last post by:
Hello, Please forgive my reposting of this note with hopefully a more relevant subject line. On an Access 2000 form under Windows 2000 I would like to use a Kodak Image Edit Control to...
0
by: doronb | last post by:
hello my question is : i define dynamic columns to datagrid , 4 columns are databound and 1 columne is "edit template column" and only this col editable , i define function for update when...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
3
by: Leo | last post by:
I have a datagrid with the first column as a Edit,Update,Cancel button column. The other 5 columns are template columns. When I click the Edit button in IE6 the row correctly displays the...
2
by: mwhalen | last post by:
Hi All, I've dynmaically created a textbox, but I can't edit it. When I click on it, the cursor flashes for a second, but then goes away and I can't enter any text or do anything with the value...
2
by: Luqman | last post by:
How can I put GridView and DetailView control to Edit Mode with one click of button ? I don't want to show built-in Edit Buttons of above controls. Best Regards, Luqman
2
by: Vish | last post by:
Hi, I amplanning on having a rea-only and edit states for my form. But it do not want my form and its controls to look different or disabled. I am planning on having a edit button that brings...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
8
by: =?Utf-8?B?bWlrZWc=?= | last post by:
Hi, I am building a small Help Desk application for my company and need to be able to edit "open" help desk issues. I use a simple datagrid to display each issue (6 per page) , with an Edit...
1
by: Arielle | last post by:
Background: I have a generated datalist to display information and I need to add the capability to have a button (Edit button) so that users can change the information. I'm sure once I figure it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.