Pyside2 - How to create notes/comments and display them corresponding to selected item from list
-
wrote on 24 Nov 2019, 14:57 last edited by younglegend
I have been creating a tool that displays multiple file versions from a folder in a QListWidget.
I would like to save notes/comments for each version and display them using QTextEdit corresponding to the item in the list that i click. Like a version manger. How shall i go about this? Kinda stuck... Thank you!
import sys from PySide2 import QtCore, QtGui, QtWidgets class Dialog(QtWidgets.QDialog): NumList = 20 def __init__(self): super(Dialog, self).__init__() self.createHorizontalGroupBox() self.createVerticalGroupBox() mainLayout = QtWidgets.QVBoxLayout() mainLayout.addWidget(self.verticalGroupBox) mainLayout.addWidget(self.horizontalGroupBox) self.setWindowTitle("File Manager v1.0") self.setLayout(mainLayout) def createVerticalGroupBox(self): self.verticalGroupBox = QtWidgets.QGroupBox("List Files") layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(25,25,25,25) layout.setSpacing(7) file_listbox = QtWidgets.QListWidget() for i in range(Dialog.NumList): file_list = ("File_v%d" % (i+1)) file_listbox.addItem(file_list) layout.addWidget(file_listbox) self.verticalGroupBox.setLayout(layout) def createHorizontalGroupBox(self): self.horizontalGroupBox = QtWidgets.QGroupBox("Notes") layoutB = QtWidgets.QGridLayout() layoutB.setContentsMargins(25, 25, 25, 25) layoutB.setSpacing(7) layoutB.setColumnStretch(0,5) self.notes_editor = QtWidgets.QTextEdit() self.notes_editor.setPlainText("Test..") layoutB.addWidget(self.notes_editor,0, 2, 4, 1) self.edit_button = QtWidgets.QPushButton("Edit..") layoutB.addWidget(self.edit_button,0,5) self.save_button = QtWidgets.QPushButton("Save") layoutB.addWidget(self.save_button,1,5) self.horizontalGroupBox.setLayout(layoutB) app = QtWidgets.QApplication(sys.argv) dialog = Dialog() sys.exit(dialog.exec_()) -
Hi and welcome to devnet,
How are you storing these different file versions ?
-
wrote on 24 Nov 2019, 23:07 last edited by
@SGaist Cheers!
If i understood you right, i'm storing these versions as fileName_v001, fileName_v002 and so on... -
Then this might come as a silly question but since there's VCS like
git, are you sure you are using the tool ?Anyway, for your current system, you could have a second file following the name schema with a different extension for the notes. Or have them in a SQLite database.
-
Then this might come as a silly question but since there's VCS like
git, are you sure you are using the tool ?Anyway, for your current system, you could have a second file following the name schema with a different extension for the notes. Or have them in a SQLite database.
wrote on 25 Nov 2019, 00:02 last edited by@SGaist That's where i'm stuck, i have no idea how to implement it with PySide. I like to manually type my tools using examples/forum guides as reference. But examples for vcs with Qt is something i never came across with google search. Which is surprising...
-
@SGaist That's where i'm stuck, i have no idea how to implement it with PySide. I like to manually type my tools using examples/forum guides as reference. But examples for vcs with Qt is something i never came across with google search. Which is surprising...
@younglegend said in Pyside2 - How to create notes/comments and display them corresponding to selected item from list:
But examples for vcs with Qt is something i never came across with google search
Well, it does not have anything to do with Qt actually. Qt is a C++ framework, so you write code using Qt as framework. In your case it's Python code, but this does not change anything. Just use a VCS as you could do with any project.
-
I have been creating a tool that displays multiple file versions from a folder in a QListWidget.
I would like to save notes/comments for each version and display them using QTextEdit corresponding to the item in the list that i click. Like a version manger. How shall i go about this? Kinda stuck... Thank you!
import sys from PySide2 import QtCore, QtGui, QtWidgets class Dialog(QtWidgets.QDialog): NumList = 20 def __init__(self): super(Dialog, self).__init__() self.createHorizontalGroupBox() self.createVerticalGroupBox() mainLayout = QtWidgets.QVBoxLayout() mainLayout.addWidget(self.verticalGroupBox) mainLayout.addWidget(self.horizontalGroupBox) self.setWindowTitle("File Manager v1.0") self.setLayout(mainLayout) def createVerticalGroupBox(self): self.verticalGroupBox = QtWidgets.QGroupBox("List Files") layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(25,25,25,25) layout.setSpacing(7) file_listbox = QtWidgets.QListWidget() for i in range(Dialog.NumList): file_list = ("File_v%d" % (i+1)) file_listbox.addItem(file_list) layout.addWidget(file_listbox) self.verticalGroupBox.setLayout(layout) def createHorizontalGroupBox(self): self.horizontalGroupBox = QtWidgets.QGroupBox("Notes") layoutB = QtWidgets.QGridLayout() layoutB.setContentsMargins(25, 25, 25, 25) layoutB.setSpacing(7) layoutB.setColumnStretch(0,5) self.notes_editor = QtWidgets.QTextEdit() self.notes_editor.setPlainText("Test..") layoutB.addWidget(self.notes_editor,0, 2, 4, 1) self.edit_button = QtWidgets.QPushButton("Edit..") layoutB.addWidget(self.edit_button,0,5) self.save_button = QtWidgets.QPushButton("Save") layoutB.addWidget(self.save_button,1,5) self.horizontalGroupBox.setLayout(layoutB) app = QtWidgets.QApplication(sys.argv) dialog = Dialog() sys.exit(dialog.exec_())wrote on 25 Nov 2019, 08:55 last edited by JonB@younglegend
I'm not suggesting it's a good idea to do it this way, but....If you do not want to go down the road of a VCS tool or a database or similar to hold your file versions and comments (which is a whole different ballgame), but instead stick to no more than the simple file handling you currently have, then:
Your files seem to be named
File_vnumber. So store your comments in similarly named files, so you can pair them against your file version files. Either e.g.File_Comment_vnumber, or create a sub-directory named e.g.Commentsand store the corresponding comments in the same-namedFile_vnumber but in theCommentssub-directory.... -
@younglegend
I'm not suggesting it's a good idea to do it this way, but....If you do not want to go down the road of a VCS tool or a database or similar to hold your file versions and comments (which is a whole different ballgame), but instead stick to no more than the simple file handling you currently have, then:
Your files seem to be named
File_vnumber. So store your comments in similarly named files, so you can pair them against your file version files. Either e.g.File_Comment_vnumber, or create a sub-directory named e.g.Commentsand store the corresponding comments in the same-namedFile_vnumber but in theCommentssub-directory....wrote on 25 Nov 2019, 16:03 last edited by@JonB I would gladly avoid vcs as my tool is fairly simple. But the problem is, being a beginner myself i couldn't find a forum discussion regarding this topic or a similar example i could improvise on.
-
@JonB I would gladly avoid vcs as my tool is fairly simple. But the problem is, being a beginner myself i couldn't find a forum discussion regarding this topic or a similar example i could improvise on.
wrote on 25 Nov 2019, 16:07 last edited by JonB@younglegend
Which is why I have suggested a very simple solution for you just using similarly named files. Whether that's adequate for whatever you are producing only you know. -
wrote on 26 Nov 2019, 01:20 last edited by younglegend
@Denni-0 Thanks for such a nice explanation Denni! It looks cleaner now. And yes, switching to pyside was pretty straight forward.
I actually had a very different kind of layout workflow before. Then i came across some examples that came with pyside packages folder which had everything i need. almost....
-
wrote on 28 Nov 2019, 15:28 last edited by
Bump..! Any help with this please? Still stuck at the same place with little to no progress..
-
Bump..! Any help with this please? Still stuck at the same place with little to no progress..
wrote on 28 Nov 2019, 15:45 last edited by JonB@younglegend
Help with what exactly? I thought you had copied Denni's stuff or whatever? I thought you were going to implemented what i suggested about keeping your comment in a "shadow" file for each file?Just to be 100% clear again. If you want a "proper" program for managing file versions + comments, you don't want to write it yourself, you should use a VCS out there like
gitorgithub. If however you want to knock up something to learn Qt, you could follow my simple suggestion, or you could get (a lot) more involved by doing it via a database from Qt....
5/12