Beispiel #1
0
 def closeEvent(self, event):
     event.ignore()
     close_state = Configure.read_config()
     if close_state == '0':
         self.hide_or_display()
     elif close_state == '2':
         QtGui.qApp.quit()
     else:
         self.close_dialog = CloseDialog(self)
         self.close_dialog.setModal(False)
         self.jiajia = self.close_dialog.exec_()
         Configure.write_config(self.jiajia)
         if self.jiajia == 0:
             self.hide_or_display()
             #self.ask_next_time = False
         elif self.jiajia == 1:
             self.hide_or_display()
             #self.ask_next_time = True
         elif self.jiajia == 2:
             self.ask_next_time = False
             QtGui.qApp.quit()
         elif self.jiajia == 3:
             self.ask_next_time = True
             QtGui.qApp.quit()
Beispiel #2
0
class MainWindow(QWidget, Ui_Form):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.setupUi(self)
        self.connect(self.pushButton, SIGNAL("clicked()"), self.translate)
        self.pushButton.setAutoDefault(True)

        self.word_completer = QCompleter()
        self.lineEdit.setCompleter(self.word_completer)
        self.word_completer.setCaseSensitivity(Qt.CaseInsensitive)
        model = QStringListModel()
        self.word_completer.setModel(model)
        self.get_word_list(model)

        self.real_time_status = True
        self.move_to_center()
        self.creat_menu()
        #self.hotkey()
        htmlfile = open("./template/index.html", 'r')
        self.textEdit.setText(self.tr(htmlfile.read()))
        htmlfile.close()

    def get_word_list(self, model):
        file = open('./word.ldc', "r")
        word_list = []
        for eachline in file:
            word_list.append(eachline.strip())
        file.close()

        model.setStringList(word_list)

    def hide_or_display(self):
        if self.isVisible():
            self.hide()
        else:
            self.setVisible(True)

    def about_lindict(self):
        QtGui.QMessageBox.about(self, u'关于 LinDict', u'LinDict by Jactry Zeng')

    def creat_menu(self):
        self.hide_action = QtGui.QAction(u'显示/隐藏窗口', self, triggered=self.hide_or_display)
        self.real_time_action = QtGui.QAction(u'划词翻译', self, checkable=True, triggered=self.change_real_time_status)
        #self.real_time_action.setShortcut(QKeySequence('X'))
        #self.real_time_action.setShortcutContext(Qt.ApplicationShortcut)
        self.about_action = QtGui.QAction(u'关于 Lindict', self, triggered=self.about_lindict)
        self.quit_action = QtGui.QAction(u'退出', self, triggered=QtGui.qApp.quit)
        self.real_time_action.setChecked(True)
        self.tray = LinTray(self)
        self.tray_menu = QtGui.QMenu()
        self.tray_menu.addAction(self.hide_action)
        self.tray_menu.addAction(self.real_time_action)
        self.tray_menu.addSeparator()
        self.tray_menu.addAction(self.about_action)
        self.tray_menu.addSeparator()
        self.tray_menu.addAction(self.quit_action)
        self.tray.setContextMenu(self.tray_menu)
        self.tray.show()

    def change_real_time_status(self):
        if self.real_time_status:
            self.real_time_action.setChecked(False)
            self.real_time_status = False
        else:
            self.real_time_action.setChecked(True)
            self.real_time_status = True

    def translate(self):
        res = Lookup.look_up(self.lineEdit.text())
        if not res:
            htmlfile = open("./template/404.html", 'r')
            self.textEdit.setText(self.tr(htmlfile.read()))
            htmlfile.close()
        else:
            reload(sys)
            sys.setdefaultencoding('utf-8')
            res = unicode(res)
            self.textEdit.setText(res)

    def move_to_center(self):
        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Return and self.lineEdit.text() != "":
            self.translate()
        #elif event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_S:
        #    self.change_real_time_status()

    def closeEvent(self, event):
        event.ignore()
        close_state = Configure.read_config()
        if close_state == '0':
            self.hide_or_display()
        elif close_state == '2':
            QtGui.qApp.quit()
        else:
            self.close_dialog = CloseDialog(self)
            self.close_dialog.setModal(False)
            self.jiajia = self.close_dialog.exec_()
            Configure.write_config(self.jiajia)
            if self.jiajia == 0:
                self.hide_or_display()
                #self.ask_next_time = False
            elif self.jiajia == 1:
                self.hide_or_display()
                #self.ask_next_time = True
            elif self.jiajia == 2:
                self.ask_next_time = False
                QtGui.qApp.quit()
            elif self.jiajia == 3:
                self.ask_next_time = True
                QtGui.qApp.quit()
       # delete self.close_dialog
            #self.close_dialog.exec()
            #self.setEnabled(False)
    """