[PyQt] how aim same function to other tables

Josh Stratton strattonbrazil at gmail.com
Wed Aug 24 19:12:45 BST 2011


Can you pull the table name out of the event object?  Another option
is to make a unique function for each table, which calls the addFriend
function itself with the table name.  That way you won't have to
duplicate addFriend code.

example:

addFriend(event, table):
....

def table1AddFriend(event): # connect to this
     addFriend(event, table1)

etc.

These wrapper functions, I believe, can be anonymous so you can make
them dynamically.

On Wed, Aug 24, 2011 at 10:18 AM, Tony Peña <emperor.cu at gmail.com> wrote:
>
> hi I want to use same function to other tables like this
> tablename = Searchtable .... but could be table1 table2 table3 ... table n
> addAction.triggered.connect(self.addFriend) <- This works ok def
> addFriend(self, event): tablename = 'SearchtableWidget' table_obj =
> getattr(self.ui, tablename) current_row = table_obj.currentRow() current_vid
> = table_obj.item(current_row, 0) current_realname =
> table_obj.item(current_row, 2) total_vid = len(vid) insert = True if
> total_vid >= 0: for i in range(0, total_vid): if
> int(str(current_vid.text())) == vid[i][0]: ..... rest code run fine ....
> ------------------------------------------------------------------- if i
> pass this to prepare the connect when right-click button is active...
> addAction.triggered.connect(self.addFriend(self, 'SearchtableWidget')) <--
> need fix this because is running function before connected :| def
> addFriend(self, event, tablename): table_obj = getattr(self.ui, tablename)
> <-this receive Searchtable same like before BUT... current_row =
> table_obj.currentRow() current_vid = table_obj.item(current_row, 0)
> current_realname = table_obj.item(current_row, 2) total_vid = len(vid)
> insert = True if total_vid >= 0: for i in range(0, total_vid): if
> int(str(current_vid.text())) == vid[i][0]: current_vid.text() <-
> current.text() method NOT WORK... because when came tablename as argument is
> NoneType
>                                             ...stop here...
> I guess to need some help with how can connect to a function with ARG as
> options...
> any idea?
>
> --
> Antonio Peña
> Secure email with PGP 0x8B021001 available at http://pgp.mit.edu
> Fingerprint: 74E6 2974 B090 366D CE71  7BB2 6476 FA09 8B02 1001
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


More information about the PyQt mailing list