mirror of
https://github.com/ralsina/xrandroll.git
synced 2024-11-21 18:42:22 +00:00
Parse a little more
This commit is contained in:
parent
91353d5951
commit
002c12a2c0
@ -43,8 +43,8 @@ class Mode:
|
|||||||
self.data = data
|
self.data = data
|
||||||
self.header = data[0]
|
self.header = data[0]
|
||||||
self.name = parse.search("({mode_name})", self.header)["mode_name"]
|
self.name = parse.search("({mode_name})", self.header)["mode_name"]
|
||||||
self.res_x = parse.search("h: width {res_x:d}", data[1])["res_x"]
|
self.res_x = parse.search("h: width{:s}{res_x:d}", data[1])["res_x"]
|
||||||
self.res_y = parse.search("v: height {res_y:d}", data[2])["res_y"]
|
self.res_y = parse.search("v: height{:s}{res_y:d}", data[2])["res_y"]
|
||||||
self.refresh = parse.search("{refresh:f}Hz", data[2])["refresh"]
|
self.refresh = parse.search("{refresh:f}Hz", data[2])["refresh"]
|
||||||
self.preferred = "+preferred" in self.header
|
self.preferred = "+preferred" in self.header
|
||||||
self.current = "*current" in self.header
|
self.current = "*current" in self.header
|
||||||
@ -64,6 +64,8 @@ class Monitor:
|
|||||||
|
|
||||||
self.header = data.pop(0)
|
self.header = data.pop(0)
|
||||||
self.pos_x, self.pos_y = parse.search("+{:d}+{:d}", self.header)
|
self.pos_x, self.pos_y = parse.search("+{:d}+{:d}", self.header)
|
||||||
|
self.output = parse.search("{}{:s}", self.header)[0]
|
||||||
|
|
||||||
modes_data = _split_by_lines_matching("^ [^ ]", data)
|
modes_data = _split_by_lines_matching("^ [^ ]", data)
|
||||||
fields_data = _split_by_lines_matching(r"^\t[^ ]", modes_data.pop(0))
|
fields_data = _split_by_lines_matching(r"^\t[^ ]", modes_data.pop(0))
|
||||||
|
|
||||||
@ -75,6 +77,9 @@ class Monitor:
|
|||||||
for f in (Field(d) for d in fields_data):
|
for f in (Field(d) for d in fields_data):
|
||||||
self.fields[f.name] = f
|
self.fields[f.name] = f
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"Monitor: {self.output}"
|
||||||
|
|
||||||
def get_current_mode_name(self):
|
def get_current_mode_name(self):
|
||||||
for k, v in self.modes.values():
|
for k, v in self.modes.values():
|
||||||
if v.current:
|
if v.current:
|
||||||
|
@ -9,16 +9,17 @@ def read_data():
|
|||||||
data = subprocess.check_output(
|
data = subprocess.check_output(
|
||||||
["xrandr", "--verbose"], encoding="utf-8"
|
["xrandr", "--verbose"], encoding="utf-8"
|
||||||
).splitlines()
|
).splitlines()
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def parse_data(data):
|
||||||
# Going to pretend there can only be one screen because life is short.
|
# Going to pretend there can only be one screen because life is short.
|
||||||
screen = _split_by_lines_matching("^Screen ", data)[0]
|
screen = _split_by_lines_matching("^Screen ", data)[0]
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for monitor_data in _split_by_lines_matching(r"^[^ \t].*", screen[1:]):
|
for monitor_data in _split_by_lines_matching(r"^[^ \t].*", screen[1:]):
|
||||||
result.append(Monitor(monitor_data))
|
result.append(Monitor(monitor_data))
|
||||||
|
return result
|
||||||
|
|
||||||
def parse_data(data):
|
|
||||||
print(data)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user