Pamhyr2: Minor change and method documentation.

setup.py
Pierre-Antoine Rouby 2024-04-22 16:29:23 +02:00
parent 145c301eed
commit acbd3537c0
4 changed files with 78 additions and 29 deletions

View File

@ -70,6 +70,7 @@ class SQLModel(SQL):
return True return True
def _create(self): def _create(self):
raise NotImplementedMethodeError(self, self._create) raise NotImplementedMethodeError(self, self._create)
def _update_submodel(self, version): def _update_submodel(self, version):

View File

@ -56,7 +56,7 @@ class PamhyrModelDict(SQLSubModel):
def __len__(self): def __len__(self):
return len(self._dict) return len(self._dict)
def is_defined(self, key): def __contains__(self, key):
return key in self._dict return key in self._dict
def set(self, key, new): def set(self, key, new):

View File

@ -62,6 +62,14 @@ class PamhyrModelList(SQLSubModel):
@property @property
def lst(self): def lst(self):
"""Return the PamhyrList as a Python list
Return the PamhyrList as a Python list. This list is the
current list used in the PamhyrList object. **If you need to
modify it, please make a copy.**
Returns: The Python list
"""
return self._lst return self._lst
def __len__(self): def __len__(self):
@ -70,11 +78,11 @@ class PamhyrModelList(SQLSubModel):
def index(self, el): def index(self, el):
return self._lst.index(el) return self._lst.index(el)
def get(self, row): def get(self, index):
return self._lst[row] return self._lst[index]
def set(self, row, new): def set(self, index, new):
self._lst[row] = new self._lst[index] = new
if self._status is not None: if self._status is not None:
self._status.modified() self._status.modified()
@ -96,6 +104,14 @@ class PamhyrModelList(SQLSubModel):
self._status.modified() self._status.modified()
def delete(self, lst): def delete(self, lst):
"""Delete a list of elements
Args:
lst: The list of elements
Returns:
Nothing
"""
for el in lst: for el in lst:
self._lst.remove(el) self._lst.remove(el)
@ -103,6 +119,14 @@ class PamhyrModelList(SQLSubModel):
self._status.modified() self._status.modified()
def delete_i(self, indexes): def delete_i(self, indexes):
"""Delete elements from list of indexes
Args:
indexes: The elements indexes
Returns:
Nothing
"""
lst = list( lst = list(
map( map(
lambda x: x[1], lambda x: x[1],
@ -178,16 +202,32 @@ class PamhyrModelListWithTab(SQLSubModel):
################ ################
def len(self, lst): def len(self, lst):
"""Size of tab list
Args:
lst: The tab name
Returns:
The size of the tab list
"""
return len(self._tabs[lst]) return len(self._tabs[lst])
def get_tab(self, lst): def get_tab(self, lst):
"""Get tab list (copy) from name
Args:
lst: The tab name
Returns:
Nothing
"""
return self._tabs[lst].copy() return self._tabs[lst].copy()
def get(self, lst, row): def get(self, lst, index):
return self._tabs[lst][row] return self._tabs[lst][index]
def set(self, lst, row, new): def set(self, lst, index, new):
self._tabs[lst][row] = new self._tabs[lst][index] = new
self._status.modified() self._status.modified()
def new(self, lst, index): def new(self, lst, index):
@ -203,15 +243,43 @@ class PamhyrModelListWithTab(SQLSubModel):
raise NotImplementedMethodeError(self, self.new) raise NotImplementedMethodeError(self, self.new)
def insert(self, lst, index, new): def insert(self, lst, index, new):
"""Insert element in tab
Args:
lst: The tab name
index: The index of new element
new: The new elements
Returns:
Nothing
"""
self._tabs[lst].insert(index, new) self._tabs[lst].insert(index, new)
self._status.modified() self._status.modified()
def delete(self, lst, els): def delete(self, lst, els):
"""Delete elements from specific tab
Args:
lst: The tab name
els: The elements list
Returns:
Nothing
"""
for el in els: for el in els:
self._tabs[lst].remove(el) self._tabs[lst].remove(el)
self._status.modified() self._status.modified()
def delete_i(self, lst, indexes): def delete_i(self, lst, indexes):
"""Delete elements from specific tab
Args:
lst: The tab name
indexes: The elements indexes
Returns:
Nothing
"""
els = list( els = list(
map( map(
lambda x: x[1], lambda x: x[1],

View File

@ -77,30 +77,10 @@ class ReplWindow(PamhyrWindow):
layout.insertWidget(0, self._editor) layout.insertWidget(0, self._editor)
def setup_connections(self): def setup_connections(self):
self._hup_sc = QShortcut(QKeySequence("ctrl+Up"), self)
self._hdown_sc = QShortcut(QKeySequence("ctrl+Down"), self)
self._hup_sc.activated.connect(self.history_up)
self._hdown_sc.activated.connect(self.history_down)
self.find(QPushButton, "pushButton").clicked.connect(self.eval_python) self.find(QPushButton, "pushButton").clicked.connect(self.eval_python)
def history_up(self):
if self._history_ind < len(self._history):
self._history_ind += 1
self._editor.setText(self._history[-self._history_ind])
def history_down(self):
if self._history_ind > 0:
self._history_ind -= 1
self._editor.setText(self._history[-self._history_ind])
else:
self._editor.setText("")
def eval_python(self): def eval_python(self):
code = self._editor.text() code = self._editor.text()
self._history.append(code)
self._editor.setText("")
self._history_ind = 0
# Code to rich_code # Code to rich_code
rich_code = code.strip().split("\n") rich_code = code.strip().split("\n")