Re: [Tutor] Gtk - relational data display and edit

2011-04-26 Thread bodsda
Thanks for your reply.

Unfortunately I can't change the data format because it is output from a closed 
source app.

I can't figure out a way to create the entry widgets on the fly because they 
need to be bound to a variable to attach them to a gtk.Table and to be able to 
read the data from them

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Walter Prins 
Date: Tue, 26 Apr 2011 16:55:36 
To: 
Cc: 
Subject: Re: [Tutor] Gtk - relational data display and edit

On 26 April 2011 16:34,  wrote:

> Hi,
>
> I am reading in data from a csv file which will be in a format like this
>
> User1, attrib1, attrib2
> User2, attrib1, attrib2
> Etc.
>

Why would the data be in this format?  Are you defining it?  Reason I ask is
that, relationally speaking, (e.g. database design-wise) this is a
denormalised representation and you'd do better to store a single attribute
per record.  E.g. have entities, User, Attrib, and have relationship table
User_Attrib that contains only user, attrib pairs.  But, maybe such ideas
are overkill for your app.



> And need to display this in a window. My initial thought was to use
> gtk.Entry widgets because I will need to edit this data, but I don't think
> this will work as I will also need to read the data back, in relation to the
> user column, e.g I will have something like
>
> [Psuedocode]
> For I in entries:
>A = usercolumn
>B = attrib1column
>C = attrib2column
>
>Somefunction(A,B,C)
> [/psuedocode]
>
> I don't think I could use this method with entry boxes as I have no idea
> how many entries there will be (column length will be fixed) so I can't
> create the entry widgets beforehand
>
> Anyone have any suggestions?
>

Well if you can count the number of entries on reading the file (whatever
the shape of the file) then in principle you can dynamically create the
correct number of entry boxes on the fly.  Of course, if you store one
attribe per record, then counting the number of attributes (records) for a
given user becomes quite easy of course. But even if you don't do this, and
you have the file structure you described, you can code reader code that
would internally store the attributes and the number of attributes for each
user, enabling you to write code to create the UI with the appropriate
number of entry widgets.

Walter

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Gtk - relational data display and edit

2011-04-26 Thread Knacktus

Am 26.04.2011 17:34, schrieb bod...@googlemail.com:

Hi,

I am reading in data from a csv file which will be in a format like this

User1, attrib1, attrib2
User2, attrib1, attrib2
Etc.

And need to display this in a window. My initial thought was to use gtk.Entry 
widgets because I will need to edit this data, but I don't think this will work 
as I will also need to read the data back, in relation to the user column, e.g 
I will have something like

[Psuedocode]
For I in entries:
 A = usercolumn
 B = attrib1column
 C = attrib2column

 Somefunction(A,B,C)
[/psuedocode]

I don't think I could use this method with entry boxes as I have no idea how 
many entries there will be (column length will be fixed) so I can't create the 
entry widgets beforehand



You could use a table widget. I'm sure GTK has something like that (I'm 
using Qt).


Otherwise, creating a "dynamic" widget for one set of your data is not 
as hard as it might sound. You need to keeping references to the 
composing widgets, for example in a dict. Here's some PyQt Pseudocode:



# You can retrieve the dictionary and the fieldnames with help of the
# csv module
att_name_to_value = {"User": "User1", "Att1": "attrib1", "Att1": "attrib1"}
fieldnames = ["User", "Att1", "Att2"]

att_name_to_line_edit = {}

# This is Qt specific
layout = QtGui.QGridLayout()

