def robot(): ''' # 简单机器人实现 ''' qq = SmartQQ() w = Window(qq) qq.login() # 登录验证 slf = qq.get_self_info() # 获取个人信息,主要是获取gid,发送信息会用到。 friends = qq.get_friends_info() # 获取好友列表 groups = qq.get_group_list() # 获取群列表 onli = qq.get_online_buddies2() # 获取在线好友 rev = qq.get_recent_list2() # 获取最近列表 img = qq.get_self_img() # 获取个人头像 w.show_self_info(img=img, data=slf) # 显示个人信息 gui.groups = groups gui.friends = friends # 循环主题 def recv_func(): while 1: get_msg = qq.get_chat_msg() print("get_msg %s" % get_msg) if get_msg != None: send_msg = "我不明白你的意思." if get_msg["poll_type"] == "group_message": w.group_msg_handle(get_msg["from_uin"], get_msg["send_uin"], get_msg["content"]) if get_msg["content"].find("@"+qq.qqname) >= 0 and gui.auto_send_name['group'] != None and \ get_msg["from_uin"] == groups[gui.auto_send_name['group']]['gid']: if get_msg["content"].find("自动回复") >= 0: send_msg = messge_text.messge_re[random.randint(0, 53)] qq.send_qun_msg(groups[gui.auto_send_name['group']]['gid'], send_msg) print("机器人回复 : %s" % send_msg) if get_msg["poll_type"] == "message" : w.friend_msg_handle(get_msg["from_uin"], get_msg["content"]) if gui.auto_send_name['friend'] != None and get_msg["from_uin"] == friends[gui.auto_send_name['friend']]['uin']: if get_msg["content"].find("自动回复") >= 0: send_msg = messge_text.messge_re[random.randint(0, 53)] qq.send_buddy_msg(friends[gui.auto_send_name['friend']]['uin'], send_msg) print("机器人回复 : %s" % send_msg) w.friend_msg_handle(get_msg["from_uin"], send_msg,True) time.sleep(1) t = threading.Thread(target=recv_func) t.start() w.run()
def main(): """Main function""" # Extract arguments or get random SMILES smiles = None informalName = None ex = get_example(None if len(sys.argv) < 2 else sys.argv[1]) if not ex: smiles = sys.argv[1] print "\n>>> Using input `%s` as SMILES.\n" % smiles else: informalName = ex[1] smiles = ex[2] print "\n>>> Using %s per argument.\n" % informalName # Init GUI. win = Window('Chemical Structure Diagram Generation (WIP)') # Set globals. Globals.drawable = win.drawable Globals.debugText = win.debugText Globals.window = win Globals.ringGroups = None Globals.molecule = None # Set callbacks. win.drawCallback = gui_draw_callback win.smilesCallback = gui_smiles_text_callback # Process initial data. parse_smiles_text(smiles, informalName) try: # Run GUI. win.run() except KeyboardInterrupt: print ""
class MediaPlayer: def __init__(self): self.DefineFunctionArgList() self.service = pydbus.SystemBus().get('org.bluez', '/') self.Update_obj_list() self.player_connected = False self.TerminateFlag = False self.obj_list_updater_thread = Thread(target=self.ObjListUpdater) self.track_info_updater_thread = Thread(target=self.TrackInfoUpdater) self.obj_list_updater_thread.start() self.track_info_updater_thread.start() self.Start() def ObjListUpdater(self): self.system_bus = pydbus.SystemBus() self.system_bus.subscribe(sender='org.bluez', signal='PropertiesChanged', signal_fired=self.Update_obj_list) loop = MainLoop() timeout_add(100, self.checkTerminate, loop) loop.run() def Update_obj_list(self, *args): self.obj_list = self.service.GetManagedObjects() def TrackInfoUpdater(self): while self.TerminateFlag is False: try: self.track_info = self.media_player.Get( 'org.bluez.MediaPlayer1', 'Track') self.track_info['Position'] = self.media_player.Get( 'org.bluez.MediaPlayer1', 'Position') self.track_info['Status'] = self.media_player.Get( 'org.bluez.MediaPlayer1', 'Status') except: self.track_info = { 'Title': '', 'Album': '', 'Artist': '', 'Genre': '', 'Duration': 0, 'Position': 0, 'Status': 'stopped' } sleep(0.2) def GetTrackInfo(self): return self.track_info def Start(self): self.ConnectMediaPlayer() def ConnectMediaPlayer(self): while self.player_connected is not True: for obj_path in self.obj_list.keys(): if "player" in obj_path: self.player_path = obj_path self.device_path = self.obj_list[ self.player_path]['org.bluez.MediaPlayer1']['Device'] self.device_name = self.obj_list[ self.device_path]['org.bluez.Device1']['Alias'] self.player_connected = self.obj_list[self.device_path][ 'org.bluez.MediaControl1']['Connected'] break sleep(0.2) self.media_player = pydbus.SystemBus().get('org.bluez', self.player_path) self.CreateWindow() def CheckConnection(self): if self.player_path not in self.obj_list and \ self.obj_list[self.device_path]['org.bluez.MediaControl1']['Connected'] is False: self.player_connected = False self.root.destroy() self.Start() def isPlayerConnected(self): return self.player_connected def Play(self): self.media_player.Play() def Pause(self): self.media_player.Pause() def Next(self): self.media_player.Next() def Previous(self): self.media_player.Previous() def Terminate(self): self.TerminateFlag = True def checkTerminate(self, loop): if self.TerminateFlag is True: loop.quit() else: timeout_add(100, self.checkTerminate, loop) def DefineFunctionArgList(self): self.func_list = { 'Terminate': self.Terminate, 'Play': self.Play, 'Pause': self.Pause, 'Next': self.Next, 'Previous': self.Previous, 'isPlayerConnected': self.isPlayerConnected, 'CheckConnection': self.CheckConnection, 'GetTrackInfo': self.GetTrackInfo } def CreateWindow(self): self.root = Window(self.func_list) self.root.run()
surface = ImageSurface(FORMAT_ARGB32, 500, 500) ctx = Context(surface) # Background height = 500 pat = SolidPattern(1.0, 1.0, 1.0, 0.9) ctx.rectangle (0,0, 500, 500) ctx.set_source (pat) ctx.fill () """ win = Window("Testing") win.setText(hexane) win.run() def draw_line(x1, y1, x2, y2): ctx.new_path() ctx.set_source_rgb(0.0, 0.0, 0.0) ctx.move_to(x1, y1) ctx.line_to(x2, y2) ctx.close_path() ctx.stroke() def write_text(x, y, text): ctx.set_source_rgb(0.0, 0.0, 0.0) ctx.select_font_face ("Sans", FONT_SLANT_NORMAL, FONT_WEIGHT_BOLD)
surface = ImageSurface(FORMAT_ARGB32, 500, 500) ctx = Context(surface) # Background height = 500 pat = SolidPattern(1.0, 1.0, 1.0, 0.9) ctx.rectangle (0,0, 500, 500) ctx.set_source (pat) ctx.fill () """ win = Window("Testing") win.setText(hexane) win.run() def draw_line(x1, y1, x2, y2): ctx.new_path() ctx.set_source_rgb(0.0, 0.0, 0.0) ctx.move_to(x1, y1) ctx.line_to(x2, y2) ctx.close_path() ctx.stroke() def write_text(x, y, text): ctx.set_source_rgb(0.0, 0.0, 0.0) ctx.select_font_face("Sans", FONT_SLANT_NORMAL, FONT_WEIGHT_BOLD) ctx.set_font_size(21)