165 lines
3.1 KiB
Python
165 lines
3.1 KiB
Python
|
|
window = None
|
||
|
|
|
||
|
|
class project:
|
||
|
|
list_id = []
|
||
|
|
def __init__(self, id):
|
||
|
|
self.id = id
|
||
|
|
|
||
|
|
def __enter__(self):
|
||
|
|
project.list_id.append(self.id)
|
||
|
|
return self
|
||
|
|
|
||
|
|
def __exit__(self, *args):
|
||
|
|
project.list_id.pop()
|
||
|
|
|
||
|
|
class sheet:
|
||
|
|
list_widget = []
|
||
|
|
def __init__(self, sheet_id):
|
||
|
|
widget = window.widget_display.map_table[sheet_id]
|
||
|
|
self.id = sheet_id
|
||
|
|
self.widget = widget
|
||
|
|
|
||
|
|
def __enter__(self):
|
||
|
|
sheet.list_widget.append(self.widget)
|
||
|
|
return self
|
||
|
|
|
||
|
|
def __exit__(self, *args):
|
||
|
|
sheet.list_widget.pop()
|
||
|
|
|
||
|
|
def at(self, *args):
|
||
|
|
c = cell(*args, widget = self.widget)
|
||
|
|
return c
|
||
|
|
|
||
|
|
def __getitem__(self, index):
|
||
|
|
if type(index) is tuple:
|
||
|
|
return self.at(*index)
|
||
|
|
else:
|
||
|
|
return self.at(index)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def row(self):
|
||
|
|
return self.widget.row
|
||
|
|
|
||
|
|
@row.setter
|
||
|
|
def row(self, row):
|
||
|
|
self.widget.row = row
|
||
|
|
|
||
|
|
@property
|
||
|
|
def col(self):
|
||
|
|
return self.widget.col
|
||
|
|
|
||
|
|
@col.setter
|
||
|
|
def col(self, col):
|
||
|
|
self.widget.col = col
|
||
|
|
|
||
|
|
def clear(self):
|
||
|
|
self.widget.clear()
|
||
|
|
|
||
|
|
def clear_content(self):
|
||
|
|
self.widget.clearContents()
|
||
|
|
|
||
|
|
def initial(self):
|
||
|
|
self.widget.initial()
|
||
|
|
|
||
|
|
def reset_content(self):
|
||
|
|
self.widget.reset_content()
|
||
|
|
|
||
|
|
def fit_content(self):
|
||
|
|
self.widget.fit_content()
|
||
|
|
|
||
|
|
def load_data(self, *arg, **kwarg):
|
||
|
|
self.widget.load_data(*arg, **kwarg)
|
||
|
|
|
||
|
|
def dump_data(self, *arg, **kwarg):
|
||
|
|
return self.widget.dump_data(*arg, **kwarg)
|
||
|
|
|
||
|
|
def load_str(self, *arg, **kwarg):
|
||
|
|
self.widget.load_str(*arg, **kwarg)
|
||
|
|
|
||
|
|
def dump_str(self, *arg, **kwarg):
|
||
|
|
return self.widget.dump_str(*arg, **kwarg)
|
||
|
|
|
||
|
|
def load_file(self, *arg, **kwarg):
|
||
|
|
self.widget.load_file(*arg, **kwarg)
|
||
|
|
|
||
|
|
def dump_file(self, *arg, **kwarg):
|
||
|
|
self.widget.dump_file(*arg, **kwarg)
|
||
|
|
|
||
|
|
class cell:
|
||
|
|
def __init__(self, *arg, widget = None):
|
||
|
|
if len(arg) == 1:
|
||
|
|
pos = arg[0]
|
||
|
|
pos = pos.lower()
|
||
|
|
row = None
|
||
|
|
col = None
|
||
|
|
match = re.match(r"([a-z]+)(\d+)", pos)
|
||
|
|
if not match:
|
||
|
|
raise RuntimeError(f"unrecognized pos: \"{pos}\"")
|
||
|
|
row = match.group(2)
|
||
|
|
cl = match.group(1)
|
||
|
|
row = int(row) - 1
|
||
|
|
col = 0
|
||
|
|
for chr in cl:
|
||
|
|
col *= 26
|
||
|
|
col += ord(chr) - ord("a")
|
||
|
|
|
||
|
|
elif len(arg) == 2:
|
||
|
|
row = arg[0]
|
||
|
|
col = arg[1]
|
||
|
|
else:
|
||
|
|
raise RuntimeError("The number of params should not be more than 2")
|
||
|
|
|
||
|
|
self.item = None
|
||
|
|
if widget is None and sheet.list_widget:
|
||
|
|
widget = sheet.list_widget[-1]
|
||
|
|
if widget:
|
||
|
|
self.item = widget.at(row, col)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def text(self):
|
||
|
|
return self.item.text
|
||
|
|
|
||
|
|
@text.setter
|
||
|
|
def text(self, s):
|
||
|
|
self.item.text = s
|
||
|
|
|
||
|
|
@property
|
||
|
|
def value(self):
|
||
|
|
return self.item.value
|
||
|
|
|
||
|
|
@value.setter
|
||
|
|
def value(self, v):
|
||
|
|
self.item.value = v
|
||
|
|
|
||
|
|
def empty(self):
|
||
|
|
return self.item.empty()
|
||
|
|
|
||
|
|
def clear(self):
|
||
|
|
self.item.value = None
|
||
|
|
|
||
|
|
class graph:
|
||
|
|
list_widget = []
|
||
|
|
def __init__(self, graph_id):
|
||
|
|
widget = window.widget_display.map_graph[graph_id]
|
||
|
|
self.id = graph_id
|
||
|
|
self.widget = widget
|
||
|
|
|
||
|
|
def __enter__(self):
|
||
|
|
graph.list_widget.append(self.widget)
|
||
|
|
return self
|
||
|
|
|
||
|
|
def __exit__(self, *args):
|
||
|
|
graph.list_widget.pop()
|
||
|
|
|
||
|
|
def plot(self, *arg, **kwarg):
|
||
|
|
self.widget.plot(*arg, **kwarg)
|
||
|
|
|
||
|
|
def plot(*arg, **kwarg):
|
||
|
|
widget = graph.list_widget[-1]
|
||
|
|
widget.plot(*arg, **kwarg)
|
||
|
|
|
||
|
|
def param(id):
|
||
|
|
map_input = window.widget_interact.widget_grid.map_input
|
||
|
|
result = map_input.get(id)
|
||
|
|
return result
|