Skip to content

Commit

Permalink
Ignore faulty dpi setting on startup fixing Issue #1024
Browse files Browse the repository at this point in the history
  • Loading branch information
MAKOMO committed Dec 1, 2022
1 parent cfbcb50 commit b2dc579
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions src/artisanlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,21 @@ def clear_phases(self):
self.ax.grid(False)
self.ax.set_xlim(0,100 + 2*self.m + 2*self.g)

# a similar function is define in aw:ApplicationWindow
def setdpi(self,dpi,moveWindow=True):
if aw and self.fig:
dpi = (dpi + self.dpi_offset) * aw.devicePixelRatio()
self.fig.set_dpi(dpi)
if moveWindow:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
self.fig.canvas.draw()
self.fig.canvas.update()
FigureCanvas.updateGeometry(self) #@UndefinedVariable
aw.scroll.setMaximumHeight(self.sizeHint().height())
if aw and self.fig and dpi >= 40:
try:
dpi = (dpi + self.dpi_offset) * aw.devicePixelRatio()
self.fig.set_dpi(dpi)
if moveWindow:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
self.fig.canvas.draw()
self.fig.canvas.update()
FigureCanvas.updateGeometry(self) #@UndefinedVariable
aw.scroll.setMaximumHeight(self.sizeHint().height())
except Exception as e: # pylint: disable=broad-except
_log.exception(e)

# data is expected to be a None or a list of tuples of the form
# (label, total_time, (phase1_time, phase2_time, phase3_time), active, color)
Expand Down Expand Up @@ -17547,7 +17551,9 @@ def __init__(self, parent = None, *, locale, WebEngineSupport):
settings = QSettings()
if settings.contains('dpi') and (not settings.contains('resetqsettings') or toInt(settings.value('resetqsettings',self.resetqsettings)) == 0):
try:
self.dpi = toInt(settings.value('dpi',self.dpi))
dpi = toInt(settings.value('dpi',self.dpi))
if dpi >= 40:
self.dpi = dpi
except Exception: # pylint: disable=broad-except
pass

Expand Down Expand Up @@ -23559,23 +23565,26 @@ def resizeEvent(self, event):
super().resizeEvent(event)

def setdpi(self,dpi,moveWindow=True):
if aw:
aw.dpi = dpi
# on mpl >= v2 we assume hidpi support and consider the pixel ratio
self.qmc.fig.set_dpi(dpi*aw.devicePixelRatio())
#move widget to update display
if moveWindow:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
aw.qmc.fig.canvas.draw()
aw.qmc.fig.canvas.update()
aw.qmc.adjustSize()
FigureCanvas.updateGeometry(aw.qmc) #@UndefinedVariable
QApplication.processEvents()
if aw.qmc.statssummary:
aw.qmc.redraw(recomputeAllDeltas=False)
if aw.qpc:
aw.qpc.setdpi(dpi,moveWindow)
if aw and dpi >= 40:
try:
aw.dpi = dpi
# on mpl >= v2 we assume hidpi support and consider the pixel ratio
self.qmc.fig.set_dpi(dpi*aw.devicePixelRatio())
#move widget to update display
if moveWindow:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
aw.qmc.fig.canvas.draw()
aw.qmc.fig.canvas.update()
aw.qmc.adjustSize()
FigureCanvas.updateGeometry(aw.qmc) #@UndefinedVariable
QApplication.processEvents()
if aw.qmc.statssummary:
aw.qmc.redraw(recomputeAllDeltas=False)
if aw.qpc:
aw.qpc.setdpi(dpi,moveWindow)
except Exception as e: # pylint: disable=broad-except
_log.exception(e)

def enableSaveActions(self):
if aw:
Expand Down

0 comments on commit b2dc579

Please sign in to comment.