Пример #1
0
 def user_login(self):
     LoginScreen(controller=self)
Пример #2
0
    def main(self):
        """
        Main function of app. loads login screen if needed and starts main screen
        """
        app = QtWidgets.QApplication(sys.argv)
        app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
        self.app = app

        if platform.system() == 'Linux':
            QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)

        with open(curr_directory() + '/styles/dark_style.qss') as fl:
            style = fl.read()
        app.setStyleSheet(style)

        encrypt_save = toxes.ToxES()

        if self.path is not None:
            path = os.path.dirname(self.path) + '/'
            name = os.path.basename(self.path)[:-4]
            data = ProfileHelper(path, name).open_profile()
            if encrypt_save.is_data_encrypted(data):
                data = self.enter_pass(data)
            settings = Settings(name)
            self.tox = profile.tox_factory(data, settings)
        else:
            auto_profile = Settings.get_auto_profile()
            if not auto_profile[0]:
                # show login screen if default profile not found
                current_locale = QtCore.QLocale()
                curr_lang = current_locale.languageToString(
                    current_locale.language())
                langs = Settings.supported_languages()
                if curr_lang in langs:
                    lang_path = langs[curr_lang]
                    translator = QtCore.QTranslator()
                    translator.load(curr_directory() + '/translations/' +
                                    lang_path)
                    app.installTranslator(translator)
                    app.translator = translator
                ls = LoginScreen()
                ls.setWindowIconText("Toxygen")
                profiles = ProfileHelper.find_profiles()
                ls.update_select(map(lambda x: x[1], profiles))
                _login = self.Login(profiles)
                ls.update_on_close(_login.login_screen_close)
                ls.show()
                app.exec_()
                if not _login.t:
                    return
                elif _login.t == 1:  # create new profile
                    _login.name = _login.name.strip()
                    name = _login.name if _login.name else 'toxygen_user'
                    pr = map(lambda x: x[1], ProfileHelper.find_profiles())
                    if name in list(pr):
                        msgBox = QtWidgets.QMessageBox()
                        msgBox.setWindowTitle(
                            QtWidgets.QApplication.translate(
                                "MainWindow", "Error"))
                        text = (QtWidgets.QApplication.translate(
                            "MainWindow",
                            'Profile with this name already exists'))
                        msgBox.setText(text)
                        msgBox.exec_()
                        return
                    self.tox = profile.tox_factory()
                    self.tox.self_set_name(
                        bytes(_login.name, 'utf-8') if _login.
                        name else b'Toxygen User')
                    self.tox.self_set_status_message(b'Toxing on Toxygen')
                    reply = QtWidgets.QMessageBox.question(
                        None, 'Profile {}'.format(name),
                        QtWidgets.QApplication.translate(
                            "login", 'Do you want to set profile password?'),
                        QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
                    if reply == QtWidgets.QMessageBox.Yes:
                        set_pass = SetProfilePasswordScreen(encrypt_save)
                        set_pass.show()
                        self.app.lastWindowClosed.connect(self.app.quit)
                        self.app.exec_()
                    reply = QtWidgets.QMessageBox.question(
                        None, 'Profile {}'.format(name),
                        QtWidgets.QApplication.translate(
                            "login",
                            'Do you want to save profile in default folder? If no, profile will be saved in program folder'
                        ), QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
                    if reply == QtWidgets.QMessageBox.Yes:
                        path = Settings.get_default_path()
                    else:
                        path = curr_directory() + '/'
                    try:
                        ProfileHelper(path, name).save_profile(
                            self.tox.get_savedata())
                    except Exception as ex:
                        print(str(ex))
                        log('Profile creation exception: ' + str(ex))
                        msgBox = QtWidgets.QMessageBox()
                        msgBox.setText(
                            QtWidgets.QApplication.translate(
                                "login",
                                'Profile saving error! Does Toxygen have permission to write to this directory?'
                            ))
                        msgBox.exec_()
                        return
                    path = Settings.get_default_path()
                    settings = Settings(name)
                    if curr_lang in langs:
                        settings['language'] = curr_lang
                    settings.save()
                else:  # load existing profile
                    path, name = _login.get_data()
                    if _login.default:
                        Settings.set_auto_profile(path, name)
                    data = ProfileHelper(path, name).open_profile()
                    if encrypt_save.is_data_encrypted(data):
                        data = self.enter_pass(data)
                    settings = Settings(name)
                    self.tox = profile.tox_factory(data, settings)
            else:
                path, name = auto_profile
                data = ProfileHelper(path, name).open_profile()
                if encrypt_save.is_data_encrypted(data):
                    data = self.enter_pass(data)
                settings = Settings(name)
                self.tox = profile.tox_factory(data, settings)

        if Settings.is_active_profile(path, name):  # profile is in use
            reply = QtWidgets.QMessageBox.question(
                None, 'Profile {}'.format(name),
                QtWidgets.QApplication.translate(
                    "login",
                    'Other instance of Toxygen uses this profile or profile was not properly closed. Continue?'
                ), QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
            if reply != QtWidgets.QMessageBox.Yes:
                return
        else:
            settings.set_active_profile()

        # application color scheme
        for theme in settings.built_in_themes().keys():
            if settings['theme'] == theme:
                with open(curr_directory() +
                          settings.built_in_themes()[theme]) as fl:
                    style = fl.read()
                app.setStyleSheet(style)

        lang = Settings.supported_languages()[settings['language']]
        translator = QtCore.QTranslator()
        translator.load(curr_directory() + '/translations/' + lang)
        app.installTranslator(translator)
        app.translator = translator

        # tray icon
        self.tray = QtWidgets.QSystemTrayIcon(
            QtGui.QIcon(curr_directory() + '/images/icon.png'))
        self.tray.setObjectName('tray')

        self.ms = MainWindow(self.tox, self.reset, self.tray)
        app.aboutToQuit.connect(self.ms.close_window)

        class Menu(QtWidgets.QMenu):
            def newStatus(self, status):
                if not Settings.get_instance().locked:
                    profile.Profile.get_instance().set_status(status)
                    self.aboutToShowHandler()
                    self.hide()

            def aboutToShowHandler(self):
                status = profile.Profile.get_instance().status
                act = self.act
                if status is None or Settings.get_instance().locked:
                    self.actions()[1].setVisible(False)
                else:
                    self.actions()[1].setVisible(True)
                    act.actions()[0].setChecked(False)
                    act.actions()[1].setChecked(False)
                    act.actions()[2].setChecked(False)
                    act.actions()[status].setChecked(True)
                self.actions()[2].setVisible(
                    not Settings.get_instance().locked)

            def languageChange(self, *args, **kwargs):
                self.actions()[0].setText(
                    QtWidgets.QApplication.translate('tray', 'Open Toxygen'))
                self.actions()[1].setText(
                    QtWidgets.QApplication.translate('tray', 'Set status'))
                self.actions()[2].setText(
                    QtWidgets.QApplication.translate('tray', 'Exit'))
                self.act.actions()[0].setText(
                    QtWidgets.QApplication.translate('tray', 'Online'))
                self.act.actions()[1].setText(
                    QtWidgets.QApplication.translate('tray', 'Away'))
                self.act.actions()[2].setText(
                    QtWidgets.QApplication.translate('tray', 'Busy'))

        m = Menu()
        show = m.addAction(
            QtWidgets.QApplication.translate('tray', 'Open Toxygen'))
        sub = m.addMenu(QtWidgets.QApplication.translate('tray', 'Set status'))
        onl = sub.addAction(QtWidgets.QApplication.translate('tray', 'Online'))
        away = sub.addAction(QtWidgets.QApplication.translate('tray', 'Away'))
        busy = sub.addAction(QtWidgets.QApplication.translate('tray', 'Busy'))
        onl.setCheckable(True)
        away.setCheckable(True)
        busy.setCheckable(True)
        m.act = sub
        exit = m.addAction(QtWidgets.QApplication.translate('tray', 'Exit'))

        def show_window():
            s = Settings.get_instance()

            def show():
                if not self.ms.isActiveWindow():
                    self.ms.setWindowState(self.ms.windowState()
                                           & ~QtCore.Qt.WindowMinimized
                                           | QtCore.Qt.WindowActive)
                    self.ms.activateWindow()
                self.ms.show()

            if not s.locked:
                show()
            else:

                def correct_pass():
                    show()
                    s.locked = False
                    s.unlockScreen = False

                if not s.unlockScreen:
                    s.unlockScreen = True
                    self.p = UnlockAppScreen(toxes.ToxES.get_instance(),
                                             correct_pass)
                    self.p.show()

        def tray_activated(reason):
            if reason == QtWidgets.QSystemTrayIcon.DoubleClick:
                show_window()

        def close_app():
            if not Settings.get_instance().locked:
                settings.closing = True
                self.ms.close()

        show.triggered.connect(show_window)
        exit.triggered.connect(close_app)
        m.aboutToShow.connect(lambda: m.aboutToShowHandler())
        onl.triggered.connect(lambda: m.newStatus(0))
        away.triggered.connect(lambda: m.newStatus(1))
        busy.triggered.connect(lambda: m.newStatus(2))

        self.tray.setContextMenu(m)
        self.tray.show()
        self.tray.activated.connect(tray_activated)

        self.ms.show()

        updating = False
        if settings['update'] and updater.updater_available(
        ) and updater.connection_available():  # auto update
            version = updater.check_for_updates()
            if version is not None:
                if settings['update'] == 2:
                    updater.download(version)
                    updating = True
                else:
                    reply = QtWidgets.QMessageBox.question(
                        None, 'Toxygen',
                        QtWidgets.QApplication.translate(
                            "login",
                            'Update for Toxygen was found. Download and install it?'
                        ), QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
                    if reply == QtWidgets.QMessageBox.Yes:
                        updater.download(version)
                        updating = True

        if updating:
            data = self.tox.get_savedata()
            ProfileHelper.get_instance().save_profile(data)
            settings.close()
            del self.tox
            return

        plugin_helper = PluginLoader(self.tox, settings)  # plugin support
        plugin_helper.load()

        start()
        # init thread
        self.init = self.InitThread(self.tox, self.ms, self.tray)
        self.init.start()

        # starting threads for tox iterate and toxav iterate
        self.mainloop = self.ToxIterateThread(self.tox)
        self.mainloop.start()
        self.avloop = self.ToxAVIterateThread(self.tox.AV)
        self.avloop.start()

        if self.uri is not None:
            self.ms.add_contact(self.uri)

        app.lastWindowClosed.connect(app.quit)
        app.exec_()

        self.init.stop = True
        self.mainloop.stop = True
        self.avloop.stop = True
        plugin_helper.stop()
        stop()
        self.mainloop.wait()
        self.init.wait()
        self.avloop.wait()
        self.tray.hide()
        data = self.tox.get_savedata()
        ProfileHelper.get_instance().save_profile(data)
        settings.close()
        del self.tox
Пример #3
0
import curses
from loginscreen import LoginScreen
import time
from Animators import Animators
from menu import Menu
from myApp import MyApp

screen = LoginScreen()
screen.welcome()
selection = screen.selector(0)
username = ""
password = ""
login_success = False
while not login_success:
    if selection:
        login_success = screen.create_user()
        username = screen.username
        password = screen.password
    else:
        login_success = screen.login()
        username = screen.username
        password = screen.password

userpass = {'user': username, 'pass': password}
if login_success:
    curses.wrapper(MyApp, userpass)
else:
    print 'oops! something didn\'t work'
Пример #4
0
 def login_screen_setup(self):  ########### Screen 2 ##########
     self.login_scr = LoginScreen()
     self.sm.add_widget(self.login_scr)
Пример #5
0
    def main(self):
        """
        Main function of app. loads login screen if needed and starts main screen
        """
        app = QtGui.QApplication(sys.argv)
        app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
        self.app = app

        if platform.system() == 'Linux':
            QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)

        # application color scheme
        with open(curr_directory() + '/styles/style.qss') as fl:
            dark_style = fl.read()
        app.setStyleSheet(dark_style)

        encrypt_save = toxencryptsave.ToxEncryptSave()

        if self.path is not None:
            path = os.path.dirname(self.path) + '/'
            name = os.path.basename(self.path)[:-4]
            data = ProfileHelper(path, name).open_profile()
            if encrypt_save.is_data_encrypted(data):
                data = self.enter_pass(data)
            settings = Settings(name)
            self.tox = profile.tox_factory(data, settings)
        else:
            auto_profile = Settings.get_auto_profile()
            if not auto_profile[0]:
                # show login screen if default profile not found
                current_locale = QtCore.QLocale()
                curr_lang = current_locale.languageToString(current_locale.language())
                langs = Settings.supported_languages()
                if curr_lang in langs:
                    lang_path = langs[curr_lang]
                    translator = QtCore.QTranslator()
                    translator.load(curr_directory() + '/translations/' + lang_path)
                    app.installTranslator(translator)
                    app.translator = translator
                ls = LoginScreen()
                ls.setWindowIconText("Toxygen")
                profiles = ProfileHelper.find_profiles()
                ls.update_select(map(lambda x: x[1], profiles))
                _login = self.Login(profiles)
                ls.update_on_close(_login.login_screen_close)
                ls.show()
                app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
                app.exec_()
                if not _login.t:
                    return
                elif _login.t == 1:  # create new profile
                    _login.name = _login.name.strip()
                    name = _login.name if _login.name else 'toxygen_user'
                    pr = map(lambda x: x[1], ProfileHelper.find_profiles())
                    if name in list(pr):
                        msgBox = QtGui.QMessageBox()
                        msgBox.setWindowTitle(
                            QtGui.QApplication.translate("MainWindow", "Error", None, QtGui.QApplication.UnicodeUTF8))
                        text = (QtGui.QApplication.translate("MainWindow",
                                                             'Profile with this name already exists',
                                                             None, QtGui.QApplication.UnicodeUTF8))
                        msgBox.setText(text)
                        msgBox.exec_()
                        return
                    self.tox = profile.tox_factory()
                    self.tox.self_set_name(bytes(_login.name, 'utf-8') if _login.name else b'Toxygen User')
                    self.tox.self_set_status_message(b'Toxing on Toxygen')
                    reply = QtGui.QMessageBox.question(None,
                                                       'Profile {}'.format(name),
                                                       QtGui.QApplication.translate("login",
                                                                                    'Do you want to set profile password?',
                                                                                    None,
                                                                                    QtGui.QApplication.UnicodeUTF8),
                                                       QtGui.QMessageBox.Yes,
                                                       QtGui.QMessageBox.No)
                    if reply == QtGui.QMessageBox.Yes:
                        set_pass = SetProfilePasswordScreen(encrypt_save)
                        set_pass.show()
                        self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()"))
                        self.app.exec_()
                    ProfileHelper(Settings.get_default_path(), name).save_profile(self.tox.get_savedata())
                    path = Settings.get_default_path()
                    settings = Settings(name)
                    if curr_lang in langs:
                        settings['language'] = curr_lang
                    settings.save()
                else:  # load existing profile
                    path, name = _login.get_data()
                    if _login.default:
                        Settings.set_auto_profile(path, name)
                    data = ProfileHelper(path, name).open_profile()
                    if encrypt_save.is_data_encrypted(data):
                        data = self.enter_pass(data)
                    settings = Settings(name)
                    self.tox = profile.tox_factory(data, settings)
            else:
                path, name = auto_profile
                data = ProfileHelper(path, name).open_profile()
                if encrypt_save.is_data_encrypted(data):
                    data = self.enter_pass(data)
                settings = Settings(name)
                self.tox = profile.tox_factory(data, settings)

        if Settings.is_active_profile(path, name):  # profile is in use
            reply = QtGui.QMessageBox.question(None,
                                               'Profile {}'.format(name),
                                               QtGui.QApplication.translate("login", 'Other instance of Toxygen uses this profile or profile was not properly closed. Continue?', None, QtGui.QApplication.UnicodeUTF8),
                                               QtGui.QMessageBox.Yes,
                                               QtGui.QMessageBox.No)
            if reply != QtGui.QMessageBox.Yes:
                return
        else:
            settings.set_active_profile()

        lang = Settings.supported_languages()[settings['language']]
        translator = QtCore.QTranslator()
        translator.load(curr_directory() + '/translations/' + lang)
        app.installTranslator(translator)
        app.translator = translator

        # tray icon
        self.tray = QtGui.QSystemTrayIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
        self.tray.setObjectName('tray')

        self.ms = MainWindow(self.tox, self.reset, self.tray)

        class Menu(QtGui.QMenu):

            def newStatus(self, status):
                profile.Profile.get_instance().set_status(status)
                self.aboutToShow()
                self.hide()

            def aboutToShow(self):
                status = profile.Profile.get_instance().status
                act = self.act
                if status is None or Settings.get_instance().locked:
                    self.actions()[1].setVisible(False)
                else:
                    self.actions()[1].setVisible(True)
                    act.actions()[0].setChecked(False)
                    act.actions()[1].setChecked(False)
                    act.actions()[2].setChecked(False)
                    act.actions()[status].setChecked(True)
                self.actions()[2].setVisible(not Settings.get_instance().locked)

            def languageChange(self, *args, **kwargs):
                self.actions()[0].setText(QtGui.QApplication.translate('tray', 'Open Toxygen', None, QtGui.QApplication.UnicodeUTF8))
                self.actions()[1].setText(QtGui.QApplication.translate('tray', 'Set status', None, QtGui.QApplication.UnicodeUTF8))
                self.actions()[2].setText(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8))
                self.act.actions()[0].setText(QtGui.QApplication.translate('tray', 'Online', None, QtGui.QApplication.UnicodeUTF8))
                self.act.actions()[1].setText(QtGui.QApplication.translate('tray', 'Away', None, QtGui.QApplication.UnicodeUTF8))
                self.act.actions()[2].setText(QtGui.QApplication.translate('tray', 'Busy', None, QtGui.QApplication.UnicodeUTF8))

        m = Menu()
        show = m.addAction(QtGui.QApplication.translate('tray', 'Open Toxygen', None, QtGui.QApplication.UnicodeUTF8))
        sub = m.addMenu(QtGui.QApplication.translate('tray', 'Set status', None, QtGui.QApplication.UnicodeUTF8))
        onl = sub.addAction(QtGui.QApplication.translate('tray', 'Online', None, QtGui.QApplication.UnicodeUTF8))
        away = sub.addAction(QtGui.QApplication.translate('tray', 'Away', None, QtGui.QApplication.UnicodeUTF8))
        busy = sub.addAction(QtGui.QApplication.translate('tray', 'Busy', None, QtGui.QApplication.UnicodeUTF8))
        onl.setCheckable(True)
        away.setCheckable(True)
        busy.setCheckable(True)
        m.act = sub
        exit = m.addAction(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8))

        def show_window():
            def show():
                if not self.ms.isActiveWindow():
                    self.ms.setWindowState(self.ms.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
                    self.ms.activateWindow()
                self.ms.show()
            if not Settings.get_instance().locked:
                show()
            else:
                def correct_pass():
                    show()
                    Settings.get_instance().locked = False
                self.p = UnlockAppScreen(toxencryptsave.ToxEncryptSave.get_instance(), correct_pass)
                self.p.show()

        m.connect(show, QtCore.SIGNAL("triggered()"), show_window)
        m.connect(exit, QtCore.SIGNAL("triggered()"), lambda: app.exit())
        m.connect(m, QtCore.SIGNAL("aboutToShow()"), lambda: m.aboutToShow())
        sub.connect(onl, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(0))
        sub.connect(away, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(1))
        sub.connect(busy, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(2))

        self.tray.setContextMenu(m)
        self.tray.show()

        self.ms.show()

        plugin_helper = PluginLoader(self.tox, settings)  # plugin support
        plugin_helper.load()

        # init thread
        self.init = self.InitThread(self.tox, self.ms, self.tray)
        self.init.start()

        # starting threads for tox iterate and toxav iterate
        self.mainloop = self.ToxIterateThread(self.tox)
        self.mainloop.start()
        self.avloop = self.ToxAVIterateThread(self.tox.AV)
        self.avloop.start()

        if self.uri is not None:
            self.ms.add_contact(self.uri)

        app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
        app.exec_()
        self.init.stop = True
        self.mainloop.stop = True
        self.avloop.stop = True
        plugin_helper.stop()
        self.mainloop.wait()
        self.init.wait()
        self.avloop.wait()
        data = self.tox.get_savedata()
        ProfileHelper.get_instance().save_profile(data)
        settings.close()
        del self.tox
Пример #6
0
    def __init__(self):
        self.displaysize=(300,300)#(920,680)#
        self.worldsize=(0,0)
        #view port
        self.viewport=[0,0]#[int(self.player.x+self.displaysize[0]/2),int(self.player.y+self.displaysize[1]/2)]
        self.viewboxdim=[50,50] #w, h
        self.FPS=200#600#60
        #objects
        self.walls=[]
        self.npcs=[]
        self.attacks=[]
        self.otherplayers=[]
        self.grounditems=[]
        
        #interfaces
        self.inventory=Inventory(self)
        self.chat=Chat(self)
        self.rightclick=rightClick(self)
        self.combatstatusbars=statusbars(self)
        self.abilitybar=abilitybar(self)
        #inputs
        self.keyspressed=[] #for key HOLD DOWN
        self.keyspress=[] #for key DOWN 
        self.mouse_x=0
        self.mouse_y=0
        self.mouse_left=False
        self.mouse_left_up=False
        self.mouse_left_down=False
        
        self.mouse_right=False
        self.mouse_right_up=False
        self.mouse_right_down=False
        
        self.mouse_middle=False
        self.mouse_middle_up=False
        self.mouse_middle_down=False
        
        self.mouse_left_previous=False
        self.mouse_right_previous=False
        self.mouse_middle_previous=False
        
        #network
        self.client=Client("127.0.0.1",1337, self).start()
        #wait for terrain to load from server
        
        
        
        #log in screen
        self.loggedin=False
        self.loginscreen=LoginScreen()
        while self.loggedin==False:
            self.loginscreen.start()
            
            #if the window is exitted, stop the connection to the server
            if self.loginscreen.running==False:
                self.client.stop()
                return
                sys.exit()
            #get the name, pass, and which button was pressed
            name=str.join("",self.loginscreen.name_string)
            password=str.join("",self.loginscreen.password_string)
            login=self.loginscreen.login
        
            #try to log in
            t=time.time()
            self.client.log(name, password, login)
            while self.client.loginStatus==login_status["wait"]:
                if time.time()-t>10:
                    time.sleep(1)
                    print("connection to server timed out")
                    return
            print(self.client.loginStatus)
            if self.client.loginStatus==login_status["success"]:
                self.loggedin=True
                self.loginscreen.stop()
            else:
                self.client.loginStatus=login_status["wait"]
                

                
                
            
            
        #scene
        pygame.init()
        pygame.font.init()
        self.fontobject = pygame.font.Font(None,18)
        self.screen = pygame.display.set_mode(self.displaysize, pygame.HWSURFACE)
        #self.surface = pygame.Surface(self.displaysize, pygame.HWSURFACE | pygame.SRCALPHA)
        self.surface = pygame.Surface((150,150), pygame.HWSURFACE | pygame.SRCALPHA)
        self.clock=pygame.time.Clock()

        self.running=True
        

        
        #players
        self.player=player_self(self, name, self.client.pid, 100, 10).start()
        self.client.updatePlayerStart()
Пример #7
0
    def main(self):
        """
        Main function of app. loads login screen if needed and starts main screen
        """
        app = QtGui.QApplication(sys.argv)
        app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))

        # application color scheme
        with open(curr_directory() + '/styles/style.qss') as fl:
            dark_style = fl.read()
        app.setStyleSheet(dark_style)

        auto_profile = Settings.get_auto_profile()
        if not auto_profile:
            # show login screen if default profile not found
            current_locale = QtCore.QLocale()
            curr_lang = current_locale.languageToString(
                current_locale.language())
            langs = Settings.supported_languages()
            if curr_lang in map(lambda x: x[0], langs):
                lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1]
                translator = QtCore.QTranslator()
                translator.load(curr_directory() + '/translations/' +
                                lang_path)
                app.installTranslator(translator)
                app.translator = translator
            ls = LoginScreen()
            ls.setWindowIconText("Toxygen")
            profiles = ProfileHelper.find_profiles()
            ls.update_select(map(lambda x: x[1], profiles))
            _login = self.Login(profiles)
            ls.update_on_close(_login.login_screen_close)
            ls.show()
            app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app,
                        QtCore.SLOT("quit()"))
            app.exec_()
            if not _login.t:
                return
            elif _login.t == 1:  # create new profile
                name = _login.name if _login.name else 'toxygen_user'
                self.tox = tox_factory()
                self.tox.self_set_name(
                    _login.name if _login.name else 'Toxygen User')
                self.tox.self_set_status_message('Toxing on Toxygen')
                ProfileHelper.save_profile(self.tox.get_savedata(), name)
                path = Settings.get_default_path()
                settings = Settings(name)
            else:  # load existing profile
                path, name = _login.get_data()
                if _login.default:
                    Settings.set_auto_profile(path, name)
                data = ProfileHelper.open_profile(path, name)
                settings = Settings(name)
                self.tox = tox_factory(data, settings)
        else:
            path, name = auto_profile
            path = path.encode(locale.getpreferredencoding())
            data = ProfileHelper.open_profile(path, name)
            settings = Settings(name)
            self.tox = tox_factory(data, settings)

        if ProfileHelper.is_active_profile(path, name):  # profile is in use
            reply = QtGui.QMessageBox.question(
                None, 'Profile {}'.format(name),
                QtGui.QApplication.translate(
                    "login",
                    'Looks like other instance of Toxygen uses this profile! Continue?',
                    None, QtGui.QApplication.UnicodeUTF8),
                QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
            if reply != QtGui.QMessageBox.Yes:
                return
        else:
            settings.set_active_profile()

        lang = filter(lambda x: x[0] == settings['language'],
                      Settings.supported_languages())[0]
        translator = QtCore.QTranslator()
        translator.load(curr_directory() + '/translations/' + lang[1])
        app.installTranslator(translator)
        app.translator = translator

        self.ms = MainWindow(self.tox, self.reset)

        # tray icon
        self.tray = QtGui.QSystemTrayIcon(
            QtGui.QIcon(curr_directory() + '/images/icon.png'))
        self.tray.setObjectName('tray')

        class Menu(QtGui.QMenu):
            def languageChange(self, *args, **kwargs):
                self.actions()[0].setText(
                    QtGui.QApplication.translate(
                        'tray', 'Open Toxygen', None,
                        QtGui.QApplication.UnicodeUTF8))
                self.actions()[1].setText(
                    QtGui.QApplication.translate(
                        'tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8))

        m = Menu()
        show = m.addAction(
            QtGui.QApplication.translate('tray', 'Open Toxygen', None,
                                         QtGui.QApplication.UnicodeUTF8))
        exit = m.addAction(
            QtGui.QApplication.translate('tray', 'Exit', None,
                                         QtGui.QApplication.UnicodeUTF8))

        def show_window():
            if not self.ms.isActiveWindow():
                self.ms.setWindowState(self.ms.windowState()
                                       & ~QtCore.Qt.WindowMinimized
                                       | QtCore.Qt.WindowActive)
                self.ms.activateWindow()

        m.connect(show, QtCore.SIGNAL("triggered()"), show_window)
        m.connect(exit, QtCore.SIGNAL("triggered()"), lambda: app.exit())
        self.tray.setContextMenu(m)
        self.tray.show()

        self.ms.show()
        QtGui.QApplication.setStyle(get_style(
            settings['theme']))  # set application style

        # init thread
        self.init = self.InitThread(self.tox, self.ms, self.tray)
        self.init.start()

        # starting threads for tox iterate and toxav iterate
        self.mainloop = self.ToxIterateThread(self.tox)
        self.mainloop.start()
        self.avloop = self.ToxAVIterateThread(self.tox.AV)
        self.avloop.start()
        app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app,
                    QtCore.SLOT("quit()"))
        app.exec_()
        self.init.stop = True
        self.mainloop.stop = True
        self.avloop.stop = True
        self.mainloop.wait()
        self.init.wait()
        self.avloop.wait()
        data = self.tox.get_savedata()
        ProfileHelper.save_profile(data)
        settings.close()
        del self.tox
Пример #8
0
class world:
    def __init__(self):
        self.displaysize=(300,300)#(920,680)#
        self.worldsize=(0,0)
        #view port
        self.viewport=[0,0]#[int(self.player.x+self.displaysize[0]/2),int(self.player.y+self.displaysize[1]/2)]
        self.viewboxdim=[50,50] #w, h
        self.FPS=200#600#60
        #objects
        self.walls=[]
        self.npcs=[]
        self.attacks=[]
        self.otherplayers=[]
        self.grounditems=[]
        
        #interfaces
        self.inventory=Inventory(self)
        self.chat=Chat(self)
        self.rightclick=rightClick(self)
        self.combatstatusbars=statusbars(self)
        self.abilitybar=abilitybar(self)
        #inputs
        self.keyspressed=[] #for key HOLD DOWN
        self.keyspress=[] #for key DOWN 
        self.mouse_x=0
        self.mouse_y=0
        self.mouse_left=False
        self.mouse_left_up=False
        self.mouse_left_down=False
        
        self.mouse_right=False
        self.mouse_right_up=False
        self.mouse_right_down=False
        
        self.mouse_middle=False
        self.mouse_middle_up=False
        self.mouse_middle_down=False
        
        self.mouse_left_previous=False
        self.mouse_right_previous=False
        self.mouse_middle_previous=False
        
        #network
        self.client=Client("127.0.0.1",1337, self).start()
        #wait for terrain to load from server
        
        
        
        #log in screen
        self.loggedin=False
        self.loginscreen=LoginScreen()
        while self.loggedin==False:
            self.loginscreen.start()
            
            #if the window is exitted, stop the connection to the server
            if self.loginscreen.running==False:
                self.client.stop()
                return
                sys.exit()
            #get the name, pass, and which button was pressed
            name=str.join("",self.loginscreen.name_string)
            password=str.join("",self.loginscreen.password_string)
            login=self.loginscreen.login
        
            #try to log in
            t=time.time()
            self.client.log(name, password, login)
            while self.client.loginStatus==login_status["wait"]:
                if time.time()-t>10:
                    time.sleep(1)
                    print("connection to server timed out")
                    return
            print(self.client.loginStatus)
            if self.client.loginStatus==login_status["success"]:
                self.loggedin=True
                self.loginscreen.stop()
            else:
                self.client.loginStatus=login_status["wait"]
                

                
                
            
            
        #scene
        pygame.init()
        pygame.font.init()
        self.fontobject = pygame.font.Font(None,18)
        self.screen = pygame.display.set_mode(self.displaysize, pygame.HWSURFACE)
        #self.surface = pygame.Surface(self.displaysize, pygame.HWSURFACE | pygame.SRCALPHA)
        self.surface = pygame.Surface((150,150), pygame.HWSURFACE | pygame.SRCALPHA)
        self.clock=pygame.time.Clock()

        self.running=True
        

        
        #players
        self.player=player_self(self, name, self.client.pid, 100, 10).start()
        self.client.updatePlayerStart()
        


    def start(self):
        if self.loggedin==True:
            self.update()
        return self
    
    def update(self):
        while self.running:
            self.keyspress=[]#reset the tapped keys
            
            self.draw()
            
            #reset the mouse vars
            self.mouse_left_up=False
            self.mouse_left_down=False
            self.mouse_right_up=False
            self.mouse_right_down=False
            self.mouse_middle_up=False
            self.mouse_middle_down=False
            
            self.mouse_left_previous=self.mouse_left
            self.mouse_right_previous=self.mouse_right
            self.mouse_middle_previous=self.mouse_middle
            
            #mouse inputs
            mouse = pygame.mouse.get_pos() 
            self.mouse_x=mouse[0]
            self.mouse_y=mouse[1]
            clicks = pygame.mouse.get_pressed()
            self.mouse_left=clicks[0]
            self.mouse_middle=clicks[1]
            self.mouse_right=clicks[2]
            
            if self.mouse_left and self.mouse_left_previous==False:
                self.mouse_left_down=True
            if self.mouse_right and self.mouse_right_previous==False:
                self.mouse_right_down=True
            if self.mouse_left==False and self.mouse_left_previous:
                self.mouse_left_up=True
            if self.mouse_right==False and self.mouse_right_previous:
                self.mouse_right_up=True
            if self.mouse_middle and self.mouse_middle_previous==False:
                self.mouse_middle_down=True
            if self.mouse_middle==False and self.mouse_middle_previous:
                self.mouse_middle_up=True
                
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.stop()
                    return
                #keyboard
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        self.stop()
                        return
                    else:
                        self.keyspressed.append(event.key)
                        self.keyspress.append(event.key)
                elif event.type == pygame.KEYUP:
                    if event.key in self.keyspressed:
                        self.keyspressed.remove(event.key)

                        
            #self.player.update()
            self.chat.update()
            self.inventory.update()
            
            #update the view port
            
            centerx=-(self.player.x-self.displaysize[0]/2)
            centery=-(self.player.y-self.displaysize[1]/2)
            if self.viewport[0]<centerx-self.viewboxdim[0]:
                self.viewport[0]=centerx-self.viewboxdim[0]
            if self.viewport[0]>centerx+self.viewboxdim[0]:
                self.viewport[0]=centerx+self.viewboxdim[0]
            if self.viewport[1]<centery-self.viewboxdim[1]:
                self.viewport[1]=centery-self.viewboxdim[1]
            if self.viewport[1]>centery+self.viewboxdim[1]:
                self.viewport[1]=centery+self.viewboxdim[1]
            #self.viewport[0]=-(self.player.x-self.displaysize[0]/2)
            #self.viewport[1]=-(self.player.y-self.displaysize[1]/2)
            
            '''
            if self.chat.chatting==False:
                if ord("g") in self.keyspress or self.mouse_middle_down:
                        self.mouse_drag_pos=(self.mouse_x,self.mouse_y)
                if ord("g") in self.keyspressed or self.mouse_middle:
                    self.viewport[0]+=self.mouse_x-self.mouse_drag_pos[0]
                    self.viewport[1]+=self.mouse_y-self.mouse_drag_pos[1]
                    self.mouse_drag_pos=(self.mouse_x,self.mouse_y)
            '''
            #print(self.viewport)
            
            
           
    def draw(self):
        self.screen.fill((255,255,255))
        self.surface.fill((0,0,0,0))
        
        #draw bounding box of world
        pygame.draw.line(self.screen, (0,0,0), (self.viewport[0],self.viewport[1]),(self.viewport[0],self.worldsize[1]+self.viewport[1]),1)
        pygame.draw.line(self.screen, (0,0,0), (self.viewport[0],self.viewport[1]),(self.worldsize[0]+self.viewport[0],self.viewport[1]),1)
        pygame.draw.line(self.screen, (0,0,0), (self.viewport[0],self.worldsize[1]+self.viewport[1]),(self.worldsize[0]+self.viewport[0],self.worldsize[1]+self.viewport[1]),1)
        pygame.draw.line(self.screen, (0,0,0), (self.worldsize[0]+self.viewport[0],self.viewport[1]),(self.worldsize[0]+self.viewport[0],self.worldsize[1]+self.viewport[1]),1)
        
        self.player.draw()
        
        for c in self.npcs:
             if (self.player.x-self.displaysize[0]<c.x<self.player.x+self.displaysize[0]
                and self.player.y-self.displaysize[1]<c.y<self.player.y+self.displaysize[1]):
                 if c.hp>0:
                     c.draw()
                

        for c in self.otherplayers:
             if (self.player.x-self.displaysize[0]<c.x<self.player.x+self.displaysize[0]
                and self.player.y-self.displaysize[1]<c.y<self.player.y+self.displaysize[1]):
                 c.draw()
                 
        
        for i in self.grounditems:
            if (self.player.x-self.displaysize[0]<i.x<self.player.x+self.displaysize[0]
                and self.player.y-self.displaysize[1]<i.y<self.player.y+self.displaysize[1]):
                    i.draw()
                   
        
        for x in range(max(int(-self.viewport[0]/16),0),min(len(self.walls),int((self.displaysize[0]-self.viewport[0]+16)/16))):
            #for y in range(len(x)):
            for y in range(max(int(-self.viewport[1]/16),0),min(len(self.walls[x]),int((self.displaysize[1]-self.viewport[1]+16)/16))):
                if not self.walls[x][y]==None:
                    self.walls[x][y].draw()
        
        for c in self.attacks:
             if (self.player.x-self.displaysize[0]<c.x<self.player.x+self.displaysize[0]
                and self.player.y-self.displaysize[1]<c.y<self.player.y+self.displaysize[1]):
                 c.draw()
        #interfaces
        self.inventory.draw()
        self.chat.draw()
        self.combatstatusbars.draw()
        self.abilitybar.draw()
        
        self.rightclick.draw()
        
        self.screen.blit(self.fontobject.render(str(int(self.clock.get_fps())), 1, (0,0,0)),(self.displaysize[0]-25,5)) 

        
        self.screen.blit(self.surface, (0,0))
        
        
        
        pygame.display.update()
        self.clock.tick(self.FPS)
        
    def stop(self):
        self.running=False
        self.player.stop()
        self.client.stop()
        for c in self.otherplayers:
            c.stop()
        for c in self.npcs:
            c.stop()
        pygame.quit() 
         
    def findPlayer(self, pid):
        for c in self.otherplayers:
            if c.getpid()==pid:
                return c
        print("cant find player with pid "+str(pid))
        return None
    
    def findNPC(self, pid):
        for c in self.npcs:
            if c.pid==pid:
                return c
        print("cant find NPC with pid "+str(pid))
        return None
    def findItem(self, iid):
        for i in self.grounditems:
            if i.getiid()==iid:
                return i
        print("cant find item with iid "+str(iid))
        return None
Пример #9
0
    def main(self):
        """
        Main function of app. loads login screen if needed and starts main screen
        """
        app = QtGui.QApplication(sys.argv)
        app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
        self.app = app

        # application color scheme
        with open(curr_directory() + '/styles/style.qss') as fl:
            dark_style = fl.read()
        app.setStyleSheet(dark_style)

        encrypt_save = toxencryptsave.LibToxEncryptSave()

        if self.path is not None:
            path = os.path.dirname(self.path) + '/'
            name = os.path.basename(self.path)[:-4]
            data = ProfileHelper(path, name).open_profile()
            if encrypt_save.is_data_encrypted(data):
                data = self.enter_pass(data)
            settings = Settings(name)
            self.tox = tox_factory(data, settings)
        else:
            auto_profile = Settings.get_auto_profile()
            if not auto_profile[0]:
                # show login screen if default profile not found
                current_locale = QtCore.QLocale()
                curr_lang = current_locale.languageToString(
                    current_locale.language())
                langs = Settings.supported_languages()
                if curr_lang in langs:
                    lang_path = langs[curr_lang]
                    translator = QtCore.QTranslator()
                    translator.load(curr_directory() + '/translations/' +
                                    lang_path)
                    app.installTranslator(translator)
                    app.translator = translator
                ls = LoginScreen()
                ls.setWindowIconText("Toxygen")
                profiles = ProfileHelper.find_profiles()
                ls.update_select(map(lambda x: x[1], profiles))
                _login = self.Login(profiles)
                ls.update_on_close(_login.login_screen_close)
                ls.show()
                app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app,
                            QtCore.SLOT("quit()"))
                app.exec_()
                if not _login.t:
                    return
                elif _login.t == 1:  # create new profile
                    _login.name = _login.name.strip()
                    name = _login.name if _login.name else 'toxygen_user'
                    self.tox = tox_factory()
                    self.tox.self_set_name(
                        bytes(_login.name, 'utf-8') if _login.
                        name else b'Toxygen User')
                    self.tox.self_set_status_message(b'Toxing on Toxygen')
                    ProfileHelper(Settings.get_default_path(),
                                  name).save_profile(self.tox.get_savedata())
                    path = Settings.get_default_path()
                    settings = Settings(name)
                else:  # load existing profile
                    path, name = _login.get_data()
                    if _login.default:
                        Settings.set_auto_profile(path, name)
                    data = ProfileHelper(path, name).open_profile()
                    if encrypt_save.is_data_encrypted(data):
                        data = self.enter_pass(data)
                    settings = Settings(name)
                    self.tox = tox_factory(data, settings)
            else:
                path, name = auto_profile
                data = ProfileHelper(path, name).open_profile()
                if encrypt_save.is_data_encrypted(data):
                    data = self.enter_pass(data)
                settings = Settings(name)
                self.tox = tox_factory(data, settings)

        if Settings.is_active_profile(path, name):  # profile is in use
            reply = QtGui.QMessageBox.question(
                None, 'Profile {}'.format(name),
                QtGui.QApplication.translate(
                    "login",
                    'Looks like other instance of Toxygen uses this profile! Continue?',
                    None, QtGui.QApplication.UnicodeUTF8),
                QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
            if reply != QtGui.QMessageBox.Yes:
                return
        else:
            settings.set_active_profile()

        lang = Settings.supported_languages()[settings['language']]
        translator = QtCore.QTranslator()
        translator.load(curr_directory() + '/translations/' + lang)
        app.installTranslator(translator)
        app.translator = translator

        # tray icon
        self.tray = QtGui.QSystemTrayIcon(
            QtGui.QIcon(curr_directory() + '/images/icon.png'))
        self.tray.setObjectName('tray')

        self.ms = MainWindow(self.tox, self.reset, self.tray)

        class Menu(QtGui.QMenu):
            def newStatus(self, status):
                profile.Profile.get_instance().set_status(status)
                self.aboutToShow()
                self.hide()

            def aboutToShow(self):
                status = profile.Profile.get_instance().status
                act = self.act
                if status is None:
                    self.actions()[1].setVisible(False)
                else:
                    self.actions()[1].setVisible(True)
                    act.actions()[0].setChecked(False)
                    act.actions()[1].setChecked(False)
                    act.actions()[2].setChecked(False)
                    act.actions()[status].setChecked(True)

            def languageChange(self, *args, **kwargs):
                self.actions()[0].setText(
                    QtGui.QApplication.translate(
                        'tray', 'Open Toxygen', None,
                        QtGui.QApplication.UnicodeUTF8))
                self.actions()[1].setText(
                    QtGui.QApplication.translate(
                        'tray', 'Set status', None,
                        QtGui.QApplication.UnicodeUTF8))
                self.actions()[2].setText(
                    QtGui.QApplication.translate(
                        'tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8))
                self.act.actions()[0].setText(
                    QtGui.QApplication.translate(
                        'tray', 'Online', None,
                        QtGui.QApplication.UnicodeUTF8))
                self.act.actions()[1].setText(
                    QtGui.QApplication.translate(
                        'tray', 'Away', None, QtGui.QApplication.UnicodeUTF8))
                self.act.actions()[2].setText(
                    QtGui.QApplication.translate(
                        'tray', 'Busy', None, QtGui.QApplication.UnicodeUTF8))

        m = Menu()
        show = m.addAction(
            QtGui.QApplication.translate('tray', 'Open Toxygen', None,
                                         QtGui.QApplication.UnicodeUTF8))
        sub = m.addMenu(
            QtGui.QApplication.translate('tray', 'Set status', None,
                                         QtGui.QApplication.UnicodeUTF8))
        onl = sub.addAction(
            QtGui.QApplication.translate('tray', 'Online', None,
                                         QtGui.QApplication.UnicodeUTF8))
        away = sub.addAction(
            QtGui.QApplication.translate('tray', 'Away', None,
                                         QtGui.QApplication.UnicodeUTF8))
        busy = sub.addAction(
            QtGui.QApplication.translate('tray', 'Busy', None,
                                         QtGui.QApplication.UnicodeUTF8))
        onl.setCheckable(True)
        away.setCheckable(True)
        busy.setCheckable(True)
        m.act = sub
        exit = m.addAction(
            QtGui.QApplication.translate('tray', 'Exit', None,
                                         QtGui.QApplication.UnicodeUTF8))

        def show_window():
            if not self.ms.isActiveWindow():
                self.ms.setWindowState(self.ms.windowState()
                                       & ~QtCore.Qt.WindowMinimized
                                       | QtCore.Qt.WindowActive)
                self.ms.activateWindow()
            self.ms.show()

        m.connect(show, QtCore.SIGNAL("triggered()"), show_window)
        m.connect(exit, QtCore.SIGNAL("triggered()"), lambda: app.exit())
        m.connect(m, QtCore.SIGNAL("aboutToShow()"), lambda: m.aboutToShow())
        sub.connect(onl, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(0))
        sub.connect(away, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(1))
        sub.connect(busy, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(2))

        self.tray.setContextMenu(m)
        self.tray.show()

        self.ms.show()

        plugin_helper = PluginLoader(self.tox, settings)  # plugin support
        plugin_helper.load()

        # init thread
        self.init = self.InitThread(self.tox, self.ms, self.tray)
        self.init.start()

        # starting threads for tox iterate and toxav iterate
        self.mainloop = self.ToxIterateThread(self.tox)
        self.mainloop.start()
        self.avloop = self.ToxAVIterateThread(self.tox.AV)
        self.avloop.start()

        if self.uri is not None:
            self.ms.add_contact(self.uri)

        app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app,
                    QtCore.SLOT("quit()"))
        app.exec_()
        self.init.stop = True
        self.mainloop.stop = True
        self.avloop.stop = True
        plugin_helper.stop()
        self.mainloop.wait()
        self.init.wait()
        self.avloop.wait()
        data = self.tox.get_savedata()
        ProfileHelper.get_instance().save_profile(data)
        settings.close()
        del self.tox
Пример #10
0
    def main(self):
        """
        Main function of app. loads login screen if needed and starts main screen
        """
        app = QtGui.QApplication(sys.argv)
        app.setWindowIcon(QtGui.QIcon(curr_directory() + "/images/icon.png"))
        self.app = app

        if platform.system() == "Linux":
            QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)

        # application color scheme
        with open(curr_directory() + "/styles/style.qss") as fl:
            dark_style = fl.read()
        app.setStyleSheet(dark_style)

        encrypt_save = toxencryptsave.ToxEncryptSave()

        if self.path is not None:
            path = os.path.dirname(self.path) + "/"
            name = os.path.basename(self.path)[:-4]
            data = ProfileHelper(path, name).open_profile()
            if encrypt_save.is_data_encrypted(data):
                data = self.enter_pass(data)
            settings = Settings(name)
            self.tox = profile.tox_factory(data, settings)
        else:
            auto_profile = Settings.get_auto_profile()
            if not auto_profile[0]:
                # show login screen if default profile not found
                current_locale = QtCore.QLocale()
                curr_lang = current_locale.languageToString(current_locale.language())
                langs = Settings.supported_languages()
                if curr_lang in langs:
                    lang_path = langs[curr_lang]
                    translator = QtCore.QTranslator()
                    translator.load(curr_directory() + "/translations/" + lang_path)
                    app.installTranslator(translator)
                    app.translator = translator
                ls = LoginScreen()
                ls.setWindowIconText("Toxygen")
                profiles = ProfileHelper.find_profiles()
                ls.update_select(map(lambda x: x[1], profiles))
                _login = self.Login(profiles)
                ls.update_on_close(_login.login_screen_close)
                ls.show()
                app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
                app.exec_()
                if not _login.t:
                    return
                elif _login.t == 1:  # create new profile
                    _login.name = _login.name.strip()
                    name = _login.name if _login.name else "toxygen_user"
                    pr = map(lambda x: x[1], ProfileHelper.find_profiles())
                    if name in list(pr):
                        msgBox = QtGui.QMessageBox()
                        msgBox.setWindowTitle(
                            QtGui.QApplication.translate("MainWindow", "Error", None, QtGui.QApplication.UnicodeUTF8)
                        )
                        text = QtGui.QApplication.translate(
                            "MainWindow", "Profile with this name already exists", None, QtGui.QApplication.UnicodeUTF8
                        )
                        msgBox.setText(text)
                        msgBox.exec_()
                        return
                    self.tox = profile.tox_factory()
                    self.tox.self_set_name(bytes(_login.name, "utf-8") if _login.name else b"Toxygen User")
                    self.tox.self_set_status_message(b"Toxing on Toxygen")
                    reply = QtGui.QMessageBox.question(
                        None,
                        "Profile {}".format(name),
                        QtGui.QApplication.translate(
                            "login", "Do you want to set profile password?", None, QtGui.QApplication.UnicodeUTF8
                        ),
                        QtGui.QMessageBox.Yes,
                        QtGui.QMessageBox.No,
                    )
                    if reply == QtGui.QMessageBox.Yes:
                        set_pass = SetProfilePasswordScreen(encrypt_save)
                        set_pass.show()
                        self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()"))
                        self.app.exec_()
                    reply = QtGui.QMessageBox.question(
                        None,
                        "Profile {}".format(name),
                        QtGui.QApplication.translate(
                            "login",
                            "Do you want to save profile in default folder? If no, profile will be saved in program folder",
                            None,
                            QtGui.QApplication.UnicodeUTF8,
                        ),
                        QtGui.QMessageBox.Yes,
                        QtGui.QMessageBox.No,
                    )
                    if reply == QtGui.QMessageBox.Yes:
                        path = Settings.get_default_path()
                    else:
                        path = curr_directory() + "/"
                    try:
                        ProfileHelper(path, name).save_profile(self.tox.get_savedata())
                    except Exception as ex:
                        print(str(ex))
                        log("Profile creation exception: " + str(ex))
                        msgBox = QtGui.QMessageBox()
                        msgBox.setText(
                            QtGui.QApplication.translate(
                                "login",
                                "Profile saving error! Does Toxygen have permission to write to this directory?",
                                None,
                                QtGui.QApplication.UnicodeUTF8,
                            )
                        )
                        msgBox.exec_()
                        return
                    path = Settings.get_default_path()
                    settings = Settings(name)
                    if curr_lang in langs:
                        settings["language"] = curr_lang
                    settings.save()
                else:  # load existing profile
                    path, name = _login.get_data()
                    if _login.default:
                        Settings.set_auto_profile(path, name)
                    data = ProfileHelper(path, name).open_profile()
                    if encrypt_save.is_data_encrypted(data):
                        data = self.enter_pass(data)
                    settings = Settings(name)
                    self.tox = profile.tox_factory(data, settings)
            else:
                path, name = auto_profile
                data = ProfileHelper(path, name).open_profile()
                if encrypt_save.is_data_encrypted(data):
                    data = self.enter_pass(data)
                settings = Settings(name)
                self.tox = profile.tox_factory(data, settings)

        if Settings.is_active_profile(path, name):  # profile is in use
            reply = QtGui.QMessageBox.question(
                None,
                "Profile {}".format(name),
                QtGui.QApplication.translate(
                    "login",
                    "Other instance of Toxygen uses this profile or profile was not properly closed. Continue?",
                    None,
                    QtGui.QApplication.UnicodeUTF8,
                ),
                QtGui.QMessageBox.Yes,
                QtGui.QMessageBox.No,
            )
            if reply != QtGui.QMessageBox.Yes:
                return
        else:
            settings.set_active_profile()

        lang = Settings.supported_languages()[settings["language"]]
        translator = QtCore.QTranslator()
        translator.load(curr_directory() + "/translations/" + lang)
        app.installTranslator(translator)
        app.translator = translator

        # tray icon
        self.tray = QtGui.QSystemTrayIcon(QtGui.QIcon(curr_directory() + "/images/icon.png"))
        self.tray.setObjectName("tray")

        self.ms = MainWindow(self.tox, self.reset, self.tray)
        app.aboutToQuit.connect(self.ms.close_window)

        class Menu(QtGui.QMenu):
            def newStatus(self, status):
                profile.Profile.get_instance().set_status(status)
                self.aboutToShow()
                self.hide()

            def aboutToShow(self):
                status = profile.Profile.get_instance().status
                act = self.act
                if status is None or Settings.get_instance().locked:
                    self.actions()[1].setVisible(False)
                else:
                    self.actions()[1].setVisible(True)
                    act.actions()[0].setChecked(False)
                    act.actions()[1].setChecked(False)
                    act.actions()[2].setChecked(False)
                    act.actions()[status].setChecked(True)
                self.actions()[2].setVisible(not Settings.get_instance().locked)

            def languageChange(self, *args, **kwargs):
                self.actions()[0].setText(
                    QtGui.QApplication.translate("tray", "Open Toxygen", None, QtGui.QApplication.UnicodeUTF8)
                )
                self.actions()[1].setText(
                    QtGui.QApplication.translate("tray", "Set status", None, QtGui.QApplication.UnicodeUTF8)
                )
                self.actions()[2].setText(
                    QtGui.QApplication.translate("tray", "Exit", None, QtGui.QApplication.UnicodeUTF8)
                )
                self.act.actions()[0].setText(
                    QtGui.QApplication.translate("tray", "Online", None, QtGui.QApplication.UnicodeUTF8)
                )
                self.act.actions()[1].setText(
                    QtGui.QApplication.translate("tray", "Away", None, QtGui.QApplication.UnicodeUTF8)
                )
                self.act.actions()[2].setText(
                    QtGui.QApplication.translate("tray", "Busy", None, QtGui.QApplication.UnicodeUTF8)
                )

        m = Menu()
        show = m.addAction(QtGui.QApplication.translate("tray", "Open Toxygen", None, QtGui.QApplication.UnicodeUTF8))
        sub = m.addMenu(QtGui.QApplication.translate("tray", "Set status", None, QtGui.QApplication.UnicodeUTF8))
        onl = sub.addAction(QtGui.QApplication.translate("tray", "Online", None, QtGui.QApplication.UnicodeUTF8))
        away = sub.addAction(QtGui.QApplication.translate("tray", "Away", None, QtGui.QApplication.UnicodeUTF8))
        busy = sub.addAction(QtGui.QApplication.translate("tray", "Busy", None, QtGui.QApplication.UnicodeUTF8))
        onl.setCheckable(True)
        away.setCheckable(True)
        busy.setCheckable(True)
        m.act = sub
        exit = m.addAction(QtGui.QApplication.translate("tray", "Exit", None, QtGui.QApplication.UnicodeUTF8))

        def show_window():
            def show():
                if not self.ms.isActiveWindow():
                    self.ms.setWindowState(self.ms.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
                    self.ms.activateWindow()
                self.ms.show()

            if not Settings.get_instance().locked:
                show()
            else:

                def correct_pass():
                    show()
                    Settings.get_instance().locked = False

                self.p = UnlockAppScreen(toxencryptsave.ToxEncryptSave.get_instance(), correct_pass)
                self.p.show()

        def tray_activated(reason):
            if reason == QtGui.QSystemTrayIcon.DoubleClick:
                show_window()

        def close_app():
            settings.closing = True
            self.ms.close()

        m.connect(show, QtCore.SIGNAL("triggered()"), show_window)
        m.connect(exit, QtCore.SIGNAL("triggered()"), close_app)
        m.connect(m, QtCore.SIGNAL("aboutToShow()"), lambda: m.aboutToShow())
        sub.connect(onl, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(0))
        sub.connect(away, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(1))
        sub.connect(busy, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(2))

        self.tray.setContextMenu(m)
        self.tray.show()
        self.tray.activated.connect(tray_activated)

        self.ms.show()

        updating = False
        if settings["update"] and updater.updater_available() and updater.connection_available():  # auto update
            version = updater.check_for_updates()
            if version is not None:
                if settings["update"] == 2:
                    updater.download(version)
                    updating = True
                else:
                    reply = QtGui.QMessageBox.question(
                        None,
                        "Toxygen",
                        QtGui.QApplication.translate(
                            "login",
                            "Update for Toxygen was found. Download and install it?",
                            None,
                            QtGui.QApplication.UnicodeUTF8,
                        ),
                        QtGui.QMessageBox.Yes,
                        QtGui.QMessageBox.No,
                    )
                    if reply == QtGui.QMessageBox.Yes:
                        updater.download(version)
                        updating = True

        if updating:
            data = self.tox.get_savedata()
            ProfileHelper.get_instance().save_profile(data)
            settings.close()
            del self.tox
            return

        plugin_helper = PluginLoader(self.tox, settings)  # plugin support
        plugin_helper.load()

        start()
        # init thread
        self.init = self.InitThread(self.tox, self.ms, self.tray)
        self.init.start()

        # starting threads for tox iterate and toxav iterate
        self.mainloop = self.ToxIterateThread(self.tox)
        self.mainloop.start()
        self.avloop = self.ToxAVIterateThread(self.tox.AV)
        self.avloop.start()

        if self.uri is not None:
            self.ms.add_contact(self.uri)

        app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
        app.exec_()

        self.init.stop = True
        self.mainloop.stop = True
        self.avloop.stop = True
        plugin_helper.stop()
        stop()
        self.mainloop.wait()
        self.init.wait()
        self.avloop.wait()
        data = self.tox.get_savedata()
        ProfileHelper.get_instance().save_profile(data)
        settings.close()
        del self.tox
Пример #11
0
import curses
from loginscreen import LoginScreen
import time
from Animators import Animators
from menu import Menu
from myApp import MyApp

screen = LoginScreen()
screen.welcome()
selection = screen.selector(0)
username = ""
password = ""
login_success = False
while not login_success:
    if selection:
        login_success = screen.create_user()
        username = screen.username
        password = screen.password
    else:
        login_success = screen.login()
        username = screen.username
        password = screen.password

userpass = {'user':username, 'pass':password}
if login_success:
	curses.wrapper(MyApp, userpass)
else:
	print 'oops! something didn\'t work'


Пример #12
0
    def main(self):
        """
        Main function of app. loads login screen if needed and starts main screen
        """
        app = QtGui.QApplication(sys.argv)
        app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))

        # application color scheme
        with open(curr_directory() + '/styles/style.qss') as fl:
            dark_style = fl.read()
        app.setStyleSheet(dark_style)

        auto_profile = Settings.get_auto_profile()
        if not auto_profile:
            # show login screen if default profile not found
            current_locale = QtCore.QLocale()
            curr_lang = current_locale.languageToString(current_locale.language())
            langs = Settings.supported_languages()
            if curr_lang in map(lambda x: x[0], langs):
                lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1]
                translator = QtCore.QTranslator()
                translator.load(curr_directory() + '/translations/' + lang_path)
                app.installTranslator(translator)
                app.translator = translator
            ls = LoginScreen()
            ls.setWindowIconText("Toxygen")
            profiles = ProfileHelper.find_profiles()
            ls.update_select(map(lambda x: x[1], profiles))
            _login = self.Login(profiles)
            ls.update_on_close(_login.login_screen_close)
            ls.show()
            app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
            app.exec_()
            if not _login.t:
                return
            elif _login.t == 1:  # create new profile
                name = _login.name if _login.name else 'toxygen_user'
                self.tox = tox_factory()
                self.tox.self_set_name(_login.name if _login.name else 'Toxygen User')
                self.tox.self_set_status_message('Toxing on Toxygen')
                ProfileHelper.save_profile(self.tox.get_savedata(), name)
                path = Settings.get_default_path()
                settings = Settings(name)
            else:  # load existing profile
                path, name = _login.get_data()
                if _login.default:
                    Settings.set_auto_profile(path, name)
                data = ProfileHelper.open_profile(path, name)
                settings = Settings(name)
                self.tox = tox_factory(data, settings)
        else:
            path, name = auto_profile
            path = path.encode(locale.getpreferredencoding())
            data = ProfileHelper.open_profile(path, name)
            settings = Settings(name)
            self.tox = tox_factory(data, settings)

        if ProfileHelper.is_active_profile(path, name):  # profile is in use
            reply = QtGui.QMessageBox.question(None,
                                               'Profile {}'.format(name),
                                               QtGui.QApplication.translate("login", 'Looks like other instance of Toxygen uses this profile! Continue?', None, QtGui.QApplication.UnicodeUTF8),
                                               QtGui.QMessageBox.Yes,
                                               QtGui.QMessageBox.No)
            if reply != QtGui.QMessageBox.Yes:
                return
        else:
            settings.set_active_profile()

        lang = filter(lambda x: x[0] == settings['language'], Settings.supported_languages())[0]
        translator = QtCore.QTranslator()
        translator.load(curr_directory() + '/translations/' + lang[1])
        app.installTranslator(translator)
        app.translator = translator

        self.ms = MainWindow(self.tox, self.reset)

        # tray icon
        self.tray = QtGui.QSystemTrayIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
        self.tray.setObjectName('tray')

        class Menu(QtGui.QMenu):
            def languageChange(self, *args, **kwargs):
                self.actions()[0].setText(QtGui.QApplication.translate('tray', 'Open Toxygen', None, QtGui.QApplication.UnicodeUTF8))
                self.actions()[1].setText(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8))

        m = Menu()
        show = m.addAction(QtGui.QApplication.translate('tray', 'Open Toxygen', None, QtGui.QApplication.UnicodeUTF8))
        exit = m.addAction(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8))

        def show_window():
            if not self.ms.isActiveWindow():
                self.ms.setWindowState(self.ms.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
                self.ms.activateWindow()

        m.connect(show, QtCore.SIGNAL("triggered()"), show_window)
        m.connect(exit, QtCore.SIGNAL("triggered()"), lambda: app.exit())
        self.tray.setContextMenu(m)
        self.tray.show()

        self.ms.show()
        QtGui.QApplication.setStyle(get_style(settings['theme']))  # set application style

        # init thread
        self.init = self.InitThread(self.tox, self.ms, self.tray)
        self.init.start()

        # starting threads for tox iterate and toxav iterate
        self.mainloop = self.ToxIterateThread(self.tox)
        self.mainloop.start()
        self.avloop = self.ToxAVIterateThread(self.tox.AV)
        self.avloop.start()
        app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
        app.exec_()
        self.init.stop = True
        self.mainloop.stop = True
        self.avloop.stop = True
        self.mainloop.wait()
        self.init.wait()
        self.avloop.wait()
        data = self.tox.get_savedata()
        ProfileHelper.save_profile(data)
        settings.close()
        del self.tox