Issues with ObjectListView

Hello,
I have been using the ObjectListView 1.2 to display data, and I have found some problems. I have been able to solve some of them but not others. I provide a zip file, so you only need to run the test.py file to reproduce the problems. So, I make a short list:

a) I managed to sort the rows within each group. However, when I sort the data using the English Name or Scientific Name columns I need the GROUPS to be sorted according to the Species ID number. Now it is orderer alphabetically. Note that, for example, the Montagu's Harrier group has 2 rows with the same number (1001), This is the numbers which should be used to sort the groups

b) Is there a way to hide columns? I would like to hide the Species ID column. I know that some versions of ObjectListView provide a IsVisible argument on ColumnDefn, but since I use Linux I must use ObjectListView 1.2

c) Is there a way to make the group title expand across different column? I mean that I would like it not to be hidden when narrowing a column

d) can I modify the group title? I would like to remove/modify the section "(6 items)"

Well, I thin these are the ones I couldn't solve. Can anyone help?
Cheers!

Dani

test.zip (2.29 KB)

···

--
Daniel Valverde Saub�
c/Joan Maragall 37 4 2
17002 Girona
Spain
Tel�fon m�bil: +34651987662
e-mail: dani.valverde@gmail.com
http://www.acrocephalus.net
http://natupics.blogspot.com

Si no �s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar�s a estalviar aigua, energia i recursos forestals. GR�CIES!

Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU!

If you don't need the column, then don't create it. The data is still
accessible because OLV uses objects, so you can always grab the row
object and still get the species ID from it.

···

On Oct 20, 5:17 am, Dani Valverde <dani.valve...@gmail.com> wrote:

Hello,
I have been using the ObjectListView 1.2 to display data, and I have
found some problems. I have been able to solve some of them but not
others. I provide a zip file, so you only need to run the test.py file
to reproduce the problems. So, I make a short list:

a) I managed to sort the rows within each group. However, when I sort
the data using the English Name or Scientific Name columns I need the
GROUPS to be sorted according to the Species ID number. Now it is
orderer alphabetically. Note that, for example, the Montagu's Harrier
group has 2 rows with the same number (1001), This is the numbers which
should be used to sort the groups

b) Is there a way to hide columns? I would like to hide the Species ID
column. I know that some versions of ObjectListView provide a IsVisible
argument on ColumnDefn, but since I use Linux I must use ObjectListView 1.2

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Thank you Mike. This may be a naive question, but how do I grab the column? Do you know how can I solve the a) issue? This is quite important for me, as the logical sorting of my object is not alphabetical, but the one provided by the column Species ID.
Cheers!

Dani

···

On 10/20/2010 04:25 PM, Mike Driscoll wrote:

On Oct 20, 5:17 am, Dani Valverde<dani.valve...@gmail.com> wrote:
   

Hello,
I have been using the ObjectListView 1.2 to display data, and I have
found some problems. I have been able to solve some of them but not
others. I provide a zip file, so you only need to run the test.py file
to reproduce the problems. So, I make a short list:

a) I managed to sort the rows within each group. However, when I sort
the data using the English Name or Scientific Name columns I need the
GROUPS to be sorted according to the Species ID number. Now it is
orderer alphabetically. Note that, for example, the Montagu's Harrier
group has 2 rows with the same number (1001), This is the numbers which
should be used to sort the groups

b) Is there a way to hide columns? I would like to hide the Species ID
column. I know that some versions of ObjectListView provide a IsVisible
argument on ColumnDefn, but since I use Linux I must use ObjectListView 1.2
     
If you don't need the column, then don't create it. The data is still
accessible because OLV uses objects, so you can always grab the row
object and still get the species ID from it.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

--
Daniel Valverde Saub�
c/Joan Maragall 37 4 2
17002 Girona
Spain
Tel�fon m�bil: +34651987662
e-mail: dani.valverde@gmail.com
http://www.acrocephalus.net
http://natupics.blogspot.com

Si no �s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar�s a estalviar aigua, energia i recursos forestals. GR�CIES!

Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU!

What do you mean by grab? Each row is an object. So all the attributes
in your class that the row is based on are available whether or not
you turned them into columns. Let's say you have the following
attributes in a car class:

self.color
self.type
self.weight

You create a two column OLV widget with color and type as the two
columns. If you bind to the select event, you can print out ALL the
properties for that row:

def onItemSelected(self, event):
    row = self.OLVWidget.GetFocusedRow()
    modelObj = self.OLVWidget.GetObjectAt(row)
    print modelObj.color, modelObj.type, modelObj.weight

This is probably the most obvious event. You can also grab all the
rows and iterate over them too. To sort by the ID, you'll have to look
at the documentation...as I recall, it had some special sorting
capabilities. If those don't work, then create a list of rows and sort
by the id. Here's an example using the Car class:

<code>

···

On Oct 20, 9:44 am, Dani Valverde <dani.valve...@gmail.com> wrote:

On 10/20/2010 04:25 PM, Mike Driscoll wrote:

> On Oct 20, 5:17 am, Dani Valverde<dani.valve...@gmail.com> wrote:

>> Hello,
>> I have been using the ObjectListView 1.2 to display data, and I have
>> found some problems. I have been able to solve some of them but not
>> others. I provide a zip file, so you only need to run the test.py file
>> to reproduce the problems. So, I make a short list:

>> a) I managed to sort the rows within each group. However, when I sort
>> the data using the English Name or Scientific Name columns I need the
>> GROUPS to be sorted according to the Species ID number. Now it is
>> orderer alphabetically. Note that, for example, the Montagu's Harrier
>> group has 2 rows with the same number (1001), This is the numbers which
>> should be used to sort the groups

>> b) Is there a way to hide columns? I would like to hide the Species ID
>> column. I know that some versions of ObjectListView provide a IsVisible
>> argument on ColumnDefn, but since I use Linux I must use ObjectListView 1.2

> If you don't need the column, then don't create it. The data is still
> accessible because OLV uses objects, so you can always grab the row
> object and still get the species ID from it.

> -------------------
> Mike Driscoll

> Blog: http://blog.pythonlibrary.org

Thank you Mike. This may be a naive question, but how do I grab the
column? Do you know how can I solve the a) issue? This is quite
important for me, as the logical sorting of my object is not
alphabetical, but the one provided by the column Species ID.
Cheers!

Dani

########################################################################
class Car:
    """"""

#----------------------------------------------------------------------
    def __init__(self, color, weight, carType):
        """Constructor"""
        self.color = color
        self.weight = weight
        self.type = carType

if __name__ == "__main__":
    ford = Car("blue", 1200, "car")
    chevy = Car("green", 1800, "truck")
    mg = Car("red", 1500, "car")

    from operator import attrgetter
    x = [ford, chevy, mg]
    y = sorted(x, key=attrgetter('weight'))
</code>

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Dani,

Hello,
I have been using the ObjectListView 1.2 to display data, and I have
found some problems. I have been able to solve some of them but not
others. I provide a zip file, so you only need to run the test.py file
to reproduce the problems. So, I make a short list:

a) I managed to sort the rows within each group. However, when I sort
the data using the English Name or Scientific Name columns I need the
GROUPS to be sorted according to the Species ID number. Now it is
orderer alphabetically. Note that, for example, the Montagu's Harrier
group has 2 rows with the same number (1001), This is the numbers which
should be used to sort the groups

b) Is there a way to hide columns? I would like to hide the Species ID
column. I know that some versions of ObjectListView provide a IsVisible
argument on ColumnDefn, but since I use Linux I must use ObjectListView 1.2

If you don't need the column, then don't create it. The data is still
accessible because OLV uses objects, so you can always grab the row
object and still get the species ID from it.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Thank you Mike. This may be a naive question, but how do I grab the column? Do you know how can I solve the a) issue? This is quite important for me, as the logical sorting of my object is not alphabetical, but the one provided by the column Species ID.

Maybe attached will help - but I am not sure I get exactly what you like to do.

You might also look at the class documentation of ColumnDef for more details/options you have for it.
http://objectlistview.sourceforge.net/python/majorClasses.html

Maybe what you are needing is "ColumnDef.SortListItemsBy" and the sort event - haven't used these myself.

Werner

test.py (2.07 KB)

···

On 20/10/2010 16:44, Dani Valverde wrote:

