bitwidgets: Add a "Dialog" box to the toolkit

This allows for simple messages to be displayed on top of the screen.
This commit is contained in:
June Tate-Gans 2021-05-09 23:12:55 -05:00
parent 9d7d4fafa2
commit e1b7befb82

View File

@ -0,0 +1,36 @@
from g13gui.bitwidgets.widget import Widget
from g13gui.bitwidgets.rectangle import Rectangle
from g13gui.bitwidgets.label import Label
from g13gui.bitwidgets.fonts import Fonts
from g13gui.bitwidgets import DISPLAY_WIDTH
from g13gui.bitwidgets import DISPLAY_HEIGHT
class Dialog(Widget):
def __init__(self, text):
Widget.__init__(self)
self._text = text
self._rect = Rectangle(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1,
fill=False, outline=True, width=3)
self._label = Label(0, 0, text, font=Fonts.LARGE)
self.addChild(self._rect)
self.addChild(self._label)
self._updateLayout()
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self.setProperty('text', value)
self._label.text = value
self._updateLayout()
def _updateLayout(self):
(w, h) = self._label.bounds
x = ((DISPLAY_WIDTH - 1) // 2) - (w // 2)
y = ((DISPLAY_HEIGHT - 1) // 2) - (h // 2)
self._label.position = (x, y)