Skip to content

Commit 3943da2

Browse files
authored
Add files via upload
1 parent 6a64413 commit 3943da2

File tree

6 files changed

+80
-26
lines changed

6 files changed

+80
-26
lines changed

moleditpy-linux/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "MoleditPy-linux"
77

8-
version = "2.4.5"
8+
version = "2.4.6"
99

1010
license = {file = "LICENSE"}
1111

moleditpy-linux/src/MoleditPy_linux.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.4
22
Name: MoleditPy-linux
3-
Version: 2.4.5
3+
Version: 2.4.6
44
Summary: A cross-platform, simple, and intuitive molecular structure editor built in Python. It allows 2D molecular drawing and 3D structure visualization. It supports exporting structure files for input to DFT calculation software.
55
Author-email: HiroYokoyama <[email protected]>
66
License: GNU GENERAL PUBLIC LICENSE

moleditpy-linux/src/moleditpy_linux/modules/atom_item.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,32 @@ def update_style(self):
6060
win = self.scene().views()[0].window()
6161
if win and hasattr(win, 'settings'):
6262
font_size = win.settings.get('atom_font_size_2d', 20)
63+
font_family = win.settings.get('atom_font_family_2d', FONT_FAMILY)
64+
else:
65+
font_family = FONT_FAMILY
6366
except Exception:
64-
pass
65-
self.font = QFont(FONT_FAMILY, font_size, FONT_WEIGHT_BOLD)
67+
font_family = FONT_FAMILY
68+
69+
self.font = QFont(font_family, font_size, FONT_WEIGHT_BOLD)
6670
self.prepareGeometryChange()
6771

6872
self.is_visible = not (self.symbol == 'C' and len(self.bonds) > 0 and self.charge == 0 and self.radical == 0)
6973
self.update()
7074

7175
def boundingRect(self):
7276
# --- paint()メソッドと完全に同じロジックでテキストの位置とサイズを計算 ---
73-
# Get dynamic font size
77+
# Get dynamic font size and family
7478
font_size = 20
79+
font_family = FONT_FAMILY
7580
try:
7681
if self.scene() and self.scene().views():
7782
win = self.scene().views()[0].window()
7883
if win and hasattr(win, 'settings'):
7984
font_size = win.settings.get('atom_font_size_2d', 20)
85+
font_family = win.settings.get('atom_font_family_2d', FONT_FAMILY)
8086
except Exception:
8187
pass
82-
font = QFont(FONT_FAMILY, font_size, FONT_WEIGHT_BOLD)
88+
font = QFont(font_family, font_size, FONT_WEIGHT_BOLD)
8389
fm = QFontMetricsF(font)
8490

8591
hydrogen_part = ""
@@ -197,7 +203,9 @@ def paint(self, painter, option, widget):
197203
if self.scene() and self.scene().views():
198204
win = self.scene().views()[0].window()
199205
if win and hasattr(win, 'settings'):
200-
if win.settings.get('atom_use_bond_color_2d', False):
206+
# Force Hydrogen to use bond color (invisible on white bg otherwise)
207+
# OR if the global setting is checked
208+
if self.symbol == 'H' or win.settings.get('atom_use_bond_color_2d', False):
201209
bond_col = win.settings.get('bond_color_2d', '#222222')
202210
color = QColor(bond_col)
203211
except Exception:
@@ -374,11 +382,9 @@ def itemChange(self, change, value):
374382
res = super().itemChange(change, value)
375383
if change == QGraphicsItem.GraphicsItemChange.ItemPositionHasChanged:
376384
if self.flags() & QGraphicsItem.GraphicsItemFlag.ItemIsMovable:
377-
# Prevent cascading updates during batch operations
378-
if not getattr(self, '_updating_position', False):
379-
for bond in self.bonds:
380-
if bond.scene(): # Only update if bond is still in scene
381-
bond.update_position()
385+
for bond in self.bonds:
386+
if bond.scene():
387+
bond.update_position()
382388

383389
return res
384390