On 10/20/2010 04:25 PM, Mike Driscoll wrote:

On Oct 20, 5:17 am, Dani Valverde<dani.valve...@gmail.com> wrote:

Thank you Werner and Mike. Now I am able to modify the group title, but I cannot figure out how to hide (or not to create) a column while using it to sort the rows and I still have problems to sort groups.
Cheers!

Dani

···

On 10/20/2010 05:38 PM, werner wrote:

Dani,

On 20/10/2010 16:44, Dani Valverde wrote:

On 10/20/2010 04:25 PM, Mike Driscoll wrote:

On Oct 20, 5:17 am, Dani Valverde<dani.valve...@gmail.com> wrote:

Hello,
I have been using the ObjectListView 1.2 to display data, and I have
found some problems. I have been able to solve some of them but not
others. I provide a zip file, so you only need to run the test.py file
to reproduce the problems. So, I make a short list:

a) I managed to sort the rows within each group. However, when I sort
the data using the English Name or Scientific Name columns I need the
GROUPS to be sorted according to the Species ID number. Now it is
orderer alphabetically. Note that, for example, the Montagu's Harrier
group has 2 rows with the same number (1001), This is the numbers which
should be used to sort the groups

b) Is there a way to hide columns? I would like to hide the Species ID
column. I know that some versions of ObjectListView provide a IsVisible
argument on ColumnDefn, but since I use Linux I must use ObjectListView 1.2

If you don't need the column, then don't create it. The data is still
accessible because OLV uses objects, so you can always grab the row
object and still get the species ID from it.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Thank you Mike. This may be a naive question, but how do I grab the column? Do you know how can I solve the a) issue? This is quite important for me, as the logical sorting of my object is not alphabetical, but the one provided by the column Species ID.

Maybe attached will help - but I am not sure I get exactly what you like to do.

You might also look at the class documentation of ColumnDef for more details/options you have for it.
Major Classes Reference — ObjectListView v1.2 documentation

Maybe what you are needing is "ColumnDef.SortListItemsBy" and the sort event - haven't used these myself.

Werner

--
Daniel Valverde Saub�
c/Joan Maragall 37 4 2
17002 Girona
Spain
Tel�fon m�bil: +34651987662
e-mail: dani.valverde@gmail.com
http://www.acrocephalus.net
http://natupics.blogspot.com

Si no �s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar�s a estalviar aigua, energia i recursos forestals. GR�CIES!

Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU!

...

Thank you Werner and Mike. Now I am able to modify the group title, but I cannot figure out how to hide (or not to create) a column while using it to sort the rows and I still have problems to sort groups.

See attached, speciesID is no longer in the list but still used to group.

Werner

test.py (2.08 KB)

···

On 20/10/2010 20:27, Dani Valverde wrote:

Hello Werner,
In your example, speciesID is no longer in the list but it isn't used either. What I mean is that when you sort the data by (for example) the Country column you get the species alphabetically sorted instead of sorting them according to their speciesID number.
Cheers!

Dani

···

On 10/21/2010 12:12 AM, werner wrote:

On 20/10/2010 20:27, Dani Valverde wrote:
...

Thank you Werner and Mike. Now I am able to modify the group title, but I cannot figure out how to hide (or not to create) a column while using it to sort the rows and I still have problems to sort groups.

See attached, speciesID is no longer in the list but still used to group.

Werner

--
Daniel Valverde Saub�
c/Joan Maragall 37 4 2
17002 Girona
Spain
Tel�fon m�bil: +34651987662
e-mail: dani.valverde@gmail.com
http://www.acrocephalus.net
http://natupics.blogspot.com

Si no �s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar�s a estalviar aigua, energia i recursos forestals. GR�CIES!

Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU!

Hi Dani,

...

Thank you Werner and Mike. Now I am able to modify the group title, but I cannot figure out how to hide (or not to create) a column while using it to sort the rows and I still have problems to sort groups.

See attached, speciesID is no longer in the list but still used to group.

Werner

Hello Werner,
In your example, speciesID is no longer in the list but it isn't used either. What I mean is that when you sort the data by (for example) the Country column you get the species alphabetically sorted instead of sorting them according to their speciesID number.

