GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 22, 2014 3:22 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: create a 2-d list and store data in it in python3
PostPosted: Wed Apr 02, 2014 10:50 am 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Hi,
I am trying to write a gtk3 app using python3. But I am a newbie in python. Currently I am having problem storing the data in a 2-d list. The list should be dynamic.
The complete code is :
Code:
from gi.repository import Gtk, GObject

class EntryWindow(Gtk.Window):

  def __init__(self):
    Gtk.Window.__init__(self, title="Generate Init")
    self.set_size_request(100, 50)

    self.grid=Gtk.Grid()
    self.add(self.grid)
    self.q=0
#Initilize the array
    self.lstAtm=[1]

#Create Initial Entry
    self.BSite = Gtk.Button("ADD SITE")                                 
    self.ESite = Gtk.Entry()                                            #Number of atom in that site
    self.LSite = Gtk.Label("New Site With ")
    self.LSite2 = Gtk.Label("atoms ")
    self.EGroup= Gtk.Entry()                                            #Space group number
    self.LGroup= Gtk.Label("Space Group Number")
    self.ESite.set_placeholder_text("Number of Site")
    self.EGroup.set_placeholder_text("Space Group Number")
    self.BSub=Gtk.Button("Submit")                                      #Submit button to write to
    self.BSub.set_sensitive(False)                                      #file                   
    self.grid.attach(self.BSub,0,4,4,1)
    self.grid.attach(self.LSite,0,0,1,1)
    self.grid.attach_next_to(self.ESite,self.LSite,Gtk.PositionType.RIGHT,1,1)
    self.grid.attach_next_to(self.LSite2,self.ESite,Gtk.PositionType.RIGHT,1,1)
    self.grid.attach_next_to(self.BSite,self.LSite2,Gtk.PositionType.RIGHT,1,1)
    self.grid.attach_next_to(self.LGroup,self.LSite,Gtk.PositionType.TOP,1,1)
    self.grid.attach_next_to(self.EGroup,self.LGroup,Gtk.PositionType.RIGHT,1,1)
    self.BSite.connect("clicked",self.get_site)
    self.BSub.connect("clicked",self.print_data)


  def get_site(self,ESite):
    self.numSite = self.ESite.get_text()
    txtCoord="coordinate at site "+str(self.q)
    self.LCoord=Gtk.Label(txtCoord)
    self.ECoordX=Gtk.Entry()
    self.ECoordY=Gtk.Entry()
    self.ECoordZ=Gtk.Entry()
    if int(self.numSite) > 0:
     self.q =self.q+1
     print(self.q)
     print(self.q, int(self.numSite))
     for row in range(self.q): self.lstAtm +=[[0]*int(self.numSite)]
     for self.i in range(1,int(self.numSite)+1):
       Gtk.Grid.insert_row(self.grid,1)
       self.EConc=Gtk.Entry()
       self.LConc=Gtk.Label("Conc")
       self.EAtom=Gtk.Entry()
       self.LAtom=Gtk.Label()
       self.grid.attach(self.EAtom,1,1,1,1)
       self.grid.attach_next_to(self.LAtom,self.EAtom,Gtk.PositionType.LEFT,1,1)
       self.grid.attach_next_to(self.LConc,self.EAtom,Gtk.PositionType.RIGHT,1,1)
       self.grid.attach_next_to(self.EConc,self.LConc,Gtk.PositionType.RIGHT,1,1)
       txtAtom="Atom "+ str(self.i)+" at Site "+str(self.q)
       self.LAtom.set_text(txtAtom)
       self.lstAtm.append[self.q][self.i]=self.EAtom.get_text()
       #win.show_all()
     Gtk.Grid.insert_row(self.grid,1)
     self.grid.attach(self.ECoordX,1,1,1,1)
     self.grid.attach_next_to(self.ECoordY,self.ECoordX,Gtk.PositionType.RIGHT,1,1)
     self.grid.attach_next_to(self.ECoordZ,self.ECoordY,Gtk.PositionType.RIGHT,1,1)
     self.grid.attach_next_to(self.LCoord,self.ECoordX,Gtk.PositionType.LEFT,1,1)
     self.BSub.set_sensitive(True)
     win.show_all()

  def print_data(self, BSub):
      print("from p",self.numSite)

win = EntryWindow()   
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()


Being a newbie, the list is defined and used in

Code:
line 13 self.lstAtm=[1]
line 48 for row in range(self.q): self.lstAtm +=[[0]*int(self.numSite)]
line 61 self.lstAtm.append[self.q][self.i]=self.EAtom.get_text()


Being a newbie, can you kindly show me what I am doing wrong and how to set up the list correctly?


Top
 Profile  
 
 Post subject: Re: create a 2-d list and store data in it in python3
PostPosted: Wed Apr 02, 2014 5:25 pm 
Offline
Familiar Face

Joined: Mon Mar 31, 2014 9:59 pm
Posts: 16
I received the following error when trying to run it. Is that a crystallography application?

Code:
Traceback (most recent call last):
  File "test2.py", line 61, in get_site
    self.lstAtm.append[self.q][self.i]=self.EAtom.get_text()
TypeError: 'builtin_function_or_method' object is not subscriptable


I am also just learning Gtk and Python, so I couldn't figure out what the mistake is.

_________________
I am learning to develop GTK+ (GTK 3.10) programs written in Python 3.4.0, designed with Glade 3.16.1, with plots using Matplotlib 1.4. I program and test using Ubuntu 14.04 (64bit) and Gedit. (http://gtk3-matplotlib-cookbook.readthedocs.org)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group