本文整理汇总了Python中pubsub.publish函数的典型用法代码示例。如果您正苦于以下问题:Python publish函数的具体用法?Python publish怎么用?Python publish使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了publish函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent, pos):
global widgets_list
pb_editor.DirtyUIBase.__init__(self, parent)
self.static_box=wx.StaticBox(self, -1, "Category")
hs=wx.StaticBoxSizer(self.static_box, wx.HORIZONTAL)
self.categories=[]
self.category=wx.ListBox(self, -1, choices=self.categories)
pubsub.subscribe(self.OnUpdateCategories, pubsub.ALL_CATEGORIES)
pubsub.publish(pubsub.REQUEST_CATEGORIES)
vbs=wx.BoxSizer(wx.VERTICAL)
vbs.Add(wx.StaticText(self, -1, 'Master Category'), 0,
wx.TOP|wx.LEFT, 5)
vbs.Add(self.category, 1, wx.EXPAND|wx.ALL, 5)
hs.Add(vbs, 1, wx.EXPAND|wx.ALL, 5)
vbs=wx.BoxSizer(wx.VERTICAL)
self.but=wx.Button(self, wx.NewId(), "Manage Categories:")
add_btn=wx.Button(self, -1, 'Add ->')
del_btn=wx.Button(self, -1, '<- Remove')
vbs.Add(self.but, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
vbs.Add(add_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
vbs.Add(del_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
hs.Add(vbs, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
wx.EVT_BUTTON(self, add_btn.GetId(), self.OnAddCategory)
wx.EVT_BUTTON(self, del_btn.GetId(), self.OnDelCategory)
vbs=wx.BoxSizer(wx.VERTICAL)
vbs.Add(wx.StaticText(self, -1, 'Selected Category:'), 0,
wx.TOP|wx.LEFT, 5)
self._my_category=wx.ListBox(self, -1)
vbs.Add(self._my_category, 1, wx.EXPAND|wx.ALL, 5)
hs.Add(vbs, 1, wx.EXPAND|wx.ALL, 5)
wx.EVT_BUTTON(self, self.but.GetId(), self.OnManageCategories)
self.SetSizer(hs)
hs.Fit(self)
示例2: do_load_base64
def do_load_base64(self, line):
"""
load filename=(file)
load base64=(base64 encoded)
"""
cookie = self.cookie
executor = self.bot._executor
def source_good():
self.print_response(status=RESPONSE_CODE_OK, cookie=cookie)
executor.clear_callbacks()
def source_bad(tb):
if called_good:
# good and bad callbacks shouldn't both be called
raise ValueError('Good AND Bad callbacks called !')
# TODO - get simple_trace_back of exception to send back
self.print_response(status=RESPONSE_REVERTED, keep=True, cookie=cookie)
self.print_response(tb.replace('\n', '\\n'), cookie=cookie)
executor.clear_callbacks()
called_good = False
source = str(base64.b64decode(line))
# Test compile
pubsub.publish("shoebot", SOURCE_CHANGED_EVENT)
executor.load_edited_source(source, good_cb=source_good, bad_cb=source_bad)
示例3: record_to_file
def record_to_file(file_name, append=False):
"start a data recording session into the specified file"
global DR_On, _the_recorder
if DR_On and _the_recorder:
_the_recorder.stop()
_rec=DR_Rec_File(file_name, append)
_rec.start()
pubsub.publish(pubsub.DR_RECORD, data=_rec)
示例4: playback_from_file
def playback_from_file(file_name):
"start a playback session from the specified file"
global DR_Play, _the_player
if DR_Play and _the_player:
_the_player.stop()
_player=DR_Read_File(file_name)
_player.start()
pubsub.publish(pubsub.DR_PLAY, data=_player)
示例5: stop
def stop():
"stop a recording and/or playback session"
global DR_Play, DR_On, _the_recorder, _the_player
if DR_On and _the_recorder:
_the_recorder.stop()
if DR_Play and _the_player:
_the_player.stop()
pubsub.publish(pubsub.DR_STOP)
示例6: test_unsubscribe
def test_unsubscribe(self):
sub = pubsub.subscribe('test')
pubsub.publish('test', 'hello world 1')
sub.unsubscribe()
pubsub.publish('test', 'hello world 2')
msgs = list(sub.listen(block=False))
self.assertEqual(len(msgs), 1)
self.assertEqual(msgs[0]['data'], 'hello world 1')
示例7: handle_data
def handle_data(protocol, data, address):
proto = protocol()
try:
event = proto.read(data)
except (ValueError, TypeError):
log.exception("Error decoding event from %s", address)
return
else:
pubsub.publish("events", event)
示例8: handle_accept
def handle_accept(self):
conn, addr = self.accept()
# Drop existing connection.
if self._handler is not None:
self._handler.handle_close()
self._handler = MonkeyHandler(conn)
pubsub.publish('conn', addr, self._handler)
示例9: do_window_close
def do_window_close(self, widget,data=None):
pubsub.publish("shoebot", "quit")
if self.has_server:
self.sock.close()
self.hide_variables_window()
self.destroy()
self.window_open = False
示例10: _populate
def _populate(self):
for k,e in self._data.items():
if e.name:
if not self._name_map.has_key(e.number):
self._name_map[e.number]=e.name
else:
if not self._name_map.has_key(e.number):
pubsub.publish(pubsub.REQUEST_PB_LOOKUP,
{ 'item': e.number } )
self.list_widget.populate()
self.CalculateStats()
self._publish_today_data()
示例11: _populate
def _populate(self):
self._clear()
self._node_dict={}
for k,e in self._data.items():
if e.name:
if not self._name_map.has_key(e.number):
self._name_map[e.number]=e.name
else:
if not self._name_map.has_key(e.number):
pubsub.publish(pubsub.REQUEST_PB_LOOKUP,
{ 'item': e.number } )
self._display_func[self._by_mode]()
self._OnExpandAll(None)
self._publish_today_data()
示例12: publish_event
def publish_event(event_t, data=None, extra_channels=None, wait=None):
"""
Publish an event ot any subscribers.
:param event_t: event type
:param data: event data
:param extra_channels:
:param wait:
:return:
"""
event = Event(event_t, data)
pubsub.publish("shoebot", event)
for channel_name in extra_channels or []:
pubsub.publish(channel_name, event)
if wait is not None:
channel = pubsub.subscribe(wait)
channel.listen(wait)
示例13: OnRename
def OnRename(self, _=None):
items=self.GetSelectedItems()
if len(items)!=1:
return
old_name=items[0].name
dlg=wx.TextEntryDialog(self, "Enter a new name:", "Item Rename",
old_name)
if dlg.ShowModal()==wx.ID_OK:
new_name=dlg.GetValue()
if len(new_name) and new_name!=old_name:
old_name=items[0].name
new_name=self.get_media_name_from_filename(new_name)
items[0].RenameInIndex(new_name)
pubsub.publish(pubsub.MEDIA_NAME_CHANGED,
data={ pubsub.media_change_type: self.media_notification_type,
pubsub.media_old_name: old_name,
pubsub.media_new_name: new_name })
dlg.Destroy()
示例14: populate
def populate(self):
self.nodes={}
self.nodes_keys={}
index=0
for k,e in self._stats._data.items():
if len(e._from) and not self._name_map.has_key(e._from):
pubsub.publish(pubsub.REQUEST_PB_LOOKUP,
{ 'item': e._from } )
if len(e._to) and not self._name_map.has_key(e._to):
pubsub.publish(pubsub.REQUEST_PB_LOOKUP,
{ 'item': e._to } )
if len(e.callback) and not self._name_map.has_key(e.callback):
pubsub.publish(pubsub.REQUEST_PB_LOOKUP,
{ 'item': e.callback } )
if e.folder==self._display_filter:
col=self._item_list.GetColumn(0)
col.SetMask(wx.LIST_MASK_TEXT)
if e.folder==sms.SMSEntry.Folder_Inbox:
col.SetText("From")
name=e._from
else:
col.SetText("To")
name=e._to
self._item_list.SetColumn(0, col)
if name!=None and name!="":
temp=self._name_map.get(name, None)
if temp !=None:
name=temp
self.nodes[index]=(name, e.get_date_time_str(), e.subject)
self.nodes_keys[index]=k
self._data_map[k]=index
index+=1
self._item_list.ResetView(self.nodes, self.nodes_keys)
self.publish_today_data()
示例15: populate
def populate(self):
self.nodes={}
self.nodes_keys={}
index=0
for k,e in self._stats._data.items():
if len(e._from) and not self._name_map.has_key(e._from):
pubsub.publish(pubsub.REQUEST_PB_LOOKUP,
{ 'item': e._from } )
if len(e._to) and not self._name_map.has_key(e._to):
pubsub.publish(pubsub.REQUEST_PB_LOOKUP,
{ 'item': e._to } )
if len(e.callback) and not self._name_map.has_key(e.callback):
pubsub.publish(pubsub.REQUEST_PB_LOOKUP,
{ 'item': e.callback } )
if self._display_filter=='All' or e.folder==self._display_filter:
_from=self._me_name if e.folder in (e.Folder_Sent, e.Folder_Saved) \
else self._number2name(e._from)
_to=self._me_name if e.folder==e.Folder_Inbox \
else self._number2name(e._to)
self.nodes[index]=(_from, _to, e.get_date_time_str())
self.nodes_keys[index]=k
self._data_map[k]=index
index+=1
self._item_list.ResetView(self.nodes, self.nodes_keys)
self.publish_today_data()