It is used on line 15: "myKey = '%s - %s' % (data.speciesID, data.species)"

Should the items always be sorted by speciesID? If yes, then using "SortBy(0)" should do the trick.

If you need a different sort depending on which column one groups by then the olv method "SortListItemsBy" might work for you, but I never used this.

Werner

test.py (2.1 KB)

···

On 25/10/2010 11:29, Dani Valverde wrote:

On 10/21/2010 12:12 AM, werner wrote:

On 20/10/2010 20:27, Dani Valverde wrote:

Hello,
The items should always be sorted by speciesID. However, if I don't include the speciedID column as ColumnDefn they are always sorted alphabetically. What I would like is to sort them by speciesID even inside each group whithout showing the speciesID column. I can do it if I show the column without any problem, but once I remove the column items are always sorted alphabetically. I've had a look to the 'SortListItemsBy', but I cannot figure out how does it work. What is the comparison function? How do I construct and use it?
Cheers!

Dani

···

On 10/25/2010 12:25 PM, werner wrote:

Hi Dani,

On 25/10/2010 11:29, Dani Valverde wrote:

On 10/21/2010 12:12 AM, werner wrote:

On 20/10/2010 20:27, Dani Valverde wrote:
...

Thank you Werner and Mike. Now I am able to modify the group title, but I cannot figure out how to hide (or not to create) a column while using it to sort the rows and I still have problems to sort groups.

See attached, speciesID is no longer in the list but still used to group.

Werner

Hello Werner,
In your example, speciesID is no longer in the list but it isn't used either. What I mean is that when you sort the data by (for example) the Country column you get the species alphabetically sorted instead of sorting them according to their speciesID number.

It is used on line 15: "myKey = '%s - %s' % (data.speciesID, data.species)"

Should the items always be sorted by speciesID? If yes, then using "SortBy(0)" should do the trick.

If you need a different sort depending on which column one groups by then the olv method "SortListItemsBy" might work for you, but I never used this.

Werner

--
Daniel Valverde Saub�
c/Joan Maragall 37 4 2
17002 Girona
Spain
Tel�fon m�bil: +34651987662
e-mail: dani.valverde@gmail.com
http://www.acrocephalus.net
http://natupics.blogspot.com

Si no �s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar�s a estalviar aigua, energia i recursos forestals. GR�CIES!

Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU!

Hi Dani,

...

Thank you Werner and Mike. Now I am able to modify the group title, but I cannot figure out how to hide (or not to create) a column while using it to sort the rows and I still have problems to sort groups.

See attached, speciesID is no longer in the list but still used to group.

Werner

Hello Werner,
In your example, speciesID is no longer in the list but it isn't used either. What I mean is that when you sort the data by (for example) the Country column you get the species alphabetically sorted instead of sorting them according to their speciesID number.

It is used on line 15: "myKey = '%s - %s' % (data.speciesID, data.species)"

Should the items always be sorted by speciesID? If yes, then using "SortBy(0)" should do the trick.

If you need a different sort depending on which column one groups by then the olv method "SortListItemsBy" might work for you, but I never used this.

Werner

Hello,
The items should always be sorted by speciesID. However, if I don't include the speciedID column as ColumnDefn they are always sorted alphabetically. What I would like is to sort them by speciesID even inside each group whithout showing the speciesID column. I can do it if I show the column without any problem, but once I remove the column items are always sorted alphabetically.

In the example I attached to the previous post I moved speciesID to the end and set the min/max to 0 - just noticed you need to change the line "self.Olv.SortBy(0)" to "self.Olv.SortBy(10)" for it to sort on it. BTW, isn't this a bit confusing to sort by something the user can't see?

I've had a look to the 'SortListItemsBy', but I cannot figure out how does it work. What is the comparison function? How do I construct and use it?

If I read the doc correctly this function should look similar to the one in olv._objectComparer.

Werner

···

On 25/10/2010 12:43, Dani Valverde wrote:

On 10/25/2010 12:25 PM, werner wrote:

On 25/10/2010 11:29, Dani Valverde wrote:

On 10/21/2010 12:12 AM, werner wrote:

On 20/10/2010 20:27, Dani Valverde wrote:

Cheers!

Dani