for row, fieldname in enumerate(fieldnames):
label = QtGui.QLabel(fieldname)
line_edit = QtGui.QLineEdit(att_name_to_value[fieldname]
att_name_to_line_edit[fieldname] = line_edit
# add the label to the first col
layout.addWidget(label, row, 0)
# add the line_edit to the second col
layout.addWidget(line_edit, row, 1)

my_main_widget = QtGui.QWidget()
my_main_widget.setLayout(layout)


Now, if you need to read the changed data from the widget (triggered by 
a button_clicked event or what ever) you can call a function to read the 
data like this:



def read_data_from_widget(att_name_to_line_edit):
for att_name, line_edit in att_name_to_line_edit.items():
# do the conversion, e.g. PyQt
new_text = str(line_edit.text())
# do whatever you wish with the new data ...


HTH,

Jan





Anyone have any suggestions?

Thanks,
Bodsda
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Gtk - relational data display and edit

2011-04-26 Thread Timo

On 26-04-11 17:34, bod...@googlemail.com wrote:

Hi,

I am reading in data from a csv file which will be in a format like this

User1, attrib1, attrib2
User2, attrib1, attrib2
Etc.

And need to display this in a window. My initial thought was to use gtk.Entry 
widgets because I will need to edit this data, but I don't think this will work 
as I will also need to read the data back, in relation to the user column, e.g 
I will have something like

[Psuedocode]
For I in entries:
 A = usercolumn
 B = attrib1column
 C = attrib2column

 Somefunction(A,B,C)
[/psuedocode]

I don't think I could use this method with entry boxes as I have no idea how 
many entries there will be (column length will be fixed) so I can't create the 
entry widgets beforehand
Use a gtk.Treeview for displaying this kind of data. You can also have 
editable cells inside a treeview so the user can change the data.


Cheers,
Timo


Anyone have any suggestions?

Thanks,
Bodsda
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Gtk - relational data display and edit

2011-04-26 Thread Walter Prins
On 26 April 2011 16:34,  wrote:

> Hi,
>
> I am reading in data from a csv file which will be in a format like this
>
> User1, attrib1, attrib2
> User2, attrib1, attrib2
> Etc.
>

Why would the data be in this format?  Are you defining it?  Reason I ask is
that, relationally speaking, (e.g. database design-wise) this is a
denormalised representation and you'd do better to store a single attribute
per record.  E.g. have entities, User, Attrib, and have relationship table
User_Attrib that contains only user, attrib pairs.  But, maybe such ideas
are overkill for your app.



> And need to display this in a window. My initial thought was to use
> gtk.Entry widgets because I will need to edit this data, but I don't think
> this will work as I will also need to read the data back, in relation to the
> user column, e.g I will have something like
>
> [Psuedocode]
> For I in entries:
>A = usercolumn
>B = attrib1column
>C = attrib2column
>
>Somefunction(A,B,C)
> [/psuedocode]
>
> I don't think I could use this method with entry boxes as I have no idea
> how many entries there will be (column length will be fixed) so I can't
> create the entry widgets beforehand
>
> Anyone have any suggestions?
>

Well if you can count the number of entries on reading the file (whatever
the shape of the file) then in principle you can dynamically create the
correct number of entry boxes on the fly.  Of course, if you store one
attribe per record, then counting the number of attributes (records) for a
given user becomes quite easy of course. But even if you don't do this, and
you have the file structure you described, you can code reader code that
would internally store the attributes and the number of attributes for each
user, enabling you to write code to create the UI with the appropriate
number of entry widgets.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Gtk - relational data display and edit

2011-04-26 Thread bodsda
Hi,

I am reading in data from a csv file which will be in a format like this

User1, attrib1, attrib2
User2, attrib1, attrib2
Etc.

And need to display this in a window. My initial thought was to use gtk.Entry 
widgets because I will need to edit this data, but I don't think this will work 
as I will also need to read the data back, in relation to the user column, e.g 
I will have something like

[Psuedocode]
For I in entries:
A = usercolumn
B = attrib1column
C = attrib2column

Somefunction(A,B,C)
[/psuedocode]

I don't think I could use this method with entry boxes as I have no idea how 
many entries there will be (column length will be fixed) so I can't create the 
entry widgets beforehand

Anyone have any suggestions?

Thanks,
Bodsda
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor