Commit d294013e authored by Guido van Rossum's avatar Guido van Rossum

Added class StrutAppearance (a label with with 0).

Changed minsize to getminsize.
parent cf583fae
...@@ -35,12 +35,10 @@ class LabelAppearance(): ...@@ -35,12 +35,10 @@ class LabelAppearance():
# #
# Size enquiry # Size enquiry
# #
def minsize(self, m): def getminsize(self, (m, (width, height))):
try: width = max(width, m.textwidth(self.text) + 6)
self.text = self.text height = max(height, m.lineheight() + 6)
except NameError: return width, height
self.text = ''
return m.textwidth(self.text) + 6, m.lineheight() + 6
# #
def getbounds(self): def getbounds(self):
return self.bounds return self.bounds
...@@ -143,6 +141,16 @@ class LabelAppearance(): ...@@ -143,6 +141,16 @@ class LabelAppearance():
d.invert(self.hilitebounds) d.invert(self.hilitebounds)
# A Strut is a label with no width of its own.
class StrutAppearance() = LabelAppearance():
#
def getminsize(self, (m, (width, height))):
height = max(height, m.lineheight() + 6)
return width, height
#
# ButtonAppearance displays a centered string in a box. # ButtonAppearance displays a centered string in a box.
# selected --> bold border # selected --> bold border
# disabled --> crossed out # disabled --> crossed out
...@@ -167,9 +175,12 @@ class ButtonAppearance() = LabelAppearance(): ...@@ -167,9 +175,12 @@ class ButtonAppearance() = LabelAppearance():
# #
class CheckAppearance() = LabelAppearance(): class CheckAppearance() = LabelAppearance():
# #
def minsize(self, m): def getminsize(self, (m, (width, height))):
width, height = m.textwidth(self.text) + 6, m.lineheight() + 6 minwidth = m.textwidth(self.text) + 6
return width + height + m.textwidth(' '), height minheight = m.lineheight() + 6
width = max(width, minwidth + minheight + m.textwidth(' '))
height = max(height, minheight)
return width, height
# #
def drawpict(self, d): def drawpict(self, d):
d.box(self.boxbounds) d.box(self.boxbounds)
...@@ -393,6 +404,7 @@ def _xorcross(d, bounds): ...@@ -393,6 +404,7 @@ def _xorcross(d, bounds):
# Ready-made button classes. # Ready-made button classes.
# #
class Label() = NoReactivity(), LabelAppearance(), Define(): pass class Label() = NoReactivity(), LabelAppearance(), Define(): pass
class Strut() = NoReactivity(), StrutAppearance(), Define(): pass
class PushButton() = TriggerReactivity(), ButtonAppearance(), Define(): pass class PushButton() = TriggerReactivity(), ButtonAppearance(), Define(): pass
class CheckButton() = CheckReactivity(), CheckAppearance(), Define(): pass class CheckButton() = CheckReactivity(), CheckAppearance(), Define(): pass
class RadioButton() = RadioReactivity(), RadioAppearance(), Define(): pass class RadioButton() = RadioReactivity(), RadioAppearance(), Define(): pass
......
...@@ -35,12 +35,10 @@ class LabelAppearance(): ...@@ -35,12 +35,10 @@ class LabelAppearance():
# #
# Size enquiry # Size enquiry
# #
def minsize(self, m): def getminsize(self, (m, (width, height))):
try: width = max(width, m.textwidth(self.text) + 6)
self.text = self.text height = max(height, m.lineheight() + 6)
except NameError: return width, height
self.text = ''
return m.textwidth(self.text) + 6, m.lineheight() + 6
# #
def getbounds(self): def getbounds(self):
return self.bounds return self.bounds
...@@ -143,6 +141,16 @@ class LabelAppearance(): ...@@ -143,6 +141,16 @@ class LabelAppearance():
d.invert(self.hilitebounds) d.invert(self.hilitebounds)
# A Strut is a label with no width of its own.
class StrutAppearance() = LabelAppearance():
#
def getminsize(self, (m, (width, height))):
height = max(height, m.lineheight() + 6)
return width, height
#
# ButtonAppearance displays a centered string in a box. # ButtonAppearance displays a centered string in a box.
# selected --> bold border # selected --> bold border
# disabled --> crossed out # disabled --> crossed out
...@@ -167,9 +175,12 @@ class ButtonAppearance() = LabelAppearance(): ...@@ -167,9 +175,12 @@ class ButtonAppearance() = LabelAppearance():
# #
class CheckAppearance() = LabelAppearance(): class CheckAppearance() = LabelAppearance():
# #
def minsize(self, m): def getminsize(self, (m, (width, height))):
width, height = m.textwidth(self.text) + 6, m.lineheight() + 6 minwidth = m.textwidth(self.text) + 6
return width + height + m.textwidth(' '), height minheight = m.lineheight() + 6
width = max(width, minwidth + minheight + m.textwidth(' '))
height = max(height, minheight)
return width, height
# #
def drawpict(self, d): def drawpict(self, d):
d.box(self.boxbounds) d.box(self.boxbounds)
...@@ -393,6 +404,7 @@ def _xorcross(d, bounds): ...@@ -393,6 +404,7 @@ def _xorcross(d, bounds):
# Ready-made button classes. # Ready-made button classes.
# #
class Label() = NoReactivity(), LabelAppearance(), Define(): pass class Label() = NoReactivity(), LabelAppearance(), Define(): pass
class Strut() = NoReactivity(), StrutAppearance(), Define(): pass
class PushButton() = TriggerReactivity(), ButtonAppearance(), Define(): pass class PushButton() = TriggerReactivity(), ButtonAppearance(), Define(): pass
class CheckButton() = CheckReactivity(), CheckAppearance(), Define(): pass class CheckButton() = CheckReactivity(), CheckAppearance(), Define(): pass
class RadioButton() = RadioReactivity(), RadioAppearance(), Define(): pass class RadioButton() = RadioReactivity(), RadioAppearance(), Define(): pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment