Ejemplo n.º 1
0
 def accept(self):
     if self.txtName.text().strip() == "":
         QMessageBox.information(self, self.windowTitle(),
                 self.trUtf8("请填写快捷方式的名称。"))
         self.txtName.setFocus(Qt.OtherFocusReason)
         return
     path = self.txtPath.text().strip()
     if path == "":
         QMessageBox.information(self, self.windowTitle(),
                 self.trUtf8("请填写目标文件/程序。"))
         self.txtPath.setFocus(Qt.OtherFocusReason)
         self.txtPath.selectAll()
         return
     if not os.path.exists(path):
         QMessageBox.information(self, self.windowTitle(),
                 self.trUtf8("目标文件/程序不存在。"))
         self.txtPath.setFocus(Qt.OtherFocusReason)
         self.txtPath.selectAll()
         return
     openwith = self.txtOpenwith.text().strip()
     if openwith != "":
         if not os.path.exists(openwith):
             QMessageBox.information(self, self.windowTitle(),
                     self.trUtf8("编辑程序不存在。请重新选择。该选项是选填项,并不一定要填写。"))
             self.txtOpenwith.setFocus(Qt.OtherFocusReason)
             self.txtOpenwith.selectAll()
             return
         fi = QFileInfo(openwith)
         if not fi.isExecutable():
             QMessageBox.information(self, self.windowTitle(),
                     self.trUtf8("编辑程序必须是一个可执行文件。请重新选择。该选项是选填项,并不一定要填写。"))
             self.txtOpenwith.setFocus(Qt.OtherFocusReason)
             self.txtOpenwith.selectAll()
             return
     dir = self.txtDir.text().strip()
     if dir == "":
         QMessageBox.information(self, self.windowTitle(),
                 self.trUtf8("请填写运行目录。可以使用“默认运行目录”按钮恢复默认的运行目录。"))
         self.txtDir.setFocus(Qt.OtherFocusReason)
         self.txtDir.selectAll()
         return
     if not os.path.exists(dir):
         QMessageBox.information(self, self.windowTitle(),
                 self.trUtf8("运行目录不存在。请重新选择。可以使用“默认运行目录”按钮恢复默认的运行目录。"))
         self.txtDir.setFocus(Qt.OtherFocusReason)
         self.txtDir.selectAll()
         return
     if not os.path.isdir(dir):
         QMessageBox.information(self, self.windowTitle(),
                 self.trUtf8("运行目录必须是一个目录,而非文件。请重新选择。可以使用“默认运行目录”按钮恢复默认的运行目录。"))
         self.txtDir.setFocus(Qt.OtherFocusReason)
         self.txtDir.selectAll()
         return
     QDialog.accept(self)
Ejemplo n.º 2
0
 def browseOpenwith(self):
     filename = QFileDialog.getOpenFileName(self, self.windowTitle())
     if filename == "":
         return
     fi = QFileInfo(filename)
     if fi.isSymLink():
         filename = fi.symLinkTarget()
         if not os.path.exists(filename):
             QMessageBox.information(self, self.windowTitle(),
                     self.trUtf8("快捷方式所指向的程序不正确。"))
             return
     fi = QFileInfo(filename)
     if not fi.isExecutable():
         QMessageBox.information(self, self.windowTitle(),
                 self.trUtf8("编辑程序必须是一个可执行文件。请重新选择。该选项是选填项,并不一定要填写。"))
     self.txtOpenwith.setText(fi.absoluteFilePath())