added generation exception while creating tox_options instance

This commit is contained in:
ingvar1995 2016-02-20 19:53:42 +03:00
parent 0269b81319
commit 6754b2bbbf
2 changed files with 19 additions and 4 deletions

View file

@ -4,7 +4,7 @@ from mainscreen import MainWindow
from profile import Profile
import sys
from PySide import QtCore, QtGui
from tox import Tox
from tox import Tox, tox_factory
from bootstrap import node_generator
@ -76,7 +76,7 @@ def main():
data = Profile.open_profile(path, name)
ms = MainWindow()
# creating tox instance
tox = Tox(data, settings)
tox = tox_factory(data, settings)
# bootstrap
for data in node_generator():
tox.bootstrap(*data)

View file

@ -34,7 +34,7 @@ class LibToxCore(object):
def __getattr__(self, item):
return self._libtoxcore.__getattr__(item)
class Tox(object):
libtoxcore = LibToxCore()
@ -108,7 +108,7 @@ class Tox(object):
Objects returned from this function must be freed using the tox_options_free function.
:return: A pointer to new ToxOptions object with default options or NULL on failure.
:return: A pointer to new ToxOptions object with default options or raise MemoryError.
"""
tox_err_options_new = c_int()
Tox.libtoxcore.tox_options_new.restype = POINTER(ToxOptions)
@ -1003,6 +1003,21 @@ class Tox(object):
Tox.libtoxcore.tox_kill(self._tox_pointer)
def tox_factory(data, settings):
tox_options = Tox.options_new()
tox_options.contents.udp_enabled = settings['udp_enabled']
tox_options.contents.proxy_type = settings['proxy_type']
tox_options.contents.proxy_host = settings['proxy_host']
tox_options.contents.proxy_port = settings['proxy_port']
tox_options.contents.start_port = settings['start_port']
tox_options.contents.end_port = settings['end_port']
tox_options.contents.tcp_port = settings['tcp_port']
tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['TOX_SAVEDATA_TYPE_TOX_SAVE']
tox_options.contents.savedata_data = c_char_p(data)
tox_options.contents.savedata_length = len(data)
return Tox(tox_options)
if __name__ == '__main__':
options = Tox.options_new()