[Solved] qcontrolcenter python3

Post Reply
djemos
Salix Warrior
Posts: 1193
Joined: 29. Dec 2009, 13:45
Location: Greece

[Solved] qcontrolcenter python3

Post by djemos » 15. Jan 2022, 20:46

Hi, I have ported qcontrolcenter to python3 and pyqt5.
Even it is working fine, i have some problems with greek names and in help the License.txt and instructions show characters like "b'\t\t" even in English LANG.

source and binary are here
Any help is welcome.
To see what i am talking about install the binary and run it with LANG=el qcontrolcenter and then run it with LANG=en qcontrolcenter
Of course you have to place your desktop files under ~/.qcontrolcenter/ in folders Applications/ Hardware/ Information/ System/

User avatar
gapan
Salix Wizard
Posts: 5843
Joined: 6. Jun 2009, 17:40

Re: qcontrolcenter python3

Post by gapan » 15. Jan 2022, 21:01

Hi djemos, nice!

You can fix your string issues by adding .decode('UTF-8') to your readLine commands. See this patch:

Code: Select all

--- /usr/bin/helpDialog.py	2022-01-15 22:53:30.000000000 +0200
+++ ./helpDialog.py	2022-01-15 22:59:39.340538465 +0200
@@ -70,7 +70,7 @@
 		file = QtCore.QFile("/usr/share/qcontrolcenter/INSTRUCTIONS.txt")
 		if file.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text):
 			while not file.atEnd():
-				textView.append(str(file.readLine().data()))
+				textView.append(str(file.readLine().data().decode('UTF-8')))
 				
 		textContent = None
 		vlay.addWidget(textView)
@@ -87,7 +87,7 @@
 		file = QtCore.QFile("/usr/share/qcontrolcenter/LICENSE.html")
 		if file.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text):
 			while not file.atEnd():
-				textView.append(str(file.readLine().data()))
+				textView.append(str(file.readLine().data().decode('UTF-8')))
 
 		
 		textContent = None
This is because in python3 you don't read text, even from a text file. You read a "bytes" object, which you have to decode to a string.
Image
Image

User avatar
gapan
Salix Wizard
Posts: 5843
Joined: 6. Jun 2009, 17:40

Re: qcontrolcenter python3

Post by gapan » 15. Jan 2022, 21:03

Also, all files in your package belong to djemos:users!

Other packages in the slackel repos also have the same problem!

This is caused by an old fakeroot package. Get the one from the salix 15.0 repos.
Image
Image

djemos
Salix Warrior
Posts: 1193
Joined: 29. Dec 2009, 13:45
Location: Greece

Re: qcontrolcenter python3

Post by djemos » 15. Jan 2022, 21:17

Thanks gapan. I will test it.

djemos
Salix Warrior
Posts: 1193
Joined: 29. Dec 2009, 13:45
Location: Greece

Re: qcontrolcenter python3

Post by djemos » 15. Jan 2022, 21:24

gapan this solves the problen in licence and instructions but folders in Greek do not show in the left or the title in the right.
This code is in the qcontrolcenter file.

Code: Select all

# This method populates the list of categories in the left hand dock.
	def initContentsWidget(self):
		folder = QtCore.QDir(CONFIG_DIR)
		folder.setFilter(QtCore.QDir.AllDirs)
		# Loop inside the categories in the config tree
		for folderName in folder.entryInfoList():
			# Condider only category names of al laast three characters
			if len(folderName.fileName()) > 2:
				current_dir = os.path.join( CONFIG_DIR, unicode(folderName.fileName()) )
				# Bear in mind that self.contentsWidget is a docked list item
				# configButton is an item in that list
				configButton = QtWidgets.QListWidgetItem( self.contentsWidget)
				configButton.setIcon(QtGui.QIcon( os.path.join(current_dir, FOLDER_ICON) ) )
				configButton.setText( self.getSectionTitle(current_dir) )	
							
				#configButton.setText(folderName.fileName())
				
				configButton.setTextAlignment( QtCore.Qt.AlignLeft )
				# Align center vertically (Didier)
				configButton.setTextAlignment( QtCore.Qt.AlignVCenter )
				configButton.setData( QtCore.Qt.UserRole, QtCore.QVariant( folderName.fileName()) )
				configButton.setFont(QtGui.QFont("DejaVu Sans", 11, QtGui.QFont.Bold))

	def getSectionTitle(self, dir_name):
		titleList = unicode(dir_name).split("/")
		title = titleList[len(titleList)-1]
		
		file_name = os.path.join(dir_name, FOLDER_INI)
		
		if not os.path.exists(file_name):
			return title
		
		settings = QtCore.QSettings(file_name, QtCore.QSettings.IniFormat)
		if settings.value(LANG).strip() != "":
			title = unicode(settings.value(LANG).strip())
			#title=LANG
		"""
		#if len(LANG) > 1
		if settings.value(LANG).toString() != "":
			title = unicode(settings.value(LANG).toString(), "utf-8")
		elif settings.value("default").toString() != "":
			title = unicode(settings.value("default").toString(), "utf-8")
		"""
		return title

User avatar
gapan
Salix Wizard
Posts: 5843
Joined: 6. Jun 2009, 17:40

Re: qcontrolcenter python3

Post by gapan » 15. Jan 2022, 21:34

djemos, I'm not sure what you're talking about. I see greek just fine, both in the left pane and the right one.
Image
Image

User avatar
gapan
Salix Wizard
Posts: 5843
Joined: 6. Jun 2009, 17:40

Re: qcontrolcenter python3

Post by gapan » 15. Jan 2022, 21:37

Image
Image

djemos
Salix Warrior
Posts: 1193
Joined: 29. Dec 2009, 13:45
Location: Greece

Re: qcontrolcenter python3

Post by djemos » 15. Feb 2022, 13:07

Problem solved changing these lines

Code: Select all

settings = QtCore.QSettings(file_name, QtCore.QSettings.IniFormat)
		if settings.value(LANG).toString().trimmed() != "":
			title = unicode(settings.value(LANG).toString(), "utf-8")
to

Code: Select all

settings = QtCore.QSettings(file_name, QtCore.QSettings.IniFormat)
QtCore.QSettings.setIniCodec(settings,"UTF-8") # Sets the codec for accessing INI files (including .conf files on Unix) 

		if settings.value(LANG) != "":
			title = unicode(settings.value(LANG))

Post Reply