本文整理汇总了Python中bus.Bus类的典型用法代码示例。如果您正苦于以下问题:Python Bus类的具体用法?Python Bus怎么用?Python Bus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_bus_list
def _set_bus_list(self, passenger):
bus_list = []
for line in self._get_csv_list():
bus = Bus()
bus.bus_builder(line, passenger)
bus_list.append(bus)
self._bus_list = bus_list
示例2: Peer
class Peer(object):
def __init__(self, share_path, host=None, port=None):
self.host, self.port = (host or ALL), (port or PORT)
self.db = dal.DB("sqlite://")
self.db.define_table("config", dal.Field("key", key=True), dal.Field("value"))
if "peerid" not in self.db.config:
self.db.config["peerid"] = hex(random.getrandbits(48))[2:14]
self.db.define_table(
"peers",
dal.Field("peerid"),
dal.Field(
"address",
serialize=lambda x: "%s:%i" % x,
convert=lambda x: tuple(f(a) for f, a in zip((str, int), x.rsplit(":", 1))),
),
dal.Field("ignore", default=False),
)
self.db.define_table("resources", dal.Field("path", key=True), dal.Field("age", int), dal.Field("real_path"))
if os.path.isdir(share_path) and share_path[-1] != "/":
share_path += "/"
for path in find(os.path.abspath(share_path)):
short_path = path[len(share_path) :]
print path, short_path
self.db.resources.insert(path=short_path, age=mod_time(os.stat(path)), real_path=path)
self.bus = Bus()
self.bus.connect(MessageType.HeardFromPeer, self.introduce)
self.bus.connect(MessageType.Request, self.notify)
self.bus.connect(MessageType.RemoteUpdate, self.remote_update)
self.public = Broadcaster(self.bus, self.db.config["peerid"], (self.host, self.port))
self.private = Whisperer(self.bus, (self.host, self.port))
def start(self):
self.bus.start()
self.public.start()
self.private.start()
def announce(self):
self.broadcaster.send("Hello?")
def remote_update(self, message):
if self.filter(message.path):
self.private.retrieve(message.address, message.path)
def introduce(self, message):
print message
self.db.peers.insert(**message)
def notify(self, message):
print message
self.public.send(self.db.resources[message.path].age)
def stop(self):
self.private.stop()
self.public.stop()
self.bus.stop()
示例3: __init__
def __init__(self, port, baud=1000000, show_packets=False):
Bus.__init__(self, show_packets)
self.serial_port = serial.Serial(port=port,
baudrate=baud,
timeout=0.1,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
xonxoff=False,
rtscts=False,
dsrdtr=False)
示例4: get_hardware_config
def get_hardware_config():
"""
Read some sort of easy to do configuration for how the hardware is setup. Return
an array that holds MCP23017 class instances.
"""
# instantiate the bus from the class file. The class file has the
# hw configuration specific to this installation.
busses=Bus()
#return chip1
return busses.get_bus_devices() # only return bus1, dev0
示例5: TestWindow
class TestWindow(gtk.Window):
def __init__(self):
super(TestWindow,self).__init__()
self.__bus = Bus()
print self.__bus.get_name()
self.__bus.connect("disconnected", gtk.main_quit)
context_path = self.__bus.create_input_context("Test")
print context_path
self.__context = InputContext(self.__bus, context_path)
self.__context.set_capabilities (9)
self.__context.connect("commit-text", self.__commit_text_cb)
self.__context.connect("update-preedit-text", self.__update_preedit_text_cb)
self.__context.connect("show-preedit-text", self.__show_preedit_text_cb)
self.__context.connect("update-auxiliary-text", self.__update_auxiliary_text_cb)
self.__context.connect("update-lookup-table", self.__update_lookup_table_cb)
self.set_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.FOCUS_CHANGE_MASK)
self.connect("key-press-event", self.__key_press_event_cb)
self.connect("key-release-event", self.__key_release_event_cb)
self.connect("delete-event", gtk.main_quit)
self.connect("focus-in-event", lambda *args: self.__context.focus_in())
self.connect("focus-out-event", lambda *args: self.__context.focus_out())
self.show_all()
def __commit_text_cb(self, context, text):
print "commit-text:", text.text
def __update_preedit_text_cb(self, context, text, cursor_pos, visible):
print "preedit-text:", text.text, cursor_pos, visible
def __show_preedit_text_cb(self, context):
print "show-preedit-text"
def __hide_preedit_text_cb(self, context):
print "hide-preedit-text"
def __update_auxiliary_text_cb(self, context, text, visible):
print "auxiliary-text:", text.text, visible
def __update_lookup_table_cb(self, context, table, visible):
print "update-lookup-table:", visible
def __key_press_event_cb(self, widget, event):
self.__context.process_key_event(event.keyval, event.state)
def __key_release_event_cb(self, widget, event):
self.__context.process_key_event(event.keyval, event.state | modifier.RELEASE_MASK)
示例6: __init__
def __init__(self):
super(TestWindow,self).__init__()
self.__bus = Bus()
print self.__bus.get_name()
self.__bus.connect("disconnected", gtk.main_quit)
context_path = self.__bus.create_input_context("Test")
print context_path
self.__context = InputContext(self.__bus, context_path)
self.__context.set_capabilities (9)
self.__context.connect("commit-text", self.__commit_text_cb)
self.__context.connect("update-preedit-text", self.__update_preedit_text_cb)
self.__context.connect("show-preedit-text", self.__show_preedit_text_cb)
self.__context.connect("update-auxiliary-text", self.__update_auxiliary_text_cb)
self.__context.connect("update-lookup-table", self.__update_lookup_table_cb)
self.__context.connect("enabled", self.__enabled_cb)
self.__context.connect("disabled", self.__disabled_cb)
self.set_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.FOCUS_CHANGE_MASK)
self.connect("key-press-event", self.__key_press_event_cb)
self.connect("key-release-event", self.__key_release_event_cb)
self.connect("delete-event", gtk.main_quit)
self.connect("focus-in-event", lambda *args: self.__context.focus_in())
self.connect("focus-out-event", lambda *args: self.__context.focus_out())
self.show_all()
示例7: TestPanel
class TestPanel(PanelBase):
def __init__(self):
self.__bus = Bus()
self.__bus.connect("disconnected", gtk.main_quit)
super(TestPanel, self).__init__(self.__bus)
self.__bus.request_name(IBUS_SERVICE_PANEL, 0)
def focus_in(self, ic):
print "focus-in:", ic
context = InputContext(self.__bus, ic)
info = context.get_factory_info()
print "factory:", info.name
def focus_out(self, ic):
print "focus-out:", ic
def update_auxiliary_text(self, text, visible):
print "update-auxiliary-text:", text.text
def update_lookup_table(self, table, visible):
print "update-lookup-table", table
示例8: changeShape
def changeShape(self,index):
print "changeShape"
tempoffset=self.offset
self.settings.shape=self.nameid[index][1]
self.bus=Bus(self.settings.shape,self.offset,self.backsb.value(),self.forwardsb.value())
self.busname=self.nameid[index][0]
self.showMessage("Monitoring "+self.busname+".\n Alert near "+self.bus.offsetToName(self.bus.busoffset))
self.update()
self.stopcb.clear()
for n in self.bus.waypointlist:
self.stopcb.addItem(n[0])
stopnamelist=[x[0] for x in self.bus.waypointlist]
self.stopcb.setCurrentIndex(stopnamelist.index(self.bus.offsetToName(tempoffset)))
示例9: bus_data
def bus_data(self, route, sort=False):
"""Get list of timeframes of bus objects."""
# Initialize variables
bus_files = self._available_bus_files(route, sort=sort)
read_json = self._read_json
bus_data = []
for bus_file in bus_files:
bus_json = read_json(bus_file)
if bus_json is not None:
recv_time = self._date_from_file(bus_file)
buses = map(lambda x: Bus.from_json(x), bus_json["bus"])
timeframe = TimeFrame(recv_time, data=buses)
bus_data.append(timeframe)
return bus_data
示例10: __init__
def __init__(self, useLogger = False):
self.id = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
self.pose = [512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512]
self.nextPose = [512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512]
self.speed = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
self.interpolating = False
self.playing = False
self.servoCount = 12
self.lastFrame = pyb.millis()
self.port = UART_Port(1, 1000000)
self.bus = Bus(self.port, show=Bus.SHOW_PACKETS)
# Bus.SHOW_NONE
# Bus.SHOW_COMMANDS
# Bus.SHOW_PACKETS
if useLogger:
self.logger = Logger('sync_log.txt')
else:
self.logger = None
示例11: __init__
def __init__(self, username, username_password=None, realname=None, init_channels=None):
self._conn = None
self._write_conn = None
self._read_conn = None
self.username = username
self.username_password = username_password
if not realname:
self.realname = username
else:
self.realname = realname
self.bus = Bus()
self.plugins = Loader(self.bus)
self.plugins.load_plugins()
self.joined = False
if init_channels is None:
self._init_channels = []
else:
self._init_channels = init_channels
示例12: Bus
# pylint: disable=I0011,C0103
from event import Event
from bus import Bus
from listener import WeatherBot
# 1- Register listeners on the bus
bot_name = 'pyro'
zipcode = 94040
bus = Bus()
bus.register(WeatherBot(bot_name), Event.Types.message_created_event)
# 2- Let's create some events on the bus and see if our listeners pick them up
for i in range(4):
if i % 2 == 0:
print "throwing message_created_event"
bus.notify(Event(Event.Types.message_created_event, {"room_id":1, "data": "{} weather {}".format(bot_name, zipcode), "user_id": 123}))
else:
print "throwing user_joins_room"
bus.notify(Event(Event.Types.user_joins_room, {}))
示例13: Bus
from event import Event
from bus import Bus
from listener import WeatherBot
# 1- Register listeners on the bus
bus = Bus()
bus.register(WeatherBot(), Event.Types.message_created_event)
# 2- Let's create some events on the bus and see if our listeners pick them up
for i in range(4):
if i % 2 == 0:
print "throwing message_created_event"
bus.notify(Event(Event.Types.message_created_event, {"room_id":1, "data": "pyro weather 94301", "user_id": 123}))
else:
print "throwing user_joins_room"
bus.notify(Event(Event.Types.user_joins_room, {}))
示例14: Window
class Window(QtGui.QWidget):
def drawBus(self,nx,ny,angle,qp):
ang=angle/180.*math.pi
angd=15
line=8
headx=+math.sin(ang)*line+nx
heady=-math.cos(ang)*line+ny
tailx=-math.sin(ang)*line+nx
taily=+math.cos(ang)*line+ny
wing1x=-math.sin(ang+angd+math.pi)*line+headx
wing1y=+math.cos(ang+angd+math.pi)*line+heady
wing2x=-math.sin(ang-angd+math.pi)*line+headx
wing2y=+math.cos(ang-angd+math.pi)*line+heady
qp.drawLine(headx,heady,tailx,taily)
qp.drawLine(headx,heady,wing1x,wing1y)
qp.drawLine(headx,heady,wing2x,wing2y)
def backChange(self,setvalue):
if self.bus!=None:
self.bus.backward=setvalue
self.update()
def forwardChange(self,setvalue):
if self.bus!=None:
self.bus.forward=setvalue
self.update()
def showSettingWindow(self):
self.settingwindow.show()
def quitApplication(self):
self.closeSaving()
QtGui.qApp.quit()
def closeSaving(self):
self.settings.setValue('size', self.size())
self.settings.setValue('pos', self.pos())
self.settings.setValue('setsize', self.settingwindow.size())
self.settings.setValue('setpos', self.settingwindow.pos())
if self.bus!=None:
self.settings.setValue('bus', self.busname)
self.settings.setValue('offset', self.bus.busoffset)
self.settings.setValue('backward', self.bus.backward)
self.settings.setValue('forward', self.bus.forward)
def closeEvent(self, e):
self.closeSaving()
e.accept()
def changeOffset(self,index):
self.bus.busoffset=self.bus.waypointlist[index][1]
self.offset=self.bus.busoffset
#self.showMessage("Monitoring "+self.busname+".\n Alert near "+self.bus.offsetToName(self.bus.busoffset))
self.update()
def changeShape(self,index):
print "changeShape"
tempoffset=self.offset
self.settings.shape=self.nameid[index][1]
self.bus=Bus(self.settings.shape,self.offset,self.backsb.value(),self.forwardsb.value())
self.busname=self.nameid[index][0]
self.showMessage("Monitoring "+self.busname+".\n Alert near "+self.bus.offsetToName(self.bus.busoffset))
self.update()
self.stopcb.clear()
for n in self.bus.waypointlist:
self.stopcb.addItem(n[0])
stopnamelist=[x[0] for x in self.bus.waypointlist]
self.stopcb.setCurrentIndex(stopnamelist.index(self.bus.offsetToName(tempoffset)))
def __init__(self):
self.bus=None
self.count=0
super(Window, self).__init__()
#need to catch timeout exceptions etc...
self.settings = QtCore.QSettings('busSettings.ini', QtCore.QSettings.IniFormat)
self.settings.setFallbacksEnabled(False) # File only, no fallback to registry or or.
# Initial window size/pos last saved if available
#self.resize(400, 300)
#self.setGeometry(200, 200,500*self.bus.xfactor,500)
self.resize(self.settings.value('size', QtCore.QSize(350, 500)))
self.move(self.settings.value('pos', QtCore.QPoint(200, 200)))
self.offset=int(self.settings.value('offset',89))
self.busname=(self.settings.value('bus',None))
self.setWindowTitle(u"busLocator map")
self.show()
#-------------------basic menu item------------------
self.settingAction = QtGui.QAction(u"setting", self,
triggered=self.showSettingWindow)
self.minimizeAction = QtGui.QAction(u"hide", self,
triggered=self.hide)
self.restoreAction = QtGui.QAction(u"show", self,
triggered=self.showNormal)
self.quitAction = QtGui.QAction(u"exit", self,
triggered=self.quitApplication)
#add menu
self.trayIconMenu = QtGui.QMenu(self)
self.trayIconMenu.addAction(self.restoreAction)
self.trayIconMenu.addAction(self.minimizeAction)
self.trayIconMenu.addAction(self.settingAction)
self.trayIconMenu.addAction(self.quitAction)
#self.trayIconMenu.clear()
#self.trayIconMenu.addAction(self.quitAction)
self.trayIcon = QtGui.QSystemTrayIcon(self)
self.trayIcon.setContextMenu(self.trayIconMenu)
#-------------------basic menu end------------------
#-------------------icon------------------
self.icon=QtGui.QIcon(":/images/bus.ico")
self.trayIcon.setIcon(self.icon)
#.........这里部分代码省略.........
示例15: Botter
class Botter(object):
def __init__(self, username, username_password=None, realname=None, init_channels=None):
self._conn = None
self._write_conn = None
self._read_conn = None
self.username = username
self.username_password = username_password
if not realname:
self.realname = username
else:
self.realname = realname
self.bus = Bus()
self.plugins = Loader(self.bus)
self.plugins.load_plugins()
self.joined = False
if init_channels is None:
self._init_channels = []
else:
self._init_channels = init_channels
def connect(self, server, port):
LOG.info('Connect to %s:%s' % (server, port))
self._con_opts = (server, port)
self._conn = socket.create_connection((server, port))
self._conn.send("""PASS {uniquepass}\r\n
NICK {username}\r\n
USER {username} testbot testbot :{realname}\r\n""".format(uniquepass=uuid.uuid1().hex,
username=self.username,
realname=self.realname))
self._write_conn = self._conn.dup()
self._read_conn = self._conn.dup()
def pong(self, msg):
answer = msg.strip().split(':')[1]
self._write_conn.send('PONG %s\r\n' % answer)
def _parse_message(self, buf):
LOG.info('Start message parsing')
messages = []
for msg in buf.split('\r\n'):
msg = msg.strip()
if not msg:
continue
LOG.info('Parse: %s' % msg)
if msg.startswith('PING'):
self.pong(msg)
continue
if 'ERROR :Closing Link:' in msg:
self.connect(self._con_opts[0], self._con_opts[1])
return []
msg_opts = msg.split()
user_opts = msg_opts[0][1:].split('!')
if len(user_opts) > 1:
sender, user_ident = user_opts[0], user_opts[1]
else:
sender, user_ident = user_opts[0], None
receiver = msg_opts[2]
msg_type = msg_opts[1]
message = ' '.join(msg_opts[3:])[1:]
if msg_type == 'NOTICE' and receiver == 'AUTH' and message.startswith('*** You connected'):
for chan in self._init_channels:
self.join_channel(chan)
if msg_type == 'NOTICE' and sender == 'NickServ' and 'NickServ IDENTIFY' in message:
self.authorize()
continue
messages.append({'sender': sender,
'receiver': receiver,
'msg_type': msg_type,
'message': message,
'user_ident': user_ident})
return messages
def authorize(self):
LOG.info('Authorize in nickserv')
if self.username_password:
self.bus.send_out_message({'receiver':'NickServ',
'message': 'identify %s' % self.username_password})
def send_message(self, message):
if isinstance(message, list):
for m in message:
LOG.info('Send "%s" to "%s"' % (m['message'], m['receiver']))
self._write_conn.send('PRIVMSG %s :%s\r\n' % (m['receiver'], m['message']))
else:
LOG.info('Send "%s" to "%s"' % (message['message'], message['receiver']))
self._write_conn.send('PRIVMSG %s :%s\r\n' % (message['receiver'], message['message']))
def join_channel(self, channel):
LOG.info('Join to channel %s' % channel)
self.joined = True
if not channel.startswith('#'):
channel = '#' + channel
if len(channel.split(':')) > 1:
channel, password = channel.split(':')
self._write_conn.send('JOIN %s %s\r\n' % (channel, password))
else:
self._write_conn.send('JOIN %s\r\n' % channel)
#.........这里部分代码省略.........