From 137195c8f226f4e66a7e200d3c6a227898392223 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 1 Nov 2016 00:04:48 +0300 Subject: [PATCH] profile creation fixes --- .gitignore | 1 + toxygen/main.py | 6 +++--- toxygen/mainscreen.py | 2 ++ toxygen/profile.py | 8 +++++--- toxygen/settings.py | 3 ++- toxygen/util.py | 11 +++++++++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 0374978..e8841f6 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ toxygen/__pycache__ /*.egg html Toxygen.egg-info +*.tox diff --git a/toxygen/main.py b/toxygen/main.py index 586775c..430a757 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -9,7 +9,7 @@ except ImportError: from bootstrap import node_generator from mainscreen import MainWindow from callbacks import init_callbacks, stop, start -from util import curr_directory, program_version, remove +from util import curr_directory, program_version, remove, is_64_bit import styles.style import platform import toxencryptsave @@ -137,7 +137,7 @@ class Toxygen: if reply == QtGui.QMessageBox.Yes: path = Settings.get_default_path() else: - path = curr_directory() + path = curr_directory() + '/' ProfileHelper(path, name).save_profile(self.tox.get_savedata()) path = Settings.get_default_path() settings = Settings(name) @@ -446,7 +446,7 @@ def clean(): def configure(): """Removes unused libs""" d = curr_directory() + '/libs/' - is_64bits = sys.maxsize > 2 ** 32 + is_64bits = is_64_bit() if not is_64bits: if os.path.exists(d + 'libtox64.dll'): os.remove(d + 'libtox64.dll') diff --git a/toxygen/mainscreen.py b/toxygen/mainscreen.py index ec627ab..6e12ae9 100644 --- a/toxygen/mainscreen.py +++ b/toxygen/mainscreen.py @@ -554,6 +554,8 @@ class MainWindow(QtGui.QMainWindow, Singleton): item = self.friends_list.itemAt(pos) num = self.friends_list.indexFromItem(item).row() friend = Profile.get_instance().get_friend(num) + if friend is None: + return settings = Settings.get_instance() allowed = friend.tox_id in settings['auto_accept_from_friends'] auto = QtGui.QApplication.translate("MainWindow", 'Disallow auto accept', None, QtGui.QApplication.UnicodeUTF8) if allowed else QtGui.QApplication.translate("MainWindow", 'Allow auto accept', None, QtGui.QApplication.UnicodeUTF8) diff --git a/toxygen/profile.py b/toxygen/profile.py index 72ce1d5..aa16aba 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -132,14 +132,14 @@ class Profile(basecontact.BaseContact, Singleton): self._contacts = sorted(self._contacts, key=lambda x: int(x.status is not None), reverse=True) if sorting & 4: if not sorting & 2: - self._contacts = sorted(self._contacts, key=lambda x: x.name) + self._contacts = sorted(self._contacts, key=lambda x: x.name.lower()) else: # save results of prev sorting online_friends = filter(lambda x: x.status is not None, self._contacts) count = len(list(online_friends)) part1 = self._contacts[:count] part2 = self._contacts[count:] - part1 = sorted(part1, key=lambda x: x.name) - part2 = sorted(part2, key=lambda x: x.name) + part1 = sorted(part1, key=lambda x: x.name.lower()) + part2 = sorted(part2, key=lambda x: x.name.lower()) self._contacts = part1 + part2 else: # sort by number online_friends = filter(lambda x: x.status is not None, self._contacts) @@ -177,6 +177,8 @@ class Profile(basecontact.BaseContact, Singleton): return list(filter(lambda x: x.number == num, self._contacts))[0] def get_friend(self, num): + if num < 0 or num >= len(self._contacts): + return None return self._contacts[num] # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/settings.py b/toxygen/settings.py index e1a399f..2b6bef4 100644 --- a/toxygen/settings.py +++ b/toxygen/settings.py @@ -1,7 +1,7 @@ from platform import system import json import os -from util import Singleton, curr_directory, log, copy +from util import Singleton, curr_directory, log, copy, append_slash import pyaudio from toxencryptsave import ToxEncryptSave import smileys @@ -232,6 +232,7 @@ class ProfileHelper(Singleton): """ def __init__(self, path, name): Singleton.__init__(self) + path = append_slash(path) self._path = path + name + '.tox' self._directory = path # create /avatars if not exists: diff --git a/toxygen/util.py b/toxygen/util.py index 925127f..ae104a7 100644 --- a/toxygen/util.py +++ b/toxygen/util.py @@ -1,6 +1,7 @@ import os import time import shutil +import sys program_version = '0.2.6' @@ -43,6 +44,16 @@ def convert_time(t): return '%02d:%02d' % (h, m) +def append_slash(s): + if s[-1] not in ('\\', '/'): + s += '/' + return s + + +def is_64_bit(): + return sys.maxsize > 2 ** 32 + + class Singleton: _instance = None