Browse Source

Improved Docs

pull/272/head
Eugenio Parodi 1 year ago
parent
commit
a64caec778
  1. 24
      TermTk/TTkAbstract/abstracttablemodel.py
  2. 6
      TermTk/TTkCore/canvas.py
  3. 7
      TermTk/TTkCore/color.py
  4. 146
      TermTk/TTkCore/constant.py
  5. 1
      TermTk/TTkCore/shortcut.py
  6. 2
      TermTk/TTkCore/string.py
  7. 3
      docs/MDNotes/Games.md
  8. 6
      docs/source/conf.py

24
TermTk/TTkAbstract/abstracttablemodel.py

@ -97,6 +97,11 @@ class TTkAbstractTableModel():
Returns the data stored for the item referred to by the row/column.
Note: If you do not have a value to return, return *None* instead of returning 0.
:param row: the row position od the data
:type row: int
:param col: the column position of the data
:type col: int
:return: object
'''
@ -110,6 +115,13 @@ class TTkAbstractTableModel():
The base class implementation returns false. This function and :meth:`data` must be reimplemented for editable models.
:param row: the row position od the data
:type row: int
:param col: the column position of the data
:type col: int
:param data: the data to be set in the (row,col) position of the table
:type data: object
:return: bool
'''
return False
@ -136,7 +148,7 @@ class TTkAbstractTableModel():
Similarly, for vertical headers, the section number corresponds to the row number.
:param pos: the position (col or row) of the header
:type pos: tuple(int,int)
:type pos: int
:param orientation: the orienttin of the header to be retrieved
:type orientation: :class:`~TermTk.TTkCore.constant.TTkConstant.Direction`
@ -148,5 +160,13 @@ class TTkAbstractTableModel():
return TTkString(str(pos))
return TTkString()
def sort(self, col:int, order) -> None:
def sort(self, column:int, order:TTkK.SortOrder) -> None:
'''
Sorts the model by column in the given order.
:param column: The column index to be sorted, if -1 is provided the original unsorted order is used.
:type column: int
:param order: the sorting order
:type order: :class:`~TermTk.TTkCore.constant.TTkConstant.SortOrder`
'''
pass

6
TermTk/TTkCore/canvas.py

@ -674,6 +674,7 @@ class TTkCanvas:
def toAnsi(self):
# TTkLog.debug("pushToTerminal")
ret = ""
rstColor = str(TTkColor.RST)
lastcolor = TTkColor.RST
for y in range(0, self._height):
ansi = str(lastcolor)
@ -684,7 +685,10 @@ class TTkCanvas:
ansi += str(color-lastcolor)
lastcolor = color
ansi+=ch
ret += ansi + '\n'
if lastcolor != TTkColor.RST:
ret += ansi + rstColor + '\n'
else:
ret += ansi + '\n'
return ret
def pushToTerminal(self, x, y, w, h):

7
TermTk/TTkCore/color.py

@ -491,6 +491,8 @@ class TTkColor(_TTkColor):
:type color: str
:param str modifier: (experimental) the color modifier to be used to improve the **kinkiness**
:type modifier: TTkColorModifier, optional
:return: :class:`TTkColor`
'''
mod = kwargs.get('modifier', None )
link = kwargs.get('link', '' )
@ -516,6 +518,8 @@ class TTkColor(_TTkColor):
:type color: str
:param str modifier: (experimental) the color modifier to be used to improve the **kinkiness**
:type modifier: TTkColorModifier, optional
:return: :class:`TTkColor`
'''
mod = kwargs.get('modifier', None )
link = kwargs.get('link', '' )
@ -525,6 +529,7 @@ class TTkColor(_TTkColor):
color = kwargs.get('color', "" )
return TTkColor(bg=TTkColor.hexToRGB(color), colorMod=mod, link=link)
@staticmethod
def fgbg(fg:str='', bg:str='', link:str='', modifier:_TTkColorModifier=None):
''' Helper to generate a Background color
@ -542,6 +547,8 @@ class TTkColor(_TTkColor):
:type bg: str
:param str modifier: (experimental) the color modifier to be used to improve the **kinkiness**
:type modifier: TTkColorModifier, optional
:return: :class:`TTkColor`
'''
return TTkColor(fg=TTkColor.hexToRGB(fg), bg=TTkColor.hexToRGB(bg), colorMod=modifier, link=link)

146
TermTk/TTkCore/constant.py

