November 11th, 2004, 01:33 PM
Help with Boa Constructor GUI making
Hi and thanks in advance.
I am new to Python and I am using Boa Constructor to make a GUI interface. I followed the documentation for it on how to make the simple notepad program and now I need some help. I know this will be alot to ask and I might get shot down but here goes. And no, this is not a homework assignment for those that might ask.
I am trying to make an interface that will have text fields that read in data from a file and put the data into specific text boxes that allow you to change the information from those boxes. Kind of like and excel spreadsheet.
I have a file that has these numbers and letters, the first 6 charachers are just identifiers for something else and can be ignored. ie :00000 :00001. I am only concerned with the 0808 and 1A33.
Now I am trying make a simple interface that will have text boxes that only have room for 2 chars, ie 08 08 etc. I do not want anything else in these spots, but these text boxes must be able to write to the orignal file and replace the data displayed in them. So on the first line I want to change the 0808, I would have two text boxes that display the 08 08 and I can change these values to 08 22 and the new file when saved will look like this:
I hope this is making sense to someone out there that might be able to help me. If I can get a jump on how to get it to work properly I can complete the rest of the interface. I'm just getting confused on how to make seperate text boxes that act like a spreadsheet that will only allow a user to input 2 chars of 0-9, A-F only, and read and write to those specific spots in the file.
Thanks in advance for any help or direction I might get.
November 12th, 2004, 05:27 AM
In psuedo code it might go like this:
Open the file containing the values.
Read in all the lines into a list.
On the nth and nth+1 line get the last 4 characters of each line.
Split each string of 4 characters into pairs.
Open your digit dialog, passing the pairs as intialising values.
Wait for the Dialog to close and then read the result of user actions.
If the user clicked OK then read the values from the dialog and do the file update.
If the User clicked Cancel then do nothing with the data.
To update the file:
Read the lines from the file into a list as before. Modify the nth and nth+1 line with the new pairs. Then write the list out to the file.
This is a good candidate for using the wxMaskedTextCtrl. This is demoed and documented as MaskedEditControls in the wxPython demo.
With it's masking option's the choice is yours whether you have one control or 4. Either way you can use the methods such a setvalue to fill in the fields and getplainvalue to read out the contents. Just because the user clicks ok does not mean the data is valid, you will still have to check it meets your requirements and pop up an error dialog if it does not - prompting the user to keep trying.
As well as the text control(s) you would need an OK and Cancel button. If I remember right the Boa tutorial explains how to make a custom dialog.
#code to read file and extract pairs
dlg = myDigitDialog(self, pairs) #the dialog to allow editing of the pairs.
if dlg.ShowModal() == wxID_OK:
newpairs = dlg.GetValue() #updated values
#code to write the newpairs to file
November 17th, 2004, 06:42 PM
Ok, I was able to get the text boxes to work and only allow the 2 digits I needed. Still researching on how to limit the type of data that goes into the text fields, I only want HEX values in there 0-9, A-F. But I am still unclear as to how you open the file into a list then put the data needed into the right text box.
November 18th, 2004, 12:00 PM
Here are a few ideas....
This code would be in the __init_ctrls method of the dialog (set as the ValidRegex property in the Property Inspector) to limit valid chars:
#In the main code...
lines = open("myfile",'r').readlines()
firstset = line[-4:]
secondset = line[-4:]
dlg = myDigitDialog(self, firstset, secondset)
#in the __init__ method of the dialog
Heres a sample that sets and gets fields:
def __init__(self, parent):
def OnButton1Button(self, event):
value = self.maskedTextCtrl1.GetValue()