python - is it possible to set numbers as a string in a listctrl -


okay ran complications setting numbers in listctrl they're numbers in sql database , they're inserted strings... converted numbers automatically

from wx import * import item class itemmain ( wx.frame ):      def __init__( self, parent ):         wx.frame.__init__ ( self, parent, id = wx.id_any, title = u"items", pos = wx.defaultposition, size = wx.size( 517,486 ), style = wx.default_frame_style|wx.tab_traversal )          self.setsizehintssz( wx.size( -1,-1 ), wx.defaultsize )          bsizer3 = wx.boxsizer( wx.vertical )           # create item         self.ite = i.item()            self.list = wx.listctrl( self, wx.id_any, wx.defaultposition, wx.defaultsize,wx.lc_report )         self.list.insertcolumn(0,"item id")         self.list.insertcolumn(1,"item name")         self.list.insertcolumn(2,"item price")         self.list.insertcolumn(3,"stock")         self.list.bind(evt_list_item_selected,self.getselecteditems)         self.list.setminsize( wx.size( 500,300 ) )         self.list.setmaxsize( wx.size( 1000,800 ) )         self.refresh_list(none)          bsizer3.add( self.list, 0, wx.all|wx.align_center_horizontal, 5 )          bsizer4 = wx.boxsizer( wx.horizontal )         self.m_button20 = wx.button( self, wx.id_any, u"add item", wx.defaultposition, wx.defaultsize, 0 )         self.m_button20.bind(wx.evt_button, self.add_entry)         bsizer4.add( self.m_button20, 1, wx.all|wx.align_center_vertical, 5 )          self.m_button21 = wx.button( self, wx.id_any, u"update record", wx.defaultposition, wx.defaultsize, 0 )         self.m_button21.bind(wx.evt_button, self.update_entry)         bsizer4.add( self.m_button21, 1, wx.align_center_vertical|wx.all, 5 )          bsizer3.add( bsizer4, 1, wx.expand, 5 )          self.setsizer( bsizer3 )         self.layout()          self.centre( wx.both )         self.show()      def refresh_list(self, event):         """place names of each itementry list"""          self.index = 0         self.entrydict = {}         self.list.deleteallitems()         entry in self.ite.list_entries():             self.list.insertstringitem(self.index,entry.item_id)             self.list.setstringitem(self.index,1,entry.item_name)             self.list.setstringitem(self.index,2,entry.item_price)             self.list.setstringitem(self.index,3,entry.item_qty)             self.entrydict[self.index] = entry             self.index += 1       def getselecteditems(self, event):         """    gets selected items list control.         selection returned list of selected indices,         low high.         """         selection = []         self.index = self.list.getfirstselected()         selection.append(self.index)         while len(selection) != self.list.getselecteditemcount():             self.index = self.list.getnextselected(self.index)             selection.append(self.index)          return self.index       def add_entry(self, event):        """add new entry item_qty ite"""        # start out blank, generic itementry        entry = i.itementry("","","","0")        self.endiag = itemdetail(self,entry)        self.endiag.showmodal()                      self.ite.add_entry(entry.item_id,                             entry.item_name,                             entry.item_price,                             entry.item_qty )         self.refresh_list(none)      def update_entry(self, event):        """updates details of selected entry"""        e_id = self.index        entry = self.ite.list_entries()[e_id]        self.endiag2 = itemdetailu(self , entry)        self.endiag2.showmodal()         self.ite.update_entry(entry.item,                             entry.item_name,                             entry.item_price,                             entry.item_qty )        self.refresh_list(none)  def __del__( self ):     pass   class itemdetail ( wx.dialog ):      def __init__( self, parent, entry ):             wx.dialog.__init__ ( self, parent, id = wx.id_any, title =u"add item", pos = wx.defaultposition, size = wx.size( 690,500 ), style = wx.default_dialog_style )              self.entry = entry             self.setsizehintssz( wx.size( 500,500 ), wx.defaultsize )              bsizer6 = wx.boxsizer( wx.vertical )              gsizer6 = wx.gridsizer( 2, 2, 0, 0 )              self.m_statictext5 = wx.statictext( self, wx.id_any, u"id", wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext5.wrap( -1 )             gsizer6.add( self.m_statictext5, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )              self.item_id = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )             self.item_id.setminsize( wx.size( 200,15 ) )             self.item_id.setmaxsize( wx.size( 500,15 ) )              self.m_statictext6 = wx.statictext( self, wx.id_any, u"item name", wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext6.wrap( -1 )             gsizer6.add( self.m_statictext6, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )              self.item_name = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )             self.item_name.setminsize( wx.size( 200,15 ) )             self.item_name.setmaxsize( wx.size( 500,15 ) )              gsizer6.add( self.item_name, 0, wx.all|wx.align_center_vertical|wx.align_center_horizontal|wx.expand, 5 )              self.m_statictext7 = wx.statictext( self, wx.id_any, u"item price", wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext7.wrap( -1 )             gsizer6.add( self.m_statictext7, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )              self.item_price = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )             self.item_price.setminsize( wx.size( 200,15 ) )             self.item_price.setmaxsize( wx.size( 500,15 ) )              gsizer6.add( self.item_price, 0, wx.all|wx.align_center_horizontal|wx.expand|wx.align_center_vertical, 5 )              self.m_statictext7 = wx.statictext( self, wx.id_any, u"stock", wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext7.wrap( -1 )             gsizer6.add( self.m_statictext7, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )              self.m_statictext8 = wx.statictext( self, wx.id_any, self.entry.item_qty, wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext8.wrap( -1 )             gsizer6.add( self.m_statictext8, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )             bsizer6.add( gsizer6, 1, wx.expand, 5 )              bsizer13 = wx.boxsizer( wx.horizontal )              self.m_button24 = wx.button( self, wx.id_any, u"ok", wx.defaultposition, wx.defaultsize, 0 )             self.m_button24.bind(wx.evt_button, self.ok)              bsizer13.add( self.m_button24, 1, wx.all|wx.align_center_vertical, 5 )              self.m_button25 = wx.button( self, wx.id_any, u"cancel", wx.defaultposition, wx.defaultsize, 0 )             self.m_button25.bind(wx.evt_button, self.closedial)              bsizer13.add( self.m_button25, 1, wx.all|wx.align_center_vertical, 5 )              bsizer6.add( bsizer13, 1, wx.expand, 5 )              self.setsizer( bsizer6 )             self.layout()              self.centre( wx.both )      def closedial(self,event):         """closes dialog"""         self.destroy()       def ok(self, event):         """sets details of current entry"""         self.entry.set_details( str(self.item_id.getvalue()),                             str(self.item_name.getvalue()),                             str(self.item_price.getvalue()),                             str(self.item_qty.getvalue()) )         self.destroy()       def __del__( self ):             pass                   class itemdetailu ( wx.dialog ):      def __init__( self, parent, entry ):             wx.dialog.__init__ ( self, parent, id = wx.id_any, title = u"update item:", pos = wx.defaultposition, size = wx.size( 690,500 ), style = wx.default_dialog_style )              self.entry = entry             self.setsizehintssz( wx.size( 500,500 ), wx.defaultsize )              bsizer6 = wx.boxsizer( wx.vertical )              gsizer6 = wx.gridsizer( 2, 2, 0, 0 )              self.m_statictext5 = wx.statictext( self, wx.id_any, u"id", wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext5.wrap( -1 )             gsizer6.add( self.m_statictext5, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )              self.m_statictext121 = wx.statictext( self, wx.id_any, self.entry.item_id, wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext121.wrap( -1 )             gsizer6.add( self.m_statictext121, 1, wx.all|wx.align_center_vertical|wx.align_center_horizontal, 5 )               self.m_statictext6 = wx.statictext( self, wx.id_any, u"item name", wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext6.wrap( -1 )             gsizer6.add( self.m_statictext6, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )              self.item_name = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )             self.item_name.setminsize( wx.size( 200,15 ) )             self.item_name.setmaxsize( wx.size( 500,15 ) )              gsizer6.add( self.item_name, 0, wx.all|wx.align_center_vertical|wx.align_center_horizontal|wx.expand, 5 )              self.m_statictext7 = wx.statictext( self, wx.id_any, u"item price", wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext7.wrap( -1 )             gsizer6.add( self.m_statictext7, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )              self.item_price = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )             self.item_price.setminsize( wx.size( 200,15 ) )             self.item_price.setmaxsize( wx.size( 500,15 ) )              gsizer6.add( self.item_price, 0, wx.all|wx.align_center_horizontal|wx.expand|wx.align_center_vertical, 5 )              self.m_statictext7 = wx.statictext( self, wx.id_any, u"stock", wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext7.wrap( -1 )             gsizer6.add( self.m_statictext7, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )              self.m_statictext8 = wx.statictext( self, wx.id_any, self.entry.item_qty, wx.defaultposition, wx.defaultsize, 0 )             self.m_statictext8.wrap( -1 )             gsizer6.add( self.m_statictext8, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )             bsizer6.add( gsizer6, 1, wx.expand, 5 )              bsizer13 = wx.boxsizer( wx.horizontal )              self.m_button24 = wx.button( self, wx.id_any, u"ok", wx.defaultposition, wx.defaultsize, 0 )             self.m_button24.bind(wx.evt_button, self.ok)              bsizer13.add( self.m_button24, 1, wx.all|wx.align_center_vertical, 5 )              self.m_button25 = wx.button( self, wx.id_any, u"cancel", wx.defaultposition, wx.defaultsize, 0 )             self.m_button25.bind(wx.evt_button, self.closedial)              bsizer13.add( self.m_button25, 1, wx.all|wx.align_center_vertical, 5 )              bsizer6.add( bsizer13, 1, wx.expand, 5 )              self.setsizer( bsizer6 )             self.layout()              self.centre( wx.both )      def closedial(self,event):          self.destroy()      def ok(self, event):         self.entry.set_details( str(self.item_id.getvalue()),                             str(self.item_name.getvalue()),                             str(self.item_price.getvalue()),                             str(self.item_qty.getvalue()) )         self.destroy()       def __del__( self ):             pass                    def main():        ex = wx.app()      itemmain(none)      ex.mainloop()        if __name__ == '__main__':      main() 

my problem lies in setting numbers in listctrl. given convert them strings when set entries, when refreshlist function called up, error calls setstingitem value price likely happen quantity also insists insert string , what's supplied isn't string.... ideas on how can work around this? couldn't find python documentation me

as mentioned, you'll want cast items strings. casting in item code it's done behind scenes. alternative might work sub-class wx.listctrl , override setter, think that's overkill when can in item class.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -