change QPushButton to QDialogButtonBox so Qt can do the text translations
This commit is contained in:
		
							parent
							
								
									be1a29219c
								
							
						
					
					
						commit
						cea3cb0229
					
				| @ -25,7 +25,7 @@ import apt_pkg | |||||||
| from argparse import ArgumentParser | from argparse import ArgumentParser | ||||||
| import gettext | import gettext | ||||||
| 
 | 
 | ||||||
| from PyQt5.QtWidgets import (QWidget, QApplication, QLabel, QPushButton, | from PyQt5.QtWidgets import (QWidget, QApplication, QLabel, QDialogButtonBox, | ||||||
|                              QHBoxLayout, QVBoxLayout, QTreeWidget, |                              QHBoxLayout, QVBoxLayout, QTreeWidget, | ||||||
|                              QTreeWidgetItem) |                              QTreeWidgetItem) | ||||||
| from PyQt5.QtCore import Qt | from PyQt5.QtCore import Qt | ||||||
| @ -51,8 +51,8 @@ class Dialog(QWidget): | |||||||
|         self.depcache = apt_pkg.DepCache(self.cache) |         self.depcache = apt_pkg.DepCache(self.cache) | ||||||
| 
 | 
 | ||||||
|         self.initUI() |         self.initUI() | ||||||
|         self.upgradeBtn.clicked.connect(self.call_upgrade) |         self.buttonBox.rejected.connect(self.call_reject) | ||||||
|         self.closeBtn.clicked.connect(self.call_reject) |         self.buttonBox.clicked.connect(self.call_upgrade) | ||||||
| 
 | 
 | ||||||
|     def initUI(self): |     def initUI(self): | ||||||
|         ''' UI initialization ''' |         ''' UI initialization ''' | ||||||
| @ -64,14 +64,13 @@ class Dialog(QWidget): | |||||||
|         self.tw.setHeaderLabels([_('Affected Packages')]) |         self.tw.setHeaderLabels([_('Affected Packages')]) | ||||||
|         self.tw.setHeaderHidden(True) |         self.tw.setHeaderHidden(True) | ||||||
| 
 | 
 | ||||||
|         self.upgradeBtn = QPushButton("Upgrade") |         self.buttonBox = QDialogButtonBox(QDialogButtonBox.Cancel | | ||||||
|         self.closeBtn = QPushButton("Close") |                                           QDialogButtonBox.Apply) | ||||||
|         text = "" |         text = "" | ||||||
| 
 | 
 | ||||||
|         hbox = QHBoxLayout() |         hbox = QHBoxLayout() | ||||||
|         hbox.addStretch(1) |         hbox.addStretch(1) | ||||||
|         hbox.addWidget(self.upgradeBtn) |         hbox.addWidget(self.buttonBox) | ||||||
|         hbox.addWidget(self.closeBtn) |  | ||||||
|         hbox.addStretch(1) |         hbox.addStretch(1) | ||||||
| 
 | 
 | ||||||
|         vbox = QVBoxLayout() |         vbox = QVBoxLayout() | ||||||
| @ -150,34 +149,35 @@ class Dialog(QWidget): | |||||||
|         ''' when close button is pressed, quit ''' |         ''' when close button is pressed, quit ''' | ||||||
|         app.quit() |         app.quit() | ||||||
| 
 | 
 | ||||||
|     def call_upgrade(self): |     def call_upgrade(self, btnClicked): | ||||||
|         ''' starts upgrade process ''' |         if(self.buttonBox.buttonRole(btnClicked) == QDialogButtonBox.ApplyRole): | ||||||
|         self.label.setText(_("Upgrading...")) |             ''' starts upgrade process ''' | ||||||
|         # TODO maybe open another thread so notifier won't freeze |             self.label.setText(_("Upgrading...")) | ||||||
|         if self.upg_path == "terminal": |             # TODO maybe open another thread so notifier won't freeze | ||||||
|             # cmd = ['qterminal', '-e', 'sudo', 'apt', 'dist-upgrade'] |             if self.upg_path == "terminal": | ||||||
|             cmd = ['qterminal', '-e', './upg.sh'] |                 # cmd = ['qterminal', '-e', 'sudo', 'apt', 'dist-upgrade'] | ||||||
|         else: |                 cmd = ['qterminal', '-e', './upg.sh'] | ||||||
|             cmd = ['lxqt-sudo', self.upg_path, '--full-upgrade'] |             else: | ||||||
|         # process = subprocess.Popen(self.upg_path) |                 cmd = ['lxqt-sudo', self.upg_path, '--full-upgrade'] | ||||||
|         # process = subprocess.Popen(cmd, shell=True) |             # process = subprocess.Popen(self.upg_path) | ||||||
|         self.upgradeBtn.setVisible(False) |             # process = subprocess.Popen(cmd, shell=True) | ||||||
|         self.upgradeBtn.setEnabled(False) |             self.upgradeBtn.setVisible(False) | ||||||
|         process = subprocess.Popen(cmd) |             self.upgradeBtn.setEnabled(False) | ||||||
|         process.wait() |             process = subprocess.Popen(cmd) | ||||||
|  |             process.wait() | ||||||
| 
 | 
 | ||||||
|         if self.upg_path == "terminal": |             if self.upg_path == "terminal": | ||||||
|             text = _("Upgrade finished") |                 text = _("Upgrade finished") | ||||||
| 
 | 
 | ||||||
|             reboot_required_path = Path("/var/run/reboot-required") |                 reboot_required_path = Path("/var/run/reboot-required") | ||||||
|             if reboot_required_path.exists(): |                 if reboot_required_path.exists(): | ||||||
|                 text += "\n" + _("Reboot required") |                     text += "\n" + _("Reboot required") | ||||||
|             self.label.setText(text) |                 self.label.setText(text) | ||||||
|             self.closeBtn.setVisible(True) |                 self.closeBtn.setVisible(True) | ||||||
|             self.closeBtn.setEnabled(True) |                 self.closeBtn.setEnabled(True) | ||||||
| 
 | 
 | ||||||
|         else: |             else: | ||||||
|             app.quit() |                 app.quit() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class App(QApplication): | class App(QApplication): | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user