ARTICLE AD BOX
Working on a beeware briefcase app for android. The only way I have found to get images to be clickable is to use the webview widget. Currently what happens is when the image is clicked, it changes the url to toga://hunt, which doesnt exist as a website. This is detected by toga, which then prints the hunters id (this works fine) and it is then changed back to the original url of the html file.
The only issue is that when the url changes to toga://hunt, it comes up with the webpage not available screen. Is there anyway to prevent this from happening or speed up the time taken to change from hunterButton.html --> toga://hunt --> hunterButton.html?
async def hunterMessageHandler (self, webview, **kwargs): global hunterID lastUrl = None defaultUrl = f"http://127.0.0.1:{self.app.local_port} hunterButton.html" while True: await asyncio.sleep(0.01) if not hasattr(self, "hunterView"): continue url = self.hunterView.url if url != lastUrl: lastUrl = url if url == "toga://hunt": self.hunterView.evaluate_javascript(f'window.location = "http://127.0.0.1:{self.app.local_port}/hunterButton.html"') print("button clicked") jsApp.become_hunter print(f"url: {url}") hunterID = "hunter" + self.idInput.value print(f"id: {hunterID}") url = defaultUrl print(f"url: {url}") lastUrl = defaultUrlRelevant html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Hunter Button</title> </head> <body style="margin: 0; width: 200px; height: 200px;"> <img src="hunter.png" alt="" id="hunterButton" style="width: 100%; height: 100%; position: center; float: left;" onclick="huntFunction()"> </body> <script> const msg = "uu"; function huntFunction (Toga) { console.log("clicked"); window.location = "toga://hunt" } </script> </html>