Skip to main content

Posts

PyQt5 drawing lines that have mouse events

I have an application where I draw 2 custom widgets and then draw a line between them. I want to add a mousePressEvent to the line. What would be the best way to do this? I suppose I could create a QWidget of x pixel thickness and y length and then fill in the whole widget with the colour I want the line to have. Then the QWidget has the mousePressEvent that I can override. This doesn't seem like the most elegant solution and feels more like a workaround. Is there a better way? import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QPaintEvent, QPainter, QPen, QFont from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel class MyWidget(QWidget): def __init__(self, name, parent): super().__init__(parent) self.setAutoFillBackground(True) self.setFixedSize(300, 100) p = self.palette() p.setColor(self.backgroundRole(), Qt.white) self.setPalette(p) lbl_name = QLabel(name, self) lbl_name.set

force create_task execution

I used asyncio.create_task() only to realize that the task is fed to the task engine at a very late time. To make late time of execution obvious, I put some IO requests in the code below: import asyncio import requests async def func2(): # always executes last print("async asf") def func1(): asyncio.create_task(func2()) async def main(): print("main started") func1() print("main ended") # lets do some IO requests to give python plenty of time to execute func2 session = requests.Session() response = session.get("https://youtube.com") # this should be the last thing printed, but it is not print(response.status_code) if __name__ == '__main__': asyncio.run(main()) This prints: main started main ended 200 async asf Although I expected async asf to be before 200 How do you artificially trigger task execution? Is there some semantic sugar? source https://stackoverflow.com/questions/

API DELETE method issue

I have an issue with my javaScript code as the delete feature is working but, it is not deleting the right data ... Example: 1 - test1 2 - test2 3 - test3 My issue is when I try to delete test1, the program deletes test3 which means the program always deletes the last data in the list. Please, could you help? Here's my code: const url = "https://ghu8xhzgfe.execute-api.us-east-1.amazonaws.com/tasks/2877332"; let theTask = []; let text = ''; const init = () => { document.querySelector("#newTask").addEventListener("click", addNewTask); addNewTask(); getDataa(); }; const addNewTask = () => { console.log("Adding a new task..."); let xhr = new XMLHttpRequest(); let url = "https://ghu8xhzgfe.execute-api.us-east-1.amazonaws.com/tasks"; let apiKey = "Itcheui2tB58SlUGe8rrP8mskudGsNDT9nfKKG9S"; let studentId = "2877332"; let taskDescription = document.querySelector(&qu

how to open apple store as website not as app

I'm trying to make a React.js page so when you scan a Qr code it goes to this page and the page redirects to the Apple app store or Google Play depending on your phone. google play is working just fine the problem is that if you open it from iPhone it doesn't work and if you have the app already installed it opens it, I want to open the app store on the web or the app itself, and is it possible that it opens in a new window instead of the same window. thanks in advance. if (detect.os.name.toLocaleLowerCase() === "Android".toLocaleLowerCase()) { window.location = "https://play.google.com/store/apps/details?id=myAppId"; setTimeout(() => (window.location.pathname = "/download"), 10000); return <div>redirecting to GooglePlay</div>; } else if (detect.os.name.toLocaleLowerCase() === "IOS".toLocaleLowerCase()) { window.location.href = "https://apps.apple.com/eg/app/myApp"; setTimeout(()

how to tackle numpy warnings

i am trying to generate a plot with annotations, the issue is that i have for each x value multiple y values correspond to it, so in order to keep x and y similar in size, i wrote the following: x = [-2,-1,0,1,2] y = [(22.8,19.6),(8.9,13.7,14.7),(1.9,-1.8),(-3,-5.9,-13.4),(-5.7,-6.8)] however, i am constantly getting the follwoing warning: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. _data = np.array(data, dtype=dtype, copy=copy, my full code: import matplotlib.pyplot as plt import numpy as np x = [-2,-1,0,1,2] y = [(22.8,19.6),(8.9,13.7,14.7),(1.9,-1.8),(-3,-5.9,-13.4),(-5.7,-6.8)] custom_annotations = ["K464E", "K472E", "K464", "M155E", "K472", "M155A", "Q539A", "M155R",

How to make pop up with reactjs

How to make a pop-up information box when you click an element. Example like this image : Like this image, you click "View all study equipment" an element and then get that pop-up for more information. This is my code : <> <div className="description-container"> <div className="nav-tab"> <ul className="description-tab"> <li> <a href="/" className="active"> Class Description </a> </li> <li> <a href="/">Testimony</a> </li> <li> <a href="/">FAQ</a> </li> </ul> </div> </div> <div className="description-info"> <div className="desc-list"> <h2>Description</h2> <p> Websites in today's era have become a m

Python keyword in dict

I'm working with the telegram api and wanted to get the ID from the user but then I found out that one of the words is an python keyword. How to fix this? f"{update.message.from.id}" from ^^^^ source https://stackoverflow.com/questions/71945238/python-keyword-in-dict