Can't Get A Selection from Tktable...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jerry.levan@gmail.com

    #1

    Can't Get A Selection from Tktable...

    Hi,
    I have a Tktable object (self.table) and when I click on a row the
    whole row is selected.

    If I click of a button to get the row contents then

    self.table.curs election() fails with a traceback of:

    Traceback (most recent call last):
    File
    "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/python2.4/lib-tk/Tkinter.py",
    line 1345, in __call__
    return self.func(*args )
    File "/Users/jerry/python/PyPgExplorerUni/Resources/editor.py", line
    159, in deleteRow
    print self.table.curs election()
    File
    "/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/Tktable.py",
    line 139, in curselection
    return self._getCells( self.tk.call(se lf._w, 'curselection') )
    File
    "/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/Tktable.py",
    line 106, in _getCells
    for i in string.split(ce llString):
    File
    "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/python2.4/string.py",
    line 292, in split
    return s.split(sep, maxsplit)
    AttributeError: 'tuple' object has no attribute 'split'

    It is my reading that curselection will return the indices of the
    selected cells...

    Help,

    Jerry

  • jerry.levan@gmail.com

    #2
    Here is the problem, need a fix :)


    jerry.levan@gma il.com wrote:
    Hi,
    I have a Tktable object (self.table) and when I click on a row the
    whole row is selected.
    >
    If I click of a button to get the row contents then
    >
    self.table.curs election() fails with a traceback of:
    >
    Traceback (most recent call last):
    File
    "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/python2.4/lib-tk/Tkinter.py",
    line 1345, in __call__
    return self.func(*args )
    File "/Users/jerry/python/PyPgExplorerUni/Resources/editor.py", line
    159, in deleteRow
    print self.table.curs election()
    File
    "/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/Tktable.py",
    line 139, in curselection
    return self._getCells( self.tk.call(se lf._w, 'curselection') )
    File
    "/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/Tktable.py",
    line 106, in _getCells
    for i in string.split(ce llString):
    File
    "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/python2.4/string.py",
    line 292, in split
    return s.split(sep, maxsplit)
    AttributeError: 'tuple' object has no attribute 'split'
    >
    It is my reading that curselection will return the indices of the
    selected cells...
    >
    Help,
    >
    Jerry
    looking into Tktable the curselection function is defined by:

    def curselection(se lf, setValue = None):
    if setValue != None:
    self.tk.call(se lf._w, 'curselection', 'set', setValue)
    else:
    return self._getCells( self.tk.call(se lf._w, 'curselection') )

    looking at getCells we see:

    def _getCells(self, cellString):
    #JHL
    print cellString
    res = []
    for i in string.split(ce llString):
    res.append(tupl e(map(int, string.split(i, ','))))
    return res

    When I run my program and select a row the value of cellString is

    ('3,0', '3,1', '3,2', '3,3', '3,4', '3,5', '3,6')

    Which is the correct results...( ie the "fourth" row is selected and
    there are six
    columns...

    Unfortunately the above is *not* a string and hence the "for" statement
    fails.

    It is hard to believe that I am the first person to attempt to retrieve
    a selection
    from a Tktable object....

    Am I overlooking something obvious?

    Jerry

    Comment

    • jerry.levan@gmail.com

      #3
      Fix for a Tktable bug....


      jerry.levan@gma il.com wrote:
      jerry.levan@gma il.com wrote:
      Hi,
      I have a Tktable object (self.table) and when I click on a row the
      whole row is selected.

      If I click of a button to get the row contents then

      self.table.curs election() fails with a traceback of:

      Traceback (most recent call last):
      File
      "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/python2.4/lib-tk/Tkinter.py",
      line 1345, in __call__
      return self.func(*args )
      File "/Users/jerry/python/PyPgExplorerUni/Resources/editor.py", line
      159, in deleteRow
      print self.table.curs election()
      File
      "/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/Tktable.py",
      line 139, in curselection
      return self._getCells( self.tk.call(se lf._w, 'curselection') )
      File
      "/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/Tktable.py",
      line 106, in _getCells
      for i in string.split(ce llString):
      File
      "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/python2.4/string.py",
      line 292, in split
      return s.split(sep, maxsplit)
      AttributeError: 'tuple' object has no attribute 'split'

      It is my reading that curselection will return the indices of the
      selected cells...

      Help,

      Jerry
      >
      looking into Tktable the curselection function is defined by:
      >
      def curselection(se lf, setValue = None):
      if setValue != None:
      self.tk.call(se lf._w, 'curselection', 'set', setValue)
      else:
      return self._getCells( self.tk.call(se lf._w, 'curselection') )
      >
      looking at getCells we see:
      >
      def _getCells(self, cellString):
      #JHL
      print cellString
      res = []
      for i in string.split(ce llString):
      res.append(tupl e(map(int, string.split(i, ','))))
      return res
      >
      When I run my program and select a row the value of cellString is
      >
      ('3,0', '3,1', '3,2', '3,3', '3,4', '3,5', '3,6')
      >
      Which is the correct results...( ie the "fourth" row is selected and
      there are six
      columns...
      >
      Unfortunately the above is *not* a string and hence the "for" statement
      fails.
      >
      It is hard to believe that I am the first person to attempt to retrieve
      a selection
      from a Tktable object....
      >
      Am I overlooking something obvious?
      >
      Jerry
      I think I have found a bug in the Tktable.py wrapper.

      It appears that if a row is selected in a Tktable (in Python)
      then any attempt to fetch the selection with curselection
      fails when a string operation is performed on a "tuple"

      the relevant routines in Tktable.py are:


      def curselection(se lf, setValue = None):
      if setValue != None:
      self.tk.call(se lf._w, 'curselection', 'set', setValue)
      else:
      return self._getCells( self.tk.call(se lf._w, 'curselection') )

      curselection will call _getCells

      def _getCells(self, cellString):
      res = []
      #JHL
      if type(cellString ) == type(()) : return cellString
      for i in string.split(ce llString):
      res.append(tupl e(map(int, string.split(i, ','))))
      return res

      I added the "if type( ...." line to prevent the error.

      If a table row is selected cellString will look like

      ('3,0', '3,1', '3,2', '3,3', '3,4', '3,5', '3,6')

      which is of type "tuple" which fails the string.split command ;(

      I suspect it is probably best to just short circuit the call to
      _getCells.

      The following routine (with the above patch )will correctly retrieve
      the contents
      of a selected row.

      def deleteRow(self) :
      res = self.table.curs election()
      for index in res :
      print self.table.get( index)

      Tain't clear to me where this should be reported

      Jerry

      Comment

      • jerry.levan@gmail.com

        #4
        Re: Fix for a Tktable bug....


        jerry.levan@gma il.com wrote:
        jerry.levan@gma il.com wrote:
        jerry.levan@gma il.com wrote:
        Hi,
        I have a Tktable object (self.table) and when I click on a row the
        whole row is selected.
        >
        If I click of a button to get the row contents then
        >
        self.table.curs election() fails with a traceback of:
        >
        Traceback (most recent call last):
        File
        "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/python2.4/lib-tk/Tkinter.py",
        line 1345, in __call__
        return self.func(*args )
        File "/Users/jerry/python/PyPgExplorerUni/Resources/editor.py", line
        159, in deleteRow
        print self.table.curs election()
        File
        "/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/Tktable.py",
        line 139, in curselection
        return self._getCells( self.tk.call(se lf._w, 'curselection') )
        File
        "/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/Tktable.py",
        line 106, in _getCells
        for i in string.split(ce llString):
        File
        "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/python2.4/string.py",
        line 292, in split
        return s.split(sep, maxsplit)
        AttributeError: 'tuple' object has no attribute 'split'
        >
        It is my reading that curselection will return the indices of the
        selected cells...
        >
        Help,
        >
        Jerry
        looking into Tktable the curselection function is defined by:

        def curselection(se lf, setValue = None):
        if setValue != None:
        self.tk.call(se lf._w, 'curselection', 'set', setValue)
        else:
        return self._getCells( self.tk.call(se lf._w, 'curselection') )

        looking at getCells we see:

        def _getCells(self, cellString):
        #JHL
        print cellString
        res = []
        for i in string.split(ce llString):
        res.append(tupl e(map(int, string.split(i, ','))))
        return res

        When I run my program and select a row the value of cellString is

        ('3,0', '3,1', '3,2', '3,3', '3,4', '3,5', '3,6')

        Which is the correct results...( ie the "fourth" row is selected and
        there are six
        columns...

        Unfortunately the above is *not* a string and hence the "for" statement
        fails.

        It is hard to believe that I am the first person to attempt to retrieve
        a selection
        from a Tktable object....

        Am I overlooking something obvious?

        Jerry
        >
        I think I have found a bug in the Tktable.py wrapper.
        >
        It appears that if a row is selected in a Tktable (in Python)
        then any attempt to fetch the selection with curselection
        fails when a string operation is performed on a "tuple"
        >
        the relevant routines in Tktable.py are:
        >
        >
        def curselection(se lf, setValue = None):
        if setValue != None:
        self.tk.call(se lf._w, 'curselection', 'set', setValue)
        else:
        return self._getCells( self.tk.call(se lf._w, 'curselection') )
        >
        curselection will call _getCells
        >
        def _getCells(self, cellString):
        res = []
        #JHL
        if type(cellString ) == type(()) : return cellString
        for i in string.split(ce llString):
        res.append(tupl e(map(int, string.split(i, ','))))
        return res
        >
        I added the "if type( ...." line to prevent the error.
        >
        If a table row is selected cellString will look like
        >
        ('3,0', '3,1', '3,2', '3,3', '3,4', '3,5', '3,6')
        >
        which is of type "tuple" which fails the string.split command ;(
        >
        I suspect it is probably best to just short circuit the call to
        _getCells.
        >
        The following routine (with the above patch )will correctly retrieve
        the contents
        of a selected row.
        >
        def deleteRow(self) :
        res = self.table.curs election()
        for index in res :
        print self.table.get( index)
        >
        Tain't clear to me where this should be reported
        >
        Jerry
        It would not be any fun for my app users if I had to change the
        Tktable.py
        source all by myself....

        Here is another fix that involves calling Tk directly

        instead of :
        res = self.table.curs election()

        I can do:
        res = self.root.tk.ca ll(self.table,' curselection')

        root is the app top level ( self.table works also...)

        for a row the above call will return something like
        ('2,0', '2,1', '2,2', '2,3', '2,4', '2,5', '2,6')

        the "co-ordinate" strings in the above tuple can be used
        as indices into the table to retreive the selection.


        Jerry

        Comment

        Working...