def setUp(self): if len(argv) == 2: site = argv[1] else: site = None options = extract_options(site) if options['cookie_file'] is not None: options['cookie_file'] = ( expanduser("~/.eilat/cookies/") + options['cookie_file']) # Proxy if options['use_proxy']: proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('localhost') proxy.setPort(3128) QNetworkProxy.setApplicationProxy(proxy) self.mainwin = MainWin(clipboard=CLIPBOARD, options=options, parent=None) if site: self.mainwin.add_tab(site) else: self.mainwin.add_tab() self.mainwin.show()
class TestEilat(unittest.TestCase): def setUp(self): if len(argv) == 2: site = argv[1] else: site = None options = extract_options(site) if options['cookie_file'] is not None: options['cookie_file'] = ( expanduser("~/.eilat/cookies/") + options['cookie_file']) # Proxy if options['use_proxy']: proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('localhost') proxy.setPort(3128) QNetworkProxy.setApplicationProxy(proxy) self.mainwin = MainWin(clipboard=CLIPBOARD, options=options, parent=None) if site: self.mainwin.add_tab(site) else: self.mainwin.add_tab() self.mainwin.show() def testExists(self): self.assertIsNotNone(APP) #APP.close() def testEnterUrl(self): webtab = self.mainwin.tab_widget.currentWidget() #QTest.keyClicks(webtab.webkit, "LA", Qt.ControlModifier) QTest.keyClicks(webtab.address_bar, "http://theospark.net") QTest.keyClick(webtab.address_bar, "J", Qt.ControlModifier) #QTest.keyClick(webtab.address_bar, Qt.Key_Return) self.assertEqual(webtab.address_bar.text(), "http://theospark.net")
def newWxPlotFrame(): return MainWin()
# coding=utf-8 import sys from MainWin import MainWin from PyQt5.QtWidgets import QApplication if __name__ == '__main__': # 创建QApplication类的实例 app = QApplication(sys.argv) # 创建一个窗口 MainWin() # 进入程序的主循环、并通过exit_()函数确保主循环安全结束 sys.exit(app.exec_())
def main(): """ Catch the url (if any); then choose adequate defaults and build a browser window. Save cookies, if appropiate, at close. """ # Considerations: # Will use proxy? (if not google, fb, twitter... then yes) use_proxy = True # Which whitelist will use instead? host_whitelist = None # Will allow cookies? Which? Where are they saved? cookie_allow = ["github.com", "linkedin.com", "freerepublic.com"] cookie_file = None prefix = "" if len(argv) == 2: sitio = argv[1] if (sitio.split('.')[-2:] == ["facebook", "com"]): use_proxy = False host_whitelist = ["facebook.com", "akamaihd.net", "fbcdn.net"] cookie_allow = ["facebook.com"] cookie_file = "fbcookies.cj" prefix = "FB" elif (sitio.split('.')[-2:] == ["twitter", "com"]): use_proxy = False host_whitelist = ["twitter.com", "twimg.com"] cookie_allow = ["twitter.com"] cookie_file = "twcookies.cj" prefix = "TW" elif (sitio.split('.')[-2:] == ["google", "com"]): print "GOOGLE" use_proxy = False host_whitelist = [ "google.com", "google.com.mx", "googleusercontent.com", "gstatic.com", "googleapis.com" ] cookie_allow = ["google.com"] cookie_file = "gcookies.cj" prefix = "G" else: print "GENERAL" else: sitio = None print "EMPTY" # Proxy if use_proxy: proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('localhost') proxy.setPort(3128) QNetworkProxy.setApplicationProxy(proxy) app = QtGui.QApplication([]) clipboard = app.clipboard() db_log = DatabaseLog() netmanager = InterceptNAM(parent=app, name=prefix, log=db_log, whitelist=host_whitelist) cookiejar = CookieJar(parent=app, allowed=cookie_allow, storage=cookie_file) netmanager.setCookieJar(cookiejar) app.setApplicationName("Eilat") app.setApplicationVersion("1.2.002") mainwin = MainWin(netmanager, clipboard) if sitio: mainwin.add_tab(sitio) else: mainwin.add_tab() mainwin.show() def end_call(): """ The browser is closing - save cookies, if required. """ print "END" if cookie_file: print "SAVING COOKIES" with open(cookie_file, "w") as savefile: for cookie in cookiejar.allCookies(): savefile.write(cookie.toRawForm() + "\n") app.lastWindowClosed.connect(end_call) app.exec_()
import sys sys.path.append('lib') from PyQt4 import QtGui from MainWin import MainWin if __name__ == '__main__': app = QtGui.QApplication(sys.argv) mainwindows = MainWin() mainwindows.show() sys.exit(app.exec_())
def main(): """ Catch the url (if any); then choose adequate defaults and build a browser window. Save cookies, if appropiate, at close. """ # Considerations: # Will use proxy? (if not google, fb, twitter... then yes) use_proxy = True # Which whitelist will use instead? host_whitelist = None # Will allow cookies? Which? Where are they saved? cookie_allow = ["github.com", "linkedin.com", "freerepublic.com"] cookie_file = None prefix = "" if len(argv) == 2: sitio = argv[1] if (sitio.split('.')[-2:] == ["facebook","com"]): use_proxy = False host_whitelist = ["facebook.com", "akamaihd.net", "fbcdn.net"] cookie_allow = ["facebook.com"] cookie_file = "fbcookies.cj" prefix = "FB" elif (sitio.split('.')[-2:] == ["twitter","com"]): use_proxy = False host_whitelist = ["twitter.com", "twimg.com"] cookie_allow = ["twitter.com"] cookie_file = "twcookies.cj" prefix = "TW" elif (sitio.split('.')[-2:] == ["google","com"]): print "GOOGLE" use_proxy = False host_whitelist = [ "google.com", "google.com.mx", "googleusercontent.com", "gstatic.com", "googleapis.com"] cookie_allow = ["google.com"] cookie_file = "gcookies.cj" prefix = "G" else: print "GENERAL" else: sitio = None print "EMPTY" # Proxy if use_proxy: proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('localhost') proxy.setPort(3128) QNetworkProxy.setApplicationProxy(proxy) app = QtGui.QApplication([]) clipboard = app.clipboard() db_log = DatabaseLog() netmanager = InterceptNAM( parent = app, name = prefix, log = db_log, whitelist = host_whitelist) cookiejar = CookieJar( parent = app, allowed = cookie_allow, storage = cookie_file) netmanager.setCookieJar(cookiejar) app.setApplicationName("Eilat") app.setApplicationVersion("1.2.002") mainwin = MainWin(netmanager, clipboard) if sitio: mainwin.add_tab(sitio) else: mainwin.add_tab() mainwin.show() def end_call(): """ The browser is closing - save cookies, if required. """ print "END" if cookie_file: print "SAVING COOKIES" with open(cookie_file, "w") as savefile: for cookie in cookiejar.allCookies(): savefile.write(cookie.toRawForm()+"\n") app.lastWindowClosed.connect(end_call) app.exec_()