forked from CreatBot/CreatBotKlipperScreen
Update code style
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
class KlippyGcodes:
|
||||
|
||||
HOME = "G28"
|
||||
HOME_X = "G28 X"
|
||||
HOME_Y = "G28 Y"
|
||||
HOME_Z = "G28 Z"
|
||||
HOME = "G28"
|
||||
HOME_X = "G28 X"
|
||||
HOME_Y = "G28 Y"
|
||||
HOME_Z = "G28 Z"
|
||||
|
||||
MOVE = "G1"
|
||||
MOVE_ABSOLUTE = "G90"
|
||||
MOVE_RELATIVE = "G91"
|
||||
MOVE = "G1"
|
||||
MOVE_ABSOLUTE = "G90"
|
||||
MOVE_RELATIVE = "G91"
|
||||
|
||||
EXTRUDE_ABS = "M82"
|
||||
EXTRUDE_REL = "M83"
|
||||
EXTRUDE_ABS = "M82"
|
||||
EXTRUDE_REL = "M83"
|
||||
|
||||
SET_EXT_TEMP = "M104"
|
||||
MAX_EXT_TEMP = 450
|
||||
SET_EXT_TEMP = "M104"
|
||||
MAX_EXT_TEMP = 450
|
||||
|
||||
SET_BED_TEMP = "M140"
|
||||
MAX_BED_TEMP = 150
|
||||
SET_BED_TEMP = "M140"
|
||||
MAX_BED_TEMP = 150
|
||||
|
||||
SET_EXT_FACTOR = "M221"
|
||||
SET_FAN_SPEED = "M106"
|
||||
SET_SPD_FACTOR = "M220"
|
||||
SET_EXT_FACTOR = "M221"
|
||||
SET_FAN_SPEED = "M106"
|
||||
SET_SPD_FACTOR = "M220"
|
||||
|
||||
PROBE_CALIBRATE = "PROBE_CALIBRATE"
|
||||
PROBE_MOVE = "TESTZ Z="
|
||||
PROBE_ABORT = "ABORT"
|
||||
PROBE_ACCEPT = "ACCEPT"
|
||||
PROBE_MOVE = "TESTZ Z="
|
||||
PROBE_ABORT = "ABORT"
|
||||
PROBE_ACCEPT = "ACCEPT"
|
||||
|
||||
SAVE_CONFIG = "SAVE_CONFIG"
|
||||
RESTART = "RESTART"
|
||||
FIRMWARE_RESTART= "FIRMWARE_RESTART"
|
||||
SAVE_CONFIG = "SAVE_CONFIG"
|
||||
RESTART = "RESTART"
|
||||
FIRMWARE_RESTART = "FIRMWARE_RESTART"
|
||||
|
||||
|
||||
@staticmethod
|
||||
@@ -46,7 +46,7 @@ class KlippyGcodes:
|
||||
|
||||
@staticmethod
|
||||
def set_fan_speed(speed):
|
||||
speed = str( int(float(int(speed) % 101)/100*255) )
|
||||
speed = str(int(float(int(speed) % 101)/100*255))
|
||||
return "%s S%s" % (KlippyGcodes.SET_FAN_SPEED, speed)
|
||||
|
||||
@staticmethod
|
||||
|
@@ -62,10 +62,10 @@ class KlippyGtk:
|
||||
return (self.width - self.get_action_bar_width()) * self.keyboard_ratio
|
||||
|
||||
def Label(self, label, style=None):
|
||||
l = Gtk.Label(label)
|
||||
if style != None and style != False:
|
||||
l.get_style_context().add_class(style)
|
||||
return l
|
||||
la = Gtk.Label(label)
|
||||
if style is not None and style is not False:
|
||||
la.get_style_context().add_class(style)
|
||||
return la
|
||||
|
||||
def ImageLabel(self, image_name, text, size=20, style=False, width_scale=.32, height_scale=.32):
|
||||
box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=15)
|
||||
@@ -80,7 +80,7 @@ class KlippyGtk:
|
||||
box1.add(image)
|
||||
box1.add(label)
|
||||
|
||||
if style != False:
|
||||
if style is not False:
|
||||
ctx = box1.get_style_context()
|
||||
ctx.add_class(style)
|
||||
|
||||
@@ -94,31 +94,31 @@ class KlippyGtk:
|
||||
return Gtk.Image.new_from_pixbuf(pixbuf)
|
||||
|
||||
def ImageFromFile(self, filename, style=False, width_scale=1, height_scale=1):
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename,
|
||||
int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filename, int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
||||
|
||||
return Gtk.Image.new_from_pixbuf(pixbuf)
|
||||
|
||||
def PixbufFromFile(self, filename, style=False, width_scale=1, height_scale=1):
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename, int(round(self.img_width * width_scale)),
|
||||
int(round(self.img_height * height_scale)), True)
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filename, int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
||||
|
||||
return pixbuf
|
||||
|
||||
def PixbufFromHttp(self, resource, style=False, width_scale=1, height_scale=1):
|
||||
response = self.screen.apiclient.get_thumbnail_stream(resource)
|
||||
if response == False:
|
||||
if response is False:
|
||||
return None
|
||||
stream = Gio.MemoryInputStream.new_from_data(response, None)
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(stream, int(round(self.img_width * width_scale)),
|
||||
int(round(self.img_height * height_scale)), True)
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
|
||||
stream, int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
||||
|
||||
return pixbuf
|
||||
|
||||
def ProgressBar(self, style=False):
|
||||
bar = Gtk.ProgressBar()
|
||||
|
||||
if style != False:
|
||||
if style is not False:
|
||||
ctx = bar.get_style_context()
|
||||
ctx.add_class(style)
|
||||
|
||||
@@ -131,13 +131,13 @@ class KlippyGtk:
|
||||
b.set_can_focus(False)
|
||||
b.props.relief = Gtk.ReliefStyle.NONE
|
||||
|
||||
if style != None:
|
||||
if style is not None:
|
||||
b.get_style_context().add_class(style)
|
||||
|
||||
return b
|
||||
|
||||
def ButtonImage(self, image_name, label=None, style=None, width_scale=1.38, height_scale=1.38,
|
||||
position=Gtk.PositionType.TOP, word_wrap=True):
|
||||
position=Gtk.PositionType.TOP, word_wrap=True):
|
||||
filename = "%s/styles/%s/images/%s.svg" % (klipperscreendir, self.theme, str(image_name))
|
||||
if not os.path.exists(filename):
|
||||
logging.error("Unable to find button image (theme, image): (%s, %s)" % (self.theme, str(image_name)))
|
||||
@@ -168,10 +168,10 @@ class KlippyGtk:
|
||||
child = b.get_children()[0].get_children()[0].get_children()[1]
|
||||
child.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
|
||||
child.set_line_wrap(True)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if style != None:
|
||||
if style is not None:
|
||||
b.get_style_context().add_class(style)
|
||||
|
||||
return b
|
||||
@@ -222,7 +222,6 @@ class KlippyGtk:
|
||||
img = Gtk.Image.new_from_pixbuf(pixbuf)
|
||||
|
||||
b = Gtk.ToggleButton(label=label)
|
||||
#b.props.relief = Gtk.RELIEF_NONE
|
||||
b.set_image(img)
|
||||
b.set_hexpand(True)
|
||||
b.set_vexpand(True)
|
||||
@@ -231,7 +230,7 @@ class KlippyGtk:
|
||||
b.set_always_show_image(True)
|
||||
b.props.relief = Gtk.ReliefStyle.NONE
|
||||
|
||||
if style != False:
|
||||
if style is not False:
|
||||
ctx = b.get_style_context()
|
||||
ctx.add_class(style)
|
||||
|
||||
@@ -241,7 +240,7 @@ class KlippyGtk:
|
||||
g = Gtk.Grid()
|
||||
g.set_row_homogeneous(True)
|
||||
g.set_column_homogeneous(True)
|
||||
if width != None and height != None:
|
||||
if width is not None and height is not None:
|
||||
g.set_size_request(width, height)
|
||||
return g
|
||||
|
||||
@@ -263,12 +262,12 @@ class KlippyGtk:
|
||||
def formatTimeString(self, seconds):
|
||||
time = int(seconds)
|
||||
text = ""
|
||||
if int(time/3600) !=0:
|
||||
if int(time/3600) != 0:
|
||||
text += str(int(time/3600))+"h "
|
||||
text += str(int(time/60)%60)+"m "+str(time%60)+"s"
|
||||
text += str(int(time/60) % 60)+"m "+str(time % 60)+"s"
|
||||
return text
|
||||
|
||||
def formatTemperatureString(self, temp, target):
|
||||
if (target > temp-2 and target < temp+2) or round(target,0) == 0:
|
||||
return str(round(temp,1)) + "°C" #°C →"
|
||||
if (target > temp-2 and target < temp+2) or round(target, 0) == 0:
|
||||
return str(round(temp, 1)) + "°C" # °C →"
|
||||
return str(round(temp)) + " → " + str(round(target)) + "°C"
|
||||
|
@@ -13,7 +13,7 @@ class KlippyRest:
|
||||
|
||||
def get_oneshot_token(self):
|
||||
r = self.send_request("access/oneshot_token")
|
||||
if r == False:
|
||||
if r is False:
|
||||
return False
|
||||
return r['result']
|
||||
|
||||
@@ -31,18 +31,18 @@ class KlippyRest:
|
||||
def send_request(self, method):
|
||||
url = "http://%s:%s/%s" % (self.ip, self.port, method)
|
||||
logging.debug("Sending request to %s" % url)
|
||||
headers = {} if self.api_key == False else {"x-api-key":self.api_key}
|
||||
headers = {} if self.api_key is False else {"x-api-key": self.api_key}
|
||||
try:
|
||||
r = requests.get(url, headers=headers)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
if r.status_code != 200:
|
||||
return False
|
||||
|
||||
#TODO: Try/except
|
||||
# TODO: Try/except
|
||||
try:
|
||||
data = json.loads(r.content)
|
||||
except:
|
||||
except Exception:
|
||||
logging.exception("Unable to parse response from moonraker:\n %s" % r.content)
|
||||
return False
|
||||
|
||||
|
@@ -14,12 +14,10 @@ gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, Gdk, GLib
|
||||
from ks_includes.KlippyGcodes import KlippyGcodes
|
||||
|
||||
#f = open("/home/pi/.moonraker_api_key", "r")
|
||||
api_key = "" #f.readline()
|
||||
#f.close()
|
||||
api_key = ""
|
||||
|
||||
api = {
|
||||
"printer_info": {
|
||||
"printer_info": {
|
||||
"url": "/printer/info",
|
||||
"method": "get_printer_info"
|
||||
},
|
||||
@@ -48,33 +46,32 @@ class KlippyWebsocket(threading.Thread):
|
||||
|
||||
def initial_connect(self):
|
||||
# Enable a timeout so that way if moonraker is not running, it will attempt to reconnect
|
||||
if self.timeout == None:
|
||||
if self.timeout is None:
|
||||
self.timeout = GLib.timeout_add(500, self.reconnect)
|
||||
self.connect()
|
||||
|
||||
def connect (self):
|
||||
def connect(self):
|
||||
def ws_on_close(ws, a=None, b=None):
|
||||
self.on_close(ws)
|
||||
|
||||
def ws_on_error(ws, msg):
|
||||
self.on_error(ws, msg)
|
||||
|
||||
def ws_on_message(ws, msg):
|
||||
self.on_message(ws, msg)
|
||||
|
||||
def ws_on_open(ws):
|
||||
self.on_open(ws)
|
||||
|
||||
try:
|
||||
token = self._screen.apiclient.get_oneshot_token()
|
||||
except:
|
||||
except Exception:
|
||||
logging.debug("Unable to get oneshot token")
|
||||
return False
|
||||
|
||||
self.ws_url = "ws://%s/websocket?token=%s" % (self._url, token)
|
||||
self.ws = websocket.WebSocketApp(self.ws_url,
|
||||
on_close = ws_on_close,
|
||||
on_error = ws_on_error,
|
||||
on_message = ws_on_message,
|
||||
on_open = ws_on_open
|
||||
)
|
||||
self.ws = websocket.WebSocketApp(
|
||||
self.ws_url, on_close=ws_on_close, on_error=ws_on_error, on_message=ws_on_message, on_open=ws_on_open)
|
||||
|
||||
self._wst = threading.Thread(target=self.ws.run_forever)
|
||||
self._wst.daemon = True
|
||||
@@ -115,11 +112,11 @@ class KlippyWebsocket(threading.Thread):
|
||||
return
|
||||
|
||||
def send_method(self, method, params={}, callback=None, *args):
|
||||
if self.is_connected() == False:
|
||||
if self.is_connected() is False:
|
||||
return False
|
||||
|
||||
self._req_id += 1
|
||||
if callback != None:
|
||||
if callback is not None:
|
||||
self.callback_table[self._req_id] = [callback, method, params, [*args]]
|
||||
|
||||
data = {
|
||||
@@ -135,7 +132,7 @@ class KlippyWebsocket(threading.Thread):
|
||||
logging.info("Moonraker Websocket Open")
|
||||
logging.info("Self.connected = %s" % self.is_connected())
|
||||
self.connected = True
|
||||
if self.timeout != None:
|
||||
if self.timeout is not None:
|
||||
GLib.source_remove(self.timeout)
|
||||
self.timeout = None
|
||||
if "on_connect" in self._callback:
|
||||
@@ -145,18 +142,18 @@ class KlippyWebsocket(threading.Thread):
|
||||
)
|
||||
|
||||
def on_close(self, ws):
|
||||
if self.is_connected() == False:
|
||||
if self.is_connected() is False:
|
||||
logging.debug("Connection already closed")
|
||||
return
|
||||
|
||||
if self.closing == True:
|
||||
if self.closing is True:
|
||||
logging.debug("Closing websocket")
|
||||
self.ws.stop()
|
||||
return
|
||||
|
||||
logging.info("Moonraker Websocket Closed")
|
||||
self.connected = False
|
||||
if self.timeout == None:
|
||||
if self.timeout is None:
|
||||
self.timeout = GLib.timeout_add(500, self.reconnect)
|
||||
|
||||
if "on_close" in self._callback:
|
||||
@@ -179,7 +176,7 @@ class KlippyWebsocket(threading.Thread):
|
||||
logging.debug("Websocket error: %s" % error)
|
||||
|
||||
class MoonrakerApi:
|
||||
def __init__ (self, ws):
|
||||
def __init__(self, ws):
|
||||
self._ws = ws
|
||||
|
||||
def emergency_stop(self):
|
||||
@@ -207,7 +204,6 @@ class MoonrakerApi:
|
||||
)
|
||||
|
||||
def get_file_list(self, callback=None, *args):
|
||||
#Commenting this log for being too noisy
|
||||
logging.debug("Sending server.files.list")
|
||||
return self._ws.send_method(
|
||||
"server.files.list",
|
||||
@@ -217,7 +213,6 @@ class MoonrakerApi:
|
||||
)
|
||||
|
||||
def get_file_metadata(self, filename, callback=None, *args):
|
||||
#logging.debug("Sending server.files.metadata: %s", filename)
|
||||
return self._ws.send_method(
|
||||
"server.files.metadata",
|
||||
{"filename": filename},
|
||||
@@ -300,13 +295,14 @@ class MoonrakerApi:
|
||||
*args
|
||||
)
|
||||
else:
|
||||
logging.debug("Sending printer.gcode.script: %s",
|
||||
KlippyGcodes.set_ext_temp(target, heater.replace("tool","")))
|
||||
#TODO: Add max/min limits
|
||||
logging.debug(
|
||||
"Sending printer.gcode.script: %s",
|
||||
KlippyGcodes.set_ext_temp(target, heater.replace("tool", "")))
|
||||
# TODO: Add max/min limits
|
||||
return self._ws.send_method(
|
||||
"printer.gcode.script",
|
||||
{
|
||||
"script": KlippyGcodes.set_ext_temp(target, heater.replace("tool",""))
|
||||
"script": KlippyGcodes.set_ext_temp(target, heater.replace("tool", ""))
|
||||
},
|
||||
callback,
|
||||
*args
|
||||
|
@@ -11,12 +11,12 @@ from io import StringIO
|
||||
from os import path
|
||||
|
||||
SCREEN_BLANKING_OPTIONS = [
|
||||
"300", #5 Minutes
|
||||
"900", #15 Minutes
|
||||
"1800", #30 Minutes
|
||||
"3600", #1 Hour
|
||||
"7200", #2 Hours
|
||||
"14400", #4 Hours
|
||||
"300", # 5 Minutes
|
||||
"900", # 15 Minutes
|
||||
"1800", # 30 Minutes
|
||||
"3600", # 1 Hour
|
||||
"7200", # 2 Hours
|
||||
"14400", # 4 Hours
|
||||
]
|
||||
|
||||
class ConfigError(Exception):
|
||||
@@ -44,9 +44,9 @@ class KlipperScreenConfig:
|
||||
|
||||
includes = [i[8:] for i in self.defined_config.sections() if i.startswith("include ")]
|
||||
for include in includes:
|
||||
self._include_config("/".join(self.config_path.split("/")[:-1]),include)
|
||||
self._include_config("/".join(self.config_path.split("/")[:-1]), include)
|
||||
|
||||
for i in ['menu __main','menu __print','menu __splashscreen','preheat']:
|
||||
for i in ['menu __main', 'menu __print', 'menu __splashscreen', 'preheat']:
|
||||
for j in self.defined_config.sections():
|
||||
if j.startswith(i):
|
||||
for k in list(self.config.sections()):
|
||||
@@ -56,12 +56,12 @@ class KlipperScreenConfig:
|
||||
|
||||
self.log_config(self.defined_config)
|
||||
self.config.read_string(user_def)
|
||||
if saved_def != None:
|
||||
if saved_def is not None:
|
||||
self.config.read_string(saved_def)
|
||||
logging.info("====== Saved Def ======\n%s\n=======================" % saved_def)
|
||||
except KeyError:
|
||||
raise ConfigError(f"Error reading config: {self.config_path}")
|
||||
except:
|
||||
except Exception:
|
||||
logging.exception("Unknown error with config")
|
||||
|
||||
printers = sorted([i for i in self.config.sections() if i.startswith("printer ")])
|
||||
@@ -92,10 +92,10 @@ class KlipperScreenConfig:
|
||||
logging.debug("Configured printers: %s" % json.dumps(conf_printers_debug, indent=2))
|
||||
|
||||
lang = self.get_main_config_option("language", None)
|
||||
lang = [lang] if lang != None and lang != "default" else None
|
||||
lang = [lang] if lang is not None and lang != "default" else None
|
||||
logging.info("Detected language: %s" % lang)
|
||||
self.lang = gettext.translation('KlipperScreen', localedir='ks_includes/locales', languages=lang,
|
||||
fallback=True)
|
||||
fallback=True)
|
||||
|
||||
self._create_configurable_options(screen)
|
||||
|
||||
@@ -108,55 +108,57 @@ class KlipperScreenConfig:
|
||||
{"invert_y": {"section": "main", "name": _("Invert Y"), "type": "binary", "value": "False"}},
|
||||
{"invert_z": {"section": "main", "name": _("Invert Z"), "type": "binary", "value": "False"}},
|
||||
{"language": {"section": "main", "name": _("Language"), "type": "dropdown", "value": "system_lang",
|
||||
"callback": screen.restart_warning, "options":[
|
||||
{"name": "System Default", "value": "system_lang"}
|
||||
"callback": screen.restart_warning, "options": [
|
||||
{"name": "System Default", "value": "system_lang"}
|
||||
]}},
|
||||
{"move_speed": {"section": "main", "name": _("Move Speed (mm/s)"), "type": "scale", "value": "20",
|
||||
"range": [5,100], "step": 1
|
||||
}},
|
||||
{"move_speed": {
|
||||
"section": "main", "name": _("Move Speed (mm/s)"), "type": "scale", "value": "20",
|
||||
"range": [5, 100], "step": 1}},
|
||||
{"print_sort_dir": {"section": "main", "type": None, "value": "name_asc"}},
|
||||
{"print_estimate_method": {"section": "main", "name": _("Estimated Time Method"), "type": "dropdown",
|
||||
"value": "file","options":[
|
||||
{"print_estimate_method": {
|
||||
"section": "main", "name": _("Estimated Time Method"), "type": "dropdown",
|
||||
"value": "file", "options": [
|
||||
{"name": _("File Estimation (default)"), "value": "file"},
|
||||
{"name": _("Duration Only"), "value": "duration"},
|
||||
{"name": _("Filament Used"), "value": "filament"},
|
||||
{"name": _("Slicer"), "value": "slicer"}
|
||||
]}},
|
||||
{"screen_blanking": {"section": "main", "name": _("Screen Power Off Time"), "type": "dropdown",
|
||||
"value": "3600", "callback": screen.set_screenblanking_timeout, "options":[
|
||||
{"name": _("Off"), "value": "off"}
|
||||
]}},
|
||||
{"theme": {"section": "main", "name": _("Icon Theme"), "type": "dropdown",
|
||||
"value": "z-bolt", "callback": screen.restart_warning, "options":[
|
||||
{"name": _("Slicer"), "value": "slicer"}]}},
|
||||
{"screen_blanking": {
|
||||
"section": "main", "name": _("Screen Power Off Time"), "type": "dropdown",
|
||||
"value": "3600", "callback": screen.set_screenblanking_timeout, "options": [
|
||||
{"name": _("Off"), "value": "off"}]
|
||||
}},
|
||||
{"theme": {
|
||||
"section": "main", "name": _("Icon Theme"), "type": "dropdown",
|
||||
"value": "z-bolt", "callback": screen.restart_warning, "options": [
|
||||
{"name": _("Z-bolt (default)"), "value": "z-bolt"},
|
||||
{"name": _("Colorized"), "value": "colorized"}
|
||||
]}},
|
||||
{"name": _("Colorized"), "value": "colorized"}]}},
|
||||
{"24htime": {"section": "main", "name": _("24 Hour Time"), "type": "binary", "value": "True"}},
|
||||
{"side_macro_shortcut": {"section": "main", "name": _("Macro shortcut on sidebar"), "type": "binary",
|
||||
{"side_macro_shortcut": {
|
||||
"section": "main", "name": _("Macro shortcut on sidebar"), "type": "binary",
|
||||
"value": "True", "callback": screen.toggle_macro_shortcut}},
|
||||
{"font_size": {"section": "main", "name": _("Font Size"), "type": "dropdown",
|
||||
"value": "medium", "callback": screen.restart_warning, "options":[
|
||||
{"font_size": {
|
||||
"section": "main", "name": _("Font Size"), "type": "dropdown",
|
||||
"value": "medium", "callback": screen.restart_warning, "options": [
|
||||
{"name": _("Small"), "value": "small"},
|
||||
{"name": _("Medium (default)"), "value": "medium"},
|
||||
{"name": _("Large"), "value": "large"},
|
||||
]}},
|
||||
#{"": {"section": "main", "name": _(""), "type": ""}}
|
||||
{"name": _("Large"), "value": "large"}]}},
|
||||
# {"": {"section": "main", "name": _(""), "type": ""}}
|
||||
]
|
||||
|
||||
lang_path = os.path.join(os.getcwd(), 'ks_includes/locales')
|
||||
langs = [d for d in os.listdir(lang_path) if not os.path.isfile(os.path.join(lang_path,d))]
|
||||
langs = [d for d in os.listdir(lang_path) if not os.path.isfile(os.path.join(lang_path, d))]
|
||||
langs.sort()
|
||||
lang_opt = self.configurable_options[3]['language']['options']
|
||||
|
||||
for l in langs:
|
||||
lang_opt.append({"name": l, "value": l})
|
||||
for lang in langs:
|
||||
lang_opt.append({"name": lang, "value": lang})
|
||||
|
||||
index = self.configurable_options.index(
|
||||
[i for i in self.configurable_options if list(i)[0]=="screen_blanking"][0])
|
||||
[i for i in self.configurable_options if list(i)[0] == "screen_blanking"][0])
|
||||
for num in SCREEN_BLANKING_OPTIONS:
|
||||
hour = int(int(num)/3600)
|
||||
if hour > 0:
|
||||
name = str(hour) + " " + _n("hour","hours", hour)
|
||||
name = str(hour) + " " + _n("hour", "hours", hour)
|
||||
else:
|
||||
name = str(int(int(num)/60)) + " " + _("minutes")
|
||||
self.configurable_options[index]['screen_blanking']['options'].append({
|
||||
@@ -183,7 +185,7 @@ class KlipperScreenConfig:
|
||||
logging.info("Config Error: Directory %s does not exist" % parent_dir)
|
||||
return
|
||||
files = os.listdir(parent_dir)
|
||||
regex = "^%s$" % file.replace('*','.*')
|
||||
regex = "^%s$" % file.replace('*', '.*')
|
||||
for file in files:
|
||||
if re.match(regex, file):
|
||||
parse_files.append(os.path.join(parent_dir, file))
|
||||
@@ -211,17 +213,17 @@ class KlipperScreenConfig:
|
||||
return [None, None]
|
||||
with open(config_path) as file:
|
||||
for line in file:
|
||||
line = line.replace('\n','')
|
||||
line = line.replace('\n', '')
|
||||
if line == self.do_not_edit_line:
|
||||
found_saved = True
|
||||
saved_def = []
|
||||
continue
|
||||
if found_saved == False:
|
||||
user_def.append(line.replace('\n',''))
|
||||
if found_saved is False:
|
||||
user_def.append(line.replace('\n', ''))
|
||||
else:
|
||||
if line.startswith(self.do_not_edit_prefix):
|
||||
saved_def.append(line[(len(self.do_not_edit_prefix)+1):])
|
||||
return ["\n".join(user_def), None if saved_def == None else "\n".join(saved_def)]
|
||||
return ["\n".join(user_def), None if saved_def is None else "\n".join(saved_def)]
|
||||
|
||||
def get_config_file_location(self, file):
|
||||
logging.info("Passed config file: %s" % file)
|
||||
@@ -305,23 +307,23 @@ class KlipperScreenConfig:
|
||||
opt = item[name]
|
||||
curval = self.config[opt['section']].get(name)
|
||||
if curval != opt["value"] or (
|
||||
self.defined_config != None and opt['section'] in self.defined_config.sections() and
|
||||
self.defined_config[opt['section']].get(name,None) not in (None, curval)):
|
||||
self.defined_config is not None and opt['section'] in self.defined_config.sections() and
|
||||
self.defined_config[opt['section']].get(name, None) not in (None, curval)):
|
||||
if opt['section'] not in save_config.sections():
|
||||
save_config.add_section(opt['section'])
|
||||
save_config.set(opt['section'], name, str(curval))
|
||||
|
||||
macro_sections = [i for i in self.config.sections() if i.startswith("displayed_macros")]
|
||||
for macro_sec in macro_sections:
|
||||
for item in self.config.options(macro_sec):
|
||||
value = self.config[macro_sec].getboolean(item, fallback=True)
|
||||
if value == False or (self.defined_config != None and
|
||||
macro_sec in self.defined_config.sections() and
|
||||
self.defined_config[macro_sec].getboolean(item, fallback=True) == False and
|
||||
self.defined_config[macro_sec].getboolean(item, fallback=True) != value):
|
||||
if macro_sec not in save_config.sections():
|
||||
save_config.add_section(macro_sec)
|
||||
save_config.set(macro_sec, item, str(value))
|
||||
for item in self.config.options(macro_sec):
|
||||
value = self.config[macro_sec].getboolean(item, fallback=True)
|
||||
if value is False or (self.defined_config is not None and
|
||||
macro_sec in self.defined_config.sections() and
|
||||
self.defined_config[macro_sec].getboolean(item, fallback=True) is False and
|
||||
self.defined_config[macro_sec].getboolean(item, fallback=True) != value):
|
||||
if macro_sec not in save_config.sections():
|
||||
save_config.add_section(macro_sec)
|
||||
save_config.set(macro_sec, item, str(value))
|
||||
|
||||
save_output = self._build_config_string(save_config).split("\n")
|
||||
for i in range(len(save_output)):
|
||||
@@ -333,24 +335,25 @@ class KlipperScreenConfig:
|
||||
else:
|
||||
user_def, saved_def = self.separate_saved_config(self.config_path)
|
||||
|
||||
extra_lb = "\n" if saved_def != None else ""
|
||||
contents = "%s\n%s%s\n%s\n%s\n%s\n" % (user_def, self.do_not_edit_line, extra_lb,
|
||||
self.do_not_edit_prefix, "\n".join(save_output), self.do_not_edit_prefix)
|
||||
extra_lb = "\n" if saved_def is not None else ""
|
||||
contents = "%s\n%s%s\n%s\n%s\n%s\n" % (
|
||||
user_def, self.do_not_edit_line, extra_lb, self.do_not_edit_prefix, "\n".join(save_output),
|
||||
self.do_not_edit_prefix)
|
||||
|
||||
if self.config_path != self.default_config_path:
|
||||
path = self.config_path
|
||||
else:
|
||||
path = os.path.expanduser("~/")
|
||||
if os.path.exists(path+"klipper_config/"):
|
||||
path = path + "klipper_config/KlipperScreen.conf"
|
||||
path = path + "klipper_config/KlipperScreen.conf"
|
||||
else:
|
||||
path = path + "KlipperScreen.conf"
|
||||
path = path + "KlipperScreen.conf"
|
||||
|
||||
try:
|
||||
file = open(path, 'w')
|
||||
file.write(contents)
|
||||
file.close()
|
||||
except:
|
||||
except Exception:
|
||||
logging.error("Error writing configuration file in %s" % path)
|
||||
|
||||
def set(self, section, name, value):
|
||||
@@ -390,7 +393,7 @@ class KlipperScreenConfig:
|
||||
|
||||
try:
|
||||
item["params"] = json.loads(cfg.get("params", "{}"))
|
||||
except:
|
||||
except Exception:
|
||||
logging.debug("Unable to parse parameters for [%s]" % name)
|
||||
item["params"] = {}
|
||||
|
||||
|
@@ -34,7 +34,7 @@ class KlippyFiles():
|
||||
|
||||
def _callback(self, result, method, params):
|
||||
if method == "server.files.list":
|
||||
if "result" in result and isinstance(result['result'],list):
|
||||
if "result" in result and isinstance(result['result'], list):
|
||||
newfiles = []
|
||||
deletedfiles = self.filelist.copy()
|
||||
for item in result['result']:
|
||||
@@ -67,7 +67,7 @@ class KlippyFiles():
|
||||
self.run_callbacks(newfiles)
|
||||
elif method == "server.files.metadata":
|
||||
if "error" in result.keys():
|
||||
logging.debug("Error in getting metadata for %s. Retrying in 6 seconds" %(params['filename']))
|
||||
logging.debug("Error in getting metadata for %s. Retrying in 6 seconds" % (params['filename']))
|
||||
return
|
||||
|
||||
for x in result['result']:
|
||||
@@ -77,14 +77,14 @@ class KlippyFiles():
|
||||
|
||||
for thumbnail in self.files[params['filename']]['thumbnails']:
|
||||
thumbnail['local'] = False
|
||||
if self.gcodes_path != None:
|
||||
if self.gcodes_path is not None:
|
||||
fpath = os.path.join(self.gcodes_path, params['filename'])
|
||||
fdir = os.path.dirname(fpath)
|
||||
path = os.path.join(fdir, thumbnail['relative_path'])
|
||||
if os.access(path, os.R_OK):
|
||||
thumbnail['local'] = True
|
||||
thumbnail['path'] = path
|
||||
if thumbnail['local'] == False:
|
||||
if thumbnail['local'] is False:
|
||||
fdir = os.path.dirname(params['filename'])
|
||||
thumbnail['path'] = os.path.join(fdir, thumbnail['relative_path'])
|
||||
self.run_callbacks(mods=[params['filename']])
|
||||
@@ -107,13 +107,13 @@ class KlippyFiles():
|
||||
"modified": item['modified']
|
||||
}
|
||||
self.request_metadata(filename)
|
||||
if notify == True:
|
||||
if notify is True:
|
||||
self.run_callbacks(newfiles=[filename])
|
||||
|
||||
def add_file_callback(self, callback):
|
||||
try:
|
||||
self.callbacks.append(callback)
|
||||
except:
|
||||
except Exception:
|
||||
logging.debug("Callback not found: %s" % callback)
|
||||
|
||||
def process_update(self, data):
|
||||
@@ -150,7 +150,7 @@ class KlippyFiles():
|
||||
return None
|
||||
|
||||
thumb = self.files[filename]['thumbnails'][0]
|
||||
if thumb['local'] == False:
|
||||
if thumb['local'] is False:
|
||||
return ['http', thumb['path']]
|
||||
return ['file', thumb['path']]
|
||||
|
||||
@@ -174,10 +174,10 @@ class KlippyFiles():
|
||||
self.filelist.remove(filename)
|
||||
self.files.pop(filename, None)
|
||||
|
||||
if notify == True:
|
||||
if notify is True:
|
||||
self.run_callbacks(deletedfiles=[filename])
|
||||
|
||||
def ret_file_data (self, filename):
|
||||
def ret_file_data(self, filename):
|
||||
print("Getting file info for %s" % (filename))
|
||||
self._screen._ws.klippy.get_file_metadata(filename, self._callback)
|
||||
|
||||
@@ -195,6 +195,6 @@ class KlippyFiles():
|
||||
|
||||
def get_file_info(self, filename):
|
||||
if filename not in self.files:
|
||||
return {"path":None,"modified":0,"size":0}
|
||||
return {"path": None, "modified": 0, "size": 0}
|
||||
|
||||
return self.files[filename]
|
||||
|
@@ -46,15 +46,15 @@ try:
|
||||
libXext.XCloseDisplay(display)
|
||||
return state
|
||||
dpms_loaded = True
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def get_network_interfaces():
|
||||
stream = os.popen("ip addr | grep ^'[0-9]' | cut -d ' ' -f 2 | grep -o '[a-zA-Z0-9\.]*'")
|
||||
stream = os.popen("ip addr | grep ^'[0-9]' | cut -d ' ' -f 2 | grep -o '[a-zA-Z0-9\\.]*'")
|
||||
return [i for i in stream.read().strip().split('\n') if not i.startswith('lo')]
|
||||
|
||||
def get_wireless_interfaces():
|
||||
p = subprocess.Popen(["which","iwconfig"], stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen(["which", "iwconfig"], stdout=subprocess.PIPE)
|
||||
|
||||
while p.poll() is None:
|
||||
time.sleep(.1)
|
||||
@@ -64,12 +64,12 @@ def get_wireless_interfaces():
|
||||
try:
|
||||
p = subprocess.Popen(["iwconfig"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
result = p.stdout.read().decode('ascii').split('\n')
|
||||
except:
|
||||
except Exception:
|
||||
logging.info("Error with running iwconfig command")
|
||||
return None
|
||||
interfaces = []
|
||||
for line in result:
|
||||
match = re.search('^(\S+)\s+.*$', line)
|
||||
match = re.search('^(\\S+)\\s+.*$', line)
|
||||
if match:
|
||||
interfaces.append(match.group(1))
|
||||
|
||||
@@ -99,15 +99,17 @@ def patch_threading_excepthook():
|
||||
Inspired by https://bugs.python.org/issue1230540
|
||||
"""
|
||||
old_init = threading.Thread.__init__
|
||||
|
||||
def new_init(self, *args, **kwargs):
|
||||
old_init(self, *args, **kwargs)
|
||||
old_run = self.run
|
||||
|
||||
def run_with_excepthook(*args, **kwargs):
|
||||
try:
|
||||
old_run(*args, **kwargs)
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except:
|
||||
except Exception:
|
||||
sys.excepthook(*sys.exc_info(), thread_identifier=threading.get_ident())
|
||||
self.run = run_with_excepthook
|
||||
threading.Thread.__init__ = new_init
|
||||
@@ -160,7 +162,8 @@ def setup_logging(log_file, software_version):
|
||||
listener.start()
|
||||
|
||||
def logging_exception_handler(type, value, tb, thread_identifier=None):
|
||||
logging.exception("Uncaught exception %s: %s\nTraceback: %s" % (type, value, "\n".join(traceback.format_tb(tb))))
|
||||
logging.exception(
|
||||
"Uncaught exception %s: %s\nTraceback: %s" % (type, value, "\n".join(traceback.format_tb(tb))))
|
||||
sys.excepthook = logging_exception_handler
|
||||
logging.captureWarnings(True)
|
||||
|
||||
|
@@ -2,7 +2,7 @@ import gi
|
||||
import logging
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gdk, GLib
|
||||
from gi.repository import Gdk, GLib
|
||||
from ks_includes.KlippyGcodes import KlippyGcodes
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class Printer:
|
||||
r['min_x'] = float(r['min_x'])
|
||||
r['max_y'] = float(r['max_y'])
|
||||
r['min_y'] = float(r['min_y'])
|
||||
r['points'] = [[float(j.strip()) for j in i.split(",")] for i in r['points'].strip().split("\n")]
|
||||
r['points'] = [[float(j.strip()) for j in i.split(",")] for i in r['points'].strip().split("\n")]
|
||||
self.process_update(data)
|
||||
|
||||
logging.info("Klipper version: %s", self.klipper['version'])
|
||||
@@ -109,9 +109,9 @@ class Printer:
|
||||
return updates
|
||||
|
||||
def evaluate_state(self):
|
||||
wh_state = self.data['webhooks']['state'].lower() # possible values: startup, ready, shutdown, error
|
||||
idle_state = self.data['idle_timeout']['state'].lower() # possible values: Idle, printing, ready
|
||||
print_state = self.data['print_stats']['state'].lower() # possible values: complete, paused, printing, standby
|
||||
wh_state = self.data['webhooks']['state'].lower() # possible values: startup, ready, shutdown, error
|
||||
idle_state = self.data['idle_timeout']['state'].lower() # possible values: Idle, printing, ready
|
||||
print_state = self.data['print_stats']['state'].lower() # possible values: complete, paused, printing, standby
|
||||
|
||||
if wh_state == "ready":
|
||||
new_state = "ready"
|
||||
@@ -120,7 +120,7 @@ class Printer:
|
||||
elif idle_state == "printing":
|
||||
if print_state == "complete":
|
||||
new_state = "ready"
|
||||
elif print_state != "printing": # Not printing a file, toolhead moving
|
||||
elif print_state != "printing": # Not printing a file, toolhead moving
|
||||
new_state = "busy"
|
||||
else:
|
||||
new_state = "printing"
|
||||
@@ -141,7 +141,7 @@ class Printer:
|
||||
logging.debug("Changing state from '%s' to '%s'" % (self.state, state))
|
||||
prev_state = self.state
|
||||
self.state = state
|
||||
if self.state_callbacks[state] != None:
|
||||
if self.state_callbacks[state] is not None:
|
||||
logging.debug("Adding callback for state: %s" % state)
|
||||
Gdk.threads_add_idle(
|
||||
GLib.PRIORITY_HIGH_IDLE,
|
||||
@@ -213,7 +213,7 @@ class Printer:
|
||||
}
|
||||
}
|
||||
|
||||
sections = ["bed_mesh","bltouch","probe","quad_gantry_level","z_tilt"]
|
||||
sections = ["bed_mesh", "bltouch", "probe", "quad_gantry_level", "z_tilt"]
|
||||
for section in sections:
|
||||
if self.config_section_exists(section):
|
||||
data["printer"][section] = self.get_config_section(section).copy()
|
||||
@@ -231,10 +231,10 @@ class Printer:
|
||||
return
|
||||
return self.power_devices[device]['status']
|
||||
|
||||
def get_stat(self, stat, substat = None):
|
||||
def get_stat(self, stat, substat=None):
|
||||
if stat not in self.data:
|
||||
return {}
|
||||
if substat != None:
|
||||
if substat is not None:
|
||||
if substat in self.data[stat]:
|
||||
return self.data[stat][substat]
|
||||
return {}
|
||||
@@ -246,7 +246,7 @@ class Printer:
|
||||
def set_dev_temps(self, dev, temp, target=None):
|
||||
if dev in self.devices:
|
||||
self.devices[dev]['temperature'] = temp
|
||||
if target != None:
|
||||
if target is not None:
|
||||
self.devices[dev]['target'] = target
|
||||
|
||||
def get_dev_stats(self, dev):
|
||||
|
@@ -24,7 +24,7 @@ class ScreenPanel:
|
||||
self.layout = Gtk.Layout()
|
||||
self.layout.set_size(self._screen.width, self._screen.height)
|
||||
|
||||
action_bar_width = self._gtk.get_action_bar_width() if action_bar == True else 0
|
||||
action_bar_width = self._gtk.get_action_bar_width() if action_bar is True else 0
|
||||
self.content = Gtk.Box(spacing=0)
|
||||
|
||||
def initialize(self, panel_name):
|
||||
@@ -45,7 +45,7 @@ class ScreenPanel:
|
||||
return None
|
||||
|
||||
loc = self._files.get_thumbnail_location(filename)
|
||||
if loc == None:
|
||||
if loc is None:
|
||||
return None
|
||||
if loc[0] == "file":
|
||||
return self._gtk.PixbufFromFile(loc[1], None, width, height)
|
||||
@@ -60,23 +60,22 @@ class ScreenPanel:
|
||||
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
|
||||
|
||||
def menu_item_clicked(self, widget, panel, item):
|
||||
print("### Creating panel "+ item['panel'] + " : %s %s" % (panel, item))
|
||||
print("### Creating panel " + item['panel'] + " : %s %s" % (panel, item))
|
||||
if "items" in item:
|
||||
self._screen.show_panel(self._screen._cur_panels[-1] + '_' + panel, item['panel'], item['name'],
|
||||
1, False, items=item['items'])
|
||||
1, False, items=item['items'])
|
||||
return
|
||||
self._screen.show_panel(self._screen._cur_panels[-1] + '_' + panel, item['panel'], item['name'],
|
||||
1, False)
|
||||
1, False)
|
||||
|
||||
def menu_return(self, widget, home=False):
|
||||
if home == False:
|
||||
if home is False:
|
||||
self._screen._menu_go_back()
|
||||
return
|
||||
self._screen._menu_go_home()
|
||||
|
||||
def set_title(self, title):
|
||||
self.title = title
|
||||
#self.title.set_label(title)
|
||||
|
||||
def show_all(self):
|
||||
self._screen.show_all()
|
||||
@@ -87,7 +86,7 @@ class ScreenPanel:
|
||||
|
||||
def update_temp(self, dev, temp, target, name=None):
|
||||
if dev in self.labels:
|
||||
if name == None:
|
||||
if name is None:
|
||||
self.labels[dev].set_label(self._gtk.formatTemperatureString(temp, target))
|
||||
else:
|
||||
self.labels[dev].set_label("%s\n%s" % (name, self._gtk.formatTemperatureString(temp, target)))
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import os, signal
|
||||
import os
|
||||
import signal
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
@@ -57,7 +58,7 @@ class WifiManager():
|
||||
self.soc = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
self.soc.bind(KS_SOCKET_FILE)
|
||||
self.soc.connect("/var/run/wpa_supplicant/%s" % interface)
|
||||
except:
|
||||
except Exception:
|
||||
logging.info("Error connecting to wifi socket: %s" % interface)
|
||||
return
|
||||
|
||||
@@ -77,15 +78,15 @@ class WifiManager():
|
||||
def add_network(self, ssid, psk):
|
||||
for id in list(self.supplicant_networks):
|
||||
if self.supplicant_networks[id]['ssid'] == ssid:
|
||||
#Modify network
|
||||
# Modify network
|
||||
return
|
||||
|
||||
# TODO: Add wpa_cli error checking
|
||||
network_id = self.wpa_cli("ADD_NETWORK")
|
||||
commands = [
|
||||
'ENABLE_NETWORK %s' % (network_id),
|
||||
'SET_NETWORK %s ssid "%s"' % (network_id, ssid.replace('"','\"')),
|
||||
'SET_NETWORK %s psk "%s"' % (network_id, psk.replace('"','\"'))
|
||||
'SET_NETWORK %s ssid "%s"' % (network_id, ssid.replace('"', '\"')),
|
||||
'SET_NETWORK %s psk "%s"' % (network_id, psk.replace('"', '\"'))
|
||||
]
|
||||
self.wpa_cli_batch(commands)
|
||||
|
||||
@@ -96,7 +97,7 @@ class WifiManager():
|
||||
id = i
|
||||
break
|
||||
|
||||
if id == None:
|
||||
if id is None:
|
||||
logging.info("Error adding network")
|
||||
return False
|
||||
|
||||
@@ -118,7 +119,7 @@ class WifiManager():
|
||||
id = netid
|
||||
break
|
||||
|
||||
if id == None:
|
||||
if id is None:
|
||||
logging.info("Wifi network is not defined in wpa_supplicant")
|
||||
return False
|
||||
|
||||
@@ -134,7 +135,7 @@ class WifiManager():
|
||||
id = i
|
||||
break
|
||||
|
||||
if id == None:
|
||||
if id is None:
|
||||
logging.debug("Unable to find network in wpa_supplicant")
|
||||
return
|
||||
self.wpa_cli("REMOVE_NETWORK %s" % id)
|
||||
@@ -243,7 +244,7 @@ class WifiManager():
|
||||
|
||||
aps = []
|
||||
for res in results:
|
||||
match = re.match("^([a-f0-9:]+)\s+([0-9]+)\s+([\-0-9]+)\s+(\S+)\s+(.+)?", res)
|
||||
match = re.match("^([a-f0-9:]+)\\s+([0-9]+)\\s+([\\-0-9]+)\\s+(\\S+)\\s+(.+)?", res)
|
||||
if match:
|
||||
net = {
|
||||
"mac": match.group(1),
|
||||
@@ -286,10 +287,10 @@ class WifiManager():
|
||||
cb, new_networks, deleted_networks)
|
||||
|
||||
def wpa_cli(self, command, wait=True):
|
||||
if wait == False:
|
||||
if wait is False:
|
||||
self.wpa_thread.skip_command()
|
||||
self.soc.send(command.encode())
|
||||
if wait == True:
|
||||
if wait is True:
|
||||
resp = self.queue.get()
|
||||
return resp
|
||||
|
||||
@@ -299,7 +300,7 @@ class WifiManager():
|
||||
|
||||
|
||||
class WpaSocket(Thread):
|
||||
def __init__ (self, wm, queue, callback):
|
||||
def __init__(self, wm, queue, callback):
|
||||
super().__init__()
|
||||
self.queue = queue
|
||||
self.callback = callback
|
||||
@@ -311,10 +312,10 @@ class WpaSocket(Thread):
|
||||
def run(self):
|
||||
event = threading.Event()
|
||||
logging.debug("Setting up wifi event loop")
|
||||
while self._stop_loop == False:
|
||||
while self._stop_loop is False:
|
||||
try:
|
||||
msg = self.soc.recv(4096).decode().strip()
|
||||
except:
|
||||
except Exception:
|
||||
# TODO: Socket error
|
||||
continue
|
||||
if msg.startswith("<"):
|
||||
@@ -322,7 +323,7 @@ class WpaSocket(Thread):
|
||||
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.wm.scan_results)
|
||||
elif "CTRL-EVENT-DISCONNECTED" in msg:
|
||||
self.callback("connecting_status", msg)
|
||||
match = re.match('<3>CTRL-EVENT-DISCONNECTED bssid=(\S+) reason=3 locally_generated=1', msg)
|
||||
match = re.match('<3>CTRL-EVENT-DISCONNECTED bssid=(\\S+) reason=3 locally_generated=1', msg)
|
||||
if match:
|
||||
for net in self.wm.networks:
|
||||
if self.wm.networks[net]['mac'] == match.group(1):
|
||||
@@ -353,117 +354,117 @@ class WifiChannels:
|
||||
@staticmethod
|
||||
def lookup(freq):
|
||||
if freq == "2412":
|
||||
return ("2.4","1")
|
||||
return ("2.4", "1")
|
||||
if freq == "2417":
|
||||
return ("2.4","2")
|
||||
return ("2.4", "2")
|
||||
if freq == "2422":
|
||||
return ("2.4","3")
|
||||
return ("2.4", "3")
|
||||
if freq == "2427":
|
||||
return ("2.4","4")
|
||||
return ("2.4", "4")
|
||||
if freq == "2432":
|
||||
return ("2.4","5")
|
||||
return ("2.4", "5")
|
||||
if freq == "2437":
|
||||
return ("2.4","6")
|
||||
return ("2.4", "6")
|
||||
if freq == "2442":
|
||||
return ("2.4","7")
|
||||
return ("2.4", "7")
|
||||
if freq == "2447":
|
||||
return ("2.4","8")
|
||||
return ("2.4", "8")
|
||||
if freq == "2452":
|
||||
return ("2.4","9")
|
||||
return ("2.4", "9")
|
||||
if freq == "2457":
|
||||
return ("2.4","10")
|
||||
return ("2.4", "10")
|
||||
if freq == "2462":
|
||||
return ("2.4","11")
|
||||
return ("2.4", "11")
|
||||
if freq == "2467":
|
||||
return ("2.4","12")
|
||||
return ("2.4", "12")
|
||||
if freq == "2472":
|
||||
return ("2.4","13")
|
||||
return ("2.4", "13")
|
||||
if freq == "2484":
|
||||
return ("2.4","14")
|
||||
return ("2.4", "14")
|
||||
if freq == "5035":
|
||||
return ("5","7")
|
||||
return ("5", "7")
|
||||
if freq == "5040":
|
||||
return ("5","8")
|
||||
return ("5", "8")
|
||||
if freq == "5045":
|
||||
return ("5","9")
|
||||
return ("5", "9")
|
||||
if freq == "5055":
|
||||
return ("5","11")
|
||||
return ("5", "11")
|
||||
if freq == "5060":
|
||||
return ("5","12")
|
||||
return ("5", "12")
|
||||
if freq == "5080":
|
||||
return ("5","16")
|
||||
return ("5", "16")
|
||||
if freq == "5170":
|
||||
return ("5","34")
|
||||
return ("5", "34")
|
||||
if freq == "5180":
|
||||
return ("5","36")
|
||||
return ("5", "36")
|
||||
if freq == "5190":
|
||||
return ("5","38")
|
||||
return ("5", "38")
|
||||
if freq == "5200":
|
||||
return ("5","40")
|
||||
return ("5", "40")
|
||||
if freq == "5210":
|
||||
return ("5","42")
|
||||
return ("5", "42")
|
||||
if freq == "5220":
|
||||
return ("5","44")
|
||||
return ("5", "44")
|
||||
if freq == "5230":
|
||||
return ("5","46")
|
||||
return ("5", "46")
|
||||
if freq == "5240":
|
||||
return ("5","48")
|
||||
return ("5", "48")
|
||||
if freq == "5260":
|
||||
return ("5","52")
|
||||
return ("5", "52")
|
||||
if freq == "5280":
|
||||
return ("5","56")
|
||||
return ("5", "56")
|
||||
if freq == "5300":
|
||||
return ("5","60")
|
||||
return ("5", "60")
|
||||
if freq == "5320":
|
||||
return ("5","64")
|
||||
return ("5", "64")
|
||||
if freq == "5500":
|
||||
return ("5","100")
|
||||
return ("5", "100")
|
||||
if freq == "5520":
|
||||
return ("5","104")
|
||||
return ("5", "104")
|
||||
if freq == "5540":
|
||||
return ("5","108")
|
||||
return ("5", "108")
|
||||
if freq == "5560":
|
||||
return ("5","112")
|
||||
return ("5", "112")
|
||||
if freq == "5580":
|
||||
return ("5","116")
|
||||
return ("5", "116")
|
||||
if freq == "5600":
|
||||
return ("5","120")
|
||||
return ("5", "120")
|
||||
if freq == "5620":
|
||||
return ("5","124")
|
||||
return ("5", "124")
|
||||
if freq == "5640":
|
||||
return ("5","128")
|
||||
return ("5", "128")
|
||||
if freq == "5660":
|
||||
return ("5","132")
|
||||
return ("5", "132")
|
||||
if freq == "5680":
|
||||
return ("5","136")
|
||||
return ("5", "136")
|
||||
if freq == "5700":
|
||||
return ("5","140")
|
||||
return ("5", "140")
|
||||
if freq == "5720":
|
||||
return ("5","144")
|
||||
return ("5", "144")
|
||||
if freq == "5745":
|
||||
return ("5","149")
|
||||
return ("5", "149")
|
||||
if freq == "5765":
|
||||
return ("5","153")
|
||||
return ("5", "153")
|
||||
if freq == "5785":
|
||||
return ("5","157")
|
||||
return ("5", "157")
|
||||
if freq == "5805":
|
||||
return ("5","161")
|
||||
return ("5", "161")
|
||||
if freq == "5825":
|
||||
return ("5","165")
|
||||
return ("5", "165")
|
||||
if freq == "4915":
|
||||
return ("5","183")
|
||||
return ("5", "183")
|
||||
if freq == "4920":
|
||||
return ("5","184")
|
||||
return ("5", "184")
|
||||
if freq == "4925":
|
||||
return ("5","185")
|
||||
return ("5", "185")
|
||||
if freq == "4935":
|
||||
return ("5","187")
|
||||
return ("5", "187")
|
||||
if freq == "4940":
|
||||
return ("5","188")
|
||||
return ("5", "188")
|
||||
if freq == "4945":
|
||||
return ("5","189")
|
||||
return ("5", "189")
|
||||
if freq == "4960":
|
||||
return ("5","192")
|
||||
return ("5", "192")
|
||||
if freq == "4980":
|
||||
return ("5","196")
|
||||
return None;
|
||||
return ("5", "196")
|
||||
return None
|
||||
|
Reference in New Issue
Block a user