#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    17
    Rep Power
    0

    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.

    example:

    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.
    :000000808
    :000011A33


    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:
    :000000822
    :000011A33

    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.
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    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.

    The Dialog:
    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:
    #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
    grimey
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    17
    Rep Power
    0
    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.
  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Here are a few ideas....
    Code:
    #In the main code...
    lines = open("myfile",'r').readlines()
    
    firstset = line[0][-4:]
    secondset = line[1][-4:]
    dlg = myDigitDialog(self, firstset, secondset)
    ......
    
    #in the __init__ method of the dialog
    #set values
    self.maskedTextCtrl1.SetValue(firstset[0:2])
    self.maskedTextCtrl2.SetValue(firstset[2:])
    self.maskedTextCtrl3.SetValue(secondset[0:2])
    self.maskedTextCtrl4.SetValue(secondset[2:])
    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:
    Code:
            self.maskedTextCtrl1.SetValidRegex('^[0-9a-fA-F]{2}')
    Heres a sample that sets and gets fields:
    Code:
        def __init__(self, parent):
            self._init_ctrls(parent)
            self.maskedTextCtrl1.SetValue('FF')
    
        def OnButton1Button(self, event):
            if self.maskedTextCtrl1.IsValid():
                value = self.maskedTextCtrl1.GetValue()
                self.staticText1.SetLabel(value)
            else:
                self.staticText1.SetLabel("Not valid")
            event.Skip()
    grim

IMN logo majestic logo threadwatch logo seochat tools logo