def getListView(self,name): if not name in self.__listviews: from ListView import ListView lv = ListView() lv.addListener(self.__class__.ListViewListener(self, name, lv)) self.__listviews[name] = lv return self.__listviews[name]
def __init__(self): ''' 一些初始设置 ''' super().__init__() self.setWindowTitle('公众号:学点编程吧--QQ') self.setWindowFlags(Qt.Dialog) self.setMinimumSize(200, 600) self.setWhatsThis('这个一个模拟QQ软件') self.setWindowIcon(QIcon('./res/log.ico')) pListView = ListView() pListView.setViewMode(QListView.ListMode) # 设置模型 pListView.setStyleSheet("QListView{icon-size:70px}") # 设置QListView图标的大小70像素 dic_list = {'listview': pListView, 'groupname': "我的好友"} # 当前listview对象和分组名称放入到一个字典 pListView.setListMap(dic_list) # 这个字典放入到map_listview这个列表 self.addItem(pListView, "我的好友") self.show()
def initUI(self): self.statusBar().showMessage('准备就绪') self.setGeometry(100, 100, 800, 600) self.setWindowTitle('关注微信公众号:月小水长') self.setWindowIcon(QIcon('logo.jpg')) fpAct = QAction(QIcon('fp.png'), '找人(&FP)', self) fpAct.setShortcut('Ctrl+P') fpAct.setStatusTip('请输入微博用户昵称') fpAct.triggered.connect(self.findUser) fbAct = QAction(QIcon('fb.png'), '搜微博(&FB)', self) fbAct.setShortcut('Ctrl+B') fbAct.setStatusTip('请输入微博内容关键词') fbAct.triggered.connect(self.findTopic) menubar = self.menuBar() weiboMenu = menubar.addMenu('微博(&B)') weiboMenu.addAction(fpAct) weiboMenu.addSeparator() weiboMenu.addAction(fbAct) settingsMenu = menubar.addMenu('设置(&S)') aaAct = QAction(QIcon('aa.png'), '关于作者(&AA)', self) aaAct.setShortcut('Ctrl+A') aaAct.setStatusTip('产品作者的详细信息') aaAct.triggered.connect(self.aboutAuthor) aboutMenu = menubar.addMenu('关于(&A)') aboutMenu.addAction(aaAct) aboutMenu.addSeparator() oaAct = QAction(QIcon('oa.png'), '打开官网(&OA)', self) oaAct.setShortcut('Ctrl+O') oaAct.setStatusTip('打开产品官网') oaAct.triggered.connect(self.openAuthority) aboutMenu.addAction(oaAct) self.pListView = ListView(self) self.pListView.setViewMode(QListView.ListMode) self.pListView.setStyleSheet("QListView{icon-size:70px}") self.pListView.setGeometry(0, 20, 800, 560) self.show()
def addGroupSlot(self): ''' 增加分组 ''' groupname = QInputDialog.getText(self, "输入分组名", "") # groupname这里返回的是一个元组,其中第0个元素是分组名,第1个元素返回是否按了确定键 if groupname[0] and groupname[1]: pListView1 = ListView() pListView1.setViewMode(QListView.ListMode) pListView1.setStyleSheet("QListView{icon-size:70px}") self.addItem(pListView1, groupname[0]) dic_list = {'listview': pListView1, 'groupname': groupname[0]} pListView1.setListMap(dic_list) # 新建一个ListView对象并将其与分组名称添加到字典当中,然后通过setListMap()将这个字典放入到map_listview这个列表中 elif groupname[0] == '' and groupname[1]: QMessageBox.warning(self, "警告", "我说你没有填写分组名哦~!")
def __init__(self, search_handler, item_renderer, *columns): self.__search_handler = search_handler # build bookmarks list self.__bookmarks = BookmarkList() self.__browser = gtk.VBox() # build search bar self.__searchbar = SearchBar() self.__searchbar.show_all() self.__searchbar.add_observer(self.__on_search) self.__browser.pack_start(self.__searchbar, False, False, 0) # build list view scrwin = gtk.ScrolledWindow() scrwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.__browser.pack_end(scrwin, True, True, 0) self.__list = ListView(columns, item_renderer) self.__list.connect("row-activated", self.__on_activate_item) scrwin.add(self.__list)
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent border_width = 1 border_style = SUNKEN background_colour = "#FFFFFF" default_height = 600 nav_frame = Frame( self, height=default_height, width=200, bd=border_width, relief=border_style, bg=background_colour ) content_frame = Frame(self, height=default_height, width=804, bd=border_width, relief=border_style) content_frame.parent = parent nav_frame.grid(column=0, row=0) content_frame.grid(column=1, row=0) nav_frame.grid_propagate(0) content_frame.pack_propagate(0) # Create fonts for navLabels fontMouseOver = tkFont.Font(family="Helvetica", size=14, underline=True) fontMouseOut = tkFont.Font(family="Helvetica", size=14, underline=False) # Creating Navigation Labels self.lNavStudentRecords = Label( nav_frame, text="Student Records", bg="white", font=fontMouseOut, bd=border_width, relief=border_style, width=20, ) self.lNavViewLists = Label( nav_frame, text="View Word Lists", bg="white", font=fontMouseOut, bd=border_width, relief=border_style, width=20, ) self.lNavCreateLists = Label( nav_frame, text="Create Word Lists", bg="white", font=fontMouseOut, bd=border_width, relief=border_style, width=20, ) buttonBack = Button(nav_frame, text="Back", command=self.parent.new_list) # Binding Mouse events to the Labels # Mouse Clicks self.lNavViewLists.bind("<Button-1>", partial(self.switch_frame, 2)) self.lNavCreateLists.bind("<Button-1>", partial(self.switch_frame, 1)) self.lNavStudentRecords.bind("<Button-1>", partial(self.switch_frame, 3)) # Mouse Movements self.lNavViewLists.bind("<Enter>", lambda (event): self.lNavViewLists.configure(font=fontMouseOver)) self.lNavCreateLists.bind("<Enter>", lambda (event): self.lNavCreateLists.configure(font=fontMouseOver)) self.lNavViewLists.bind("<Leave>", lambda (event): self.lNavViewLists.configure(font=fontMouseOut)) self.lNavCreateLists.bind("<Leave>", lambda (event): self.lNavCreateLists.configure(font=fontMouseOut)) self.lNavStudentRecords.bind("<Enter>", lambda (event): self.lNavStudentRecords.configure(font=fontMouseOver)) self.lNavStudentRecords.bind("<Leave>", lambda (event): self.lNavStudentRecords.configure(font=fontMouseOut)) # Gridding the labels # self.lNavStudentRecords.grid(column=0, row=0) self.lNavViewLists.grid(column=0, row=1) self.lNavCreateLists.grid(column=0, row=2) buttonBack.grid(column=0, row=3) # Creating the two views we have so far self.viewcreate = CreateView(content_frame, default_height, 800, border_style, border_width, background_colour) self.viewlists = ListView(content_frame, default_height, 800, border_style, border_width, background_colour) self.viewlists.pack()
class ItemBrowser(Observable): OBS_ACTIVATE_ITEM = 0 def __init__(self, search_handler, item_renderer, *columns): self.__search_handler = search_handler # build bookmarks list self.__bookmarks = BookmarkList() self.__browser = gtk.VBox() # build search bar self.__searchbar = SearchBar() self.__searchbar.show_all() self.__searchbar.add_observer(self.__on_search) self.__browser.pack_start(self.__searchbar, False, False, 0) # build list view scrwin = gtk.ScrolledWindow() scrwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.__browser.pack_end(scrwin, True, True, 0) self.__list = ListView(columns, item_renderer) self.__list.connect("row-activated", self.__on_activate_item) scrwin.add(self.__list) # # Returns the widgets. # def get_widgets(self): return (self.__bookmarks, self.__browser) # # Adds a category to the bookmarks list. # def add_category(self, name, label, items): self.__bookmarks.add_category(name, name) items = list(set(items)) items.sort(lambda a,b: cmp(a[1], b[1])) for icon, label, expr in items: if (icon): pixbuf = gtk.gdk.pixbuf_new_from_file(icon) else: pixbuf = None self.__bookmarks.add_item(name, pixbuf, label, self.__on_select_entry, expr) #end for self.__bookmarks.select_category(0) # # Sets a search query manually. # def set_query(self, expr): self.__searchbar.set_query(expr) # # Returns the currently selected item. # def get_selected_item(self): return self.__list.get_selected_item() def __on_select_entry(self, expr): self.set_query(expr) def __on_search(self, src, cmd, expr): assert (self.__search_handler) self.__list.clear() matches = self.__search_handler(expr) if (matches): for item in matches: self.__list.add_item(item) return matches def __on_activate_item(self, *args): item = self.__list.get_selected_item() self.update_observer(self.OBS_ACTIVATE_ITEM, item)
class ScrapyGUI(QMainWindow): def __init__(self): global ss, vgs, us, ts super().__init__() self.initUI() ss.ps.connect(self.search_user) vgs.ps.connect(self.start_user) us.ps.connect(self.run_user) ts.ps.connect(self.topic_finished) def initUI(self): self.statusBar().showMessage('准备就绪') self.setGeometry(100, 100, 800, 600) self.setWindowTitle('关注微信公众号:月小水长') self.setWindowIcon(QIcon('logo.jpg')) fpAct = QAction(QIcon('fp.png'), '找人(&FP)', self) fpAct.setShortcut('Ctrl+P') fpAct.setStatusTip('请输入微博用户昵称') fpAct.triggered.connect(self.findUser) fbAct = QAction(QIcon('fb.png'), '搜微博(&FB)', self) fbAct.setShortcut('Ctrl+B') fbAct.setStatusTip('请输入微博内容关键词') fbAct.triggered.connect(self.findTopic) menubar = self.menuBar() weiboMenu = menubar.addMenu('微博(&B)') weiboMenu.addAction(fpAct) weiboMenu.addSeparator() weiboMenu.addAction(fbAct) settingsMenu = menubar.addMenu('设置(&S)') aaAct = QAction(QIcon('aa.png'), '关于作者(&AA)', self) aaAct.setShortcut('Ctrl+A') aaAct.setStatusTip('产品作者的详细信息') aaAct.triggered.connect(self.aboutAuthor) aboutMenu = menubar.addMenu('关于(&A)') aboutMenu.addAction(aaAct) aboutMenu.addSeparator() oaAct = QAction(QIcon('oa.png'), '打开官网(&OA)', self) oaAct.setShortcut('Ctrl+O') oaAct.setStatusTip('打开产品官网') oaAct.triggered.connect(self.openAuthority) aboutMenu.addAction(oaAct) self.pListView = ListView(self) self.pListView.setViewMode(QListView.ListMode) self.pListView.setStyleSheet("QListView{icon-size:70px}") self.pListView.setGeometry(0, 20, 800, 560) self.show() def findUser(self): global filter group = QInputDialog.getText(self, "输入用户昵称", "") self.searchedUser = group[0] if (len(group[0]) > 0): self.pListView.clearData() WeiboSearchScrapy(keyword=group[0]) def findTopic(self): dialog = MyDialog(self, info='主题') dialog.show() if (dialog.exec_() == QDialog.Accepted): print(dialog.getData()) group = dialog.getData() topic = group[0] filter = 1 if group[1] == True else 0 WeiboTopicScrapy(keyword=topic, filter=filter) QMessageBox.about(self, "提示", "已成功将抓取【{}】主题的任务提交后台,结束会通知您".format(topic)) def aboutAuthor(self): QMessageBox.about(self, "作者介绍", "简介:985计算机本科在读\nQQ:2391527690\n微信公众号:月小水长") def openAuthority(self): webbrowser.open("https://inspurer.github.io/") def search_user(self, msg): print(msg) if msg == 'EOF': QMessageBox.about(self, '提示', '【{}】相关的用户信息加载完毕'.format(self.searchedUser)) return elif msg == 'NetError': QMessageBox.warning(self, '警告', '请先检查电脑联网情况') return data = json.loads(msg) self.pListView.addItem(data) self.show() # 监听窗口大小变化事件 def resizeEvent(self, *args, **kwargs): w, h = self.width(), self.height() self.pListView.setGeometry(0, 20, w, h - 40) def start_user(self, msg): print('wwww', msg) res = QMessageBox.question(self, "提示", "只抓取原创微博吗?") if res == QMessageBox.Yes: WeiboUserScrapy(user_id=int(msg), filter=1) else: WeiboUserScrapy(user_id=int(msg), filter=0) def run_user(self, flag, value): print(flag, value) if flag == 'start': self.totalPageNum = value self.progress = QProgressDialog(self) self.progress.setWindowTitle("请稍等") self.progress.setLabelText("正在准备抓取...") ''' 如果任务的预期持续时间小于minimumDuration,则对话框根本不会出现。这样可以防止弹出对话框,快速完成任务。对于预期超过minimumDuration的任务,对话框将在minimumDuration时间之后或任何进度设置后立即弹出。 如果设置为0,则只要设置任何进度,将始终显示对话框。 默认值为4000毫秒,即4秒。 ''' self.progress.setMinimumDuration(1) self.progress.setWindowModality(Qt.WindowModal) # 去掉取消按钮 self.progress.setCancelButtonText(None) self.progress.setRange(0, self.totalPageNum) self.progress.setValue(1) if flag == 'run': self.progress.setValue(value) self.progress.setLabelText("正在抓取第{}/{}页".format( value, self.totalPageNum)) if value == self.totalPageNum: self.progress.destroy() QMessageBox.about(self, "提示", "抓取结束") def topic_finished(self, msg): QMessageBox.about(self, "提示", msg) ...