@ -78,7 +78,12 @@ class TTkConstant:
TIME_EVENT = 0x10
class Direction(int):
'''This class type is used to describe the direction'''
'''This class type is used to describe the direction
.. autosummary::
HORIZONTAL
VERTICAL
'''
HORIZONTAL = 0x01 + 0x02
'''Horizontal direction'''
VERTICAL = 0x04 + 0x08
@ -105,8 +110,11 @@ class TTkConstant:
Checked
'''
Unchecked = 0x00
'''The item is unchecked.'''
PartiallyChecked = 0x01
'''The item is partially checked. Items in hierarchical models may be partially checked if some, but not all, of their children are checked.'''
Checked = 0x02
'''The item is checked.'''
Unchecked = CheckState.Unchecked
PartiallyChecked = CheckState.PartiallyChecked
@ -114,6 +122,11 @@ class TTkConstant:
class InsertPolicy(int):
'''Specifies what the :class:`~TermTk.TTkWidgets.combobox.TTkComboBox` should do when a new string is entered by the user.
.. autosummary::
NoInsert
InsertAtTop
InsertAtBottom
'''
NoInsert = 0x00
'''The string will not be inserted into the combobox.'''
@ -131,7 +144,14 @@ class TTkConstant:
# '''The string is inserted in the alphabetic order in the combobox.'''
class DragDropMode(int):
'''Specifies the Drag and Drop mode allowed by this widget'''
'''Specifies the Drag and Drop mode allowed by this widget
.. autosummary::
NoDragDrop
AllowDrag
AllowDrop
AllowDragDrop
'''
NoDragDrop = 0x00
'''No Drag and Drop is allowed'''
AllowDrag = 0x01
@ -155,7 +175,12 @@ class TTkConstant:
DontShowIndicatorWhenChildless = ChildIndicatorPolicy.DontShowIndicatorWhenChildless
class SortOrder():
'''This enum describes how the items in a widget are sorted.'''
'''This enum describes how the items in a widget are sorted.
.. autosummary::
AscendingOrder
DescendingOrder
'''
AscendingOrder = 0x00
'''The items are sorted ascending e.g. starts with 'AAA' ends with 'ZZZ' in Latin-1 locales'''
DescendingOrder = 0x01
@ -177,6 +202,15 @@ class TTkConstant:
'''Input Mouse Key
Events reported by :class:`~TermTk.TTkCore.TTkTerm.inputmouse.TTkMouseEvent` -> :class:`~TermTk.TTkCore.TTkTerm.inputmouse.TTkMouseEvent.key`
.. autosummary::
NoButton
AllButtons
LeftButton
RightButton
MidButton
MiddleButton
Wheel
'''
NoButton = 0x00000000
'''The button state does not refer to any button.'''
@ -202,7 +236,13 @@ class TTkConstant:
Wheel = MouseKey.Wheel
class WrapMode(int):
'''Those constants describes how text is wrapped in a document.'''
'''Those constants describes how text is wrapped in a document.
.. autosummary::
WordWrap
WrapAnywhere
WrapAtWordBoundaryOrAnywhere
'''
# NoWrap = 0x00
# '''Text is not wrapped at all.'''
WordWrap = 0x01
@ -221,9 +261,19 @@ class TTkConstant:
WrapAtWordBoundaryOrAnywhere = WrapMode.WrapAtWordBoundaryOrAnywhere
class LineWrapMode(int):
'''Those constants describes which wrapping status is required in the document
.. autosummary::
NoWrapk
WidgetWidthk
FixedWidthk
'''
NoWrap = 0x00
'''No Wrapping is applied'''
WidgetWidth = 0x01
'''Wrapping around the Widget width'''
FixedWidth = 0x03
'''Wrapping around a fixed width'''
NoWrap = LineWrapMode.NoWrap
WidgetWidth = LineWrapMode.WidgetWidth
@ -235,6 +285,15 @@ class TTkConstant:
'''Input Mouse Event
Events reported by :class:`~TermTk.TTkCore.TTkTerm.inputmouse.TTkMouseEvent` -> :class:`~TermTk.TTkCore.TTkTerm.inputmouse.TTkMouseEvent.evt`
.. autosummary::
NoEvent
Press
Release
Drag
Move
WHEEL_Up
WHEEL_Down
'''
NoEvent = 0x00000000
Press = 0x00010000
@ -294,7 +353,13 @@ class TTkConstant:
JUSTIFY = Alignment.JUSTIFY
class FileMode(int):
'''FileMode'''
'''FileMode
.. autosummary::
AnyFile
ExistingFile
Directory
'''
AnyFile = 0
'''The name of a file, whether it exists or not.'''
ExistingFile = 1
@ -309,14 +374,33 @@ class TTkConstant:
# ExistingFiles = FileMode.ExistingFiles
class AcceptMode(int):
'''AcceptMode'''
'''AcceptMode
.. autosummary::
AcceptOpen
AcceptSave
'''
AcceptOpen = 0
'''Open'''
AcceptSave = 1
'''Save'''
class TTkItemSelectionModel(int):
'''These values describes the way the selection model will be updated.'''
'''These values describes the way the selection model will be updated.
.. autosummary::
NoUpdate
Clear
Select
Deselect
Toggle
Current
Rows
Columns
SelectCurrent
ToggleCurrent
ClearAndSelect
'''
NoUpdate = 0x0000
'''No selection will be made.'''
Clear = 0x0001
@ -342,7 +426,12 @@ class TTkConstant:
# LayoutItem Types
class LayoutItemTypes(int):
'''Types used internally in :mod:`~TermTk.TTkLayouts`'''
'''Types used internally in :mod:`~TermTk.TTkLayouts`
.. autosummary::
LayoutItem
WidgetItem
'''
LayoutItem = 0x01
'''Item Type Layout'''
WidgetItem = 0x02
@ -353,6 +442,16 @@ class TTkConstant:
WidgetItem = LayoutItemTypes.WidgetItem
class WindowFlag(int):
'''
Those flags are used to enable customization of the window controls.
.. autosummary::
WindowReduceButtonHint
WindowMinimizeButtonHint
WindowMaximizeButtonHint
WindowMinMaxButtonsHint
WindowCloseButtonHint
'''
# FramelessWindowHint = 0x00000800
# ''' Produces a borderless window.'''
# CustomizeWindowHint = 0x02000000
@ -384,6 +483,10 @@ class TTkConstant:
'''Input Key Types
Key type reported by :class:`~TermTk.TTkCore.TTkTerm.inputkey.TTkKeyEvent` -> :class:`~TermTk.TTkCore.TTkTerm.inputkey.TTkKeyEvent.key`
.. autosummary::
Character
SpecialKey
'''
Character = 0x0001
'''Input Char Key'''
@ -398,6 +501,19 @@ class TTkConstant:
'''Input :class:`~TermTk.TTkCore.constant.TTkConstant.KeyType.SpecialKey` modifiers
Modifier reported by :class:`~TermTk.TTkCore.TTkTerm.inputkey.TTkKeyEvent` -> :class:`~TermTk.TTkCore.TTkTerm.inputkey.TTkKeyEvent.mod`
.. autosummary::
NoModifier
ShiftModifier
ControlModifier
AltModifier
MetaModifier
KeypadModifier
GroupSwitchModifier
SHIFT
META
CTRL
ALT
'''
NoModifier = 0x00000000
'''No modifier key is pressed.'''
@ -437,9 +553,17 @@ class TTkConstant:
ALT = KeyModifier.ALT
class ShortcutContext(int):
'''For a :class:`~TermTk.TTkCore.shortcut.TTkShortcut` event to occur,
the shortcut's key sequence must be entered by the user in a context where the shortcut is active.
The possible contexts are these:'''
'''
For a :class:`~TermTk.TTkCore.shortcut.TTkShortcut` event to occur,
the shortcut's key sequence must be entered by the user in a context where the shortcut is active.
The possible contexts are these:
.. autosummary::
WidgetShortcut
WidgetWithChildrenShortcut
WindowShortcut
ApplicationShortcut
'''
WidgetShortcut = 0x00
'''The shortcut is active when its parent widget has focus.'''
WidgetWithChildrenShortcut = 0x03

1
TermTk/TTkCore/shortcut.py

@ -56,6 +56,7 @@ class TTkKeySequence():
pass
class TTkShortcut():
'''TTkShortcut'''
_shortcuts = {}
__slots__ = (
'_key', '_parent', '_shortcutContext',

2
TermTk/TTkCore/string.py

@ -62,7 +62,7 @@ class TTkString():
__slots__ = ('_text','_colors','_baseColor','_hasTab','_hasSpecialWidth')
def __init__(self, text="", color=None):
def __init__(self, text:str="", color:TTkColor=None) -> None:
if issubclass(type(text), TTkString):
self._text = text._text
self._colors = text._colors if color is None else [color]*len(self._text)

3
docs/MDNotes/Games.md

@ -21,7 +21,7 @@ For this reason games like MarioBros are not technically possible on a terminal
* Syndicate
* Lemmings
* Puzzle bobble
* Minesweeper
* Minesweeper - CrapSweeper
* Any terminal roguelike
* Whac-A-Mole
* Dungeon Master
@ -29,6 +29,7 @@ For this reason games like MarioBros are not technically possible on a terminal
* Pacman (Does not require long keypresses)
* Nibbles (Does not require long keypresses)
* Canabalt (Mouse Press)
* Plants VS Zombies (the table prototype with green theme and icons looks very similar)
# 7DRL
https://itch.io/jam/7drl-challenge-2024

6
docs/source/conf.py

@ -144,7 +144,11 @@ autodocgen_config = {
}
# autodoc_default_options = { 'inherited-members':True }
autodoc_default_options = {}
autodoc_default_options = {
'exclude-members': ('as_integer_ratio , bit_count , bit_length , '
'conjugate , denominator , from_bytes , imag , '
'numerator , real , to_bytes')
}
# Mock pyodide to avoid autogen failure
class pyodideProxy(): pass

Loading…
Cancel
Save