File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 2222
2323class MainWindow (QMainWindow ,MainMixin ):
2424
25- name = 'CQ GUI '
25+ name = 'CQ-Editor '
2626 org = 'CadQuery'
2727
2828 def __init__ (self ,parent = None ):
@@ -258,6 +258,8 @@ def prepare_actions(self):
258258 # trigger re-render when file is modified externally or saved
259259 self .components ['editor' ].triggerRerender \
260260 .connect (self .components ['debugger' ].render )
261+ self .components ['editor' ].sigFilenameChanged \
262+ .connect (self .handle_filename_change )
261263
262264 def prepare_console (self ):
263265
@@ -325,6 +327,11 @@ def cq_documentation(self):
325327
326328 open_url ('https://cadquery.readthedocs.io/en/latest/' )
327329
330+ def handle_filename_change (self , fname ):
331+
332+ new_title = fname if fname else "*"
333+ self .setWindowTitle (f"{ self .name } : { new_title } " )
334+
328335if __name__ == "__main__" :
329336
330337 pass
Original file line number Diff line number Diff line change @@ -1229,3 +1229,27 @@ def test_render_ais(main):
12291229 console .execute ('show(ais)' )
12301230 qtbot .wait (500 )
12311231 assert (obj_tree_comp .CQ .childCount () == 2 )
1232+
1233+ def test_window_title (monkeypatch , main ):
1234+
1235+ fname = 'test_window_title.py'
1236+
1237+ with open (fname , 'w' ) as f :
1238+ f .write (code )
1239+
1240+ qtbot , win = main
1241+
1242+ #monkeypatch QFileDialog methods
1243+ def filename (* args , ** kwargs ):
1244+ return fname , None
1245+
1246+ monkeypatch .setattr (QFileDialog , 'getOpenFileName' ,
1247+ staticmethod (filename ))
1248+
1249+ win .components ["editor" ].open ()
1250+ assert (win .windowTitle ().endswith (fname ))
1251+
1252+ # handle a new file
1253+ win .components ["editor" ].new ()
1254+ # I don't really care what the title is, as long as it's not a filename
1255+ assert (not win .windowTitle ().endswith ('.py' ))
You can’t perform that action at this time.
0 commit comments