Skip to content

Commit 025bd52

Browse files
author
Pierre Raybaut
committed
QwtScaleDiv/QwtScaleDraw: fixed when there are no ticks defined
1 parent 302132b commit 025bd52

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

qwt/qwt_scale_div.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class QwtScaleDiv(object):
1111
MinorTick, MediumTick, MajorTick, NTickTypes = range(4)
1212

1313
def __init__(self, *args):
14+
self.__ticks = None
1415
if len(args) == 2 and isinstance(args[1], (tuple, list)):
1516
interval, ticks = args
1617
self.__lowerBound = interval.minValue()
@@ -63,6 +64,8 @@ def range(self):
6364
return self.__upperBound - self.__lowerBound
6465

6566
def __eq__(self, other):
67+
if self.__ticks is None:
68+
return False
6669
if self.__lowerBound != other.__lowerBound or\
6770
self.__upperBound != other.__upperBound:
6871
return False
@@ -111,7 +114,7 @@ def setTicks(self, tickType, ticks):
111114
self.__ticks[tickType] = ticks
112115

113116
def ticks(self, tickType):
114-
if tickType in range(self.NTickTypes):
117+
if self.__ticks is not None and tickType in range(self.NTickTypes):
115118
return self.__ticks[tickType]
116119
else:
117120
return []

qwt/qwt_scale_draw.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,18 @@ def labelAlignment(self):
550550
return self.__data.labelAlignment
551551

552552
def maxLabelWidth(self, font):
553+
ticks = self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
554+
if not ticks:
555+
return 0
553556
return ceil(max([self.labelSize(font, v).width()
554-
for v in self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
555-
if self.scaleDiv().contains(v)]))
557+
for v in ticks if self.scaleDiv().contains(v)]))
556558

557559
def maxLabelHeight(self, font):
560+
ticks = self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
561+
if not ticks:
562+
return 0
558563
return ceil(max([self.labelSize(font, v).height()
559-
for v in self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
560-
if self.scaleDiv().contains(v)]))
564+
for v in ticks if self.scaleDiv().contains(v)]))
561565

562566
def updateMap(self):
563567
pos = self.__data.pos

0 commit comments

Comments
 (0)