Skip to content

Commit

Permalink
Merge pull request #441 from mattgibbs/font_size_fix
Browse files Browse the repository at this point in the history
Fix and improve font size adjustments
  • Loading branch information
hhslepicka authored Nov 30, 2018
2 parents 349cd4f + 1631739 commit 293ceec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
9 changes: 5 additions & 4 deletions pydm/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ def __init__(self, ui_file=None, command_line_args=[], display_args=[],

# Open a window if required.
if ui_file is not None:
apply_stylesheet(stylesheet_path)
self.make_main_window()
self.make_main_window(stylesheet_path=stylesheet_path)
self.make_window(ui_file, macros, command_line_args)
elif use_main_window:
self.make_main_window()
self.make_main_window(stylesheet_path=stylesheet_path)

self.had_file = ui_file is not None
# Re-enable sigint (usually blocked by pyqt)
Expand Down Expand Up @@ -226,7 +225,7 @@ def new_window(self, ui_file, macros=None, command_line_args=None):
# All new windows are spawned as new processes.
self.new_pydm_process(ui_file, macros, command_line_args)

def make_main_window(self):
def make_main_window(self, stylesheet_path=None):
"""
Instantiate a new PyDMMainWindow, add it to the application's
list of windows. Typically, this function is only called as part
Expand All @@ -238,6 +237,8 @@ def make_main_window(self):
hide_status_bar=self.hide_status_bar)

self.main_window = main_window
if stylesheet_path:
apply_stylesheet(stylesheet_path, widget=self.main_window)
self.main_window.update_tools_menu()

if self.fullscreen:
Expand Down
12 changes: 11 additions & 1 deletion pydm/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, parent=None, hide_nav_bar=False, hide_menu_bar=False, hide_st
self.ui.setupUi(self)
self._display_widget = None
self._showing_file_path_in_title_bar = False
self.default_font_size = QApplication.instance().font().pointSizeF()
self.ui.navbar.setIconSize(QSize(24, 24))
self.ui.navbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
# No search bar for now, since there isn't really any capability to search yet.
Expand All @@ -49,6 +50,7 @@ def __init__(self, parent=None, hide_nav_bar=False, hide_menu_bar=False, hide_st
self.ui.actionReload_Display.triggered.connect(self.reload_display)
self.ui.actionIncrease_Font_Size.triggered.connect(self.increase_font_size)
self.ui.actionDecrease_Font_Size.triggered.connect(self.decrease_font_size)
self.ui.actionDefault_Font_Size.triggered.connect(self.reset_font_size)
self.ui.actionEnter_Fullscreen.triggered.connect(self.enter_fullscreen)
self.ui.actionShow_File_Path_in_Title_Bar.triggered.connect(self.toggle_file_path_in_title_bar)
self.ui.actionShow_Navigation_Bar.triggered.connect(self.toggle_nav_bar)
Expand Down Expand Up @@ -415,6 +417,13 @@ def decrease_font_size(self, checked):
current_font.setPointSizeF(current_font.pointSizeF() / 1.1)
QApplication.instance().setFont(current_font)
QTimer.singleShot(0, self.resizeForNewDisplayWidget)

@Slot(bool)
def reset_font_size(self, checked):
current_font = QApplication.instance().font()
current_font.setPointSizeF(self.default_font_size)
QApplication.instance().setFont(current_font)
QTimer.singleShot(0, self.resizeForNewDisplayWidget)

@Slot(bool)
def enter_fullscreen(self, checked=False):
Expand All @@ -434,7 +443,8 @@ def show_about_window(self, checked):
a.show()

def resizeForNewDisplayWidget(self):
self.resize(self._new_widget_size)
if not self.isFullScreen():
self.resize(self._new_widget_size)

def closeEvent(self, event):
self.clear_display_widget()
Expand Down
9 changes: 9 additions & 0 deletions pydm/pydm.ui
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<addaction name="actionEnter_Fullscreen"/>
<addaction name="actionIncrease_Font_Size"/>
<addaction name="actionDecrease_Font_Size"/>
<addaction name="actionDefault_Font_Size"/>
<addaction name="separator"/>
<addaction name="actionShow_File_Path_in_Title_Bar"/>
<addaction name="actionShow_Navigation_Bar"/>
Expand Down Expand Up @@ -272,6 +273,14 @@
<string>F11</string>
</property>
</action>
<action name="actionDefault_Font_Size">
<property name="text">
<string>Default Font Size</string>
</property>
<property name="shortcut">
<string>Ctrl+0</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
7 changes: 6 additions & 1 deletion pydm/pydm_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'pydm.ui'
#
# Created by: PyQt5 UI code generator 5.6
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!

Expand Down Expand Up @@ -93,6 +93,8 @@ def setupUi(self, MainWindow):
self.actionLoadTool.setObjectName("actionLoadTool")
self.actionEnter_Fullscreen = QtWidgets.QAction(MainWindow)
self.actionEnter_Fullscreen.setObjectName("actionEnter_Fullscreen")
self.actionDefault_Font_Size = QtWidgets.QAction(MainWindow)
self.actionDefault_Font_Size.setObjectName("actionDefault_Font_Size")
self.menuFile.addAction(self.actionOpen_File)
self.menuFile.addSeparator()
self.menuFile.addAction(self.actionEdit_in_Designer)
Expand All @@ -102,6 +104,7 @@ def setupUi(self, MainWindow):
self.menuView.addAction(self.actionEnter_Fullscreen)
self.menuView.addAction(self.actionIncrease_Font_Size)
self.menuView.addAction(self.actionDecrease_Font_Size)
self.menuView.addAction(self.actionDefault_Font_Size)
self.menuView.addSeparator()
self.menuView.addAction(self.actionShow_File_Path_in_Title_Bar)
self.menuView.addAction(self.actionShow_Navigation_Bar)
Expand Down Expand Up @@ -158,4 +161,6 @@ def retranslateUi(self, MainWindow):
self.actionLoadTool.setText(_translate("MainWindow", "Load..."))
self.actionEnter_Fullscreen.setText(_translate("MainWindow", "Enter Fullscreen"))
self.actionEnter_Fullscreen.setShortcut(_translate("MainWindow", "F11"))
self.actionDefault_Font_Size.setText(_translate("MainWindow", "Default Font Size"))
self.actionDefault_Font_Size.setShortcut(_translate("MainWindow", "Ctrl+0"))

0 comments on commit 293ceec

Please sign in to comment.