It's ok. The only caveat I can think of is that the above technique
doesn't extend well if you want to make use of the full power of pubsub
(hierarchy of topics). You could of course eventually change statusText
= 1 to statusBarTextUpdate = "statusBar.text.update" etc, the one
advantage there is if your editor helps you remember the vars with code
completion, otherwise you still have to remember fairly long names.
Oliver
···
-----Original Message-----
From: Werner F. Bruhin [mailto:werner.bruhin@free.fr]
I just recently started using Publish/Subscribe, but I find myself
constantly searching for what the right string is to use.
So, I ended up doing this:
# to subscribe
mypub.publisher.subscribe(functionToCall, mypub.statusText) #
instead of just passing 'statusText'
# to notify
mypub.publisher.sendMessage(mypub.statusText, _('Text for
status line'))
And in the mypub module I define the variables.
# Define variables for valid pubsub stuff, one could use strings but
this is
statusText = 1 # pass status text in data section
dataNeedsSaving = 2 # pass parent in data section to limit
propagation, e.g. self.parent
comboBoxRefresh = 3 # pass table name in data section,
e.g. 'country_ls'
etc.
But I wonder if that is a good way to go or if there are
better ways of doing this.
Hi Oliver,
Oliver Schoenborn wrote:
From: Werner F. Bruhin [mailto:werner.bruhin@free.fr]
I just recently started using Publish/Subscribe, but I find myself constantly searching for what the right string is to use.
So, I ended up doing this:
# to subscribe
mypub.publisher.subscribe(functionToCall, mypub.statusText) # instead of just passing 'statusText'
# to notify
mypub.publisher.sendMessage(mypub.statusText, _('Text for status line'))
And in the mypub module I define the variables.
# Define variables for valid pubsub stuff, one could use strings but this is
statusText = 1 # pass status text in data section
dataNeedsSaving = 2 # pass parent in data section to limit propagation, e.g. self.parent
comboBoxRefresh = 3 # pass table name in data section, e.g. 'country_ls'
etc.
But I wonder if that is a good way to go or if there are better ways of doing this.
It's ok. The only caveat I can think of is that the above technique
doesn't extend well if you want to make use of the full power of pubsub
(hierarchy of topics). You could of course eventually change statusText
= 1 to statusBarTextUpdate = "statusBar.text.update" etc, the one
advantage there is if your editor helps you remember the vars with code
completion, otherwise you still have to remember fairly long names.
I had text strings first, but then thought int would be fine
I don't use the dot notation but do things like this:
# in the combobox custom class where self.dbTable might be 'reason_ls'
mypub.publisher.subscribe(self.NeedChoiceRefresh, (mypub.comboBoxRefresh, self.dbTable))
mypub.publisher.subscribe(self.NeedChoiceRefresh, mypub.comboBoxRefresh)
# e.g. in the table maintenance for a particular table
mypub.publisher.sendMessage(mypub.comboBoxRefresh, 'reason_ls')
# or when user changes language and lots of combobox choices need to get updated
mypub.publisher.sendMessage(mypub.comboBoxRefresh)
···
-----Original Message-----
*
*Yes, strings might be long, but at least I only have to look in one file when I am not sure if I already do something with pub/sub or not and what did I call it again. - So, it is kind of documenting what I do with pub/sub.
Oliver
Thanks and best regards
Werner