Squashed commit of the following:
commitb7dcadf359Author: Julian Freeman <freemanjulian372@gmail.com> Date: Fri Feb 2 17:55:23 2024 -0400 v1.0.0 commitd84b107177Author: Julian Freeman <freemanjulian372@gmail.com> Date: Fri Feb 2 09:35:56 2024 -0400 dev 02020935 commita69ba157a5Author: Julian Freeman <freemanjulian372@gmail.com> Date: Thu Feb 1 21:49:26 2024 -0400 dev 02012149 commit38d98dee94Author: Julian Freeman <freemanjulian372@gmail.com> Date: Thu Feb 1 18:12:45 2024 -0400 dev 02011812 commit3e17def627Author: Julian Freeman <freemanjulian372@gmail.com> Date: Thu Feb 1 11:27:24 2024 -0400 dev 02011127 commit06327f3bfcAuthor: Julian Freeman <freemanjulian372@gmail.com> Date: Thu Feb 1 00:44:45 2024 -0400 dev 24.01.31
This commit is contained in:
42
global_vars.py
Normal file
42
global_vars.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# coding: utf8
|
||||
import requests
|
||||
from PySide6 import QtWidgets
|
||||
|
||||
SoftwareStatusRole = 0x0101
|
||||
ExtensionStatusRole = 0x0102
|
||||
ExtensionIdRole = 0x0103
|
||||
|
||||
|
||||
def accept_warning(widget: QtWidgets.QWidget, condition: bool,
|
||||
caption: str = "Warning", text: str = "Are you sure to continue?") -> bool:
|
||||
if condition:
|
||||
b = QtWidgets.QMessageBox.question(widget, caption, text)
|
||||
if b == QtWidgets.QMessageBox.StandardButton.No:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_with_chained_keys(dic: dict, keys: list, default=None):
|
||||
"""
|
||||
调用 get_with_chained_keys(d, ["a", "b", "c"])
|
||||
等同于 d["a"]["b"]["c"] ,
|
||||
只不过中间任意一次索引如果找不到键,则返回 default
|
||||
|
||||
:param dic: 目标字典
|
||||
:param keys: 键列表
|
||||
:param default: 找不到键时的默认返回值
|
||||
:return:
|
||||
"""
|
||||
k = keys[0]
|
||||
if k not in dic:
|
||||
return default
|
||||
if len(keys) == 1:
|
||||
return dic[k]
|
||||
return get_with_chained_keys(dic[k], keys[1:], default)
|
||||
|
||||
|
||||
def request_content(url: str) -> bytes:
|
||||
req = requests.get(url)
|
||||
if req.status_code == 200:
|
||||
return req.content
|
||||
return b""
|
||||
Reference in New Issue
Block a user