Spoolman support close #1060

Refactor post_requrest
Switching to TreeView
More spool info
redesign toggle buttons
Allow spoolman while printing
Styling checkbox as switch
render Toggle switch-like
Fixed wrong timezones
Filtering spools
Removed translations of Spoolman
Spool image can be overided in theme
Added switch-on/off symbols to toggle
rename iter to i to avoid shadowing built-in function
remove redundant parenthesis
convert spoolcompare to static
merge check and treeview shared props
reduce spacing of buttons very useful for vertical/portrait
fix issue with remainings
add spoolman shortcut to extrude
Using backports.zoneinfo for python < 3.9
use decorators for properties
extract format_date function
change top row
last used sort
rebase on upstream
Fix for never used spools


Co-authored-by: alfrix <alfredomonclus@gmail.com>
This commit is contained in:
Blonďák
2023-08-19 23:43:45 +02:00
committed by GitHub
parent 65c4b172e8
commit af1de12f28
26 changed files with 1356 additions and 26 deletions

View File

@@ -35,18 +35,19 @@ class KlippyRest:
def get_thumbnail_stream(self, thumbnail):
return self.send_request(f"server/files/gcodes/{thumbnail}", json=False)
def send_request(self, method, json=True):
def _do_request(self, method, request_method, data=None, json=None, json_response=True):
url = f"{self.endpoint}/{method}"
headers = {} if self.api_key is False else {"x-api-key": self.api_key}
data = False
response_data = False
try:
response = requests.get(url, headers=headers, timeout=3)
callee = getattr(requests, request_method)
response = callee(url, json=json, data=data, headers=headers, timeout=3)
response.raise_for_status()
if json:
if json_response:
logging.debug(f"Sending request to {url}")
data = response.json()
response_data = response.json()
else:
data = response.content
response_data = response.content
except requests.exceptions.HTTPError as h:
self.status = self.format_status(h)
except requests.exceptions.ConnectionError as c:
@@ -59,11 +60,17 @@ class KlippyRest:
self.status = self.format_status(r)
except Exception as e:
self.status = self.format_status(e)
if data:
if response_data:
self.status = ''
else:
logging.error(self.status.replace('\n', '>>'))
return data
return response_data
def post_request(self, method, data=None, json=None, json_response=True):
return self._do_request(method, "post", data, json, json_response)
def send_request(self, method, json=True):
return self._do_request(method, "get", json_response=json)
@staticmethod
def format_status(status):