moleditpy-linux/src/moleditpy_linux/modules/bond_item.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ def get_line_in_local_coords(self):
9494
if self.atom1 is None or self.atom2 is None:
9595
return QLineF(0, 0, 0, 0)
9696
try:
97-
p2 = self.mapFromItem(self.atom2, 0, 0)
98-
return QLineF(QPointF(0, 0), p2)
99-
except (RuntimeError, TypeError):
100-
# Handle case where atoms are deleted from scene
97+
# Use pos() directly - assuming items are in scene coords (no parent)
98+
# This is robust and efficient.
99+
p1 = self.atom1.pos()
100+
p2 = self.atom2.pos()
101+
return QLineF(QPointF(0, 0), p2 - p1)
102+
except Exception:
101103
return QLineF(0, 0, 0, 0)
102104

103105
def boundingRect(self):
@@ -120,12 +122,33 @@ def boundingRect(self):
120122
except Exception:
121123
bond_offset = globals().get('BOND_OFFSET', 3.5)
122124

123-
extra = (getattr(self, 'order', 1) - 1) * bond_offset + 20
125+
# Get dynamic wedge width
126+
wedge_width = 6.0
127+
try:
128+
if self.scene() and self.scene().views():
129+
win = self.scene().views()[0].window()
130+
if win and hasattr(win, 'settings'):
131+
wedge_width = win.settings.get('bond_wedge_width_2d', 6.0)
132+
except Exception:
133+
pass
134+
135+
extra = (getattr(self, 'order', 1) - 1) * bond_offset + 50 + wedge_width
124136
rect = QRectF(line.p1(), line.p2()).normalized().adjusted(-extra, -extra, extra, extra)
125137

126138
# E/Zラベルの描画範囲も考慮して拡張(QFontMetricsFで正確に)
127139
if self.order == 2 and self.stereo in [3, 4]:
128-
font = QFont(FONT_FAMILY, FONT_SIZE_LARGE, FONT_WEIGHT_BOLD)
140+
font_size = 20
141+
font_family = FONT_FAMILY
142+
try:
143+
if self.scene() and self.scene().views():
144+
win = self.scene().views()[0].window()
145+
if win and hasattr(win, 'settings'):
146+
font_size = win.settings.get('atom_font_size_2d', 20)
147+
font_family = win.settings.get('atom_font_family_2d', FONT_FAMILY)
148+
except Exception:
149+
pass
150+
151+
font = QFont(font_family, font_size, FONT_WEIGHT_BOLD)
129152
font.setItalic(True)
130153
text = "Z" if self.stereo == 3 else "E"
131154
fm = QFontMetricsF(font)
@@ -383,7 +406,18 @@ def paint(self, painter, option, widget):
383406
painter.save() # 現在の描画設定を保存
384407

385408
# --- ラベルの設定 ---
386-
font = QFont(FONT_FAMILY, FONT_SIZE_LARGE, FONT_WEIGHT_BOLD)
409+
font_size = 20
410+
font_family = FONT_FAMILY
411+
try:
412+
if self.scene() and self.scene().views():
413+
win = self.scene().views()[0].window()
414+
if win and hasattr(win, 'settings'):
415+
font_size = win.settings.get('atom_font_size_2d', 20)
416+
font_family = win.settings.get('atom_font_family_2d', FONT_FAMILY)
417+
except Exception:
418+
pass
419+
420+
font = QFont(font_family, font_size, FONT_WEIGHT_BOLD)
387421
font.setItalic(True)
388422
text_color = QColor("gray")
389423
# 輪郭の色を背景色と同じにする(scene()がNoneのときは安全なフォールバックを使う)
@@ -442,9 +476,10 @@ def paint(self, painter, option, widget):
442476

443477

444478

445-
def update_position(self):
479+
def update_position(self, notify=True):
446480
try:
447-
self.prepareGeometryChange()
481+
if notify:
482+
self.prepareGeometryChange()
448483
if self.atom1:
449484
self.setPos(self.atom1.pos())
450485
self.update()

moleditpy-linux/src/moleditpy_linux/modules/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from rdkit import Chem
1717

1818
#Version
19-
VERSION = '2.4.5'
19+
VERSION = '2.4.6'
2020

2121
ATOM_RADIUS = 18
2222
BOND_OFFSET = 3.5

