This is my class project to be made in pythonCard :
A local community centre desires to have a user friendly application to keep track of their community members. The application must allow a user to display information about community members, including the list of activities that individual members are interested in.

The centre manager also wants the application to allow the application user to:
add an activity for a particular member
delete and activity from a member's activity list, when the member choses to withdraw from that activity
add an activity to the range of available activities
remove an activity that the centre no longer supports
add new members, and
remove those no longer interested in a relationship with the community


it have used an empty list which is appended when user details are entered into their respective textfields, and the list is diplayed in a multicolumn list. Can anyone tell me how to incorporate interests groups, and what kind of list should i use in pythonCard to carry this out !

You would use a dictionary of lists, The dictionary key is the person's name or ID, pointing to a list that can contain multiple activities for that person.

So i should use a list for user details, and a dictionary to add those users in interest groups ?


this is my code so far

#filename: user.py
import pickle


# The User class holds data about the user details.

class User():
    id = 1
#The __init__ method initializes that all attributes are null.

    
       
    def __init__(self):
        self.myList = []
        self.id = User.id
        User.id +=1
        name = None
        address = None
        contact = None
        email = None
        
      
# The set_name method accepts an argument for the users name.

    def set_name(self, name):
        self.name = name

# The set_address method accepts an argument for the users address.

    def set_address(self, address):
        self.address = address
        
# The set_contact method accepts an argument for the users contact.

    
    def set_contact(self,contact):
        self.contact = contact

# The set_email method accepts an argument for the users email.

    def set_email(self,email):
        self.email = email
    
               
    def List(self):
        row = ("", self.name, self.address, self.contact, self.email)
        self.myList.append(row)
        self.save()
        
          

         
        

    def save(self):
        pickle_file = open('my_pickled_list.pkl', 'w')
        pickle.dump(self.myList, pickle_file)
        pickle_file.close()


    def recover(self):
        pickle_file = open('my_pickled_list.pkl', 'r')
        self.myList = pickle.load(pickle_file)
        pickle_file.close()

----------------------------------------------------------------
filename = adduser.py

from PythonCard import model
from user import *

class addUser(model.Background):

        global myUser
        myUser = User()


        def reset(self):
                self.components.tfName.text = ""
                self.components.tfAddress.text = ""
                self.components.tfContact.text = ""
                self.components.tfEmail.text = ""
                

                
        def on_initialize(self, event):
                self.parent = self.getParent()
                
                
                                                            
    
        def on_close(self, event):
                self.visible = False
    
        def on_menuFileExit_select(self, event):
                self.close()
                
               

        def on_btnClear_mouseClick(self, event):
                self.reset()
                
        def on_btnAdduser_mouseClick(self, event):
                myUser.name = self.components.tfName.text
                myUser.address = self.components.tfAddress.text
                myUser.contact = self.components.tfContact.text
                myUser.email = self.components.tfEmail.text
                myUser.recover()
                self.parent.components.multiCol.items = myUser.myList[:]
                
                

        
                                 
if __name__ == '__main__':
    app = model.Application(addUser)
    app.MainLoop()

-------------------------------------------------------------

#!/usr/bin/python
# written by Muhammad Khan 0999112
# version 2.0
# Filename: MultiCol.py

"""
__version__ = "$Revision: 1.10 $"
__date__ = "$Date: 20011/05/15 22:13:31 $"
"""

from PythonCard import dialog,model
import wx
from adduser import *
from user import *
from details import *


class MultiCol(model.Background):
    global myUser
    myUser = User()
       
    def on_initialize(self,event):
        self.addUser = model.childWindow(self, addUser)
        self.addUser.visible = False
        myUser.recover()
        
    
        

    def on_btnDeleteuser_mouseClick (self, event):
        pass
        
               
    
    def on_btnAdduser_mouseClick (self, event):        
        self.addUser.visible = True

      
                             
               
            

   

    def on_btnClose_mouseClick(self,event):
                    
        confirm = dialog.messageDialog(self, 'Are you sure you want to Exit ?', 'Confirm',
                                            wx.ICON_EXCLAMATION | wx.YES_NO | wx.NO_DEFAULT) 
        if confirm.returnedString == 'Yes':
            self.close()
        else: 
            pass


if __name__ == '__main__':
    app = model.Application(MultiCol)
    app.MainLoop()

