Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Please help with wx.Dialog ???

Help
2008-05-28
2013-05-01
  • fernando paiva
    fernando paiva
    2008-05-28

    Hello All

    I am facing a problem that can not resolve. I have two wx.Dialog form, their name are: Customer and SearchCustomer
    In the form Customer I have a button that invoke a SearchCustomer form, the SearchCustomer form has a grid that is filled with the results of the consultation

    In the SearchCustomer form, I have a function below.
        def OnGridSearchCustomerGridCellLeftDclick(self, event):
            import Customer
            customer  = Customer.Customer(self)
            row = event.GetRow()
            codeOfCustomer = self.gridSearchCustomer.GetCellValue(row, 0)
            self.Close()
            customer.receiveSearch(int(codeOfCustomer))

    In the Customer form, I have a function below.
        def receiveSearch(self, codeOfCustomer):
            """ This function receive code of customer """
            self.intCtrlCode.SetValue(codeOfCustomer)
           
            try:
                _sql = """
                        SELECT customer_code, customer_name FROM customer WHERE customer_code = %s
                       """ % (codeOfCustomer)
                self.cursor.execute(_sql)
                registers = self.cursor.fetchall()        
                for x in registers:
                    self.textCtrlName.SetValue(x["customer_name"])
            except MySQLdb.Error, e:
                wx.MessageBox("Error %d: %s" %(e.args[0], e.args[1])) 

    When I give a command "print", the values is all right, but the fields "textCtrlName" not update with a Set Value. I don't understand because.

    Any Idea ???

    Please excuse my errors of English.

     
    • fernando paiva
      fernando paiva
      2008-05-29

      The Search Customer form, stay on top of a Customer form, but after the
      consultation it closes.
      I already had attemped the Refresh() of the controls, but I did not have
      success.

      Here the bind of intCtrl.
              self.intCtrlCodigo = wx.lib.intctrl.IntCtrl(allow_long=False,
                    allow_none=False, default_color=wx.BLACK,
                    id=wxID_DIALOGCLIENTESINTCTRLCODIGO, limited=False, max=None,
                    min=None, name='intCtrlCode', oob_color=wx.RED, parent=self,
                    pos=wx.Point(80, 34), size=wx.Size(58, 21),
                    style=wx.TE_RIGHT | wx.WANTS_CHARS, value=0)
              self.intCtrlCode.Bind(wx.EVT_KEY_UP, self.OnIntCtrlCodeKeyUp)

      See my new function, and look the comment.

      def receiveSearch(self, codeOfCustomer):
              """ This function receives the code and makes the consultation sql
      and fills the fields """

              self.intCtrlCode.SetValue(codeOfCustomer)

              try:
                  _sql = """
                          SELECT customer_code, customer_name FROM customer WHERE
      customer_code = %s
                         """ % (codeOfCustomer)
                  self.cursor.execute(_sql)
                  registers = self.cursor.fetchall()
                  for x in registers:
                      self.textCtrlName.SetValue(x["customer_name"])
              except MySQLdb.Error, e:
                  wx.MessageBox("Error %d: %s" %(e.args[0], e.args[1]))
              finally:
                  self.intCtrlCode.Refresh()
                  self.textCtrlName.Refresh()
                  # here I make I command print and all the data are correct, but
                  # the fields not fills
                  print self.intCtrlCode.GetValue()

      Here the function of SearchCustomer form.
      def OnGridSearchCustomerGridCellLeftDclick(self, event):
              """ This function get a code of Customer in wx.Grid and send to
      function receiveSearch in Customer form """
              import Customer
              customer  = Customer.Customer(self)
              row = event.GetRow()
              codeOfCustomer = self.gridSearchCustomer.GetCellValue(row, 0)
              customer.receiveSearch(int(codeOfCustomer))
              self.Close()

      The command "print" show all values corretly, but the fields not.

      Thanks !

       
      • I think it should work.

        can you insert a print just after:

        self.textCtrlName.SetValue(x["customer_name"])

        e.g.
        print self.textCtrlName.GetValue()
        print x["customer_name"]

        What does this show?

        BTW, I would do it a bit different, so not to couple the search dialog with a particular "result dialog" method, i.e. here it is a dialog to search/create/update supplier information, which provides the information changed in GetLastItem (in my case I use Sqlalchemy, so this is a mapper instance which contains just about everything of the supplier.  This means that I don't have to do another sql call to get the name.

        Note that use SetStringSelection as the control is a combobox and not a textctrl.

                try:
                    dlg = dialogsupplier.DialogSupplier(parent=self)
                    dlg.CenterOnScreen()
                    val = dlg.ShowModal()

                    creation = dlg.GetLastItem()

                    if creation:
                        self.supplier.SetStringSelection(creation.name.ljust(self.supplier._masklength))
                        self.supplier.Refresh()
                        self.supplier.SetModified()
                        mypub.publisher.sendMessage(mypub.dataNeedsSaving, self.tparent)
                finally:
                    dlg.Destroy()

        Hope this helps, if not can you provide a small self contained sample which shows the problem.
        Werner

         
    • fernando paiva
      fernando paiva
      2008-05-29

      Hello Werner

      But the problem is continued, the control intCtrl and textCtrl dont show the values.

      When I print self.intCtrlCode.GetValue() the value is exactly but the fields not show the values, I am trying the Refresh(), Update() and others, but still dont success.

      For example:
      finally:
         # here the intCtrlCode not dumb the value for 15
           self.intCtrlCode.SetValue(15)
         # but here
           print self.intCtrlCode.GetValue()
         # the result of print is: 15

      The fields not change but the value is get exactly, I don't understand the because.

      I already am being crazy. :)

      thanks for your help !

       
    • fernando paiva
      fernando paiva
      2008-05-29

      Werner

      when I use:
      print self.intCtrlCode.IsModified()
      return is True
      print self.intCtrlCode.GetValue()
      return for example: 15

      but the "SetValue" of field not change.

      I'm crazy now =)

      thanks