Ejemplo n.º 1
0
class PadApp(QApplication):
    def __init__(self, *args, **kwargs):
        QApplication.__init__(self, *args, **kwargs)
        self.settings = QSettings("everpad", "everpad-pad")
        self.translator = QTranslator()
        if not self.translator.load("../../i18n/%s" % QLocale.system().name()):
            self.translator.load("/usr/share/everpad/i18n/%s" % QLocale.system().name())
        # This application string can be localized to 'RTL' to switch the application layout
        # direction. See for example i18n/ar_EG.ts
        QT_TRANSLATE_NOOP("QApplication", "QT_LAYOUT_DIRECTION")
        self.installTranslator(self.translator)
        self.indicator = Indicator(self)
        self.update_icon()
        self.indicator.show()

    def update_icon(self):
        if int(self.settings.value("black-icon", 0)):
            self.icon = QIcon.fromTheme("everpad-black", QIcon("../../data/everpad-black.png"))
        else:
            self.icon = QIcon.fromTheme("everpad-mono", QIcon("../../data/everpad-mono.png"))
        self.indicator.setIcon(self.icon)

    def send_notify(self, text):
        self.indicator.showMessage("Everpad", text, QSystemTrayIcon.Information)

    def on_sync_state_changed(self, state):
        if int(self.settings.value("launcher-progress", 1)):
            self.launcher.update(
                {
                    "progress": float(state + 1) / len(SYNC_STATES),
                    "progress-visible": state not in (SYNC_STATE_START, SYNC_STATE_FINISH),
                }
            )
Ejemplo n.º 2
0
class PadApp(QApplication):
    def __init__(self, *args, **kwargs):
        QApplication.__init__(self, *args, **kwargs)
        self.settings = QSettings('everpad', 'everpad-pad')
        self.translator = QTranslator()
        if not self.translator.load('../../i18n/%s' % QLocale.system().name()):
            self.translator.load('/usr/share/everpad/i18n/%s' %
                                 QLocale.system().name())
        self.installTranslator(self.translator)
        self.indicator = Indicator(self)
        self.update_icon()
        self.indicator.show()

    def update_icon(self):
        if int(self.settings.value('black-icon', 0)):
            self.icon = QIcon.fromTheme('everpad-black',
                                        QIcon('../../data/everpad-black.png'))
        else:
            self.icon = QIcon.fromTheme('everpad-mono',
                                        QIcon('../../data/everpad-mono.png'))
        self.indicator.setIcon(self.icon)

    def send_notify(self, text):
        self.indicator.showMessage('Everpad', text,
                                   QSystemTrayIcon.Information)

    def on_sync_state_changed(self, state):
        self.launcher.update({
            'progress':
            float(state + 1) / len(SYNC_STATES),
            'progress-visible':
            state not in (SYNC_STATE_START, SYNC_STATE_FINISH),
        })
Ejemplo n.º 3
0
class PadApp(QApplication):
    def __init__(self, *args, **kwargs):
        QApplication.__init__(self, *args, **kwargs)
        self.settings = QSettings('everpad', 'everpad-pad')
        self.translator = QTranslator()
        if not self.translator.load('../../i18n/%s' % QLocale.system().name()):
            self.translator.load('/usr/share/everpad/i18n/%s' % QLocale.system().name())
        self.installTranslator(self.translator)
        self.indicator = Indicator(self)
        self.update_icon()
        self.indicator.show()

    def update_icon(self):
        if int(self.settings.value('black-icon', 0)):
            self.icon = QIcon.fromTheme('everpad-black', QIcon('../../data/everpad-black.png'))
        else:
            self.icon = QIcon.fromTheme('everpad-mono', QIcon('../../data/everpad-mono.png'))
        self.indicator.setIcon(self.icon)

    def send_notify(self, text):
        self.indicator.showMessage('Everpad', text,
            QSystemTrayIcon.Information)

    def on_sync_state_changed(self, state):
        self.launcher.update({
            'progress': float(state + 1) / len(SYNC_STATES),
            'progress-visible': state not in (SYNC_STATE_START, SYNC_STATE_FINISH),
        })
Ejemplo n.º 4
0
class PadApp(QApplication):
    def __init__(self, *args, **kwargs):
        QApplication.__init__(self, *args, **kwargs)
        self.settings = QSettings('everpad', 'everpad-pad')
        self.translator = QTranslator()
        if not self.translator.load('../../i18n/%s' % QLocale.system().name()):
            self.translator.load('/usr/share/everpad/i18n/%s' % QLocale.system().name())
        # This application string can be localized to 'RTL' to switch the application layout
        # direction. See for example i18n/ar_EG.ts
        QT_TRANSLATE_NOOP('QApplication', 'QT_LAYOUT_DIRECTION')
        self.installTranslator(self.translator)
        QNetworkProxyFactory.setUseSystemConfiguration(True)
        self.indicator = Indicator(self)
        self.update_icon()
        self.indicator.show()

    def update_icon(self):
        if int(self.settings.value('black-icon', 0)):
            self.icon = QIcon.fromTheme('everpad-black', QIcon('../../data/everpad-black.png'))
        else:
            self.icon = QIcon.fromTheme('everpad-mono', QIcon('../../data/everpad-mono.png'))
        self.indicator.setIcon(self.icon)

    def send_notify(self, text):
        self.indicator.showMessage('Everpad', text,
            QSystemTrayIcon.Information)

    def on_sync_state_changed(self, state):
        if bool(self.settings.value('launcher-progress', 1)):
            self.launcher.update({
                'progress': float(state + 1) / len(SYNC_STATES),
                'progress-visible': state not in (SYNC_STATE_START, SYNC_STATE_FINISH),
            })
Ejemplo n.º 5
0
class App(QApplication):
    """Main class"""

    def __init__(self, *args, **kwargs):
        """Init app"""
        QApplication.__init__(self, *args, **kwargs)
        self.sync_thread = SyncThread()
        self.sync_thread.start()
        self.translator = QTranslator()
        if not self.translator.load('i18n/%s' % QLocale.system().name()):
            self.translator.load('/usr/share/everpad/lang/%s' % QLocale.system().name())
        self.provider_obj = dbus.SessionBus().get_object("com.everpad.Provider", '/EverpadProvider')
        self.provider = dbus.Interface(self.provider_obj, "com.everpad.Provider")
        self.installTranslator(self.translator)
        self.icon = QIcon.fromTheme('everpad', QIcon('../everpad.png'))
        indicator = Indicator(self, self.icon)
        indicator.show()
        self.opened = {}
        self.setApplicationName('everpad')
        self.settings = gconf.client_get_default()

    @property
    def authenticated(self):
        return self.provider.authenticated()

    def send_notify(self, title, text, icon=QSystemTrayIcon.Information):
        """Send osd"""
        self.indicator.showMessage(
            title, text, icon,
        )

    @Slot()
    def end(self):
        """Exit app"""
        self.exit()