moleditpy-linux/src/moleditpy_linux/modules/settings_dialog.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
from PyQt6.QtWidgets import (
1414
QDialog, QVBoxLayout, QTabWidget, QWidget, QFormLayout, QPushButton, QHBoxLayout,
15-
QCheckBox, QComboBox, QLabel, QColorDialog, QSlider, QFrame, QMessageBox
15+
QCheckBox, QComboBox, QLabel, QColorDialog, QSlider, QFrame, QMessageBox, QFontComboBox
1616
)
1717
from PyQt6.QtWidgets import QApplication
1818
from PyQt6.QtCore import Qt
19-
from PyQt6.QtGui import QColor
19+
from PyQt6.QtGui import QColor, QFont
2020
try:
2121
from .constants import CPK_COLORS
2222
except Exception:
@@ -101,6 +101,7 @@ def __init__(self, current_settings, parent=None):
101101
'bond_cap_style_2d': 'Round',
102102
'bond_wedge_width_2d': 6.0,
103103
'bond_dash_count_2d': 8,
104+
'atom_font_family_2d': 'Arial',
104105
}
105106

106107
# --- 選択された色を管理する専用のインスタンス変数 ---
@@ -275,6 +276,13 @@ def create_2d_settings_tab(self):
275276
# --- Atom Settings ---
276277
form_layout.addRow(QLabel("<b>Atom Settings</b>"))
277278

279+
# Font Family
280+
self.atom_font_family_2d_combo = QFontComboBox()
281+
self.atom_font_family_2d_combo.setEditable(False) # Force selection from list
282+
# Filter mostly for scalable fonts if desired, but default is usually fine
283+
self.atom_font_family_2d_combo.setFontFilters(QFontComboBox.FontFilter.ScalableFonts)
284+
form_layout.addRow("Atom Label Font Family:", self.atom_font_family_2d_combo)
285+
278286
# Font Size
279287
self.atom_font_size_2d_slider = QSlider(Qt.Orientation.Horizontal)
280288
self.atom_font_size_2d_slider.setRange(8, 72)
@@ -813,10 +821,10 @@ def reset_current_tab(self):
813821
'background_color_2d': self.default_settings['background_color_2d'],
814822
'bond_color_2d': self.default_settings['bond_color_2d'],
815823
'atom_use_bond_color_2d': self.default_settings['atom_use_bond_color_2d'],
816-
'atom_use_bond_color_2d': self.default_settings['atom_use_bond_color_2d'],
817824
'bond_cap_style_2d': self.default_settings['bond_cap_style_2d'],
818825
'bond_wedge_width_2d': self.default_settings['bond_wedge_width_2d'],
819-
'bond_dash_count_2d': self.default_settings['bond_dash_count_2d']
826+
'bond_dash_count_2d': self.default_settings['bond_dash_count_2d'],
827+
'atom_font_family_2d': self.default_settings['atom_font_family_2d']
820828
},
821829
"3D Scene": {
822830
'background_color': self.default_settings['background_color'],
@@ -1258,6 +1266,7 @@ def get_settings(self):
12581266
'bond_cap_style_2d': self.bond_cap_style_2d_combo.currentText(),
12591267
'bond_wedge_width_2d': self.bond_wedge_width_2d_slider.value() / 10.0,
12601268
'bond_dash_count_2d': self.bond_dash_count_2d_slider.value(),
1269+
'atom_font_family_2d': self.atom_font_family_2d_combo.currentFont().family(),
12611270
}
12621271

12631272
def pick_bs_bond_color(self):
@@ -1519,6 +1528,10 @@ def update_ui_from_settings(self, settings_dict):
15191528
self.atom_font_size_2d_slider.setValue(int(fs_2d))
15201529
self.atom_font_size_2d_label.setText(str(fs_2d))
15211530

1531+
# Load Font Family
1532+
font_family = settings_dict.get('atom_font_family_2d', self.default_settings['atom_font_family_2d'])
1533+
self.atom_font_family_2d_combo.setCurrentFont(QFont(font_family))
1534+
15221535
self.atom_use_bond_color_2d_checkbox.setChecked(settings_dict.get('atom_use_bond_color_2d', self.default_settings.get('atom_use_bond_color_2d', False)))
15231536

15241537
self.current_bg_color_2d = settings_dict.get('background_color_2d', self.default_settings['background_color_2d'])

0 commit comments

Comments
 (0)