Skip to content

Commit

Permalink
Fix AttributeError when running on older Qt versions
Browse files Browse the repository at this point in the history
Fixes #286
  • Loading branch information
nyalldawson committed Sep 6, 2023
1 parent 49f1287 commit 569b38a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
26 changes: 15 additions & 11 deletions koordinates/gui/custom_combo_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,21 @@ def move_to_anchor_placement(self):
)
)

screen = self.anchor_widget.screen()
if screen:
screen_width = screen.size().width()
pos_on_screen = new_pos.x() - screen.geometry().left()
if pos_on_screen + self.width() > screen_width:
# align with right side of anchor widget instead, to
# avoid combo box overflowing outside of screen
right_edge = new_pos.x() + self.anchor_widget.width()
new_pos.setX(
right_edge - self.width()
)
try:
screen = self.anchor_widget.screen()
if screen:
screen_width = screen.size().width()
pos_on_screen = new_pos.x() - screen.geometry().left()
if pos_on_screen + self.width() > screen_width:
# align with right side of anchor widget instead, to
# avoid combo box overflowing outside of screen
right_edge = new_pos.x() + self.anchor_widget.width()
new_pos.setX(
right_edge - self.width()
)
except AttributeError:
# requires Qt 5.14+
pass

self.move(new_pos)

Expand Down
25 changes: 21 additions & 4 deletions koordinates/gui/dataset_browser_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ def __init__(self,

self.raw_thumbnail = None

font_scale = self.screen().logicalDotsPerInch() / 92
try:
font_scale = self.screen().logicalDotsPerInch() / 92
except AttributeError:
# requires Qt 5.14+
font_scale = 1

self.thumbnail_label = Label()
self.thumbnail_label.setFixedHeight(150)
Expand Down Expand Up @@ -597,7 +601,11 @@ def update_thumbnail(self):
thumbnail_svg, size, size)

thumbnail = self.process_thumbnail(self.raw_thumbnail)
dpi_ratio = self.window().screen().devicePixelRatio()
try:
dpi_ratio = self.window().screen().devicePixelRatio()
except AttributeError:
# requires Qt 5.14
dpi_ratio = 1
width = int(thumbnail.width() / dpi_ratio)
height = int(thumbnail.height() / dpi_ratio)
self.thumbnail_label.setFixedSize(QSize(width, height))
Expand All @@ -611,7 +619,12 @@ def process_thumbnail(self, img: Optional[QImage]) -> QImage:
size = QSize(self.width(), self.THUMBNAIL_SIZE)

image_size = size
scale_factor = self.window().screen().devicePixelRatio()
try:
scale_factor = self.window().screen().devicePixelRatio()
except AttributeError:
# requires Qt 5.14+
scale_factor = 1

if scale_factor > 1:
image_size *= scale_factor

Expand Down Expand Up @@ -720,7 +733,11 @@ def process_thumbnail(self, img: Optional[QImage]) -> QImage:
self.dataset
)

font_scale = self.screen().logicalDotsPerInch() / 92
try:
font_scale = self.screen().logicalDotsPerInch() / 92
except AttributeError:
# requires Qt 5.14 +
font_scale = 1

overlay_font_size = 7.5
if platform.system() == 'Darwin':
Expand Down
7 changes: 6 additions & 1 deletion koordinates/gui/dataset_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ def get_history_details(self) -> List[Tuple]:

def setThumbnail(self, img):
image_size = self.thumbnail_label.size()
scale_factor = self.window().screen().devicePixelRatio()
try:
scale_factor = self.window().screen().devicePixelRatio()
except AttributeError:
# requires Qt 5.14+
scale_factor = 1

if scale_factor > 1:
image_size *= scale_factor

Expand Down
7 changes: 6 additions & 1 deletion koordinates/gui/detail_widgets/header_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ def __init__(self, dataset: Dataset, parent=None):

hl.addWidget(url_frame, 1)

font_scale = self.screen().logicalDotsPerInch() / 92
try:
font_scale = self.screen().logicalDotsPerInch() / 92
except AttributeError:
# requires Qt 5.14+
font_scale = 1

org_font_size = 10
if font_scale > 1:
org_font_size = int(12 / font_scale)
Expand Down
8 changes: 7 additions & 1 deletion koordinates/gui/koordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,13 @@ def __init__(self, parent):
self.results_panel.publisher_cleared.connect(
self.filter_widget.remove_publisher_filter)

if os.name == 'nt' or self.window().screen().devicePixelRatio() > 1:
try:
device_pixel_ratio = self.window().screen().devicePixelRatio()
except AttributeError:
# requires Qt 5.14+
device_pixel_ratio = 1

if os.name == 'nt' or device_pixel_ratio > 1:
self.button_sort_order.setStyleSheet(
'QToolButton { padding-right: 30px; padding-left: 0px; }'
)
Expand Down
6 changes: 5 additions & 1 deletion koordinates/gui/results_panel/explore_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def __init__(self,
self.title_label.setWordWrap(True)

main_title_size = 14
font_scale = self.screen().logicalDotsPerInch() / 92
try:
font_scale = self.screen().logicalDotsPerInch() / 92
except AttributeError:
# requires Qt 5.14+
font_scale = 1

if platform.system() == 'Darwin':
# fonts looks smaller on a mac, where things "just work" :P
Expand Down

0 comments on commit 569b38a

Please sign in to comment.