Ejemplo n.º 6
0
def setTranslationLocale():
    global locale
    lang = settings['Main'].get('lang')
    sysLocale = QLocale.system()
    if lang and lang == sysLocale.name():
        locale = sysLocale
    elif lang and lang != sysLocale.name():
        # special case: application language is different from system's
        locale = QLocale(lang)
        QLocale.setDefault(locale)
    else:
        locale = sysLocale
        lang = settings['Main']['lang'] = locale.name()
    langPath = os.path.join(appPath, 'lang')
    logging.info('set translation(%s)', lang)
    global _trans, _transQt  # avoid being collected
    _trans = QTranslator()
    _trans.load(lang, langPath)
    _transQt = QTranslator()
    ret = _transQt.load('qt_' + lang,
                        QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    if not ret:  # frozen
        _transQt.load('qt_' + lang, langPath)
    for i in [_trans, _transQt]:
        QApplication.instance().installTranslator(i)

    global dateFmt, datetimeFmt, fullDatetimeFmt
    timeFmt = settings['Main'].get('timeFormat')
    dateFmt = settings['Main'].get('dateFormat', locale.dateFormat())
    datetimeFmt = (dateFmt + ' ' + timeFmt) if timeFmt else dateFmt
    # use hh:mm because locale.timeFormat will include seconds
    fullDatetimeFmt = dateFmt + ' ' + (timeFmt or 'hh:mm')
Ejemplo n.º 7
0
    def testUtf8(self):
        translator = QTranslator()
        translator.load(os.path.join(self.trdir, 'trans_russian.qm'))
        self.app.installTranslator(translator)

        obj = QObject()
        obj.setObjectName(obj.trUtf8('Hello World!'))
        self.assertEqual(obj.objectName(), py3k.unicode_('привет мир!'))
Ejemplo n.º 8
0
    def testLatin(self):
        #Set string value to Latin
        translator = QTranslator()
        translator.load(os.path.join(self.trdir, 'trans_latin.qm'))
        self.app.installTranslator(translator)

        obj = QObject()
        obj.setObjectName(obj.tr('Hello World!'))
        self.assertEqual(obj.objectName(), py3k.unicode_('Orbis, te saluto!'))
Ejemplo n.º 9
0
class PadApp(QApplication):
    data_changed = Signal()

    def __init__(self, *args, **kwargs):
        QApplication.__init__(self, *args, **kwargs)
        self.settings = QSettings('everpad', 'everpad-pad')
        locale = QLocale.system().name()
        self.qtTranslator = QTranslator()
        self.qtTranslator.load(
            "qt_" + locale,
            QLibraryInfo.location(QLibraryInfo.TranslationsPath))
        self.installTranslator(self.qtTranslator)
        self.appTranslator = QTranslator()
        if not self.appTranslator.load(
                locale, os.path.join(os.path.dirname(__file__), '../../i18n')):
            self.appTranslator.load(locale,
                                    resource_filename('share/everpad/i18n'))
        # This application string can be localized to 'RTL' to switch the application layout
        # direction. See for example i18n/ar_EG.ts
        QT_TRANSLATE_NOOP('QApplication', 'QT_LAYOUT_DIRECTION')
        self.installTranslator(self.appTranslator)
        QNetworkProxyFactory.setUseSystemConfiguration(True)
        self.indicator = Indicator()
        self.update_icon()
        self.indicator.show()

    def update_icon(self):
        is_black = int(self.settings.value('black-icon', 0))
        self.icon = get_tray_icon(is_black)
        self.indicator.setIcon(self.icon)

    def send_notify(self, text):
        self.indicator.showMessage('Everpad', text,
                                   QSystemTrayIcon.Information)

    def on_sync_state_changed(self, state):
        if int(self.settings.value('launcher-progress', 1)):
            self.launcher.update({
                'progress':
                float(state + 1) / len(SYNC_STATES),
                'progress-visible':
                state not in (SYNC_STATE_START, SYNC_STATE_FINISH),
            })

    def on_data_changed(self):
        """Note, notebook or tag changed"""
        self.data_changed.emit()
Ejemplo n.º 10
0
def main():
    """
    """
    from MainWindow import MainWindow

    translator = QTranslator() #Build the translator
    translator.load(":/locales/df_%s" % QLocale.system().name())
    qttranslator = QTranslator()#A translator for Qt standard strings
    qttranslator.load("qt_%s" % (QLocale.system().name()))
    App = QApplication(sys.argv) #Creating the app
    App.setOrganizationName(ORGNAME) #Setting organization and application's
    App.setApplicationName(NAME)#name. It's only useful for QSettings
    App.setApplicationVersion(VERSION)
    App.setOrganizationDomain(URL)
    App.installTranslator(translator)#Install translators into the application.
    App.installTranslator(qttranslator)
    mw = MainWindow(App) #Now it's time to instantiate the main window
    mw.show() #And show it
    sys.exit(App.exec_()) #When the app finishes, exit.
Ejemplo n.º 11
0
def main():
    """
    """
    from MainWindow import MainWindow

    translator = QTranslator()  #Build the translator
    translator.load(":/locales/df_%s" % QLocale.system().name())
    qttranslator = QTranslator()  #A translator for Qt standard strings
    qttranslator.load("qt_%s" % (QLocale.system().name()))
    App = QApplication(sys.argv)  #Creating the app
    App.setOrganizationName(ORGNAME)  #Setting organization and application's
    App.setApplicationName(NAME)  #name. It's only useful for QSettings
    App.setApplicationVersion(VERSION)
    App.setOrganizationDomain(URL)
    App.installTranslator(
        translator)  #Install translators into the application.
    App.installTranslator(qttranslator)
    mw = MainWindow(App)  #Now it's time to instantiate the main window
    mw.show()  #And show it
    sys.exit(App.exec_())  #When the app finishes, exit.
Ejemplo n.º 12
0
class PadApp(QApplication):
    data_changed = Signal()

    def __init__(self, *args, **kwargs):
        QApplication.__init__(self, *args, **kwargs)
        self.settings = QSettings('everpad', 'everpad-pad')
        locale = QLocale.system().name()
        self.qtTranslator = QTranslator()
        self.qtTranslator.load("qt_" + locale, QLibraryInfo.location(QLibraryInfo.TranslationsPath))
        self.installTranslator(self.qtTranslator)
        self.appTranslator = QTranslator()
        if not self.appTranslator.load(locale, os.path.join(os.path.dirname(__file__), '../../i18n')):
            self.appTranslator.load(locale, resource_filename('share/everpad/i18n'))
        # This application string can be localized to 'RTL' to switch the application layout
        # direction. See for example i18n/ar_EG.ts
        QT_TRANSLATE_NOOP('QApplication', 'QT_LAYOUT_DIRECTION')
        self.installTranslator(self.appTranslator)
        QNetworkProxyFactory.setUseSystemConfiguration(True)
        self.indicator = Indicator()
        self.update_icon()
        self.indicator.show()

    def update_icon(self):
        is_black = int(self.settings.value('black-icon', 0))
        self.icon = get_tray_icon(is_black)
        self.indicator.setIcon(self.icon)

    def send_notify(self, text):
        self.indicator.showMessage('Everpad', text,
            QSystemTrayIcon.Information)

    def on_sync_state_changed(self, state):
        if int(self.settings.value('launcher-progress', 1)):
            self.launcher.update({
                'progress': float(state + 1) / len(SYNC_STATES),
                'progress-visible': state not in (SYNC_STATE_START, SYNC_STATE_FINISH),
            })

    def on_data_changed(self):
        """Note, notebook or tag changed"""
        self.data_changed.emit()
Ejemplo n.º 13
0
Archivo: app.py Proyecto: marchon/ifmon
def main(argv=None):
    app = QApplication(argv or sys.argv)
    locale = QLocale.system().name()
    trans = QTranslator()
    locale_path = '%s/locale/ifmon_%s' % (os.path.dirname(os.path.dirname(
        os.path.realpath(__file__))), locale.lower())
    trans.load(locale_path)
    app.installTranslator(trans)
    try:
        setup_db()
    except:
        QMessageBox.critical(None, 'Database error',
            'Could not find the database.\n'
            'Please install it properly by running install.py on Ubuntu.\n'
            'For other Linux distributions, check the requirements.',
            QMessageBox.Ok)
        sys.exit(app.exit())
    else:
        mw = MainWindow()
        mw.show()
    sys.exit(app.exec_())
Ejemplo n.º 14
0
Archivo: app.py Proyecto: marchon/ifmon
def main(argv=None):
    app = QApplication(argv or sys.argv)
    locale = QLocale.system().name()
    trans = QTranslator()
    locale_path = '%s/locale/ifmon_%s' % (os.path.dirname(
        os.path.dirname(os.path.realpath(__file__))), locale.lower())
    trans.load(locale_path)
    app.installTranslator(trans)
    try:
        setup_db()
    except:
        QMessageBox.critical(
            None, 'Database error', 'Could not find the database.\n'
            'Please install it properly by running install.py on Ubuntu.\n'
            'For other Linux distributions, check the requirements.',
            QMessageBox.Ok)
        sys.exit(app.exit())
    else:
        mw = MainWindow()
        mw.show()
    sys.exit(app.exec_())
Ejemplo n.º 15
0
  def loadTranslations(self):
    locale = self.systemLocale()

    if locale and locale != 'en_US':
      dprint("loading translation for %s" % locale)

      t = QTranslator(self)
      ok = t.load('qt_%s' % locale, config.QT_TRANSLATIONS_LOCATION)
      assert ok, "failed to load qt translation"
      if ok:
        self.installTranslator(t)
      else:
        dwarn("warning: failed to load translation from location %s" % location)
Ejemplo n.º 16
0
  def loadTranslations(self):
    locale = self.applicationLocale()
    #if locale in config.TR_LOCALES:
    dprint("loading translation for %s" % locale)

    t = QTranslator(self)
    ok = t.load('qt_%s' % locale, config.QT_TRANSLATIONS_LOCATION)
    #assert ok, "failed to load qt translation"
    if ok:
      self.installTranslator(t)
    else:
      location = config.QT_TRANSLATIONS_LOCATION
      dprint("cannot find translation at %s" % location)

    for location in config.TR_LOCATIONS:
      t = QTranslator(self)
      ok = t.load(locale, location)
      #assert ok, "failed to load translation"
      if ok:
        self.installTranslator(t)
      else:
        dprint("cannot find translation at %s" % location)
Ejemplo n.º 17
0
class PadApp(QApplication):
    def __init__(self, *args, **kwargs):
        QApplication.__init__(self, *args, **kwargs)
        self.settings = QSettings("everpad", "everpad-pad")
        self.translator = QTranslator()
        if not self.translator.load("../../i18n/%s" % QLocale.system().name()):
            self.translator.load("/usr/share/everpad/i18n/%s" % QLocale.system().name())
        self.installTranslator(self.translator)
        self.icon = QIcon.fromTheme("everpad-mono", QIcon("../../everpad-mono.png"))
        self.indicator = Indicator(self, self.icon)
        self.indicator.show()

    def send_notify(self, text):
        self.indicator.showMessage("Everpad", text, QSystemTrayIcon.Information)

    def on_sync_state_changed(self, state):
        self.launcher.update(
            {
                "progress": float(state + 1) / len(SYNC_STATES),
                "progress-visible": state not in (SYNC_STATE_START, SYNC_STATE_FINISH),
            }
        )
Ejemplo n.º 18
0
class PadApp(QApplication):
    data_changed = Signal()

    def __init__(self, *args, **kwargs):
        QApplication.__init__(self, *args, **kwargs)
        self.settings = QSettings("everpad", "everpad-pad")
        self.translator = QTranslator()
        if not self.translator.load("../../i18n/%s" % QLocale.system().name()):
            self.translator.load("/usr/share/everpad/i18n/%s" % QLocale.system().name())
        # This application string can be localized to 'RTL' to switch the application layout
        # direction. See for example i18n/ar_EG.ts
        QT_TRANSLATE_NOOP("QApplication", "QT_LAYOUT_DIRECTION")
        self.installTranslator(self.translator)
        QNetworkProxyFactory.setUseSystemConfiguration(True)
        self.indicator = Indicator()
        self.update_icon()
        self.indicator.show()

    def update_icon(self):
        is_black = int(self.settings.value("black-icon", 0))
        self.icon = get_tray_icon(is_black)
        self.indicator.setIcon(self.icon)

    def send_notify(self, text):
        self.indicator.showMessage("Everpad", text, QSystemTrayIcon.Information)

    def on_sync_state_changed(self, state):
        if int(self.settings.value("launcher-progress", 1)):
            self.launcher.update(
                {
                    "progress": float(state + 1) / len(SYNC_STATES),
                    "progress-visible": state not in (SYNC_STATE_START, SYNC_STATE_FINISH),
                }
            )

    def on_data_changed(self):
        """Note, notebook or tag changed"""
        self.data_changed.emit()
Ejemplo n.º 19
0
  def __init__(self, oApp):
    try:
      # Install the appropriate editor translation file
      sLocale = locale.getdefaultlocale()[0]
      oTranslator = QTranslator()
      path=os.path.join('i18n', sLocale)
      if oTranslator.load(path):
        oApp.installTranslator(oTranslator)
        logging.debug( "translator: OK")
        
##      # Install the appropriate Qt translation file
##      oTranslatorQt = QTranslator()
##      print 'qt_' + sLocale, QLibraryInfo.location(QLibraryInfo.TranslationsPath)
##      if oTranslatorQt.load('qt_' + sLocale, QLibraryInfo.location(QLibraryInfo.TranslationsPath)):
##        oApp.installTranslator(oTranslatorQt)
          
    except Exception, oEx:
      logging.exception( "translator")
      pass
try:
    path.append("/usr/share/poliwireless")
except:
    pass
from poliwifi import PoliWifiLinux,workers
from PySide.QtGui import QApplication
from PySide.QtCore import QTranslator
from sys import argv
from time import sleep
import os.path as syspath
import subprocess
import locale

if __name__ == "__main__":
        
        translator = QTranslator()
        if syspath.exists('il8n/'+locale.getdefaultlocale()[0]):
            translator.load('il8n/'+locale.getdefaultlocale()[0])
        else:
            translator.load('/usr/share/poliwireless/il8n/'+locale.getdefaultlocale()[0])
        app=QApplication(argv)
        app.installTranslator(translator)
        gui = PoliWifiLinux()
        gui.show()
        app.exec_()
        
        if gui.handler.connectnow.isChecked():
            gui.nmhandler.autoConnectOn(workers.CLOSED_AP)
            sleep(2)
            
Ejemplo n.º 21
0
from PySide.QtCore import QTranslator
from PySide.QtCore import QLocale
from PySide.QtCore import QLibraryInfo
from PySide.QtCore import Qt

from qrmainwindow import QtReduceMainWindow

app = QApplication(sys.argv)

app.setOrganizationName("The Reduce Project")
app.setOrganizationDomain("reduce-algebra.sourceforge.net")
app.setApplicationName("QReduce")

qtTranslator = QTranslator(app)
qtTranslator.load("qt_" + QLocale.system().name(),
                  QLibraryInfo.location(QLibraryInfo.TranslationsPath))
app.installTranslator(qtTranslator)

qreduceTranslator = QTranslator(app)
qreduceTranslator.load(sys.path[0] + "/" + "qreducetr." +
                       str(locale.getdefaultlocale()[0]))
#app.installTranslator(qreduceTranslator)

# app.setStyleSheet("QStatusBar::item { border: 0px solid black }");

app.setWindowIcon(QIcon(sys.path[0] + "/" + "Bumblebee.png"))

if os.uname()[0] == "Darwin":
    app.setAttribute(Qt.AA_DontShowIconsInMenus)

mainwindow = QtReduceMainWindow()
Ejemplo n.º 22
0
        else:
            return ""

    def __setitem__(self, key, value):
        """Méthode magique sous-jacent à l'opérateur [] en écriture"""
        self.__settings.setValue(key, value)

    def __delitem__(self, key):
        """Méthode magique sous-jacent à l'opérateur del"""
        self.__settings.remove(key)


if __name__ == "__main__":
    """Main de test"""
    import sys
    from PySide.QtGui import QApplication
    from PySide.QtCore import QLibraryInfo, QLocale, QTranslator

    app = QApplication(sys.argv)

    locale = QLocale.system().name()
    translator = QTranslator()
    translator.load("qt_" + locale,
                    QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    app.installTranslator(translator)

    ui = ConfigUI()
    ui.show()
    ret = app.exec_()
    sys.exit(ret)
Ejemplo n.º 23
0
def createTranslator(language):
	translator = QTranslator()
	translator.load('local/' + Language.Language(language).name())
	return translator
Ejemplo n.º 24
0
import sys

from PySide.QtGui import QApplication
from PySide.QtCore import QTranslator

from gui.mainwindow import MainWindow
import constants
import utils
import texts

if __name__ == '__main__':

    app = QApplication(sys.argv)

    translator = QTranslator()
    translator.load(constants.QM_PATH)
    app.installTranslator(translator)

    mainwindow = MainWindow()

    def excepthook(excType, excValue, tracebackobj):
        msg_box = utils.getCriticalMessageBox(texts.GENERAL_ERROR_TITLE,
                                              texts.GENERAL_ERROR_MSG)
        msg_box.exec_()
        app.exit()

    sys.excepthook = excepthook

    try:
        from data.indicators.aggregation_indicators import *
        load_aggregation_operators()
Ejemplo n.º 25
0
"""
Module implementing Settings.
"""
import os
import sys
#print sys.getdefaultencoding()
from ctypes import *

from PySide import QtGui
from PySide.QtGui import *
from PySide import QtCore
from PySide.QtCore import Qt, QPoint, QTime, QTimer, QTextCodec, QTranslator
from PySide.QtCore import QTextDecoder, QByteArray
from PySide.QtGui import QApplication, QMainWindow, QTableWidgetItem, QKeyEvent, QTextCursor

from c.settings_controller import Settings

if __name__ == '__main__': 
    reload(sys)
    sys.setdefaultencoding('utf-8') 
    translator = QTranslator()
    translator.load('translations/cn')
    app = QApplication(sys.argv)
    app.installTranslator(translator)
    
    main_window = Settings()
    #main_window.showMaximized()
    main_window.show()
    sys.exit(app.exec_())
Ejemplo n.º 26
0
class Application(QObject):
    def __init__(self):
        QObject.__init__(self)
        self.__translator = QTranslator()
        self.__rules = Rules.Rules()
        self.__facts = Facts.Facts()
        self.expert = ExpertSystem.Expert(self.__rules, self.__facts)
        self.__ui = None
        self.current_question = None
        self.__finished = False

        self.__rules.add_rule(Rules.Rule("Z", ["R"]))
        self.__rules.add_rule(Rules.Rule("C", ["A", "B"]))
        self.__rules.add_rule(Rules.Rule("E", ["C", "D", "F"]))
        self.__rules.add_rule(Rules.Rule("D", ["C"]))

        self.__app = QApplication(sys.argv)

        self.__setup_language()
        self.__init_ui()

        self.reset()

    def __setup_language(self):
        system_locale, _ = locale.getdefaultlocale()
        search_folder = os.path.dirname(__file__)
        search_folder = os.path.join(search_folder, "..", "translations")
        self.__translator.load(system_locale, search_folder)
        self.__app.installTranslator(self.__translator)

    def __init_ui(self):
        self.__load_ui()
        self.__setup_slots()

    def __load_ui(self):
        ui_path = os.path.dirname(__file__)
        ui_path = os.path.join(ui_path, "MainWindow.ui")
        ui_file = QFile(ui_path)
        ui_file.open(QFile.ReadOnly)
        ui_loader = QtUiTools.QUiLoader()
        self.__ui = ui_loader.load(ui_file, None)
        ui_file.close()

        self.__ui.answerTableWidget.setHorizontalHeaderLabels([self.tr("Question"), self.tr("Answer")])

    def __setup_slots(self):
        self.__ui.answer.button(QtGui.QDialogButtonBox.Yes).clicked.connect(self.slot_answer_clicked_yes)
        self.__ui.answer.button(QtGui.QDialogButtonBox.No).clicked.connect(self.slot_answer_clicked_no)
        self.__ui.actionNew.triggered.connect(self.reset)
        self.__ui.actionLoadRules.triggered.connect(self.load_rules)

    def slot_answer_clicked_yes(self):
        self.slot_answer_clicked(True)

    def slot_answer_clicked_no(self):
        self.slot_answer_clicked(False)

    def slot_answer_clicked(self, answer):
        self.__facts.set_fact_value(self.current_question, answer)
        self.add_answer_to_list(self.current_question, answer)

        conclusion_rule = self.expert.infer_forward()
        conclusion_text = self.tr("Can't conclude")
        if conclusion_rule is not None and self.__rules.is_terminal_rule(conclusion_rule):
            conclusion_text = conclusion_rule.conclusion
            self.finished()
        self.__ui.conclusionLabel.setText(conclusion_text)

        self.next_answer()

    def add_answer_to_list(self, question, answer):
        count = self.__ui.answerTableWidget.rowCount()
        self.__ui.answerTableWidget.setRowCount(count + 1)
        self.__ui.answerTableWidget.setItem(count, 0, QtGui.QTableWidgetItem(question))
        answer_text = self.tr("Yes") if answer else self.tr("No")
        self.__ui.answerTableWidget.setItem(count, 1, QtGui.QTableWidgetItem(answer_text))

    def reset(self):
        self.__facts.reset()
        self.__ui.answer.setEnabled(True)
        self.__ui.answerTableWidget.setRowCount(0)
        self.__ui.conclusionLabel.setText(self.tr("Can't conclude"))
        self.__finished = False
        self.next_answer()

    def run(self):
        self.__ui.show()
        self.__app.exec_()

    def next_answer(self):
        question = self.expert.infer_backward()
        if question is not None and not self.__finished:
            self.current_question = question
        else:
            question = None
            self.finished()
        question = self.tr("No more questions!") if question is None else question
        self.__ui.questionLabel.setText(question)

    def finished(self):
        self.__ui.answer.setEnabled(False)
        self.__finished = True

    def load_rules(self):
        file_path, file_filter = QtGui.QFileDialog.getOpenFileName(self.__ui, self.tr("Select rules file"), "",
                                                                   self.tr("Rules file") + " (*.rules)")
        if file_path != "" and file_filter != "":
            self.__rules = RulesJsonSerializer.charge_rules(file_path)
            self.expert = ExpertSystem.Expert(self.__rules, self.__facts)
            self.reset()
Ejemplo n.º 27
0
class serverManagerWindow(QMainWindow):
    def __init__(self, _app, parent=None):
        QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.iTrayIcon = QSystemTrayIcon()
        self.iTrayIcon.setIcon(QIcon("drapes.ico"))
        self.iTrayIcon.show()
        self.iTrayIcon.setToolTip("One world, One dream!")
        self.iTrayIcon.activated.connect(self.iconActivated)
        self.quitAction = QAction("&Quit", self, triggered=QApplication.quit)
        self.trayIconMenu = QMenu(self)
        self.trayIconMenu.addAction(self.quitAction)
        self.iTrayIcon.setContextMenu(self.trayIconMenu)

        #选择MYSQL保留用户信息
        QObject.connect(self.ui.mysql_groupBox, SIGNAL("clicked()"), self, SLOT("choiceSql()"))
        #选择XT文件留用户信息
        QObject.connect(self.ui.text_groupBox, SIGNAL("clicked()"), self, SLOT("choiceTxt()"))
        #选择XML文件留用户信息
        QObject.connect(self.ui.xml_groupBox, SIGNAL("clicked()"), self, SLOT("choiceXml()"))                
        #节面显示英文
        QObject.connect(self.ui.actionEnglish, SIGNAL("activated()"), self, SLOT("loadEnglish()"))
        #节面显示中文
        QObject.connect(self.ui.actionChinese, SIGNAL("activated()"), self, SLOT("loadChinese()"))
        
        #加载配置文件
        QObject.connect(self.ui.actionLoad_Config, SIGNAL("activated()"), self, SLOT("loadConfig()"))
        #保留配置文件
        QObject.connect(self.ui.actionSave_Config, SIGNAL("activated()"), self, SLOT("saveConfig()"))
        #about操作
        QObject.connect(self.ui.actionAbout, SIGNAL("activated()"), self, SLOT("about()"))
        
        #选择XML文件
        QObject.connect(self.ui.openXml_pushButton, SIGNAL("clicked()"), self, SLOT("xml_open()"))
        #选择TXT文件
        QObject.connect(self.ui.openText_pushButton, SIGNAL("clicked()"), self, SLOT("txt_open()"))
        #启动服务
        QObject.connect(self.ui.startServer_pushButton, SIGNAL("clicked()"), self, SLOT("startServer()"))
        #停止服务
        QObject.connect(self.ui.stopServer_pushButton, SIGNAL("clicked()"), self, SLOT("stopServer()"))

        self.ui.sqlTypeComboBox.activated[str].connect(self.sqlServer)
                
        QObject.connect(self.ui.openSqlpushButton, SIGNAL("clicked()"), self, SLOT("database_open()"))
        

        #界面语言
        self.translator = None
        self.app = _app
        self.translator = QTranslator() 
        self.connect = None
        self.users = None
        self.ControlMediaPath = None
        self.ControlMedia = None
        self.delUsrInfo = None

        self.userModel = QStandardItemModel()
        self.userModel.setHorizontalHeaderItem(0, QStandardItem("user"))
        self.userModel.setHorizontalHeaderItem(1, QStandardItem("friends"))
        

        self.userModel.setVerticalHeaderItem(0, QStandardItem("1"))
        self.userModel.setVerticalHeaderItem(1, QStandardItem("2"))
        self.userModel.setVerticalHeaderItem(2, QStandardItem("3"))

        self.loginUserModel = QStandardItemModel()
        self.loginUserModel.setHorizontalHeaderItem(0, QStandardItem("user"))
        self.loginUserModel.setHorizontalHeaderItem(1, QStandardItem("instance"))
        
        self.messageModel = QStandardItemModel()
        self.messageModel.setHorizontalHeaderItem(0, QStandardItem("message"))

        #读取系统配置文件
        self.readConfig(configFile)
        self.statusBar().showMessage("server is stopped!")
        
        self.ui.userInfo_tableView.setModel(self.userModel)
        self.createUserInfoContextMenu()
        self.ui.loginUsers_tableView.setModel(self.loginUserModel)
        self.createloginUsersContextMenu()
        self.ui.messageLogs_listView.setModel(self.messageModel)

        #界面多语处理
        self.updateLanguage(self.language)
        
        self.center()
        
    def iconActivated(self, reason):
        if reason == QSystemTrayIcon.DoubleClick:
            self.show()
        print "iconActivated"
    
    def closeEvent(self, event):
        event.ignore()
        self.hide()
        print "closeEvent"

#    def changeEvent(self,event):
#        if (event.type() == QEvent.WindowStateChange) and (self.isMinimized()):
#            QTimer.singleShot(100, self, SLOT("close"))
#            
#        print "changeEvent"    
                
    def sqlServer(self, index):
        if index == "MySQL":
            self.ui.openSqlpushButton.setDisabled(True)
            self.ui.userLineEdit.setEnabled(True)
            self.ui.passwordlineEdit.setEnabled(True)        
            
        if  index == "Sqlite":
            self.ui.openSqlpushButton.setEnabled(True)
            self.ui.userLineEdit.setDisabled(True)
            self.ui.passwordlineEdit.setDisabled(True)        
        
    def center(self):  
        screen = QDesktopWidget().screenGeometry()  
        size = self.geometry()  
        self.move((screen.width() - size.width()) / 2,
            (screen.height() - size.height()) / 2)  
        
    def createUserInfoContextMenu(self):
        '''添加用户信息快捷菜单'''
        #pylint: disable=W0201
        self.addUserAct = QAction(self)
#        self.addUserAct.setText("add User")
        
        self.delUserAct = QAction(self)
#        self.delUserAct.setText("del User")

        self.undoDelUserAct = QAction(self)
#        self.undoDelUserAct.setText("undo del User")
        
        self.saveDataRowAct = QAction(self)
#        self.saveDataRowAct.setText("save Data")
        
        self.ui.userInfo_tableView.addAction(self.addUserAct)
        self.ui.userInfo_tableView.addAction(self.delUserAct)
        self.ui.userInfo_tableView.addAction(self.undoDelUserAct)
        self.ui.userInfo_tableView.addAction(self.saveDataRowAct)
        
        QObject.connect(self.addUserAct, SIGNAL("activated()"), self, SLOT("userInfoAddRow()"))
        QObject.connect(self.delUserAct, SIGNAL("activated()"), self, SLOT("userInfoDelRow()"))
        QObject.connect(self.undoDelUserAct, SIGNAL("activated()"), self, SLOT("userInfoUndoDelRow()"))        
        QObject.connect(self.saveDataRowAct, SIGNAL("activated()"), self, SLOT("userInfoSaveData()"))
        
        self.ui.userInfo_tableView.setContextMenuPolicy(Qt.ActionsContextMenu)

    
    def userInfoAddRow(self):
        '''添加一条用户数据'''
#        self.userModel.appendRow(QStandardItem(""))
        index = self.ui.userInfo_tableView.selectionModel().currentIndex()
        model = self.ui.userInfo_tableView.model()

        if not model.insertRow(index.row() + 1, index.parent()):
            return

        for column in range(model.columnCount(index.parent())):
            child = model.index(index.row() + 1, column, index.parent())
            model.setData(child, "[No data]", Qt.EditRole)
            
        uiDebug("userInfoAddRow")
    

    def userInfoDelRow(self):
        '''删除数据,且保留此次删除的数据'''
        model = self.ui.userInfo_tableView.model()
        index = self.ui.userInfo_tableView.selectionModel().currentIndex()
        user = model.item(index.row(), 0).index().data()
        friendlist = model.item(index.row(), 1).index().data()
        self.delUsrInfo = [index.row(), user, friendlist]
#        print self.delUsrInfo
        try:
            model.removeRow(index.row(), index.parent())
            self.users.deleteUser(user)
            self.users.userDataSave()
            #pylint: disable=W0702 
        except:    
            pass        
        uiDebug("userInfoDelRow")        

    def userInfoUndoDelRow(self):
        '''恢复前次删除的数据'''
        if self.delUsrInfo != None:
            model = self.ui.userInfo_tableView.model()
            if not model.insertRow(self.delUsrInfo[0]):
                return
            user = self.delUsrInfo[1]
            friendlist = self.delUsrInfo[2]      
            self.userModel.setItem(self.delUsrInfo[0], 0, QStandardItem(user))
            self.userModel.setItem(self.delUsrInfo[0], 1, QStandardItem(friendlist))
            if user != "[No data]":
                self.users.addUser(user, "admin")
            if friendlist != "[No data]":    
                for friend in friendlist.split(","):            
                    self.users.addUserFriend(user, friend)
            self.users.userDataSave()    
        self.delUsrInfo = None        
        uiDebug("userInfoUndoDelRow")


    def userInfoSaveData(self):
        '''保留用户数据'''
        if self.users:
            model = self.ui.userInfo_tableView.model()
            index = self.ui.userInfo_tableView.selectionModel().currentIndex()
            for row in range(model.rowCount(index.parent())):
                user = model.item(row, 0).index().data()
                friendlist = model.item(row, 1).index().data()
                if user != "[No data]":
                    self.users.addUser(user, "admin")
                if friendlist != "[No data]":
                    for friend in friendlist.split(","):
                        if friend != '':
                            self.users.addUserFriend(user, friend)   
        
            self.users.userDataSave()
            self.clearUserInfo()    
            self.showUserinfo()
        uiDebug("userInfoSaveData")        
    

    def showConfig(self):
        '''显示配置'''
#        print self.Config.getControlMedia()    
#        print self.Config.getControlMediaPath()   
#        print self.ControlMedia
#        print self.ControlMediaPath     
        self.ui.information_textBrowser.setText("Control Media: " + self.ControlMedia)
        self.ui.information_textBrowser.append("Control Media path: " + self.ControlMediaPath)

    def showUserinfo(self):
        '''显示用户信息'''
        userlist = self.users.getUsers()
        print "showUserinfo "
        print userlist
        row = 0
        for user in userlist:
            friends = userlist[user]
            self.userModel.setItem(row, 0, QStandardItem(user))
            self.userModel.setItem(row, 1, QStandardItem(friends))
            row = row + 1  
        #pylint: disable=W0201    
        self.delUsrInfo = None
    
    def clearUserInfo(self):
        '''清除用户信息'''
        self.userModel.clear()
        self.delUsrInfo = None

        
    def userConfig(self):
        self.showConfig()
        if self.users != None:
            del self.users        
        #服务器配置
        if self.ControlMedia == mediaValue[txt]:
            #txt文件保留用户信息
            self.users = txtUserControl(self.ControlMediaPath)
            self.ui.text_groupBox.setChecked(True)
            self.ui.text_lineEdit.setText(self.ControlMediaPath)
        elif self.ControlMedia == mediaValue[xml]:
            #xml文件保留用户信息
            self.users = xmlUserControl(self.ControlMediaPath)
            self.ui.xml_groupBox.setChecked(True)
            self.ui.xml_lineEdit.setText(self.ControlMediaPath)
            
        elif self.ControlMedia == mediaValue[mysql]:
            #mysql数据库保留用户信息   
            self.ui.mysql_groupBox.setChecked(True)
            self.ui.ServerLineEdit.setText(self.ControlMediaPath)
            self.ui.sqlTypeComboBox.setCurrentIndex(0)
#            print "mysql" 
            self.sqlServer(mysql)    
        elif self.ControlMedia == mediaValue[sqlite]:
            self.ui.mysql_groupBox.setChecked(True)
            self.ui.ServerLineEdit.setText(self.ControlMediaPath)
            self.ui.sqlTypeComboBox.setCurrentIndex(1)
            self.users = sqliteUserControl(self.ControlMediaPath)
            self.sqlServer(sqlite)
#            print "sqlite"
            
        #用户数据初始化
            
        try:     
            self.users.userDataInit()
#            self.showUserinfo()
            #pylint: disable=W0702
        except:
            self.users = None

        if self.users != None:
            self.clearUserInfo()
            self.showUserinfo()
                    
    def readConfig(self, _file):
        '''读取服务器端配置文件'''
        #pylint: disable=W0201
        self.Config = serverConfig(_file)
        self.ControlMedia = self.Config.getControlMedia() 
        self.ControlMediaPath = self.Config.getControlMediaPath()        
        self.language = self.Config.getLanguage()
        self.userConfig()
        uiDebug("readConfig")
                    
    def startServer(self):
        '''#启动服务'''
        self.ui.startServer_pushButton.setEnabled(False)
        self.ui.stopServer_pushButton.setEnabled(True)
        self.connect = server_twisted.serverMain(8002, self.users)
        self.saveConfig()
#        self.readConfig(configFile)
        self.userConfig()
        self.ui.mysql_groupBox.setDisabled(True)
        self.ui.text_groupBox.setDisabled(True)
        self.ui.xml_groupBox.setDisabled(True)
        self.statusBar().showMessage("server is starting!")
        
        if self.users != None:
            self.clearUserInfo()
            self.showUserinfo()
        uiDebug("startServer")

    def stopServer(self):
        ''' #停止服务'''
        if self.connect != None:
            self.ui.startServer_pushButton.setEnabled(True)
            self.ui.stopServer_pushButton.setEnabled(False)
            self.ui.mysql_groupBox.setDisabled(False)
            self.ui.text_groupBox.setDisabled(False)
            self.ui.xml_groupBox.setDisabled(False)  
            #pylint: disable=E1101          
            reactor.disconnectAll()
#            self.clearUserInfo()
            self.statusBar().showMessage("server is stopped!")
        uiDebug("stopServer")
        

    def loadChinese(self):
        '''加载中文'''
        self.updateLanguage(Chinese)

    def loadEnglish(self):
        '''加载英文'''
        self.updateLanguage(English)
        
    def updateLanguage(self, language):
        '''设置界面语言'''
        if self.translator != None:
            self.app.removeTranslator(self.translator)
            
        if language == Chinese:
            #中文处理
            self.translator.load(chineseLanguageFile)
            self.app.installTranslator(self.translator)  
            self.Config.setLanguage(Chinese)
        elif language == English:
            #英文处理
            self.Config.setLanguage(English)   
        else:
            pass
    
        #更新界面
        self.retranslateUi()
        #保留配置
        self.Config.saveServerConfig()
        
            
    def txt_open(self):
        self.fileOpen(self.ui.text_lineEdit, txt)
        
    def xml_open(self):
        self.fileOpen(self.ui.xml_lineEdit, xml)

    def database_open(self):
        self.fileOpen(self.ui.ServerLineEdit, mysql)

    def fileOpen(self, lineEdit, filters):
        openFile = QFileDialog.getOpenFileName(self, "Find Files", QDir.currentPath(), filters="*." + filters)
        uiDebug(openFile)
        if openFile != None :
            lineEdit.setText(openFile[0])
            self.setUserConfig()
            self.showConfig()
                    
    def choiceSql(self):
        uiDebug("choiceMysql")
        self.ui.text_groupBox.setChecked(False)
        self.ui.xml_groupBox.setChecked(False)
        if  self.ui.sqlTypeComboBox.currentText() == mysql:
            self.ui.openSqlpushButton.setDisabled(True)
            self.ui.userLineEdit.setEnabled(True)
            self.ui.passwordlineEdit.setEnabled(True)   
            
        if  self.ui.sqlTypeComboBox.currentText() == sqlite:
            self.ui.openSqlpushButton.setEnabled(True)
            self.ui.userLineEdit.setDisabled(True)
            self.ui.passwordlineEdit.setDisabled(True)
            
    def choiceTxt(self):
        uiDebug("choiceTxt")
        self.ui.mysql_groupBox.setChecked(False)
        self.ui.xml_groupBox.setChecked(False)

    def choiceXml(self):
        uiDebug("choiceXml")
        self.ui.mysql_groupBox.setChecked(False)
        self.ui.text_groupBox.setChecked(False)

    def setUserConfig(self):
        '''保留用户配置'''
        if self.ui.xml_groupBox.isChecked() == True:
            if self.ui.xml_lineEdit.text() != "":
                self.ControlMedia = xml
                self.ControlMediaPath = self.ui.xml_lineEdit.text()
                uiDebug("setUserConfig xml: " + xml)
         
        if self.ui.text_groupBox.isChecked() == True:
            if self.ui.text_lineEdit.text() != "":
                self.ControlMedia = txt
                self.ControlMediaPath = self.ui.text_lineEdit.text()
                uiDebug("setUserConfig txt: " + txt)
         
        if self.ui.mysql_groupBox.isChecked() == True:
            if self.ui.sqlTypeComboBox.currentText() == mysql:
                self.ControlMedia = mysql
                uiDebug("setUserConfig mysql: " + mysql)
            if self.ui.sqlTypeComboBox.currentText() == sqlite:
                self.ControlMedia = sqlite
                uiDebug("setUserConfig sqlite: " + sqlite)
            self.ControlMediaPath = self.ui.ServerLineEdit.text()

        self.Config.setContrlMedia(self.ControlMedia)
        self.Config.setControlMediaPath(self.ControlMediaPath)
        self.userConfig()    
        
    def createloginUsersContextMenu(self):
        '''添加登陆用户快捷菜单'''
        #pylint: disable=W0201
        self.killUserAct = QAction(self)
#        self.killUserAct.setText("kill user")
        
        self.messageUserAct = QAction(self)
#        self.messageUserAct.setText("message user")
        
        self.ui.loginUsers_tableView.addAction(self.killUserAct)
        self.ui.loginUsers_tableView.addAction(self.messageUserAct)
        
        QObject.connect(self.killUserAct, SIGNAL("activated()"), self, SLOT("killUser()"))
        QObject.connect(self.messageUserAct, SIGNAL("activated()"), self, SLOT("messageUser()"))
        
        self.ui.loginUsers_tableView.setContextMenuPolicy(Qt.ActionsContextMenu)

    def killUser(self):
        '''踢出一个用户'''
        try:
            index = self.ui.loginUsers_tableView.selectionModel().currentIndex()
            model = self.ui.loginUsers_tableView.model()
            user = model.item(index.row(), 0).index().data()
            self.connect.killUser(user)
            #pylint: disable=W0702
        except:
            pass    
#        model.removeRow(index.row(), index.parent())
        uiDebug("killUser")

    def messageUser(self):
        '''发送消息给用户'''
        uiDebug("messageUser")        
    
    def addUsers(self, user, instance):
        '''添加一条登陆用户数据'''

        index = self.ui.loginUsers_tableView.selectionModel().currentIndex()
        model = self.ui.loginUsers_tableView.model()
        row = model.rowCount(index.parent())
        model.setItem(row, 0, QStandardItem(user))
        model.setItem(row, 1, QStandardItem(str(instance)))
        
        uiDebug("loginUser")
    
    def removeUser(self, user):
        '''删除一条登陆用户数据'''
        index = self.ui.loginUsers_tableView.selectionModel().currentIndex()
        model = self.ui.loginUsers_tableView.model()
        maxRow = model.rowCount(index.parent())
#        print user
        for row in range(maxRow):
#            print row
#            print model.item(row, 0).index().data()
#            print type(model.item(row, 0).index().data())
            if user == model.item(row, 0).index().data():
                model.removeRow(row, index.parent())                             
                
        uiDebug("logoutUser")

    def refreshReceMessage(self, message):
        '''添加接收信息'''
        model = self.ui.messageLogs_listView.model()
#        model.setItem(model.rowCount(),QStandardItem(message))
        model.appendRow(QStandardItem(message))
        uiDebug("refreshReceMessage")        

    def refreshSendMessage(self, message):
        '''添加发送信息'''
        model = self.ui.messageLogs_listView.model()
#        model.setItem(model.rowCount(),QStandardItem(message))
        model.appendRow(QStandardItem(message))
        uiDebug("refreshSendMessage")        

    def retranslateUi(self):
        self.addUserAct.setText(QApplication.translate("MainWindow", "add User", None, QApplication.UnicodeUTF8))
        self.delUserAct.setText(QApplication.translate("MainWindow", "del User", None, QApplication.UnicodeUTF8))
        self.undoDelUserAct.setText(QApplication.translate("MainWindow", "undo del  User", None, QApplication.UnicodeUTF8))
        self.saveDataRowAct.setText(QApplication.translate("MainWindow", "save Data", None, QApplication.UnicodeUTF8))
        self.killUserAct.setText(QApplication.translate("MainWindow", "kill User", None, QApplication.UnicodeUTF8))
        self.messageUserAct.setText(QApplication.translate("MainWindow", "message User", None, QApplication.UnicodeUTF8))
        self.quitAction.setText(QApplication.translate("MainWindow", "Quit", None, QApplication.UnicodeUTF8))
        self.iTrayIcon.setToolTip(QApplication.translate("MainWindow", "One world, One dream!", None, QApplication.UnicodeUTF8))
        
        self.ui.retranslateUi(self)

    def loadConfig(self):
        '''加载配置文件'''
        configfile = QFileDialog.getOpenFileName(self, "Load Config File", QDir.currentPath(), filter="*.cfg")
        uiDebug(configfile)
        if configfile != None :
            self.readConfig(configfile)
            self.stopServer()
            self.startServer()
            self.showConfig()
        uiDebug("loadConfig") 

    def saveConfig(self):
        '''保留配置文件'''
        self.setUserConfig()
        self.Config.saveServerConfig()
        uiDebug("saveConfig") 

    def about(self):
        '''about'''
        aboutInfo = '''<HTML>
         <p>xdIm ver 0.2.0</p>
         <p>xdIm program is a software program by xd.</p>
         <p>Copy Right : "(C) 2008-2010 Programmers and Coders Everywhere"</p>
         <p><a href="http://www.xdIm.org/">http://www.xdIm.org</a></p>
         </HTML>"'''
         
        tranAboutInfo = QApplication.translate("MainWindow", aboutInfo, None, QApplication.UnicodeUTF8)
        QMessageBox.information(self, "xdIm information", tranAboutInfo)
        uiDebug("about") 
Ejemplo n.º 28
0
            return self.__settings.value(key)
        else:
            return ""

    def __setitem__(self, key, value):
        """Méthode magique sous-jacent à l'opérateur [] en écriture"""
        self.__settings.setValue(key, value)

    def __delitem__(self, key):
        """Méthode magique sous-jacent à l'opérateur del"""
        self.__settings.remove(key)

if __name__ == "__main__":
    """Main de test"""
    import sys
    from PySide.QtGui import QApplication
    from PySide.QtCore import QLibraryInfo, QLocale, QTranslator

    app = QApplication(sys.argv)

    locale = QLocale.system().name()
    translator = QTranslator()
    translator.load("qt_" + locale,
        QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    app.installTranslator(translator)

    ui = ConfigUI()
    ui.show()
    ret = app.exec_()
    sys.exit(ret)
Ejemplo n.º 29
0
Archivo: FCY.py Proyecto: uheee/FCY
# -*- coding: utf-8 -*-
from PySide.QtGui import QApplication
from PySide.QtCore import Qt, QTranslator
from ui.MainWindow import MainWindow
import sys
if __name__ == "__main__":
    app = QApplication(sys.argv)
    translator = QTranslator()
    translator.load(":/zh/qt_zh_CN.qm")
    app.installTranslator(translator)
    window = MainWindow()
    #window.setWindowFlags(window.windowFlags() &~ Qt.WindowMinMaxButtonsHint)
    window.setWindowFlags(window.windowFlags() & ~Qt.WindowMaximizeButtonHint)
    #window.setWindowFlags(Qt.FramelessWindowHint)
    window.show()
    sys.exit(app.exec_())