now the problems are:
1. I dont want to use global, but it does not work in any other way. Other files donot recognize the User class
2. The details get added on the list but i only want to diplay id and username on the multicolumn list and other details on another window(when i make it). But the multicolumn list does not allow me to slice the appended list, it takes
("", self.name, self.address, self.contact, self.email) as one item.
3. I have defined the id properly, and it should display and id when ever i add a user plus +1 but how do i represent self.id in my list ?

Please fix your enter key and use CODE tags. Please explain your package structure and what does not function in it.

#filename: user.py
import pickle

# The User class holds data about the user details.

class User():
id = 1

#The __init__ method initializes that all attributes are null.

def __init__(self):
self.myList = []
self.id = User.id
User.id +=1
name = None
address = None
contact = None
email = None


# The set_name method accepts an argument for the users name.

def set_name(self, name):
self.name = name

# The set_address method accepts an argument for the users address.

def set_address(self, address):
self.address = address

# The set_contact method accepts an argument for the users contact.

def set_contact(self,contact):
self.contact = contact

# The set_email method accepts an argument for the users email.

def set_email(self,email):
self.email = email

def List(self):
row = ("", self.name, self.address, self.contact, self.email)
self.myList.append(row)
self.save()

def save(self):
pickle_file = open('my_pickled_list.pkl', 'w')
pickle.dump(self.myList, pickle_file)
pickle_file.close()

def recover(self):
pickle_file = open('my_pickled_list.pkl', 'r')
self.myList = pickle.load(pickle_file)
pickle_file.close()
# Filename: MultiCol.py

from PythonCard import dialog,model
import wx
from adduser import *
from user import *
from details import *

class MultiCol(model.Background):
global myUser
myUser = User()

def on_initialize(self,event):
self.addUser = model.childWindow(self, addUser)
self.addUser.visible = False
myUser.recover()

def on_btnDeleteuser_mouseClick (self, event):
pass

def on_btnAdduser_mouseClick (self, event): 
self.addUser.visible = True

def on_btnClose_mouseClick(self,event):

confirm = dialog.messageDialog(self, 'Are you sure you want to Exit ?', 'Confirm',
wx.ICON_EXCLAMATION | wx.YES_NO | wx.NO_DEFAULT) 
if confirm.returnedString == 'Yes':
self.close()
else: 
pass

if __name__ == '__main__':
app = model.Application(MultiCol)
app.MainLoop()
filename = adduser.py

from PythonCard import model
from user import *

class addUser(model.Background):

global myUser
myUser = User()

def reset(self):
self.components.tfName.text = ""
self.components.tfAddress.text = ""
self.components.tfContact.text = ""
self.components.tfEmail.text = ""

def on_initialize(self, event):
self.parent = self.getParent()

def on_close(self, event):
self.visible = False

def on_menuFileExit_select(self, event):
self.close()

def on_btnClear_mouseClick(self, event):
self.reset()

def on_btnAdduser_mouseClick(self, event):
myUser.name = self.components.tfName.text
myUser.address = self.components.tfAddress.text
myUser.contact = self.components.tfContact.text
myUser.email = self.components.tfEmail.text
myUser.recover()
self.parent.components.multiCol.items = myUser.myList[:]

if __name__ == '__main__':
app = model.Application(addUser)
app.MainLoop()

Now the problems:
1. I cant get my self.id to display in the list. I want the ID to increase by 1 as each user is added. I used this method

self.id = User.id
User.id +=1

2. i want to diplay only (self.id,self.name) in the multicolumn list self.components.multiCol.items
but it treats row = ("", self.name, self.address, self.contact, self.email) as one item therefore i cant slice it. What am i doing wrong with the list ? is there a better way

Please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help.

[code]
your properly indented Python code here

[/code]

For those who might be interested, PythonCard is a somewhat outdated (last activity 2006) form builder for wxPython projects.

A proof that your concept is correct, so any problem must lay somewhere else. And you should not use "id" as a variable name as it is already used by Python.

import pickle

class User():
    id = 1
 
    def __init__(self):
        self.id = User.id
        User.id +=1

dict_of_classes = {}
for name in ["Bill", "Sally", "George"]:
    instance = User()
    print name, instance.id
    dict_of_classes[name] = instance

## second test
pickle.dump( dict_of_classes, open( "save.p", "wb" ) )
dict_read = pickle.load( open( "save.p" ) )

print
for key in dict_read:
    instance = dict_read[key]
    print key, instance.id

## add another user to the dictionary read from the file
instance = User()
print "Pete", instance.id
dict_read["Pete"] = instance
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.