[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] how aim same function to other tables
From: Josh Stratton <strattonbrazil () gmail ! com>
Date: 2011-08-24 18:12:45
Message-ID: CAPVmgLgt3ZgYETC1nuxRoy7qcx-nN1XboSTCc1H-KiKm9wK5CA () mail ! gmail ! com
[Download RAW message or body]
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@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@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic