示例#1
0
    def __init__(self, parent=None):
        super(httpWidget, self).__init__(parent)
        self.ui = Ui_HttpWidget()
        self.ui.setupUi(self)

        # set margins
        #l = self.layout()
        #l.setMargin(0)
        self.ui.horizontalLayout.setMargin(5)

        # set the default page
        url = "http://google.co.jp/"
        self.ui.url.setText(url)

        # load page
        self.ui.webView.setUrl(QtCore.QUrl(url))

        # history buttons
        self.ui.back.setEnabled(False)
        self.ui.next.setEnabled(False)

        QtCore.QObject.connect(self.ui.back, QtCore.SIGNAL("clicked()"), self.back)
        QtCore.QObject.connect(self.ui.next, QtCore.SIGNAL("clicked()"), self.next)
        QtCore.QObject.connect(self.ui.url, QtCore.SIGNAL("returnPressed()"), self.url_changed)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("linkClicked(const QUrl&)"), self.link_clicked)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("urlChanged(const QUrl&)"), self.link_clicked)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("loadProgress(int)"), self.load_progress)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("titleChanged(const QString&)"), self.title_changed)
        QtCore.QObject.connect(self.ui.reload, QtCore.SIGNAL("clicked()"), self.reload_page)
        QtCore.QObject.connect(self.ui.stop, QtCore.SIGNAL("clicked()"), self.stop_page)

        QtCore.QMetaObject.connectSlotsByName(self)
示例#2
0
	def __init__(self, parent=None):
		super(httpWidget, self).__init__(parent)
		self.ui = Ui_HttpWidget()
		self.ui.setupUi(self)
		#self.ui.resizeMax()		
		#self.resizeMax()		
		#self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
		self.resize(680, 500)
		icon2 = QtGui.QIcon()
		icon2.addPixmap(QtGui.QPixmap("title.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.setWindowIcon(icon2)
		l = self.layout()
		l.setMargin(0)
		#self.curl = 'http://localhost/jquery.mobile-1.0/jquery.mobile-1.0/jquery.mobile-1.0.docs/jquery.mobile-1.0/'		
		self.curl = "http://client.fangtee.com/"
		self.ui.webView.setUrl(QtCore.QUrl(_fromUtf8(self.curl)))
		self.ui.webView.page().mainFrame().javaScriptWindowObjectCleared.connect(self.populateJavaScriptWindowObject)
		self.mainFrame = self.ui.webView.page().mainFrame()
		
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadProgress (int)"), self.load_progress)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)		
		QtCore.QMetaObject.connectSlotsByName(self)
		
		self.workerSql = WorkerSql()
		self.connect(self.workerSql, SIGNAL("updatePage(QString)"), self.updatePage)
		self.WorkerQeue = []
		self.calljs = CallJs()
		self.connect(self.calljs, SIGNAL("callBackFun(QString)"), self.callBackFun)
		self.username  = ''
示例#3
0
	def __init__(self, parent=None):
		super(httpWidget, self).__init__(parent)
		self.ui = Ui_HttpWidget()
		self.ui.setupUi(self)
		#self.ui.resizeMax()		
		#self.resizeMax()		
		#self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
		self.resize(1024, 768)
		icon2 = QtGui.QIcon()
		icon2.addPixmap(QtGui.QPixmap("title.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.setWindowIcon(icon2)
		l = self.layout()
		l.setMargin(0)
		
		self.curl = "assets/www/index.html"
		self.ui.webView.setUrl(QtCore.QUrl(_fromUtf8(self.curl)))
		self.ui.webView.page().mainFrame().javaScriptWindowObjectCleared.connect(self.populateJavaScriptWindowObject)
		self.mainFrame = self.ui.webView.page().mainFrame()
		

		QtCore.QMetaObject.connectSlotsByName(self)
		self.spider = Worker()
		self.connect(self.spider, SIGNAL("updatePage1(QString)"), self.updatePage1) 
		
		self.postHouse = PostHouse()
		self.connect(self.postHouse, SIGNAL("updatePage(QString)"), self.updatePage)
		self.WorkerQeue = []
		self.username  = ''
		self.spiderContnet = {}
示例#4
0
    def __init__(self, parent=None):
        print "__init__"
        super(httpWidget, self).__init__(parent)
        self.ui = Ui_HttpWidget()
        self.ui.setupUi(self)

        # set margins
        l = self.layout()
        #l.setMargin(0)
        self.ui.horizontalLayout.setMargin(5)

        # set the default page
        url = 'http://www.uqian.me'
        self.ui.url.setText(url)

        # load page
        self.ui.webView.setUrl(QtCore.QUrl(url))

        # history buttons:
        self.ui.back.setEnabled(False)
        self.ui.next.setEnabled(False)

        QtCore.QObject.connect(self.ui.back, QtCore.SIGNAL("clicked()"),
                               self.back)
        QtCore.QObject.connect(self.ui.next, QtCore.SIGNAL("clicked()"),
                               self.next)
        QtCore.QObject.connect(self.ui.url, QtCore.SIGNAL("returnPressed()"),
                               self.url_changed)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("linkClicked (const QUrl&)"),
                               self.link_clicked)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("urlChanged (const QUrl&)"),
                               self.link_clicked)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("loadProgress (int)"),
                               self.load_progress)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("titleChanged (const QString&)"),
                               self.title_changed)
        QtCore.QObject.connect(self.ui.reload, QtCore.SIGNAL("clicked()"),
                               self.reload_page)
        QtCore.QObject.connect(self.ui.stop, QtCore.SIGNAL("clicked()"),
                               self.stop_page)

        QtCore.QMetaObject.connectSlotsByName(self)
示例#5
0
	def __init__(self, parent=None, url=False, mainWindow=False, newTab=False):
		super(httpWidget, self).__init__(mainWindow.main)
		self.ui = Ui_HttpWidget()
		self.ui.setupUi(self)
		self.parent = mainWindow.main
		self.mainWindow = mainWindow
		# set the lineEdit-URL to be as high as buttons
		self.ui.url.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,QtGui.QSizePolicy.Preferred)
		
		# history buttons:
		self.ui.back.setEnabled(False)
		self.ui.next.setEnabled(False)
		
		# set the url
		if not url:
			url = self.ui.url.text()
		
		self.ui.url.setText(url)
		
		# name the tab as current folder name
		tabName = url[0:20]
		
		# load page
		self.ui.webView.setUrl(QtCore.QUrl(url))
		
		if newTab:
			index = self.parent.addTab(self, tabName)
			self.parent.setCurrentIndex(index)
		else:
			index = self.parent.currentIndex()
			self.parent.removeTab(index)
			self.parent.insertTab(index, self, tabName)
			self.parent.setCurrentIndex(index)
		
		QtCore.QObject.connect(self.ui.newTab,QtCore.SIGNAL("clicked()"), self.mainWindow.new_tab)
		QtCore.QObject.connect(self.ui.close,QtCore.SIGNAL("clicked()"), self.mainWindow.close_tab)
		QtCore.QObject.connect(self.ui.up,QtCore.SIGNAL("clicked()"), self.mainWindow.up_clicked)
		QtCore.QObject.connect(self.ui.home,QtCore.SIGNAL("clicked()"), self.mainWindow.home_clicked)
		QtCore.QObject.connect(self.ui.url,QtCore.SIGNAL("returnPressed()"), self.mainWindow.url_handler)
		
		# let use WebKit history for better quality of moving next/back
		QtCore.QObject.connect(self.ui.back,QtCore.SIGNAL("clicked()"), self.back)
		QtCore.QObject.connect(self.ui.next,QtCore.SIGNAL("clicked()"), self.next)
		
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadProgress (int)"), self.load_progress)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)
		QtCore.QObject.connect(self.ui.reload,QtCore.SIGNAL("clicked()"), self.reload_page)
		QtCore.QObject.connect(self.ui.stop,QtCore.SIGNAL("clicked()"), self.stop_page)
		
		
		QtCore.QMetaObject.connectSlotsByName(self)
示例#6
0
文件: spider_gr.py 项目: garalee/umf
	def __init__(self,q,filename=None,parent=None):
		super(httpWidget, self).__init__(parent)
		self.ui = Ui_HttpWidget()
		self.ui.setupUi(self)
		self.current_query = ""
		self.reading_time = time.time()

		filename = "df_test.csv"
		self.fp = open(filename,'aw')
		self.writer = csv.writer(self.fp,delimiter='\t')

		# set margins
		l = self.layout()
		l.setMargin(0)
		self.ui.horizontalLayout.setMargin(5)

		#############################################################################
		#Part for FACEBOOK Authentication											#
		# remove '#1.' when FACEBOOK login is needed								#
		#############################################################################

		#1. FACEBOOK_APP_ID = '178358228892649'
		#1. self.facebook = Pyfb(FACEBOOK_APP_ID)
		#############################################################################
		##>facebook.authenticate()													#
		#############################################################################
		#1. self.facebook.set_permissions(["user_about_me", "email"])
		#1. url = urllib.unquote( self.facebook.get_auth_url() )

		url = 'http://www.google.com/search?hl=en&q='+q
		self.ui.url.setText(url)

		# load page
		self.ui.webView.setUrl(QtCore.QUrl(url))
		# history buttons:
		self.ui.back.setEnabled(False)
		self.ui.next.setEnabled(False)

		QtCore.QObject.connect(self.ui.back,QtCore.SIGNAL("clicked()"), self.back)
		QtCore.QObject.connect(self.ui.next,QtCore.SIGNAL("clicked()"), self.next)
		QtCore.QObject.connect(self.ui.url,QtCore.SIGNAL("returnPressed()"), self.url_changed)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadProgress (int)"), self.load_progress)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadFinished(bool)"),self.urlExtract)
		QtCore.QObject.connect(self.ui.reload,QtCore.SIGNAL("clicked()"), self.reload_page)
		QtCore.QObject.connect(self.ui.stop,QtCore.SIGNAL("clicked()"), self.stop_page)
		QtCore.QObject.connect(self.ui.chat,QtCore.SIGNAL("clicked()"), self.chatClicked)	
		QtCore.QMetaObject.connectSlotsByName(self)
示例#7
0
class httpWidget(QtGui.QWidget):

    def __init__(self, parent=None):
        super(httpWidget, self).__init__(parent)
        self.ui = Ui_HttpWidget()
        self.ui.setupUi(self)

        # set margins
        #l = self.layout()
        #l.setMargin(0)
        self.ui.horizontalLayout.setMargin(5)

        # set the default page
        url = "http://google.co.jp/"
        self.ui.url.setText(url)

        # load page
        self.ui.webView.setUrl(QtCore.QUrl(url))

        # history buttons
        self.ui.back.setEnabled(False)
        self.ui.next.setEnabled(False)

        QtCore.QObject.connect(self.ui.back, QtCore.SIGNAL("clicked()"), self.back)
        QtCore.QObject.connect(self.ui.next, QtCore.SIGNAL("clicked()"), self.next)
        QtCore.QObject.connect(self.ui.url, QtCore.SIGNAL("returnPressed()"), self.url_changed)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("linkClicked(const QUrl&)"), self.link_clicked)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("urlChanged(const QUrl&)"), self.link_clicked)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("loadProgress(int)"), self.load_progress)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("titleChanged(const QString&)"), self.title_changed)
        QtCore.QObject.connect(self.ui.reload, QtCore.SIGNAL("clicked()"), self.reload_page)
        QtCore.QObject.connect(self.ui.stop, QtCore.SIGNAL("clicked()"), self.stop_page)

        QtCore.QMetaObject.connectSlotsByName(self)

    def url_changed(self):
        """
        Url have been changed by user
        """
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        url = self.ui.url.text()
        self.ui.webView.setUrl(QtCore.QUrl(url))

    def stop_page(self):
        """
        Stop loading the page
        """
        self.ui.webView.stop()

    def title_changed(self, title):
        """
        Web page title changed - change the tab name
        """
        self.setWindowTitle(title)

    def reload_page(self):
        """
        Reload the web page
        """
        self.ui.webView.setUrl(QtCore.QUrl(self.ui.url.text()))

    def link_clicked(self, url):
        """
        Update the URL if a link on a web page is clicked
        """
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        self.ui.url.setText(url.toString())

    def load_progress(self, load):
        """
        Page load progress
        """
        if load == 100:
            self.ui.stop.setEnabled(False)
        else:
            self.ui.stop.setEnabled(True)

    def back(self):
        """
        Back button clicked, go one page back
        """
        page = self.ui.webView.page()
        history = page.history()
        history.back()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)

    def next(self):
        """
        Next button clicked, go to next page
        """
        page = self.ui.webView.page()
        history = page.history()
        history.forward()
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)
示例#8
0
class httpWidget(QtGui.QWidget):
	def __init__(self, parent=None, url=False, mainWindow=False, newTab=False):
		super(httpWidget, self).__init__(mainWindow.main)
		self.ui = Ui_HttpWidget()
		self.ui.setupUi(self)
		self.parent = mainWindow.main
		self.mainWindow = mainWindow
		# set the lineEdit-URL to be as high as buttons
		self.ui.url.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,QtGui.QSizePolicy.Preferred)
		
		# history buttons:
		self.ui.back.setEnabled(False)
		self.ui.next.setEnabled(False)
		
		# set the url
		if not url:
			url = self.ui.url.text()
		
		self.ui.url.setText(url)
		
		# name the tab as current folder name
		tabName = url[0:20]
		
		# load page
		self.ui.webView.setUrl(QtCore.QUrl(url))
		
		if newTab:
			index = self.parent.addTab(self, tabName)
			self.parent.setCurrentIndex(index)
		else:
			index = self.parent.currentIndex()
			self.parent.removeTab(index)
			self.parent.insertTab(index, self, tabName)
			self.parent.setCurrentIndex(index)
		
		QtCore.QObject.connect(self.ui.newTab,QtCore.SIGNAL("clicked()"), self.mainWindow.new_tab)
		QtCore.QObject.connect(self.ui.close,QtCore.SIGNAL("clicked()"), self.mainWindow.close_tab)
		QtCore.QObject.connect(self.ui.up,QtCore.SIGNAL("clicked()"), self.mainWindow.up_clicked)
		QtCore.QObject.connect(self.ui.home,QtCore.SIGNAL("clicked()"), self.mainWindow.home_clicked)
		QtCore.QObject.connect(self.ui.url,QtCore.SIGNAL("returnPressed()"), self.mainWindow.url_handler)
		
		# let use WebKit history for better quality of moving next/back
		QtCore.QObject.connect(self.ui.back,QtCore.SIGNAL("clicked()"), self.back)
		QtCore.QObject.connect(self.ui.next,QtCore.SIGNAL("clicked()"), self.next)
		
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadProgress (int)"), self.load_progress)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)
		QtCore.QObject.connect(self.ui.reload,QtCore.SIGNAL("clicked()"), self.reload_page)
		QtCore.QObject.connect(self.ui.stop,QtCore.SIGNAL("clicked()"), self.stop_page)
		
		
		QtCore.QMetaObject.connectSlotsByName(self)
	
	def back(self):
		"""
		Back button clicked, go one page back
		"""
		page = self.ui.webView.page()
		history = page.history()
		history.back()
		if history.canGoBack():
			self.ui.back.setEnabled(True)
		else:
			self.ui.back.setEnabled(False)
	
	def next(self):
		"""
		Next button clicked, go to next page
		"""
		page = self.ui.webView.page()
		history = page.history()
		history.forward()
		if history.canGoForward():
			self.ui.next.setEnabled(True)
		else:
			self.ui.next.setEnabled(False)

	
	def stop_page(self):
		"""
		Stop loading the page
		"""
		self.ui.webView.stop()
	
	def title_changed(self, title):
		"""
		Web page title changed - change the tab name
		"""
		index = self.parent.currentIndex()
		self.parent.setTabText(index, title)
	
	def reload_page(self):
		"""
		Reload the web page
		"""
		self.ui.webView.setUrl(QtCore.QUrl(self.ui.url.text()))
	
	def link_clicked(self, url):
		"""
		Update the URL if a link on a web page is clicked
		"""
		page = self.ui.webView.page()
		history = page.history()
		if history.canGoBack():
			self.ui.back.setEnabled(True)
		else:
			self.ui.back.setEnabled(False)
		if history.canGoForward():
			self.ui.next.setEnabled(True)
		else:
			self.ui.next.setEnabled(False)
		
		self.ui.url.setText(url.toString())
		
		url = url.toString()
		index = self.parent.currentIndex()
		if self.mainWindow.history.has_key(index):
			if len(self.mainWindow.history[index]) < 2:
				self.mainWindow.tab.ui.back.setEnabled(False)
			# add URL if he isn't in the history
			if self.mainWindow.history[index].count(unicode(url)) < 1:
				self.mainWindow.tab.ui.back.setEnabled(True)
				self.mainWindow.history[index].append(unicode(url))
				
				# if users clicks on an item that is somewhere in future
				# delete it as he is on a new browsing path
				if self.mainWindow.future.has_key(index) and self.mainWindow.future[index].count(unicode(url)) < 1:
					self.mainWindow.future[index] = []
					self.mainWindow.tab.ui.next.setEnabled(False)
		else:
			self.mainWindow.tab.ui.back.setEnabled(False)
			self.mainWindow.history[index] = [unicode(url)]
	
	def load_progress(self, load):
		"""
		Page load progress
		"""
		if load == 100:
			self.ui.stop.setEnabled(False)
			#print self.ui.webView.page().mainFrame().childFrames()
		else:
			self.ui.stop.setEnabled(True)
示例#9
0
class httpWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(httpWidget, self).__init__(parent)
        self.ui = Ui_HttpWidget()
        self.ui.setupUi(self)

        # set margins
        l = self.layout()
        l.setMargin(0)
        self.ui.horizontalLayout.setMargin(5)

        # set the default page
        url = 'http://google.pl'
        self.ui.url.setText(url)

        # load page
        self.ui.webView.setUrl(QtCore.QUrl(url))

        # history buttons:
        self.ui.back.setEnabled(False)
        self.ui.next.setEnabled(False)

        QtCore.QObject.connect(self.ui.back, QtCore.SIGNAL("clicked()"),
                               self.back)
        QtCore.QObject.connect(self.ui.next, QtCore.SIGNAL("clicked()"),
                               self.next)
        QtCore.QObject.connect(self.ui.url, QtCore.SIGNAL("returnPressed()"),
                               self.url_changed)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("linkClicked (const QUrl&)"),
                               self.link_clicked)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("urlChanged (const QUrl&)"),
                               self.link_clicked)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("loadProgress (int)"),
                               self.load_progress)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("titleChanged (const QString&)"),
                               self.title_changed)
        QtCore.QObject.connect(self.ui.reload, QtCore.SIGNAL("clicked()"),
                               self.reload_page)
        QtCore.QObject.connect(self.ui.stop, QtCore.SIGNAL("clicked()"),
                               self.stop_page)

        QtCore.QMetaObject.connectSlotsByName(self)

    def url_changed(self):
        """
		Url have been changed by user
		"""
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        url = self.ui.url.text()
        self.ui.webView.setUrl(QtCore.QUrl(url))

    def stop_page(self):
        """
		Stop loading the page
		"""
        self.ui.webView.stop()

    def title_changed(self, title):
        """
		Web page title changed - change the tab name
		"""
        self.setWindowTitle(title)

    def reload_page(self):
        """
		Reload the web page
		"""
        self.ui.webView.setUrl(QtCore.QUrl(self.ui.url.text()))

    def link_clicked(self, url):
        """
		Update the URL if a link on a web page is clicked
		"""
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        self.ui.url.setText(url.toString())

    def load_progress(self, load):
        """
		Page load progress
		"""
        if load == 100:
            self.ui.stop.setEnabled(False)
        else:
            self.ui.stop.setEnabled(True)

    def back(self):
        """
		Back button clicked, go one page back
		"""
        page = self.ui.webView.page()
        history = page.history()
        history.back()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)

    def next(self):
        """
		Next button clicked, go to next page
		"""
        page = self.ui.webView.page()
        history = page.history()
        history.forward()
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)
示例#10
0
class httpWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        print "__init__"
        super(httpWidget, self).__init__(parent)
        self.ui = Ui_HttpWidget()
        self.ui.setupUi(self)

        # set margins
        l = self.layout()
        #l.setMargin(0)
        self.ui.horizontalLayout.setMargin(5)

        # set the default page
        url = 'http://www.uqian.me'
        self.ui.url.setText(url)

        # load page
        self.ui.webView.setUrl(QtCore.QUrl(url))

        # history buttons:
        self.ui.back.setEnabled(False)
        self.ui.next.setEnabled(False)

        QtCore.QObject.connect(self.ui.back, QtCore.SIGNAL("clicked()"),
                               self.back)
        QtCore.QObject.connect(self.ui.next, QtCore.SIGNAL("clicked()"),
                               self.next)
        QtCore.QObject.connect(self.ui.url, QtCore.SIGNAL("returnPressed()"),
                               self.url_changed)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("linkClicked (const QUrl&)"),
                               self.link_clicked)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("urlChanged (const QUrl&)"),
                               self.link_clicked)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("loadProgress (int)"),
                               self.load_progress)
        QtCore.QObject.connect(self.ui.webView,
                               QtCore.SIGNAL("titleChanged (const QString&)"),
                               self.title_changed)
        QtCore.QObject.connect(self.ui.reload, QtCore.SIGNAL("clicked()"),
                               self.reload_page)
        QtCore.QObject.connect(self.ui.stop, QtCore.SIGNAL("clicked()"),
                               self.stop_page)

        QtCore.QMetaObject.connectSlotsByName(self)

    def url_changed(self):
        print "url changed"
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        url = self.ui.url.text()
        self.ui.webView.setUrl(QtCore.QUrl(url))

    def stop_page(self):
        print "stop page"
        self.ui.webView.stop()

    def title_changed(self, title):
        print "title changed"
        self.setWindowTitle(title)

    def reload_page(self):
        print "reload page"
        self.ui.webView.setUrl(QtCore.QUrl(self.ui.url.text()))

    def link_clicked(self, url):
        print "link clicked"
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        self.ui.url.setText(url.toString())

    def load_progress(self, load):
        print "load progress"
        if load == 100:
            self.ui.stop.setEnabled(False)
        else:
            self.ui.stop.setEnabled(True)

    def back(self):
        print "back"
        page = self.ui.webView.page()
        history = page.history()
        history.back()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)

    def next(self):
        print "next"
        page = self.ui.webView.page()
        history = page.history()
        history.forward()
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)
示例#11
0
class WebTab(QtGui.QWidget):
    def __init__(self, parent=None):
        super(WebTab, self).__init__(parent)
        self.ui = Ui_HttpWidget()
        self.ui.setupUi(self)

        # set margins
        """
        l = self.layout()
        l.setMargin(0)
        self.ui.horizontalLayout.setMargin(6)
        """

        # set the default page
        url = "http://google.it"
        self.ui.url.setText(url)

        # load page
        self.ui.webView.setUrl(QtCore.QUrl(url))

        # history buttons:
        self.ui.back.setEnabled(False)
        self.ui.next.setEnabled(False)

        # stop button:
        self.ui.stop.setEnabled(False)

        QtCore.QObject.connect(self.ui.back, QtCore.SIGNAL("clicked()"), self.back)
        QtCore.QObject.connect(self.ui.next, QtCore.SIGNAL("clicked()"), self.next)
        QtCore.QObject.connect(self.ui.url, QtCore.SIGNAL("returnPressed()"), self.url_changed)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
        QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)
        QtCore.QObject.connect(self.ui.reload, QtCore.SIGNAL("clicked()"), self.reload_page)
        QtCore.QObject.connect(self.ui.stop, QtCore.SIGNAL("clicked()"), self.stop_page)

        QtCore.QMetaObject.connectSlotsByName(self)

    def url_changed(self):
        # Url have been changed by user
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        url = str(self.ui.url.text())
        # bug fix: it loads urls with no http
        if str(self.ui.url.text())[0:3] != "http":
            self.ui.url.setText("http://" + url)

        url = self.ui.url.text()
        self.ui.webView.setUrl(QtCore.QUrl(url))

    def stop_page(self):
        # Stop loading the page
        self.close()

    def title_changed(self, title):
        # Web page title changed - change the tab name
        self.setWindowTitle(title)

    def reload_page(self):
        # Reload the web page
        self.ui.webView.setUrl(QtCore.QUrl(self.ui.url.text()))

    def link_clicked(self, url):
        # Update the URL if a link on a web page is clicked
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        self.ui.url.setText(url.toString())

    def back(self):
        # Back button clicked, go one page back
        page = self.ui.webView.page()
        history = page.history()
        history.back()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)

    def next(self):
        # Next button clicked, go to next page
        page = self.ui.webView.page()
        history = page.history()
        history.forward()
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)
示例#12
0
class httpWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        print "__init__"
        super(httpWidget, self).__init__(parent)
        self.ui = Ui_HttpWidget()
        self.ui.setupUi(self)

        # set margins
        l = self.layout()
        #l.setMargin(0)
        self.ui.horizontalLayout.setMargin(5)

        # set the default page
        url = 'http://www.uqian.me'
        self.ui.url.setText(url)

        # load page
        self.ui.webView.setUrl(QtCore.QUrl(url))

        # history buttons:
        self.ui.back.setEnabled(False)
        self.ui.next.setEnabled(False)

        QtCore.QObject.connect(self.ui.back,QtCore.SIGNAL("clicked()"), self.back)
        QtCore.QObject.connect(self.ui.next,QtCore.SIGNAL("clicked()"), self.next)
        QtCore.QObject.connect(self.ui.url,QtCore.SIGNAL("returnPressed()"), self.url_changed)
        QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
        QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
        QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadProgress (int)"), self.load_progress)
        QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)
        QtCore.QObject.connect(self.ui.reload,QtCore.SIGNAL("clicked()"), self.reload_page)
        QtCore.QObject.connect(self.ui.stop,QtCore.SIGNAL("clicked()"), self.stop_page)

        QtCore.QMetaObject.connectSlotsByName(self)

    def url_changed(self):
        print "url changed"
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        url = self.ui.url.text()
        self.ui.webView.setUrl(QtCore.QUrl(url))

    def stop_page(self):
        print "stop page"
        self.ui.webView.stop()

    def title_changed(self, title):
        print "title changed"
        self.setWindowTitle(title)

    def reload_page(self):
        print "reload page"
        self.ui.webView.setUrl(QtCore.QUrl(self.ui.url.text()))

    def link_clicked(self, url):
        print "link clicked"
        page = self.ui.webView.page()
        history = page.history()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)

        self.ui.url.setText(url.toString())

    def load_progress(self, load):
        print "load progress"
        if load == 100:
            self.ui.stop.setEnabled(False)
        else:
            self.ui.stop.setEnabled(True)

    def back(self):
        print "back"
        page = self.ui.webView.page()
        history = page.history()
        history.back()
        if history.canGoBack():
            self.ui.back.setEnabled(True)
        else:
            self.ui.back.setEnabled(False)

    def next(self):
        print "next"
        page = self.ui.webView.page()
        history = page.history()
        history.forward()
        if history.canGoForward():
            self.ui.next.setEnabled(True)
        else:
            self.ui.next.setEnabled(False)
示例#13
0
class httpWidget(QtGui.QWidget):
	def __init__(self, parent=None):
		super(httpWidget, self).__init__(parent)
		self.ui = Ui_HttpWidget()
		self.ui.setupUi(self)
		#self.ui.resizeMax()		
		#self.resizeMax()		
		#self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
		self.resize(680, 500)
		icon2 = QtGui.QIcon()
		icon2.addPixmap(QtGui.QPixmap("title.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.setWindowIcon(icon2)
		l = self.layout()
		l.setMargin(0)
		#self.curl = 'http://localhost/jquery.mobile-1.0/jquery.mobile-1.0/jquery.mobile-1.0.docs/jquery.mobile-1.0/'		
		self.curl = "http://client.fangtee.com/"
		self.ui.webView.setUrl(QtCore.QUrl(_fromUtf8(self.curl)))
		self.ui.webView.page().mainFrame().javaScriptWindowObjectCleared.connect(self.populateJavaScriptWindowObject)
		self.mainFrame = self.ui.webView.page().mainFrame()
		
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadProgress (int)"), self.load_progress)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)		
		QtCore.QMetaObject.connectSlotsByName(self)
		
		self.workerSql = WorkerSql()
		self.connect(self.workerSql, SIGNAL("updatePage(QString)"), self.updatePage)
		self.WorkerQeue = []
		self.calljs = CallJs()
		self.connect(self.calljs, SIGNAL("callBackFun(QString)"), self.callBackFun)
		self.username  = ''
	def resizeMax(self):
		#self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
		desktop = QtGui.QApplication.desktop()
		rect = desktop.availableGeometry()
		self.setGeometry(rect)
	@QtCore.pyqtSlot()
	def resizeReg(self):		
		self.resize(680, 600)
	@QtCore.pyqtSlot()
	def resizeLogin(self):		
		self.resize(480, 420)
	@QtCore.pyqtSlot()
	def resizeNormal(self):		
		self.resize(1024, 768)
	def populateJavaScriptWindowObject(self):
		self.ui.webView.page().mainFrame().addToJavaScriptWindowObject('callApi', self)
	def execJs(self,methodJS):
		self.mainFrame.evaluateJavaScript("""
			%s();					
		""" % methodJS)	
	
	def updatePage(self,s): 
		self.ui.url.setText("")
		
		s = "采集中... >>>> %s" % s
		self.ui.url.setText(_fromUtf8(s))
		del s
		
	@QtCore.pyqtSlot()
	def getUsername(self):
		self.mainFrame.evaluateJavaScript("""
			setUsername('%s');                  
		""" % self.username)	
		
	@QtCore.pyqtSlot()
	def setUsername(self):
		self.username = self.mainFrame.findFirstElement('#g_username').evaluateJavaScript("this.value")
	@QtCore.pyqtSlot()
	def getResult(self):
		param = self.mainFrame.findFirstElement('#param').evaluateJavaScript("this.value")
		#print param
		paramObj = json.loads(str(param))
		
		self.calljs.param = paramObj 
		self.calljs.start()
		self.calljs.wait()

	def callBackFun(self,callbak):		
		self.mainFrame.evaluateJavaScript("""
			callbackfunction(%s);                  
		""" % callbak)	
	def updateQueue(self,s): 
		id = int(s);
		if id in self.WorkerQeue:
			self.WorkerQeue.remove(id)

		s = "%s 结束" % s
		self.mainFrame.evaluateJavaScript("""
				loadSpider();                  
			""" )
		del s
	def getJsParam(self,id):
		threadData = self.mainFrame.findFirstElement('#'+id).evaluateJavaScript("this.value")
		#print threadData
		self.tData = json.loads(str(threadData))
		
		#print self.tData
		return self.tData
	@QtCore.pyqtSlot()
	def getThreadData(self):
		if self.WorkerQeue:
			s = json.dumps(self.WorkerQeue)
			print s
			self.mainFrame.evaluateJavaScript("""
				initThreadData();
				changeThreadSta(%s,1);                  
			""" % s)
		else:
			self.mainFrame.evaluateJavaScript("""
				initThreadData();
			""")
	@QtCore.pyqtSlot()
	def startAll(self):		
		self.getJsParam("threadData");
		#print len(self.WorkerQeue)
		self.workArr = {}
		for list in self.tData:
			
			if list['id'] not in self.WorkerQeue:
				#print self.tData
				self.WorkerQeue.append(list['id'])
				#开启线程
				self.workArr[list['name']] = Worker()
				self.workArr[list['name']]._init(list)
				self.connect(self.workArr[list['name']], SIGNAL("updateQueue(QString)"), self.updateQueue) 
			print list['name']+"启动"
	@QtCore.pyqtSlot()
	def stopAll(self):		
		#self.getJsParam("threadData");
		#print len(self.WorkerQeue)
		#for list in self.tData:
			#if list['id'] in self.WorkerQeue:
				#print self.tData
				#try:
					#self.workArr[list['id']].terminate()
				#except Exception,what:
					#pass
				#else:
					#self.WorkerQeue.remove(list['id'])
		
		for row in self.workArr:
			print row
			self.workArr[row].terminate()

	@QtCore.pyqtSlot()
	def start(self):		
		self.getJsParam("threadData");
		#print len(self.WorkerQeue)
		self.workArr = {}
		if self.tData['id'] not in self.WorkerQeue:
			self.tData['status'] = 1
			#print self.tData
			self.WorkerQeue.append(self.tData['id'])
			#开启线程
			self.workArr[self.tData['name']] = Worker()
			self.workArr[self.tData['name']]._init(self.tData)
			self.connect(self.workArr[self.tData['name']], SIGNAL("updateQueue(QString)"), self.updateQueue) 
			print self.tData['name']+"启动"
			
		if self.workerSql != False:
			self.workerSql.start()
			 
	@QtCore.pyqtSlot()
	def stop(self):		
		self.getJsParam("threadData");
		if self.tData['id'] in self.WorkerQeue:
			self.workArr[self.tData['name']].terminate()
			self.WorkerQeue.remove(self.tData['id'])
			print self.tData['name']+"停止!"
			
	def title_changed(self, title):
		self.setWindowTitle(title)
		
	def link_clicked(self, url):
		pass
	
	def load_progress(self, load):
		if load == 100:
			pass#self.ui.stop.setEnabled(False)
		else:
			pass#self.ui.stop.setEnabled(True)
	@QtCore.pyqtSlot()
	def publish(self):	
		data = self.mainFrame.findFirstElement('#publishData').evaluateJavaScript("this.value")
		param = json.loads(str(data))
		print param
		pub = WorkerPub()
		pub.param = param
		pub.start()
		pub.wait()
示例#14
0
class httpWidget(QtGui.QWidget):
	def __init__(self, parent=None):
		super(httpWidget, self).__init__(parent)
		self.ui = Ui_HttpWidget()
		self.ui.setupUi(self)
		#self.ui.resizeMax()		
		#self.resizeMax()		
		#self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
		self.resize(1024, 768)
		icon2 = QtGui.QIcon()
		icon2.addPixmap(QtGui.QPixmap("title.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.setWindowIcon(icon2)
		l = self.layout()
		l.setMargin(0)
		
		self.curl = "assets/www/index.html"
		self.ui.webView.setUrl(QtCore.QUrl(_fromUtf8(self.curl)))
		self.ui.webView.page().mainFrame().javaScriptWindowObjectCleared.connect(self.populateJavaScriptWindowObject)
		self.mainFrame = self.ui.webView.page().mainFrame()
		

		QtCore.QMetaObject.connectSlotsByName(self)
		self.spider = Worker()
		self.connect(self.spider, SIGNAL("updatePage1(QString)"), self.updatePage1) 
		
		self.postHouse = PostHouse()
		self.connect(self.postHouse, SIGNAL("updatePage(QString)"), self.updatePage)
		self.WorkerQeue = []
		self.username  = ''
		self.spiderContnet = {}
	def resizeMax(self):
		#self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
		desktop = QtGui.QApplication.desktop()
		rect = desktop.availableGeometry()
		self.setGeometry(rect)
		#QString
		
	@QtCore.pyqtSlot("QString","QString","QString","QString")
	def getSpiderList(self,url,web_flag,house_flag,city):		
		print url,web_flag,house_flag
		param = {}
		param['web_flag'] 	= int(web_flag)
		param['house_flag'] = int(house_flag)
		param['url'] 		= str(url)
		param['city'] 		= int(city)
		
		if param['web_flag']   ==  1:			
			cc = fetch58.BaseCrawl(param,_Queue)
		elif param['web_flag'] ==  2:			
			cc = fetchgj.BaseCrawl(param,_Queue)
		elif param['web_flag'] ==  3:			
			cc = fetchbx.BaseCrawl(param,_Queue)
		elif param['web_flag'] ==  4:			
			cc = fetchsf.BaseCrawl(param,_Queue)
		cc.isTest =True
		cc.fetchList()
		print cc.Lists
		self.mainFrame.evaluateJavaScript("""
				parseSpiderList(%s);                  
			""" % json.dumps(cc.Lists))
	@QtCore.pyqtSlot()
	def saveContent(self):
		print self.spiderContnet
		if self.spiderContnet:
			url = "http://client.fangtee.com/houseapi/python"
			r = postContent(url,self.spiderContnet)
			self.mainFrame.evaluateJavaScript("""
				location.href="#house_list";					
			""" )
			self.mainFrame.evaluateJavaScript("""
				location.reload();					
			""" )	
			
	@QtCore.pyqtSlot("QString","QString","QString","QString")
	def fetchContent(self,url,web_flag,house_flag,city):		
		print url,web_flag,house_flag
		
		param = {}
		param['web_flag'] 	= int(web_flag)
		param['house_flag'] = int(house_flag)
		param['url'] 		= str(url)
		param['city'] 		= int(city)
		if param['web_flag']   ==  1:			
			cc = fetch58.BaseCrawl(param,_Queue)
		elif param['web_flag'] ==  2:			
			cc = fetchgj.BaseCrawl(param,_Queue)
		elif param['web_flag'] ==  3:			
			cc = fetchbx.BaseCrawl(param,_Queue)
		elif param['web_flag'] ==  4:			
			cc = fetchsf.BaseCrawl(param,_Queue)
		cc.fetchContent()
		self.spiderContnet = cc.infoT
		if cc.infoT['owner_title']:
			print str(json.dumps(cc.infoT))
			for i in cc.infoT:
				print i,cc.infoT[i]
				self.mainFrame.findFirstElement('#d_'+i).evaluateJavaScript("this.value = %s" % json.dumps(cc.infoT[i]))

	@QtCore.pyqtSlot()
	def resizeReg(self):		
		self.resize(680, 600)
	@QtCore.pyqtSlot()
	def resizeLogin(self):		
		self.resize(480, 420)
	@QtCore.pyqtSlot()
	def resizeNormal(self):		
		self.resize(1024, 768)
	def populateJavaScriptWindowObject(self):
		self.ui.webView.page().mainFrame().addToJavaScriptWindowObject('callApi', self)
	
	def updatePage1(self,s): 	
		self.mainFrame.evaluateJavaScript("""
				setSpiderState('%s');					
			""" % str(s))
		del s
	def updatePage(self,s): 	
		self.mainFrame.evaluateJavaScript("""
				setSpiderResult('%s');					
			""" % str(s))
		del s
	@QtCore.pyqtSlot("QString")
	def startSpider(self,data):
		tData = json.loads(str(data))		
		self.spider._init(tData)
		self.spider.start()
		self.postHouse.start()
示例#15
0
文件: spider_gr.py 项目: garalee/umf
class httpWidget(QtGui.QWidget):
	global clisock
	#22clisock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
	#clisock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )

	def __init__(self,q,filename=None,parent=None):
		super(httpWidget, self).__init__(parent)
		self.ui = Ui_HttpWidget()
		self.ui.setupUi(self)
		self.current_query = ""
		self.reading_time = time.time()

		filename = "df_test.csv"
		self.fp = open(filename,'aw')
		self.writer = csv.writer(self.fp,delimiter='\t')

		# set margins
		l = self.layout()
		l.setMargin(0)
		self.ui.horizontalLayout.setMargin(5)

		#############################################################################
		#Part for FACEBOOK Authentication											#
		# remove '#1.' when FACEBOOK login is needed								#
		#############################################################################

		#1. FACEBOOK_APP_ID = '178358228892649'
		#1. self.facebook = Pyfb(FACEBOOK_APP_ID)
		#############################################################################
		##>facebook.authenticate()													#
		#############################################################################
		#1. self.facebook.set_permissions(["user_about_me", "email"])
		#1. url = urllib.unquote( self.facebook.get_auth_url() )

		url = 'http://www.google.com/search?hl=en&q='+q
		self.ui.url.setText(url)

		# load page
		self.ui.webView.setUrl(QtCore.QUrl(url))
		# history buttons:
		self.ui.back.setEnabled(False)
		self.ui.next.setEnabled(False)

		QtCore.QObject.connect(self.ui.back,QtCore.SIGNAL("clicked()"), self.back)
		QtCore.QObject.connect(self.ui.next,QtCore.SIGNAL("clicked()"), self.next)
		QtCore.QObject.connect(self.ui.url,QtCore.SIGNAL("returnPressed()"), self.url_changed)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadProgress (int)"), self.load_progress)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)
		QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadFinished(bool)"),self.urlExtract)
		QtCore.QObject.connect(self.ui.reload,QtCore.SIGNAL("clicked()"), self.reload_page)
		QtCore.QObject.connect(self.ui.stop,QtCore.SIGNAL("clicked()"), self.stop_page)
		QtCore.QObject.connect(self.ui.chat,QtCore.SIGNAL("clicked()"), self.chatClicked)	
		QtCore.QMetaObject.connectSlotsByName(self)
	
	def urlExtract(self):
		url = self.ui.url.text()

		page = self.ui.webView.page()
		h = page.currentFrame().toHtml()
		h = unicode(h)

		a = h.find('id=\"resultStats\"')
		if not a == -1:
			h = h[a:]
			a = h.find('About')
			h = h[a+6:]
			a = h.find('results')
			print h[:a]
		
		if "?" in url:
			dataset = url.split("?")[1]
			for data in dataset.split("&"):
				key = data.split("=")[0]
				value = data.split("=")[1]

				if key == "q":
					record = [str(v) for v in value.split("+")]
					self.current_query = record
					record.append(h[:a])
					# time_record = strftime("%Y-%m-%d %H:%M:%S", gmtime())
					# record.append(time_record)
					self.writer.writerows([record])

		if "#" in url:
			global email_id
			dataset = url.split("#")[1]
			for data in dataset.split("&"):
				key = data.split("=")[0]
				value = data.split("=")[1]
		
		t = time.time()-self.reading_time
		self.reading_time = time.time()
		#self.writer.writerows([record])

	def chatClicked(self):
		"""
		if self.chatClient.isHidden():
			self.chatClient.show()
		else:
			self.chatClient.hide()
		"""
		#--chat_client( 'localhost', 2626)
		#11main(sys.argv, 'adf')
		#self.chroom = ChatRoomWidget(self)
		#self.chroom.show()
		pass

	
	def url_changed(self):
		"""
		Url have been changed by user
		"""

		page = self.ui.webView.page()
		history = page.history()
		if history.canGoBack():
			self.ui.back.setEnabled(True)
		else:
			self.ui.back.setEnabled(False)
		if history.canGoForward():
			self.ui.next.setEnabled(True)
		else:
			self.ui.next.setEnabled(False)
		
		url = self.ui.url.text()

		if (not ("http://" in url)) or (not ("https://")):
			url = "http://" + url

		
		self.ui.webView.setUrl(QtCore.QUrl(url))

	def stop_page(self):
		"""
		Stop loading the page
		"""
		self.ui.webView.stop()
	
	def title_changed(self, title):
		"""
		Web page title changed - change the tab name
		"""
		self.setWindowTitle(title)
	
	def reload_page(self):
		"""
		Reload the web page
		"""
		self.ui.webView.setUrl(QtCore.QUrl(self.ui.url.text()))
	
	def link_clicked(self, url):
		"""
		Update the URL if a link on a web page is clicked
		"""
			
		page = self.ui.webView.page()
		history = page.history()
		if history.canGoBack():
			self.ui.back.setEnabled(True)
		else:
			self.ui.back.setEnabled(False)

		if history.canGoForward():
			self.ui.next.setEnabled(True)
		else:
			self.ui.next.setEnabled(False)

		self.ui.url.setText(url.toString())

	
	def load_progress(self, load):
		"""
		Page load progress
		"""
		if load == 100:
			self.ui.stop.setEnabled(False)
		else:
			self.ui.stop.setEnabled(True)
		
	def back(self):
		"""
		Back button clicked, go one page back
		"""
		page = self.ui.webView.page()
		history = page.history()
		history.back()
		if history.canGoBack():
			self.ui.back.setEnabled(True)
		else:
			self.ui.back.setEnabled(False)
	
	def next(self):
		"""
		Next button clicked, go to next page
		"""
		page = self.ui.webView.page()
		history = page.history()
		history.forward()
		if history.canGoForward():
			self.ui.next.setEnabled(True)
		else:
			self.ui.next.setEnabled(False)

	def closeEvent(self,e):
		self.fp.close()


	def keyPressEvent(self,e):
		if ((e.key() == QtCore.Qt.Key_L) and (QtGui.QApplication.keyboardModifiers() & QtCore.Qt.ControlModifier)):
			self.ui.url.selectAll()
			self.ui.url.setFocus()