Skip to content

Commit 9d842f0

Browse files
authored
Merge pull request #287 from nxt-dev/dev
Release editor-v4.0.1
2 parents d48d580 + 4c0ecae commit 9d842f0

10 files changed

Lines changed: 92 additions & 53 deletions

File tree

build/release.nxt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"references": [
88
"make_unreal_plugin.nxt",
99
"make_maya_plugin.nxt",
10-
"make_blender_plugin.nxt",
1110
"../../nxt/build/release.nxt"
1211
],
1312
"comp_overrides": {
@@ -143,6 +142,7 @@
143142
},
144143
"/CreateRelease/UploadBlenderAddon": {
145144
"instance": "/GitUpload",
145+
"enabled": false,
146146
"attrs": {
147147
"asset_path": {
148148
"type": "raw",
@@ -201,7 +201,8 @@
201201
"execute_in": "/make_module_folder",
202202
"child_order": [
203203
"zip_blender_addon"
204-
]
204+
],
205+
"enabled": false
205206
},
206207
"/make_addon/zip_blender_addon": {
207208
"attrs": {

nxt_editor/constants.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Builtin
22
import os
33
import json
4-
4+
# External
5+
from Qt import QtGui, QtWidgets
56
# Internal
67
from nxt.constants import USER_DIR
78

@@ -21,11 +22,47 @@ class EDITOR_VERSION(object):
2122
VERSION = VERSION_STR
2223

2324

24-
class FONTS(object):
25-
DEFAULT_FAMILY = 'Roboto Mono'
26-
DEFAULT_SIZE = 10
25+
class _FontManager:
26+
def __init__(self):
27+
self._initialized = False
28+
self._font_db = QtGui.QFontDatabase()
29+
self.DEFAULT_SIZE = 10
30+
self._default_family = "Sans Serif"
31+
self._code_family = "Monospace"
32+
33+
def initialize(self):
34+
if self._initialized:
35+
return
36+
if not QtWidgets.QApplication.instance():
37+
return
38+
roboto_id = self._font_db.addApplicationFont(":/fonts/fonts/Roboto/Roboto-Regular.ttf")
39+
mono_id = self._font_db.addApplicationFont(":/fonts/fonts/RobotoMono/RobotoMono-Regular.ttf")
40+
41+
if roboto_id != -1:
42+
self._default_family = self._font_db.applicationFontFamilies(roboto_id)[0]
43+
if mono_id != -1:
44+
self._code_family = self._font_db.applicationFontFamilies(mono_id)[0]
45+
46+
self._initialized = True
47+
48+
@property
49+
def DEFAULT_FAMILY(self):
50+
self.initialize()
51+
return self._default_family
52+
53+
@property
54+
def MONOSPACE(self):
55+
self.initialize()
56+
return self._code_family
57+
58+
def default_font(self, size=None):
59+
return QtGui.QFont(self.DEFAULT_FAMILY, size or self.DEFAULT_SIZE)
60+
61+
def monospace_font(self, size=None):
62+
return QtGui.QFont(self.MONOSPACE, size or self.DEFAULT_SIZE)
2763

2864

65+
FONTS = _FontManager()
2966
PREF_DIR_INT = EDITOR_VERSION.MAJOR
3067
PREF_DIR_NAME = 'prefs'
3168
_pref_dir_num = str(PREF_DIR_INT)

nxt_editor/dockwidgets/code_editor.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from nxt import DATA_STATE, nxt_path
1717
from nxt.nxt_node import INTERNAL_ATTRS
1818
from nxt_editor.dockwidgets import syntax
19+
from nxt_editor.constants import FONTS
1920
import nxt_editor
2021

2122
logger = logging.getLogger(nxt_editor.LOGGER_NAME)
@@ -72,7 +73,7 @@ def __init__(self, title='Code Editor', parent=None, minimum_width=500):
7273
self.details_layout.addLayout(self.name_layout)
7374

7475
self.name_label = LabelEdit(parent=self.details_frame)
75-
self.name_label.setFont(QtGui.QFont("Roboto", 14))
76+
self.name_label.setFont(QtGui.QFont(FONTS.DEFAULT_FAMILY, 14))
7677
self.name_label.nameChangeRequested.connect(self.edit_name)
7778
self.name_layout.addWidget(self.name_label, 0, QtCore.Qt.AlignLeft)
7879

@@ -86,7 +87,7 @@ def __init__(self, title='Code Editor', parent=None, minimum_width=500):
8687
self.name_layout.addWidget(self.name_edit_button, 0, QtCore.Qt.AlignLeft)
8788

8889
self.path_label = QtWidgets.QLabel(parent=self.details_frame)
89-
self.path_label.setFont(QtGui.QFont("Roboto Mono", 8))
90+
self.path_label.setFont(QtGui.QFont(FONTS.MONOSPACE, 8))
9091
self.path_label.setStyleSheet('color: grey')
9192
self.details_layout.addWidget(self.path_label)
9293

@@ -600,9 +601,8 @@ def __init__(self, show_line_numbers=True, highlight_current_line=True,
600601
self.setFocusPolicy(QtCore.Qt.ClickFocus)
601602

602603
# font settings
603-
self.font_size = 10
604-
self.font_family = 'Roboto Mono'
605-
self.setFont(QtGui.QFont(self.font_family, self.font_size))
604+
self.font_size = FONTS.DEFAULT_SIZE
605+
self.setFont(FONTS.monospace_font(self.font_size))
606606
self.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
607607

608608
# display settings
@@ -754,7 +754,9 @@ def set_font_size(self, delta=0.0, default=False):
754754
self.font_size = 10
755755
else:
756756
self.font_size += delta
757-
self.setFont(QtGui.QFont(self.font_family, self.font_size))
757+
font = self.font()
758+
font.setPointSize(self.font_size)
759+
self.setFont(font)
758760

759761
def update_previous_scroll_positions(self):
760762
self.prev_v_scroll_value = self.verticalScrollBar().value()
@@ -1217,7 +1219,6 @@ def __init__(self, editor, color):
12171219
self.editor = editor
12181220
self.editor.blockCountChanged.connect(self.update_width)
12191221
self.editor.updateRequest.connect(self.update_contents)
1220-
self.font = QtGui.QFont()
12211222
self.color = QtGui.QColor(color)
12221223
self.update_width()
12231224

@@ -1231,7 +1232,7 @@ def paintEvent(self, event):
12311232
changed_lines = []
12321233
# Iterate over all visible text blocks in the document.
12331234
while block.isValid():
1234-
self.font.setBold(False)
1235+
self.font().setBold(False)
12351236
block_number = block.blockNumber()
12361237
block_top = self.editor.blockBoundingGeometry(block).translated(
12371238
self.editor.contentOffset()).top()
@@ -1241,7 +1242,7 @@ def paintEvent(self, event):
12411242
# We want the line number for the selected line to be bold.
12421243
painter.setPen(QtGui.QColor(colors.LIGHTER_TEXT))
12431244
if block_number == self.editor.textCursor().blockNumber():
1244-
self.font.setBold(True)
1245+
self.font().setBold(True)
12451246
else:
12461247
painter.setPen(colors.DEFAULT_TEXT)
12471248
# Draw the line number right justified at the position of the line.
@@ -1252,7 +1253,7 @@ def paintEvent(self, event):
12521253
painter.fillRect(paint_rect, colors.UNSAVED)
12531254
painter.setPen(colors.LIGHTEST_TEXT)
12541255
changed_lines.remove(block_number)
1255-
painter.setFont(self.font)
1256+
painter.setFont(self.font())
12561257
text_rect = paint_rect.marginsAdded(QtCore.QMargins(0, 0, -4, 0))
12571258
painter.drawText(text_rect, QtCore.Qt.AlignRight,
12581259
str(block_number + 1))
@@ -1288,8 +1289,8 @@ def update_contents(self, rect, scroll):
12881289

12891290
if rect.contains(self.editor.viewport().rect()):
12901291
font_size = self.editor.currentCharFormat().font().pointSize()
1291-
self.font.setPointSize(font_size)
1292-
self.font.setStyle(QtGui.QFont.StyleNormal)
1292+
self.font().setPointSize(font_size)
1293+
self.font().setStyle(QtGui.QFont.StyleNormal)
12931294
self.update_width()
12941295

12951296

@@ -1310,7 +1311,7 @@ def __init__(self, parent=None):
13101311
def paintEvent(self, event):
13111312
painter = QtGui.QPainter()
13121313
painter.begin(self)
1313-
painter.setFont(QtGui.QFont("Roboto", 14))
1314+
painter.setFont(QtGui.QFont(FONTS.MONOSPACE, 14))
13141315
font_metrics = QtGui.QFontMetrics(painter.font())
13151316
painter.setRenderHint(QtGui.QPainter.Antialiasing)
13161317
# actual_display_state

nxt_editor/dockwidgets/hotkey_editor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# Internal
88
import nxt_editor
9+
from nxt_editor.constants import FONTS
910
from nxt_editor.dockwidgets.dock_widget_base import DockWidgetBase
1011
from nxt_editor import colors, dialogs
1112

@@ -28,14 +29,14 @@
2829
'other shortcut.</p>')
2930

3031
TOOLTIP_STYLE = '''QToolTip {
31-
font-family: Roboto Mono;
32+
font-family: %s;
3233
background-color: #3E3E3E;
3334
border: 1px solid #232323;
34-
}'''
35+
}''' % (FONTS.MONOSPACE,)
3536

3637
TABLE_STYLE = '''QTableView {
37-
font-family: Roboto Mono;
38-
}'''
38+
font-family: %s;
39+
}''' % (FONTS.MONOSPACE,)
3940

4041

4142
class HotkeyEditor(DockWidgetBase):

nxt_editor/dockwidgets/output_log.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Internal
1313
import nxt_editor
1414
from nxt_editor import user_dir
15+
from nxt_editor.constants import FONTS
1516
from nxt_editor.dockwidgets.dock_widget_base import DockWidgetBase
1617
from nxt import nxt_log
1718
from nxt_editor import LoggingSignaler, colors
@@ -99,7 +100,7 @@ def format(self, record):
99100
links = []
100101
if links:
101102
text = self.format_links(text, links)
102-
msg = '<font face="Roboto Mono" color="white">{}</font>'.format(text)
103+
msg = '<font face="{}" color="white">{}</font>'.format(FONTS.MONOSPACE, text)
103104
if multi:
104105
replacement = (msg, record.msg[1])
105106
else:
@@ -377,10 +378,10 @@ def write_rich_output(self, val, level=None):
377378
else:
378379
text = val
379380
color = colors.LOGGING_COLORS.get(level, 'white')
380-
html = '<font face="Roboto Mono" color="{}">'.format(color)
381+
html = '<font face="{}" color="{}">'.format(FONTS.MONOSPACE, color)
381382
style = ("<style type='text/css'> "
382-
"pre {margin: 0; font-family: 'Roboto Mono';} "
383-
"</style>")
383+
"pre {margin: 0; font-family: '%s';} "
384+
"</style>" % (FONTS.DEFAULT_FAMILY,))
384385
text = style + ("<pre>{}</pre>".format(text))
385386
html += text + '</font>'
386387
self.rich_output_textedit.insertHtml(html)
@@ -431,7 +432,7 @@ def __init__(self, parent):
431432
self._parent = parent
432433
self.setStyleSheet(self.parent().parent().styleSheet())
433434
self.setReadOnly(True)
434-
self.setFont(QtGui.QFont('Roboto Mono', 10))
435+
self.setFont(QtGui.QFont(FONTS.MONOSPACE, 10))
435436

436437
def contextMenuEvent(self, event):
437438
menu = self.createStandardContextMenu()
@@ -447,7 +448,7 @@ def __init__(self, parent):
447448
self.anchorClicked.connect(self.parent().link_clicked)
448449
self.setStyleSheet(self.parent().parent().styleSheet())
449450
self.setOpenLinks(False)
450-
self.setFont(QtGui.QFont('Roboto Mono', 10))
451+
self.setFont(QtGui.QFont(FONTS.MONOSPACE, 10))
451452

452453
def contextMenuEvent(self, event):
453454
menu = self.createStandardContextMenu()

nxt_editor/dockwidgets/property_editor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# Internal
1818
from nxt_editor import user_dir
19+
from nxt_editor.constants import FONTS
1920
from nxt_editor.dockwidgets.dock_widget_base import DockWidgetBase
2021
from nxt_editor.pixmap_button import PixmapButton
2122
from nxt_editor.label_edit import LabelEdit
@@ -1481,11 +1482,11 @@ def __init__(self, parent=None):
14811482
}
14821483
14831484
QToolTip {
1484-
font-family: Roboto Mono;
1485+
font-family: %s;
14851486
color: white;
14861487
border: 1px solid #3E3E3E
14871488
}
1488-
'''
1489+
''' % (FONTS.MONOSPACE,)
14891490
self.setStyleSheet(style)
14901491
self._parent = parent
14911492
self.node_path_delegate = NodePathBtnDelegate(self)

