Preferences/ProgramsDialog.py

changeset 5970
411f7ba577d5
parent 5968
c5112b5cb7a9
child 5974
dfb291b5b620
equal deleted inserted replaced
5969:584c21b6587a 5970:411f7ba577d5
13 except NameError: 13 except NameError:
14 pass 14 pass
15 15
16 import os 16 import os
17 import re 17 import re
18 import sys
18 19
19 from PyQt5.QtCore import pyqtSlot, Qt, QProcess 20 from PyQt5.QtCore import pyqtSlot, Qt, QProcess
20 from PyQt5.QtGui import QCursor 21 from PyQt5.QtGui import QCursor
21 from PyQt5.QtWidgets import QApplication, QTreeWidgetItem, QHeaderView, \ 22 from PyQt5.QtWidgets import QApplication, QTreeWidgetItem, QHeaderView, \
22 QDialog, QDialogButtonBox 23 QDialog, QDialogButtonBox
212 exe = "protoc" 213 exe = "protoc"
213 if Utilities.isWindowsPlatform(): 214 if Utilities.isWindowsPlatform():
214 exe += ".exe" 215 exe += ".exe"
215 self.__createProgramEntry( 216 self.__createProgramEntry(
216 self.tr("Protobuf Compiler"), exe, '--version', 'libprotoc', -1) 217 self.tr("Protobuf Compiler"), exe, '--version', 'libprotoc', -1)
218 # 5c. grpc
219 exe = Preferences.getProtobuf("grpcPython")
220 if not exe:
221 exe = sys.executable
222 self.__createProgramEntry(
223 self.tr("grpc Compiler"), exe, '--version', 'libprotoc', -1,
224 exeModule=['-m', 'grpc_tools.protoc'])
217 225
218 # 6. do the spell checking entry 226 # 6. do the spell checking entry
219 try: 227 try:
220 import enchant 228 import enchant
221 try: 229 try:
251 259
252 # do the plugin related programs 260 # do the plugin related programs
253 pm = e5App().getObject("PluginManager") 261 pm = e5App().getObject("PluginManager")
254 for info in pm.getPluginExeDisplayData(): 262 for info in pm.getPluginExeDisplayData():
255 if info["programEntry"]: 263 if info["programEntry"]:
264 if "exeModule" not in info:
265 info["exeModule"] = None
256 self.__createProgramEntry( 266 self.__createProgramEntry(
257 info["header"], 267 info["header"],
258 info["exe"], 268 info["exe"],
259 versionCommand=info["versionCommand"], 269 versionCommand=info["versionCommand"],
260 versionStartsWith=info["versionStartsWith"], 270 versionStartsWith=info["versionStartsWith"],
261 versionPosition=info["versionPosition"], 271 versionPosition=info["versionPosition"],
262 version=info["version"], 272 version=info["version"],
263 versionCleanup=info["versionCleanup"], 273 versionCleanup=info["versionCleanup"],
274 exeModule=info["exeModule"],
264 ) 275 )
265 else: 276 else:
266 self.__createEntry( 277 self.__createEntry(
267 info["header"], 278 info["header"],
268 info["text"], 279 info["text"],
275 self.__hasSearched = True 286 self.__hasSearched = True
276 287
277 def __createProgramEntry(self, description, exe, 288 def __createProgramEntry(self, description, exe,
278 versionCommand="", versionStartsWith="", 289 versionCommand="", versionStartsWith="",
279 versionPosition=0, version="", 290 versionPosition=0, version="",
280 versionCleanup=None, versionRe=None): 291 versionCleanup=None, versionRe=None,
292 exeModule=None):
281 """ 293 """
282 Private method to generate a program entry. 294 Private method to generate a program entry.
283 295
284 @param description descriptive text (string) 296 @param description descriptive text (string)
285 @param exe name of the executable program (string) 297 @param exe name of the executable program (string)
286 @param versionCommand command line switch to get the version info 298 @param versionCommand command line switch to get the version info
287 (string) if this is empty, the given version will be shown. 299 (str). If this is empty, the given version will be shown.
288 @param versionStartsWith start of line identifying version info 300 @param versionStartsWith start of line identifying version info
289 (string) 301 (string)
290 @param versionPosition index of part containing the version info 302 @param versionPosition index of part containing the version info
291 (integer) 303 (integer)
292 @keyparam version version string to show (string) 304 @keyparam version version string to show (string)
293 @keyparam versionCleanup tuple of two integers giving string positions 305 @keyparam versionCleanup tuple of two integers giving string positions
294 start and stop for the version string (tuple of integers) 306 start and stop for the version string (tuple of integers)
295 @keyparam versionRe regexp to determine the line identifying version 307 @keyparam versionRe regexp to determine the line identifying version
296 info (string). Takes precedence over versionStartsWith. 308 info (string). Takes precedence over versionStartsWith.
309 @keyparam exeModule list of command line parameters to execute a module
310 with the program given in exe (e.g. to execute a Python module)
311 (list of str)
297 @return version string of detected or given version (string) 312 @return version string of detected or given version (string)
298 """ 313 """
299 itmList = self.programsList.findItems( 314 itmList = self.programsList.findItems(
300 description, Qt.MatchCaseSensitive) 315 description, Qt.MatchCaseSensitive)
301 if itmList: 316 if itmList:
318 (versionStartsWith != "" or 333 (versionStartsWith != "" or
319 (versionRe is not None and versionRe != "")) and \ 334 (versionRe is not None and versionRe != "")) and \
320 versionPosition: 335 versionPosition:
321 proc = QProcess() 336 proc = QProcess()
322 proc.setProcessChannelMode(QProcess.MergedChannels) 337 proc.setProcessChannelMode(QProcess.MergedChannels)
323 proc.start(exe, [versionCommand]) 338 if exeModule:
339 args = exeModule[:] + [versionCommand]
340 else:
341 args = [versionCommand]
342 proc.start(exe, args)
324 finished = proc.waitForFinished(10000) 343 finished = proc.waitForFinished(10000)
325 if finished: 344 if finished:
326 output = str(proc.readAllStandardOutput(), 345 output = str(proc.readAllStandardOutput(),
327 Preferences.getSystem("IOEncoding"), 346 Preferences.getSystem("IOEncoding"),
328 'replace') 347 'replace')
343 version = self.tr("(unknown)") 362 version = self.tr("(unknown)")
344 else: 363 else:
345 version = self.tr("(unknown)") 364 version = self.tr("(unknown)")
346 else: 365 else:
347 version = self.tr("(not executable)") 366 version = self.tr("(not executable)")
348 QTreeWidgetItem(itm, [exe, version]) 367 if exeModule:
368 QTreeWidgetItem(itm, [
369 "{0} {1}".format(exe, " ".join(exeModule)),
370 version])
371 else:
372 QTreeWidgetItem(itm, [exe, version])
349 itm.setExpanded(True) 373 itm.setExpanded(True)
350 else: 374 else:
351 itm.setText(1, self.tr("(not found)")) 375 itm.setText(1, self.tr("(not found)"))
352 QApplication.processEvents() 376 QApplication.processEvents()
353 self.programsList.header().resizeSections(QHeaderView.ResizeToContents) 377 self.programsList.header().resizeSections(QHeaderView.ResizeToContents)

eric ide

mercurial