mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 08:23:50 -04:00
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:
parent
9d7d4fafa2
commit
e1b7befb82
36
g13gui/bitwidgets/dialog.py
Normal file
36
g13gui/bitwidgets/dialog.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user