nxt_editor/main_window.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ def __init__(self, filepath=None, parent=None, start_rpc=False):
122122
style_file.open(QtCore.QFile.ReadOnly)
123123
self.stylesheet = str(style_file.readAll())
124124
self.setStyleSheet(self.stylesheet)
125-
126-
# fonts
127-
font_db = QtGui.QFontDatabase()
128-
font_db.addApplicationFont(":fonts/fonts/RobotoMono/RobotoMono-Regular.ttf")
129-
font_db.addApplicationFont(":fonts/fonts/Roboto/Roboto-Regular.ttf")
125+
self.setFont(FONTS.default_font())
130126

131127
# nxt object in charge of loaded graphs
132128
self.nxt = Session()
@@ -365,24 +361,23 @@ def decrease_font_size(self):
365361
self._change_font_size(-1)
366362

367363
def _change_font_size(self, delta, absolute=False, save=True):
368-
app = QtWidgets.QApplication.instance()
369364
if absolute:
370365
font_size = delta
371366
else:
372-
font_size = app.font().pointSize() + delta
367+
font_size = self.font().pointSize() + delta
373368
self.font_size_changed.emit(delta)
374369
if save:
375370
user_dir.user_prefs[user_dir.USER_PREF.FONT_SIZE] = font_size
376-
font = QtGui.QFont(FONTS.DEFAULT_FAMILY, font_size)
377-
app.setFont(font)
378-
379-
widgets_with_fonts = ["QMenuBar", "QTabWidget", "QMenu", "QTableView",
380-
"QLineEdit", "QComboBox", "QLabel",
381-
"QPushButton", "QTextEdit", "QWidget",
382-
"QListWidget", "QTabelWidget", "QTreeWidget",
383-
"QSpinBox", "QDoubleSpinBox", "QCheckBox"]
384-
for widget in widgets_with_fonts:
385-
app.setFont(font, widget)
371+
main_font = self.font()
372+
main_font.setPointSize(font_size)
373+
self.setFont(main_font)
374+
self.setUpdatesEnabled(False)
375+
for widget in self.findChildren(QtWidgets.QWidget):
376+
update_font = widget.font()
377+
update_font.setPointSize(font_size)
378+
widget.setFont(update_font)
379+
self.setUpdatesEnabled(True)
380+
QtWidgets.QApplication.processEvents()
386381

387382
new_cb_stylesheet = '''
388383
QCheckBox::indicator {

nxt_editor/node_graphics_item.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import nxt_editor
1414
from nxt import nxt_path, nxt_node
1515
from nxt.nxt_layer import LAYERS
16+
from nxt_editor.constants import FONTS
1617
from . import colors
1718
from nxt.stage import INTERNAL_ATTRS
1819
from .label_edit import NameEditDialog
@@ -57,8 +58,8 @@ def __init__(self, model, node_path, view):
5758
self.setAcceptHoverEvents(True)
5859

5960
# draw settings
60-
self.title_font = QtGui.QFont("Roboto Mono", 14)
61-
self.attr_font = QtGui.QFont("Roboto Mono", 9)
61+
self.title_font = QtGui.QFont(FONTS.MONOSPACE, 14)
62+
self.attr_font = QtGui.QFont(FONTS.MONOSPACE, 9)
6263
self.title_rect_height = 39
6364
self.attr_rect_height = 26
6465
self.attr_rect_opacity = 0.9

nxt_editor/stage_view.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Interal
1414
import nxt_editor
1515
from nxt import nxt_node, tokens
16+
from nxt_editor.constants import FONTS
1617
from nxt_editor.node_graphics_item import NodeGraphicsItem, NodeGraphicsPlug
1718
from nxt_editor.connection_graphics_item import AttrConnectionGraphic
1819
from nxt_editor.dialogs import NxtWarningDialog
@@ -265,14 +266,14 @@ def update_style_sheet(self):
265266
light_color.setHsv(color_obj.hsvHue(), color_obj.hsvSaturation() * 0.3, color_obj.value())
266267
style = '''
267268
QToolTip {
268-
font-family: Roboto Mono;
269+
font-family: %s;
269270
background-color: %s
270271
}
271272
272273
QRubberBand {
273274
selection-background-color: %s
274275
}
275-
''' % (light_color.name(), layer_color)
276+
''' % (FONTS.DEFAULT_FAMILY, light_color.name(), layer_color)
276277
self.setStyleSheet(style)
277278

278279
def clear(self):

nxt_editor/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"EDITOR": {
33
"MAJOR": 4,
44
"MINOR": 0,
5-
"PATCH": 0
5+
"PATCH": 1
66
}
77
}

0 commit comments

Comments
 (0)