Skip to content

Commit af742d7

Browse files
committed
Fix #55
Fix #54 Version 2.7.7
1 parent d5a9d7c commit af742d7

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

albow/demo/screens/DemoTextFieldsScreen.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def ok(cls):
4343
cls.resultLabel.text = "You are a %s called %s." % (cls.raceField.text, cls.nameField.text)
4444

4545
@classmethod
46-
def insertText(cls):
46+
def appendText(cls):
4747

4848
cls.lineCtr += 1
4949
line: str = f"Line {cls.lineCtr}{TextBox.LINE_SEPARATOR}"
@@ -53,25 +53,37 @@ def insertText(cls):
5353
cls.textBox.setText(oldLines)
5454

5555
@classmethod
56-
def deleteText(cls):
56+
def insertText(cls):
57+
cls.lineCtr += 1
58+
line: str = f'Line {cls.lineCtr}'
59+
cls.textBox.insertText(theNewLine=line)
60+
61+
@classmethod
62+
def clearText(cls):
5763

5864
cls.textBox.clearText()
5965
cls.lineCtr = 0
6066

67+
@classmethod
68+
def deleteText(cls):
69+
cls.textBox.deleteText(2)
70+
6171
@classmethod
6272
def makeTextBoxTesterContainer(cls) -> Row:
6373

64-
cls.textBox = TextBox(theNumberOfColumns=32, theNumberOfRows=6)
74+
cls.textBox = TextBox(theNumberOfColumns=20, theNumberOfRows=10)
6575

6676
checkBoxRow: Row = Row([CheckBox(), Label('Last Line Visible')])
6777

68-
insTextButton: Button = Button('Insert', action=cls.insertText)
69-
delTextButton: Button = Button('Clear ', action=cls.deleteText)
78+
appendTextButton: Button = Button('Append', action=cls.appendText)
79+
insertTextButton: Button = Button('Insert', action=cls.insertText)
80+
deleteTextButton: Button = Button('Delete', action=cls.deleteText)
81+
clearTextButton: Button = Button('Clear ', action=cls.clearText)
7082

7183
contentAttrs = {
7284
"align": "l"
7385
}
74-
buttHolder: Column = Column([insTextButton, delTextButton], **contentAttrs)
86+
buttHolder: Column = Column([appendTextButton, insertTextButton, deleteTextButton, clearTextButton], **contentAttrs)
7587
textBoxControlHolder: Column = Column([checkBoxRow, buttHolder], **contentAttrs)
7688

7789
container: Row = Row([cls.textBox, textBoxControlHolder])

albow/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = '2.7.6'
1+
version = '2.7.7'

albow/widgets/Control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from albow.utils import overridable_property
33

44

5-
class Control():
5+
class Control:
66
"""
77
Control is a mixin class for use by widgets that display and/or edit a value of some kind. It provides a value
88
property that can be linked, via a reference object, to a specific attribute or item of another object.

albow/widgets/TextBox.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ def getText(self):
9494
return self._text
9595

9696
def setText(self, theNewText: str):
97+
"""
98+
Replace the contents with this new text
99+
100+
Args:
101+
theNewText: The text that replaces what was in the widget
97102
103+
"""
98104
lines = theNewText.strip().split(TextBox.LINE_SEPARATOR)
99105
self.lines = lines
100106
self.debugJustInserted = True
@@ -129,6 +135,37 @@ def addText(self, newText: str):
129135
oldLines += f"{newText}{TextBox.LINE_SEPARATOR}"
130136
self.setText(oldLines)
131137

138+
def insertText(self, theNewLine):
139+
"""
140+
141+
Args:
142+
theNewLine:
143+
"""
144+
oldLines: str = self.getText()
145+
oldLines = f"{theNewLine}{TextBox.LINE_SEPARATOR}" + oldLines
146+
self.setText(oldLines)
147+
148+
def deleteText(self, theLineNumber: int = 0):
149+
"""
150+
Lines are defined as strings of text separated by `TextBox.LINE_SEPARATOR`
151+
Can't delete any lines if widget is empty (operation is ignored)
152+
Can't delete a line that does not exist (operation is ignored)
153+
154+
Args:
155+
theLineNumber: The line number to delete; Defaults to the first line (numbered 0)
156+
"""
157+
if len(self.getText()) > 0:
158+
oldLines: str = self.getText()
159+
splits: List[str] = oldLines.splitlines(True)
160+
self.logger.info(f'splits: {splits}')
161+
162+
if len(splits) > theLineNumber:
163+
del splits[theLineNumber]
164+
newLines: str = ''.join(splits)
165+
self.logger.info(f'newLines: {newLines}')
166+
167+
self.setText(newLines)
168+
132169
def clearText(self):
133170
"""
134171
Empties the text widget

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name="python3-albow",
13-
version="2.7.6",
13+
version="2.7.7",
1414
description="A Little Bit of Widgetry for PyGame",
1515
long_description=README,
1616
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)