예제 #1
0
class Render(QWebPage):
    def __init__(self, url):
        self.url = url
        self.app = QEventLoop()
        QWebPage.__init__(self)
        self.urls = [url]
        self.frame = self.mainFrame()
        self.viewport = self.setViewportSize(QSize(1600, 9000))
        self.network = NetworkAccessManager()
        self.setNetworkAccessManager(self.network)
        self.loadFinished.connect(self._loadFinished)
        self.linkClicked.connect(self.change)
        self.settings().setAttribute(QWebSettings.AutoLoadImages, False)
        self.settings().setAttribute(QWebSettings.JavascriptCanOpenWindows,
                                     True)
        self.setLinkDelegationPolicy(1)
        self.action(QWebPage.OpenLinkInNewWindow).setEnabled(True)
        #self.settings().clearMemoryCaches()
        #self.mainFrame().load(QUrl(self.url))
        self.network.requestSignal.connect(self.networkRequest)
        self.thread = QThread()
        self.moveToThread(self.thread)
        self.thread.started.connect(self.run)
        self.thread.run()

    def run(self):
        self.mainFrame().load(QUrl(self.urls.pop(0)))
        self.app.exec_()

    def _loadFinished(self, res):
        ilist = self.frame.findAllElements('input')
        for i in ilist:
            i.evaluateJavaScript('this.click()')
            print i.attribute("onClick")
            #self.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        #self.setLinkDelegationPolicy(0)
        alist = self.frame.findAllElements('a')
        for a in alist:
            a.evaluateJavaScript("this.click()")

        if self.frame.blockSignals(True) == False:
            print 'yes'
            self.app.quit()

    def javaScriptAlert(browser, frame, message):
        """Notifies session for alert, then pass."""
        print "signal for javaScriptAlert (class) fired"

    def networkRequest(self):
        self.urls = self.network.request_Urls
        print 'allfinished'

    def change(self, url):
        self.urls.append(url.url())
        print url.url()
        #self.setLinkDelegationPolicy(0)
        print 'change'
예제 #2
0
class SpawnerView(QWidget, Ui_spawnerView):
    def __init__(self, model=None, controller=None):
        super(SpawnerView, self).__init__()
        self.model = model
        self.setupUi(self)
        self.controllerThread = QThread()
        self.spawnWorker = None
        self.create_threads()
        self.connect_buttons()
        self.findWindow(50, 50)

    def connect_buttons(self):
        self.start.clicked.connect(self.controllerThread.run())
        self.stop.clicked.connect(self.stopSpawner)
        self.HWRange.valueChanged.connect(
            lambda: self.changeHWRange(self.HWRange.value()))
        self.SHRange.valueChanged.connect(
            lambda: self.changeSHRange(self.SHRange.value()))

    def create_threads(self, *args):
        pythoncom.CoInitialize()
        self.spawnWorker = Worker(self.startSpawner, *args)
        self.spawnWorker.moveToThread(self.controllerThread)
        self.controllerThread.started.connect(self.spawnWorker.run)

    def changeSHRange(self, shr):
        self.SHRangeValue = int(shr)

    def changeHWRange(self, hwr):
        self.HWRangeValue = int(hwr)

    def startSpawner(self, *args):
        pythoncom.CoInitialize()
        xl = win32com.client.Dispatch(
            pythoncom.CoGetInterfaceAndReleaseStream(self.hWnd,
                                                     pythoncom.IID_IDispatch))
        self.startStatus = True
        print(self.HWRange)
        while self.startStatus is True:
            self.clickWindow()
            time.sleep(int(self.HWRangeValue * 60))

    def stopSpawner(self):
        self.startStatus = False

    def resetSpawner(self):
        self.stopSpawner()
        self.HWRange = 0.00
        self.SHRange = 0, 00

    def findWindow(self, x, y):
        windowslist = []
        windows = Desktop(backend="uia").windows()
        for w in windows:
            windowslist.append(w.window_text())
        windowtitle = str([s for s in windowslist if "Minecraft*" in s][0])
        print(f"fWindow found: {windowtitle}")

        self.hWnd = win32gui.FindWindow(None, windowtitle)
        self.lParam = win32api.MAKELONG(x, y)

    def clickWindow(self):
        win32gui.SendMessage(self.hWnd, win32con.WM_LBUTTONDOWN,
                             win32con.MK_LBUTTON, self.lParam)
        win32gui.SendMessage(self.hWnd, win32con.WM_LBUTTONUP, None,
                             self.lParam)
        time.sleep(self.SHRangeValue)
        win32gui.SendMessage(self.hWnd, win32con.WM_LBUTTONDOWN,
                             win32con.MK_LBUTTON, self.lParam)
        win32gui.SendMessage(self.hWnd, win32con.WM_LBUTTONUP, None,
                             self.lParam)
        time.sleep(self.SHRangeValue)
        win32gui.SendMessage(self.hWnd, win32con.WM_LBUTTONDOWN,
                             win32con.MK_LBUTTON, self.lParam)
        win32gui.SendMessage(self.hWnd, win32con.WM_LBUTTONUP, None,
                             self.lParam)