本文整理汇总了Python中pubsub.pub.sendMessage函数的典型用法代码示例。如果您正苦于以下问题:Python sendMessage函数的具体用法?Python sendMessage怎么用?Python sendMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sendMessage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addStory
def addStory(self, story, save_extracted_text=False, save_raw_download=True, save_story_sentences=False):
"""
Save a story (python object) to the database. Return success or failure boolean.
"""
if self.storyExists(str(story["stories_id"])):
return False
story_attributes = {
"_id": str(story["stories_id"]),
"title": story["title"],
"url": story["url"],
"media_id": story["media_id"],
"collect_date": story["collect_date"],
"publish_date": story["publish_date"],
"description": story["description"],
"guid": story["guid"],
"fully_extracted": story["fully_extracted"], # TODO: look at this instead?
"stories_id": story["stories_id"],
"text": story["story_text"],
}
if (save_extracted_text == True) and ("story_text" in story):
story_attributes["story_text"] = story["story_text"]
if (save_raw_download == True) and ("first_raw_download_file" in story):
story_attributes["first_raw_download_file"] = story["first_raw_download_file"]
if "story_sentences" in story:
story_attributes["story_sentences_count"] = len(story["story_sentences"])
if save_story_sentences == True:
story_attributes["story_sentences"] = story["story_sentences"]
pub.sendMessage(self.EVENT_PRE_STORY_SAVE, db_story=story_attributes, raw_story=story)
self._db.save(story_attributes)
saved_story = self.getStory(str(story["stories_id"]))
pub.sendMessage(self.EVENT_POST_STORY_SAVE, db_story=story_attributes, raw_story=story)
return True
示例2: on_message
def on_message(self, message_string):
# Only the first connected client can execute commands
if not WebServer.clients or not self == WebServer.clients[0]:
return
if message_string:
try:
message = json.loads(message_string)
except ValueError, e:
print "Message is not in json format"
return
if "command" in message:
if message["command"] == "set_frequency":
frequency = message["args"]["frequency"]
if isinstance(frequency, int):
pub.sendMessage("set_frequency", frequency=frequency)
elif message["command"] == "set_demodulation":
demodulation = message["args"]["demodulation"]
if demodulation:
pub.sendMessage("set_demodulation", demodulation=demodulation)
elif "notification" in message:
if message["notification"] == "alive":
WebServer.last_connectivity = time.time()
示例3: input_handler
def input_handler(self, fd, event):
for ln in self.s:
try:
(key,val) = ln.split(':', 1)
if (not self.last_values.has_key(key)):
self.last_values[key] = 0;
#if (val == self.last_values[key]):
# continue # nevermind
if (key == 'photo'):
pub.sendMessage(key, level=int(val))
if (key == 'RH'):
rounded = round(float(val),1)
pub.sendMessage(key, humidity=rounded)
if (key.startswith('temp.')):
if (float(val) > 50):
pub.sendMessage('debug', msg=ln)
pub.sendMessage(key, \
tempC=float(val),
tempF=float(val)*(9.0/5.0)+32
)
self.last_values[key] = val
except ValueError:
pub.sendMessage('debug', msg=ln)
continue
示例4: read
def read(bot):
global Bot
Bot = bot
if bot.remote['nick'] and bot.remote['nick'] != bot.nick:
if bot.remote['message'].startswith(bot.prefix):
bot._debug("Command received: %s" % bot.remote['message'])
args = bot.remote['message'][1:].rstrip().split(" ")
command = args[0].lower()
if bot.remote['nick'].lower() not in bot.inv['banned']:
if command in library['admin']:
bot._debug('This is an admin-only command.')
can_do = bot.remote['host'] in [host.strip() for host in bot.config.get(bot.network, 'admin_hostnames').split(',')]
#can_do = can_do or bot.remote['nick'] in [nick.strip() for nick in bot.config.get(bot.network, 'admin').split(',')]
if can_do:
bot.previous['user'] = bot.remote['sendee']
pub.sendMessage("func.admin.%s" % library['admin'][command], bot=bot, args=args)
else:
if bot.voice:
reply(bot.remote['sendee'], "%s: Can't do that, noob." % bot.remote['nick'])
elif bot.voice and command in library['common']:
bot._debug('This is a common command.')
pub.sendMessage("func.common.%s" % library['common'][command], bot=bot, args=args)
bot.previous['user'] = bot.remote['sendee']
elif bot.remote['message'].startswith("\x01") and bot.remote['message'].endswith("\x01"):
type = bot.remote['message'][1:-1].split()[0]
args = bot.remote['message'][1:-1].split()[1:]
if type != "ACTION":
ctcp(type, args)
elif bot.remote['mid'] == "INVITE" and bot.remote['nick'].lower() not in bot.inv['banned']:
join([bot.remote['mid'], bot.remote['message']])
else:
if bot.init['registered'] and not bot.init['identified']:
if bot.remote['nick'] == "NickServ":
if "registered" in bot.remote['message']:
bot._login()
elif re.search("(accepted|identified)", bot.remote['message']):
bot.init['identified'] = True
__import__('time').sleep(3)
autojoin()
if bot.voice:
#start scanning messages for certain data
try: scanner.scan(bot)
except (__import__('urllib2').URLError, __import__('socket').timeout): util.answer(bot, "fetch: response timeout exceeded.")
else:
if (bot.remote['mid'].startswith("4") or bot.remote['mid'].startswith("5")) and bot.remote['mid'] != "462":
if bot.config.get(bot.network, 'traceback_notice_channel') == "yes" or bot.previous['user'][0] != "#":
sendto = bot.previous['user'] or self.admin
else:
sendto = bot.admin
reply(sendto, "Message from %s: Error #%s: %s" % (bot.remote['server'], bot.remote['mid'], bot.remote['message']))
if not bot.init['joined'] and not bot.init['registered']:
autojoin()
示例5: next_action
def next_action(self):
"""The core of the guiding"""
if not self.babble.finished or len(self.goalexplorer) < self.cfg.guide.min_orderbabble:
babbling = self.babble.babble(self.t)
action = Action(type = 'order', payload = babbling)
path = 0
else:
if random.random() < self.cfg.guide.ratio_orderbabble:
babbling = self.babble.babble(self.t)
action = Action(type = 'order', payload = babbling)
path = 1
else:
goal = self.goalexplorer.next_goal()
if goal is None:
babbling = self.babble.babble(self.t)
action = Action(type = 'order', payload = babbling)
path = 2
else:
action = Action(type = 'goal', payload = goal)
path = 3
pub.sendMessage('guide.next_action', guide = self, action = action, path = path)
self.latest = action
return action
示例6: save_settings
def save_settings(self, evt=None):
"""
Store the changes to the widgets to the settings.ini file
This function should probably do some validation
"""
settings_dict = settings.settings.read_settings()
for key, old_value in settings_dict.iteritems():
# This will help skip settings we don't change anyway
group, item = key.split("/")
if hasattr(self, item):
if hasattr(getattr(self, item), "text"):
new_value = getattr(self, item).text()
else:
new_value = getattr(self, item).currentText()
if type(old_value) == int:
new_value = int(new_value)
if type(old_value) == float:
new_value = float(new_value)
if type(old_value) == QtGui.QKeySequence:
new_value = QtGui.QKeySequence.fromString(new_value)
if type(old_value) == bool:
new_value = bool(new_value)
if type(old_value) == unicode:
new_value = str(new_value)
if old_value != new_value:
settings_dict[key] = new_value
settings.settings.save_settings(settings_dict)
# Notify the rest of the application that the settings have changed
# TODO: changes here should propagate to the rest of the application (like the database screen)
pub.sendMessage("changed_settings")
示例7: changeTimer
def changeTimer(self, amount):
print "Model:changeTimer amount: " + str(amount)
self.timerValue = self.timerValue - amount
#if self.timerValue > 0:
# pub.sendMessage("timer_counting", amount=1)
#pub.sendMessage("timer_counting", amount=1) # timer value is not zero, set another interrupt for 1s duration
pub.sendMessage("timer_changed", money=self.timerValue)
示例8: process_dm
def process_dm(self, data):
if self.session.db["user_name"] == data["direct_message"]["sender"]["screen_name"]:
self.put_data("sent_direct_messages", data["direct_message"])
pub.sendMessage("sent-dm", data=data["direct_message"], user=self.get_user())
else:
self.put_data("direct_messages", data["direct_message"])
pub.sendMessage("direct-message", data=data["direct_message"], user=self.get_user())
示例9: testNotifyByPrint
def testNotifyByPrint():
capture = captureStdout()
def listener1(arg1):
pass
pub.subscribe(listener1, 'baz')
pub.sendMessage('baz', arg1=123)
pub.unsubscribe(listener1, 'baz')
def doa():
def listener2():
pass
pub.subscribe(listener2, 'bar')
doa() # listener2 should be gc'd
gc.collect() # for pypy: the gc doesn't work the same as cpython's
topicMgr.delTopic('baz')
expect = """\
PUBSUB: New topic "baz" created
PUBSUB: Subscribed listener "listener1" to topic "baz"
PUBSUB: Start sending message of topic "baz"
PUBSUB: Sending message of topic "baz" to listener listener1
PUBSUB: Done sending message of topic "baz"
PUBSUB: Unsubscribed listener "listener1" from topic "baz"
PUBSUB: New topic "bar" created
PUBSUB: Subscribed listener "listener2" to topic "bar"
PUBSUB: Listener "listener2" of Topic "bar" has died
PUBSUB: Topic "baz" destroyed
"""
captured = capture.getvalue()
#print captured
#print repr(expect)
assert captured == expect, \
'\n'.join( unified_diff(expect.splitlines(), captured.splitlines(), n=0) )
示例10: openCalFrame
def openCalFrame(self):
cv2.destroyAllWindows()
self.hide()
global iteration
iteration = 0
Publisher.sendMessage("userFrameClosed", arg1="data")
subFrame = CalibrationFrame()
示例11: test_commands_created
def test_commands_created(self):
w = BaseMainWindow(None, None)
cmd1 = Command(1, 'Name1', 'Desc1', lambda: 1, [])
cmd2 = Command(2, 'Name2', 'Desc2', lambda: 1, [])
cat1 = CommandCategory('Cat1')
cat2 = CommandCategory('Cat2')
cat1.append(cmd1)
cat1.append(cat2)
cat2.append(cmd2)
tree = [cat1]
pub.sendMessage('commands.created', command_tree=tree)
self.assertEqual(1, w.main_menu.MenuCount)
self.assertEqual(2, w.main_menu.GetMenu(0).MenuItemCount)
self.assertEqual(1, w.main_menu.GetMenu(0).FindItemByPosition(1).SubMenu.MenuItemCount)
cmd1.name = 'Nome1'
cmd1.description = 'Descricao1'
cmd2.name = 'Nome2'
cmd2.description = 'Descricao2'
cat1.name = 'Categoria1'
cat2.name = 'Categoria2'
pub.sendMessage('commands.changed', command_tree=tree, accel_table=wx.AcceleratorTable([]))
self.assertEqual(cat1.name, w.main_menu.GetMenuLabel(0))
self.assertEqual(cmd1.name, w.main_menu.GetMenu(0).FindItemByPosition(0).ItemLabel)
self.assertEqual(cat2.name, w.main_menu.GetMenu(0).FindItemByPosition(1).ItemLabel)
self.assertEqual(cmd2.name, w.main_menu.GetMenu(0).FindItemByPosition(1).SubMenu.FindItemByPosition(0).ItemLabel)
示例12: __init__
def __init__(self):
# Values and symbols of the card which will be created
self.values = ['1','2','3','4','5','6','7','8','9','10','J','Q','K']
self.symbols = ['H', 'S', 'C', 'D']
# Generate the stock
self.stock = []
for symbol in self.symbols:
for value in self.values:
self.stock.append(Card(symbol, value))
shuffle(self.stock)
# Generate the waste
self.waste = []
# generate empty piles for each color
self.H = []
self.C = []
self.S = []
self.D = []
# generate empty waste
self.waste = []
# generate tableau piles used to play
self.PlayingStacks = [[], [], [], [], [], [], []]
for stack in range (0, 7):
for index in range (-1, stack):
card = self.stock.pop()
self.PlayingStacks[stack].append(card)
self.PlayingStacks[stack][-1].setFaceDown(False)
# Update GUI
pub.sendMessage('refreshGUITopic')
示例13: set_to_full
def set_to_full(self):
data = self.merge_blocks()
if self.hash_is_correct(data):
self.is_full = True
self.raw_data = data
self.write_piece_on_disk()
pub.sendMessage('PiecesManager.PieceCompleted', piece_index=self.piece_index)
示例14: connection_handler
def connection_handler(self, fd, event):
if fd == self.listener:
(con,addr) = self.listener.accept()
pub.sendMessage('TRACE.TCPSocket', msg=("Accepting connection from:" ,addr))
con.setblocking(0)
self.rosie.add_io_handler(con,
self.request_handler)
示例15: save_configuration
def save_configuration(self):
if self.codes[self.dialog.general.language.GetSelection()] != config.app["app-settings"]["language"]:
config.app["app-settings"]["language"] = self.codes[self.dialog.general.language.GetSelection()]
languageHandler.setLanguage(config.app["app-settings"]["language"])
self.needs_restart = True
if self.kmnames[self.dialog.general.km.GetSelection()] != config.app["app-settings"]["load_keymap"]:
config.app["app-settings"]["load_keymap"] =self.kmnames[self.dialog.general.km.GetSelection()]
kmFile = open(paths.config_path("keymap.keymap"), "w")
kmFile.close()
self.needs_restart = True
if config.app["app-settings"]["use_invisible_keyboard_shorcuts"] != self.dialog.get_value("general", "use_invisible_shorcuts"):
config.app["app-settings"]["use_invisible_keyboard_shorcuts"] = self.dialog.get_value("general", "use_invisible_shorcuts")
pub.sendMessage("invisible-shorcuts-changed", registered=self.dialog.get_value("general", "use_invisible_shorcuts"))
config.app["app-settings"]["voice_enabled"] = self.dialog.get_value("general", "disable_sapi5")
config.app["app-settings"]["hide_gui"] = self.dialog.get_value("general", "hide_gui")
config.app["app-settings"]["ask_at_exit"] = self.dialog.get_value("general", "ask_at_exit")
config.app["app-settings"]["handle_longtweets"] = self.dialog.get_value("general", "handle_longtweets")
config.app["app-settings"]["play_ready_sound"] = self.dialog.get_value("general", "play_ready_sound")
config.app["app-settings"]["speak_ready_msg"] = self.dialog.get_value("general", "speak_ready_msg")
if config.app["proxy"]["server"] != self.dialog.get_value("proxy", "server") or config.app["proxy"]["port"] != self.dialog.get_value("proxy", "port") or config.app["proxy"]["user"] != self.dialog.get_value("proxy", "user") or config.app["proxy"]["password"] != self.dialog.get_value("proxy", "password"):
if self.is_started == True:
self.needs_restart = True
config.app["proxy"]["server"] = self.dialog.get_value("proxy", "server")
config.app["proxy"]["port"] = self.dialog.get_value("proxy", "port")
config.app["proxy"]["user"] = self.dialog.get_value("proxy", "user")
config.app["proxy"]["password"] = self.dialog.get_value("proxy", "password")
config.app.write()