From f7e1354ae563ae6c475ee2e18764127e58073d2b Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Wed, 16 Jan 2019 13:04:51 +0100 Subject: [PATCH] Add Qt for Python templates and better support QtCreator: * Add new icons * Add support for `.pyproject` files, * Set `.pyproject` as default, but keep compatibility with `.pyqtc` * `.pyproject` is a JSON file, while `.pyqtc` is a plain-text. Python class: * Add option to ask if use PySide2 or PyQt5 * Remove the old import try-except structure * Remove iconText and add icon option * Remove shebang * Add utf-8 support Python file: * Remove code * Remove iconText and add icon option * Remove shebang * Add utf-8 support Qt for Python - Empty * Add file with basic statements to execute a QApplication Qt for Python - Window * Add file with basic statements to execute a QApplication, which contains a QMainWindow Task-number: QTCREATORBUG-21824 Change-Id: I4adb3ab6b179f084c7b674a6d4f643445fe24929 Reviewed-by: hjk Reviewed-by: Alessandro Portale Reviewed-by: Eike Ziller --- .../templates/wizards/classes/python/file.py | 46 +++-- .../wizards/classes/python/wizard.json | 11 +- .../templates/wizards/files/python/file.py | 6 +- .../templates/wizards/files/python/icon.png | Bin 0 -> 606 bytes .../wizards/files/python/icon@2x.png | Bin 0 -> 989 bytes .../wizards/files/python/wizard.json | 2 +- .../qtforpythonapplication/empty/icon.png | Bin 0 -> 728 bytes .../qtforpythonapplication/empty/icon@2x.png | Bin 0 -> 1284 bytes .../qtforpythonapplication/empty/wizard.json | 51 ++++++ .../qtforpythonapplication/main.pyproject | 3 + .../qtforpythonapplication/main_empty.py | 9 + .../qtforpythonapplication/main_mainwindow.py | 15 ++ .../mainwindow/icon.png | Bin 0 -> 855 bytes .../mainwindow/icon@2x.png | Bin 0 -> 1528 bytes .../mainwindow/wizard.json | 51 ++++++ src/plugins/pythoneditor/PythonEditor.json.in | 1 + .../pythoneditor/pythoneditorplugin.cpp | 45 ++++- src/tools/icons/qtcreatoricons.svg | 173 ++++++++++++++++-- tests/manual/debugger/python/README.md | 2 +- 19 files changed, 371 insertions(+), 44 deletions(-) create mode 100644 share/qtcreator/templates/wizards/files/python/icon.png create mode 100644 share/qtcreator/templates/wizards/files/python/icon@2x.png create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/empty/icon.png create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/empty/icon@2x.png create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/empty/wizard.json create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/main.pyproject create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_empty.py create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_mainwindow.py create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/mainwindow/icon.png create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/mainwindow/icon@2x.png create mode 100644 share/qtcreator/templates/wizards/projects/qtforpythonapplication/mainwindow/wizard.json diff --git a/share/qtcreator/templates/wizards/classes/python/file.py b/share/qtcreator/templates/wizards/classes/python/file.py index 32be237c7a1..adcbc1ed2d0 100644 --- a/share/qtcreator/templates/wizards/classes/python/file.py +++ b/share/qtcreator/templates/wizards/classes/python/file.py @@ -1,30 +1,26 @@ -# -*- coding: utf-8 -*- - -@if '%{Imports}' -try: -@if '%{ImportQtCore}' - from PySide import QtCore -@endif -@if '%{ImportQtWidgets}' - from PySide import QtWidgets -@endif -@if '%{ImportQtQuick}' - from PySide import QtQuick -@endif -except: -@if '%{ImportQtCore}' - from PyQt5.QtCore import pyqtSlot as Slot - from PyQt5 import QtCore -@endif -@if '%{ImportQtWidgets}' - from PyQt5 import QtWidgets -@endif -@if '%{ImportQtQuick}' - from PyQt5 import QtQuick +# This Python file uses the following encoding: utf-8 +@if '%{Module}' === 'PySide2' + @if '%{ImportQtCore}' +from PySide2 import QtCore + @endif + @if '%{ImportQtWidgets}' +from PySide2 import QtWidgets + @endif + @if '%{ImportQtQuick}' +from PySide2 import QtQuick + @endif +@else + @if '%{ImportQtCore}' +from PyQt5 import QtCore + @endif + @if '%{ImportQtWidgets}' +from PyQt5 import QtWidgets + @endif + @if '%{ImportQtQuick}' +from PyQt5 import QtQuick + @endif @endif - -@endif @if '%{Base}' class %{Class}(%{Base}): @else diff --git a/share/qtcreator/templates/wizards/classes/python/wizard.json b/share/qtcreator/templates/wizards/classes/python/wizard.json index 64c8d8d435a..6d1d72c63bb 100644 --- a/share/qtcreator/templates/wizards/classes/python/wizard.json +++ b/share/qtcreator/templates/wizards/classes/python/wizard.json @@ -6,7 +6,7 @@ "trDescription": "Creates new Python class file.", "trDisplayName": "Python Class", "trDisplayCategory": "Python", - "iconText": "py", + "icon": "../../files/python/icon.png", "enabled": "%{JS: [ %{Plugins} ].indexOf('PythonEditor') >= 0}", "options": @@ -30,6 +30,15 @@ "type": "LineEdit", "data": { "validator": "^(?:[^\\d\\W]\\w*|)$" } }, + { + "name": "Module", + "trDisplayName": "Python module:", + "type": "ComboBox", + "data": + { + "items": ["PySide2", "PyQt5"] + } + }, { "name": "BaseCB", "trDisplayName": "Base class:", diff --git a/share/qtcreator/templates/wizards/files/python/file.py b/share/qtcreator/templates/wizards/files/python/file.py index faa18be5bbf..003f8414973 100644 --- a/share/qtcreator/templates/wizards/files/python/file.py +++ b/share/qtcreator/templates/wizards/files/python/file.py @@ -1,2 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +# This Python file uses the following encoding: utf-8 + +# if__name__ == "__main__": +# pass diff --git a/share/qtcreator/templates/wizards/files/python/icon.png b/share/qtcreator/templates/wizards/files/python/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8ab694fe7af2e26ee39f28d5c132b63fb74c542a GIT binary patch literal 606 zcmeAS@N?(olHy`uVBq!ia0y~yU@!n-4rT@hhJ-tuTNxM_{sj1hxH2#>G&D41lr*Fj zwB{5vWEV7K=YvQqhfr(BFdN4(8|Mgn*GLDqC`Y$wM~@g6&sgt(WS^i^-=H-AkhGxi ztl)_3kjR|SsGP{Sf|#VD%)Gknf`**J#{A;ug3^|fs*aY9sjZ#UTDzvVbxm*Yp3%`W zqoZeL-^96nljikLo;P9Yf{9b+Pn^17;?#wcr!Aa3W6_l9i>J<5GGq3#nX{M8U$kb? z()Ej$tzWr%%j$L8H*VRpY3rWN+xBkRzHi(1{o8jQJb38j!NVsH9XWOM_}OD8&K^H; z?)=58=PzEnbou(_t2eLTxPAS`of|jr-nxDN_MQ88?moPG@8R8hkM7-nbpOF)(}_!4 z7#J8hN`m}?8JNT*FJHO-S6i4-o`Hdp)6>N<#N+tWE7yY#8;G<#ybvzn^qy%GpGC_( z>y~@bOTO2OuWPauzG>B@{b2vS{Fo<&3qP#ART6erw$Y({>+XYVN>fX2*7oL1P%LVQ ze!{r?1gqXeewjneQLX%2IP@>1-j!tA@@`^-$=}xx((0CkNX^?V-n_DqmBBd4AoDoG z0u8n-Cq{?-6VB4C8iG6KymK~IW_Z8YBg^ILE`FKi-~P%AipSX`Xy4>tb8pg~4-KXa z&hGx#qJCFxb@_CLnU8VKoUor)ce2}vHEy@K`T5rOsB-qi;NMT%o;+CeY|p0R^rZ({ zYVL_ndcxK#aztfklKIhuewCg3boVWN{x@n*gmuM_@clF6x&Hj+Vfn&Y7uA)1R8rcA Qfq{X+)78&qol`;+00Ac?SpWb4 literal 0 HcmV?d00001 diff --git a/share/qtcreator/templates/wizards/files/python/icon@2x.png b/share/qtcreator/templates/wizards/files/python/icon@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..8d1f275186061135b0f40f2eea9918927f54055c GIT binary patch literal 989 zcmeAS@N?(olHy`uVBq!ia0y~yU`POA4rT@hhO2JvTnr41B>_Gmt_%zep`oj?3L10r z8?p;P$jTwq+A++=G0es(+{QV=);ZkHIl|5*($PKI(IdvmBi7j?#>Fen)jQ57FvTY* z)i)^3KQuicG$Sx9BQQKOG%6<|CO;xJKRTf>HmM{btt>IMEG?@#E3Xb@eqm#7QDc5_ zQ(;+aX=O)gRYzHMXL)s3MNL;_ZFf~|cU@C|OUKmKj;XDkQ(HTywRTN!>zdZqHNCxi zdVBYbj-DAEJu|y{XLa?>>X|U7cfy>$N%Q(A&F`N)uYdCV2~!tLoVsxG^o3KVFPbuA z@wAysr_WkCWA?I{bC=JWvwY6{Rr40Ep1)|#g2ihWE?&EE$+|_$)-PVRe#x>8OO|g~ zx^mO9m7A8Y+_Zf4mKCeFtX{iy?fUI&H|$uuap&eOdpB?0yKTq*Z95KZ+j(I7&VxJm z9NN48*uDeD_8mOF|G@G62ag{)cIMRSi>J?CI(zQ&`HNRCU%qkm+O4bCZ(qN0`}W-j zckVv8d+*`hdynqje{}!BV>$NSh71f0Y$ZW{!3@liF+cxwU*M}_U|fCNl-?7tE8Gm?j7tG)!q=N@0;vP*iAq!z6Y>Ye8cUliUd<0fs#@i|cef z8;Z{bi?ek&^CmDb&q;o8`|+_=M%`2IuBzWLpW(yyURKQ+%h}^L7OaUaT5#*tn-knE zVMPmm$T?IqOqtBQhI@fA!@A4N*P4HaF+91h5`&4X*ERm`VMJ{37qbv9XSch)QWySU6#W~@JFcQ9RWuA<6^gUtU96!2_lV7avY@7~SUY(JXrcHjHq;8TA- z|4Z54pyJ7fAI#b|-&Fejz=e4;pQOM?o;aU8YX`m^p0ahu-cM9m=g1{bmwLgu>+M(H z*>V+P467NWzZ^(l&|zNleUg3i(hI-Vue-VU$$^U}J%4-Dm)zmr?|%9v%eiIl`ODdU zx7__+_3Ur?=lMAd%n}C}*bXp?7&h1y7=Gq2Y-aIJH`uv{fq{X+)78&qol`;+01H6T Av;Y7A literal 0 HcmV?d00001 diff --git a/share/qtcreator/templates/wizards/files/python/wizard.json b/share/qtcreator/templates/wizards/files/python/wizard.json index 32b720f3d40..d4a6cfd0126 100644 --- a/share/qtcreator/templates/wizards/files/python/wizard.json +++ b/share/qtcreator/templates/wizards/files/python/wizard.json @@ -6,7 +6,7 @@ "trDescription": "Creates an empty Python script file using UTF-8 charset.", "trDisplayName": "Python File", "trDisplayCategory": "Python", - "iconText": "py", + "icon": "icon.png", "enabled": "%{JS: [ %{Plugins} ].indexOf('PythonEditor') >= 0}", "pages" : diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/empty/icon.png b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/empty/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..483f71196d3a58d0ed21b675e3198a15b7880949 GIT binary patch literal 728 zcmeAS@N?(olHy`uVBq!ia0y~yU@!n-4rT@hhJ-tuTNxM_bpm`sTp1V`8X6kf+ov^m zPR%K7%qnbb>6n_G-_X(tBD3-vvI`noI;OUCOvx?)v8^0JtsTQ`9K&p#BOKhK9NnXx z++&q6YPzfHdKz0Nw{%Qx?VQ%uHNCxiMn})g&fb}wy|cRdW=)*3VA8aOQ)Vol zI&;bNSxaZkSvG6#ig^oHFIco@!Q!=xmu*<`-_-x^?^UlP}-?_<3mKrkxB7jNYCujv*f2ZzqL^A2N_|V2*G(?I9}o{h9?+ zSJd}oy6nJWb&+W9S>_EHYHpc6(*tcJ{ZFTy7Wp9Cj*^-2FO9~7Q zvGpqG%V->a)?)UsVew}dL9TVjZf|VX6Uf+m+n*eGFi_#b-rE;+f7XVXO^;tVQC;@K%%2y%b4;~1)V$u}lX!d1 zhCR=882+vG-<_4}ceh%Aujx;r!in`wJiG?Rx9+DK8wl2T8f*M~92q-FV`7_({Yw_7 jk0L3ROCGIg73fq zIW?;QB$5p#TRNt;bWF_wv$Me}TRNsfq~Ih(O-siVD~C{P$1oemFdL_ETjvNnmk4{8 zNPE{PCyy9s&sZ0)I9IPYH=hJ|-vs}V^nlQez_84qh^*jhzo%kUI+-a|;`DiyHHbn~KU>%c?soYPu?GyQ}Ma z>zgMwv`lPloz&Dixv6b(bNiH*_9-nLQ(HTywRKHz@1EY#GozztW@qor&fZx){d0OI z%$YEG{=_K@CQV&1Y1+cc(-uvcv3TmtCDUgwoiTga%sIwziFSf@RUinTROw$&|@Kn$VDU*|!y>BwV)7ZmzYXfUYvGvK9nMv#_k9J=_dDC+f(-$^L=`;tC`}(g1 z+$OHBy>ejrRXGPO<}D7^3*$F7TvJgE@Mn1SK;7t5n-GU!L-vPjEOG%%*@bVlw{3ZO zA&tqGQKS?o^pU~_5VGaWB=c&zx&EPvHn2&gqYuQ>~9Qz^E-Yz z`ZSnhva#KMM$ZlBZhBXAeaQT3?aK0SCudE&H_L*%-=!Y3KJ2}=)!2t&-p}}yJq7of zIR2iEXL_Tw=fdXXs~ig+Ho7;ib3L+`Mdd-5(v73%oDZxycr#)?-|7g^fK z!usGU|IFhN{CpMPoHyTHTY7Y>J;R>g54Z4^ESvYUiP`d(VivP3L+r!_*$-Zn|J!nd zb-V26`<3pyg#-%f>TC>N*k$_PxNpU0@jdXkKHv9c&3nxk>3U@EtoZ!V`r{m(hW%U{ zdKvyOc?X=6;d{8*^n3Khq?J0~yJzv`tv= 0}", + "featuresRequired": [ "QtSupport.Wizards.FeatureQt.5.6" ], + + "options": + [ + { "key": "MainPyFileName", "value": "main.py" }, + { "key": "PyProjectFile", "value": "main.pyproject" } + ], + + "pages": + [ + { + "trDisplayName": "Project Location", + "trShortTitle": "Location", + "typeId": "Project" + }, + { + "trDisplayName": "Project Management", + "trShortTitle": "Summary", + "typeId": "Summary" + } + ], + "generators": + [ + { + "typeId": "File", + "data": + [ + { + "source": "../main.pyproject", + "target": "%{PyProjectFile}", + "openAsProject": true + }, + { + "source": "../main_empty.py", + "target": "%{MainPyFileName}", + "openInEditor": true + } + ] + } + ] +} diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main.pyproject b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main.pyproject new file mode 100644 index 00000000000..cc7a74a3468 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main.pyproject @@ -0,0 +1,3 @@ +{ + "files": ["main.py"] +} diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_empty.py b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_empty.py new file mode 100644 index 00000000000..6cb021403b9 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_empty.py @@ -0,0 +1,9 @@ +# This Python file uses the following encoding: utf-8 +import sys +from PySide2.QtWidgets import QApplication + + +if __name__ == "__main__": + app = QApplication([]) + # ... + sys.exit(app.exec_()) diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_mainwindow.py b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_mainwindow.py new file mode 100644 index 00000000000..fa1f92c7477 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_mainwindow.py @@ -0,0 +1,15 @@ +# This Python file uses the following encoding: utf-8 +import sys +from PySide2.QtWidgets import QApplication, QMainWindow + + +class MainWindow(QMainWindow): + def __init__(self): + QMainWindow.__init__(self) + + +if __name__ == "__main__": + app = QApplication([]) + window = MainWindow() + window.show() + sys.exit(app.exec_()) diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/mainwindow/icon.png b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/mainwindow/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ba97ffd66209b8e35cabe4ab8b851aad85e092a1 GIT binary patch literal 855 zcmeAS@N?(olHy`uVBq!ia0y~yU@!n-4rT@hhJ-tuTNxM_s{(vNTp1V`8X6kf+ov^m zPR%K7%qnbb>6n_G-_X(tBD3-vvI`noI;OUCOvx?)v8^0JtsTQ`9K&p!!fl-+>|7%3 zU85Y`qn+GioIGNjJ!9Rx<9z~Ce1p>hLNfxwG6KUggTga|!n1-SvO^+sLLzg+qI1Jz z@*-mMBjXBUlS<-KN)uAclG4kQ(ks%kt21(IGxF-P^6Rq;8gdF73QJo`D?7@nIxA|r ztLl0hTPHWQPHyR#+S)m-t!sLF_l%D2867<{J9}q#_Ri|+o7FpE&cvw;CQVy7dD@~W z(-%*jxn%mRr8DL%n>BaE+y$!^ELyX0$-2c$*DqeSVfm`ftJZ8?vu^vE_1pLCJG$?{ z@q>p>9y)UB@X^ypkDWPs{Os|Q=TD!xc;?*Y%U5n(y>{!yt-CjG-Mf9~{++uI@7;fN z|H0$OkDonx`uy4RmoHwve);On>(_7Jym|NT-G>h!K7RQ4>Ep*wA3uHm^y%}LFJHfY z{r3I)4>0)o^XIQ$zkdDx{rlX{S_K9M27!_wzhDL?CC&W8ODROH`ICpPAFIx^$6!Yja0TuVay5;1b3;F1#F3#({Gfg*t=w zq}lgZ@6B}SWK&RLVOLnhu;7BY0@q)TK5H&xWA0n$r#kw!@-gV1THtkxQ6W}RCHxh` z0&QkNLD>eO8|%GI!(Rk5oOflkt}o`#>pU^xJX;Rine;t7c0P||iPgWBaL#_dZS9FO zyOkVXFIJtwIAME{y3(f|=4Z~lR$`cyxAuTh!`ZElX14_x8*X`X7tCd};r;Ra=L6;i zpROdW<+l8=^Y3Tn^=uCJ8ozcMJAS`1v!>zC%(v{-0voDdJUy{%o3+&4GiPl6bryyD z2N`6uv(1?4o_dHOTq#$hZZqTOGiPkfUe>Rgdrx_{^&Oq6U%zd<#T8}qm*z)pjBjN5 z7nWX{*%=u5_j~u81+Il2u9<=#7oIupo)J~i^Q*?^$N&4`E6Y#Lo!8aU;{Kn3fq}u( L)z4*}Q$iB}R<<*^)wcXYAy)_MejjfZK zS|>NPO>SFr(9+qHN$|D<^nCeNQVb>XCG3nx!oG-djtDKi#Now0b@%q7!jEuB7l>5MtcX3kkQYwn6U z^H}yLJ2iZ9DdF+i_sWu0uQb9Nx9(@UFc__8mBW z;LwREvYW;?dn|ANHeC6u3`;VVI{rKtI_n)&=v>!4sFiUy5IEG~0dwcVF^koMI zwhs+ESlKNK6`G22MFR!5cL=jotN3`A?l)olu`|$cp&;0E!(FBz89t1}ywG`K_@@2pg1 zOmNi|oUnvhruDsG!Fl$EDgG)BHtTH5&h4zKU}RLE#bB_zi$UV8w(rirfj?8Ymadq8 zTbDWEQugBmAuH?qSM5Dk9P{dVOcPH7r`%x&EvcPiTu zL(gILc-Dp+Ld_1AQsLa(B@NwK3>IBIjE8&*XE1Dk!O(BQutC;%oA}fl0t+s`|F?*h z;Y7BI>tK-u;|2)F&|A6#C%JUm)W1k*nX6aeG=_1+T$h&8k{ob=IOMdDp)tO&3ep?-U{Y zJeDn=vr*QlK=e=&?+1rJcV6vniE&Dp&m-bgakzK4aQ>cdqlfI01(AmTU9ZQqZ}?ut z+i`xi(w?TQuR(f;na;1PQLZnoSr?Plx`*@qva99(&z~2qyThFBW&daP|6@UHFOD%q zarHcyb#|9a%`-FmDbnX$OzJN^yL!^|-`CAzXrX!x?C>_x8I|AxM6>%+p= 0}", + "featuresRequired": [ "QtSupport.Wizards.FeatureQt.5.6" ], + + "options": + [ + { "key": "MainPyFileName", "value": "main.py" }, + { "key": "PyProjectFile", "value": "main.pyproject" } + ], + + "pages": + [ + { + "trDisplayName": "Project Location", + "trShortTitle": "Location", + "typeId": "Project" + }, + { + "trDisplayName": "Project Management", + "trShortTitle": "Summary", + "typeId": "Summary" + } + ], + "generators": + [ + { + "typeId": "File", + "data": + [ + { + "source": "../main.pyproject", + "target": "%{PyProjectFile}", + "openAsProject": true + }, + { + "source": "../main_mainwindow.py", + "target": "%{MainPyFileName}", + "openInEditor": true + } + ] + } + ] +} diff --git a/src/plugins/pythoneditor/PythonEditor.json.in b/src/plugins/pythoneditor/PythonEditor.json.in index b4505d55465..89269328b3d 100644 --- a/src/plugins/pythoneditor/PythonEditor.json.in +++ b/src/plugins/pythoneditor/PythonEditor.json.in @@ -28,6 +28,7 @@ \" \", \" \", \" Qt Creator Python project file\", + \" \", \" \", \" \", \"\" diff --git a/src/plugins/pythoneditor/pythoneditorplugin.cpp b/src/plugins/pythoneditor/pythoneditorplugin.cpp index 64722ef7496..dfd9c6a50ea 100644 --- a/src/plugins/pythoneditor/pythoneditorplugin.cpp +++ b/src/plugins/pythoneditor/pythoneditorplugin.cpp @@ -59,6 +59,10 @@ #include #include #include +#include +#include +#include +#include using namespace Core; using namespace ProjectExplorer; @@ -340,6 +344,35 @@ static QStringList readLines(const Utils::FileName &projectFile) return lines; } +static QStringList readLinesJson(const Utils::FileName &projectFile) +{ + const QString projectFileName = projectFile.fileName(); + QStringList lines = { projectFileName }; + + QFile file(projectFile.toString()); + if (!file.open(QFile::ReadOnly)) + return lines; + const QByteArray content = file.readAll(); + + // This assumes te project file is formed with only one field called + // 'files' that has a list associated of the files to include in the project. + if (!content.isEmpty()) { + const QJsonDocument doc = QJsonDocument::fromJson(content); + const QJsonObject obj = doc.object(); + if (obj.contains("files")) { + QJsonValue files = obj.value("files"); + QJsonArray files_array = files.toArray(); + QSet visited; + for (const auto &file : files_array) + visited.insert(file.toString()); + + lines.append(visited.toList()); + } + } + + return lines; +} + bool PythonProject::saveRawFileList(const QStringList &rawFileList) { bool result = saveRawList(rawFileList, projectFilePath().toString()); @@ -418,7 +451,15 @@ bool PythonProject::renameFile(const QString &filePath, const QString &newFilePa void PythonProject::parseProject() { m_rawListEntries.clear(); - m_rawFileList = readLines(projectFilePath()); + const Utils::FileName filePath = projectFilePath(); + // The PySide project file is JSON based + if (filePath.endsWith(".pyproject")) + m_rawFileList = readLinesJson(filePath); + // To keep compatibility with PyQt we keep the compatibility with plain + // text files as project files. + else if (filePath.endsWith(".pyqtc")) + m_rawFileList = readLines(filePath); + m_files = processEntries(m_rawFileList, &m_rawListEntries); } @@ -449,7 +490,7 @@ void PythonProject::refresh(Target *target) auto newRoot = std::make_unique(this); for (const QString &f : m_files) { const QString displayName = baseDir.relativeFilePath(f); - FileType fileType = f.endsWith(".pyqtc") ? FileType::Project : FileType::Source; + FileType fileType = f.endsWith(".pyproject") || f.endsWith(".pyqtc") ? FileType::Project : FileType::Source; newRoot->addNestedNode(std::make_unique(FileName::fromString(f), displayName, fileType)); if (fileType == FileType::Source) { diff --git a/src/tools/icons/qtcreatoricons.svg b/src/tools/icons/qtcreatoricons.svg index 24f73e097e0..86fcbb48d00 100644 --- a/src/tools/icons/qtcreatoricons.svg +++ b/src/tools/icons/qtcreatoricons.svg @@ -2645,18 +2645,21 @@ id="path5662-0" inkscape:connector-curvature="0" sodipodi:nodetypes="cccccccc" /> - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/manual/debugger/python/README.md b/tests/manual/debugger/python/README.md index 0ed136ee403..31b9e70a18e 100644 --- a/tests/manual/debugger/python/README.md +++ b/tests/manual/debugger/python/README.md @@ -1,4 +1,4 @@ -- qtcreator -load PythonEditor ./python.pyqtc +- qtcreator -load PythonEditor ./python.pyproject (or ./python.pyqtc) - Switch active runconfiguration to main.py -