Use a "core" parameter for each tab object instead of a singleton

fixes the circular import issue
This commit is contained in:
mathieui 2016-06-30 23:57:12 +02:00
parent 8f7be37a70
commit 8383f77341
13 changed files with 41 additions and 45 deletions

View file

@ -276,7 +276,7 @@ class CommandCore:
if not isinstance(self.core.current_tab(), tabs.MucTab):
return self.core.information('Please provide a server', 'Error')
jid = safeJID(self.core.current_tab().name).server
list_tab = tabs.MucListTab(jid)
list_tab = tabs.MucListTab(self.core, jid)
self.core.add_tab(list_tab, True)
cb = list_tab.on_muc_list_item_received
self.core.xmpp.plugin['xep_0030'].get_items(jid=jid,
@ -491,7 +491,7 @@ class CommandCore:
if tab:
self.core.current_tab_nb = tab.nb
else:
tab = tabs.BookmarksTab(self.core.bookmarks)
tab = tabs.BookmarksTab(self.core, self.core.bookmarks)
self.core.tabs.append(tab)
self.core.current_tab_nb = tab.nb
old_tab.on_lose_focus()
@ -959,7 +959,7 @@ class CommandCore:
"""/xml_tab"""
xml_tab = self.core.focus_tab_named('XMLTab', tabs.XMLTab)
if not xml_tab:
tab = tabs.XMLTab()
tab = tabs.XMLTab(self.core)
self.core.add_tab(tab, True)
self.core.xml_tab = tab
@ -968,7 +968,7 @@ class CommandCore:
if not args:
return self.help('ad-hoc')
jid = safeJID(args[0])
list_tab = tabs.AdhocCommandsListTab(jid)
list_tab = tabs.AdhocCommandsListTab(self.core, jid)
self.core.add_tab(list_tab, True)
cb = list_tab.on_list_received
self.core.xmpp.plugin['xep_0050'].get_commands(jid=jid, local=False,

View file

@ -531,7 +531,7 @@ class Core(object):
self.stdscr = curses.initscr()
self._init_curses(self.stdscr)
self.call_for_resize()
default_tab = tabs.RosterInfoTab()
default_tab = tabs.RosterInfoTab(self)
default_tab.on_gain_focus()
self.tabs.append(default_tab)
self.information('Welcome to poezio!', 'Info')
@ -1056,16 +1056,16 @@ class Core(object):
if not target:
if new_pos < len(self.tabs):
old_tab = self.tabs[old_pos]
self.tabs[new_pos], self.tabs[old_pos] = old_tab, tabs.GapTab()
self.tabs[new_pos], self.tabs[old_pos] = old_tab, tabs.GapTab(self)
else:
self.tabs.append(self.tabs[old_pos])
self.tabs[old_pos] = tabs.GapTab()
self.tabs[old_pos] = tabs.GapTab(self)
else:
if new_pos > old_pos:
self.tabs.insert(new_pos, tab)
self.tabs[old_pos] = tabs.GapTab()
self.tabs[old_pos] = tabs.GapTab(self)
elif new_pos < old_pos:
self.tabs[old_pos] = tabs.GapTab()
self.tabs[old_pos] = tabs.GapTab(self)
self.tabs.insert(new_pos, tab)
else:
return False
@ -1230,9 +1230,9 @@ class Core(object):
DynamicConversationTab
"""
if safeJID(jid).resource:
new_tab = tabs.StaticConversationTab(jid)
new_tab = tabs.StaticConversationTab(self, jid)
else:
new_tab = tabs.DynamicConversationTab(jid)
new_tab = tabs.DynamicConversationTab(self, jid)
if not focus:
new_tab.state = "private"
self.add_tab(new_tab, focus)
@ -1253,7 +1253,7 @@ class Core(object):
tab = self.get_tab_by_name(room_name, tabs.MucTab)
if not tab:
return None
new_tab = tabs.PrivateTab(complete_jid, tab.own_nick)
new_tab = tabs.PrivateTab(self, complete_jid, tab.own_nick)
if hasattr(tab, 'directed_presence'):
new_tab.directed_presence = tab.directed_presence
if not focus:
@ -1268,7 +1268,7 @@ class Core(object):
"""
Open a new tab.MucTab containing a muc Room, using the specified nick
"""
new_tab = tabs.MucTab(room, nick, password=password)
new_tab = tabs.MucTab(self, room, nick, password=password)
self.add_tab(new_tab, focus)
self.refresh_window()
return new_tab
@ -1279,7 +1279,7 @@ class Core(object):
The callback are called with the completed form as parameter in
addition with kwargs
"""
form_tab = tabs.DataFormsTab(form, on_cancel, on_send, kwargs)
form_tab = tabs.DataFormsTab(self, form, on_cancel, on_send, kwargs)
self.add_tab(form_tab, True)
### Modifying actions ###
@ -1363,7 +1363,7 @@ class Core(object):
self.tabs.pop()
nb -= 1
else:
self.tabs[nb] = tabs.GapTab()
self.tabs[nb] = tabs.GapTab(self)
else:
self.tabs.remove(tab)
logger.close(tab.name)

View file

@ -15,8 +15,8 @@ class AdhocCommandsListTab(ListTab):
plugin_commands = {}
plugin_keys = {}
def __init__(self, jid):
ListTab.__init__(self, jid.full,
def __init__(self, core, jid):
ListTab.__init__(self, core, jid.full,
"“Enter”: execute selected command.",
'Ad-hoc commands of JID %s (Loading)' % jid,
(('Node', 0), ('Description', 1)))

View file

@ -83,7 +83,8 @@ STATE_PRIORITY = {
class Tab(object):
plugin_commands = {}
plugin_keys = {}
def __init__(self):
def __init__(self, core):
self.core = core
if not hasattr(self, 'name'):
self.name = self.__class__.__name__
self.input = None
@ -101,10 +102,6 @@ class Tab(object):
def size(self):
return self.core.size
@property
def core(self):
return Singleton(core.Core)
@property
def nb(self):
for index, tab in enumerate(self.core.tabs):
@ -425,8 +422,8 @@ class ChatTab(Tab):
"""
plugin_commands = {}
plugin_keys = {}
def __init__(self, jid=''):
Tab.__init__(self)
def __init__(self, core, jid=''):
Tab.__init__(self, core)
self.name = jid
self.text_win = None
self._text_buffer = TextBuffer()
@ -688,8 +685,8 @@ class ChatTab(Tab):
class OneToOneTab(ChatTab):
def __init__(self, jid=''):
ChatTab.__init__(self, jid)
def __init__(self, core, jid=''):
ChatTab.__init__(self, core, jid)
# Set to true once the first disco is done
self.__initial_disco = False
@ -860,4 +857,3 @@ class OneToOneTab(ChatTab):
self.add_message(msg, typ=0)
self.core.refresh_window()

View file

@ -17,8 +17,8 @@ class BookmarksTab(Tab):
a 4 widgets to set the jid/password/autojoin/storage method
"""
plugin_commands = {}
def __init__(self, bookmarks: BookmarkList):
Tab.__init__(self)
def __init__(self, core, bookmarks: BookmarkList):
Tab.__init__(self, core)
self.name = "Bookmarks"
self.bookmarks = bookmarks
self.new_bookmarks = []

View file

@ -38,8 +38,8 @@ class ConversationTab(OneToOneTab):
plugin_keys = {}
additional_informations = {}
message_type = 'chat'
def __init__(self, jid):
OneToOneTab.__init__(self, jid)
def __init__(self, core, jid):
OneToOneTab.__init__(self, core, jid)
self.nick = None
self.nick_sent = False
self.state = 'normal'

View file

@ -14,8 +14,8 @@ class DataFormsTab(Tab):
a form that the user needs to fill.
"""
plugin_commands = {}
def __init__(self, form, on_cancel, on_send, kwargs):
Tab.__init__(self)
def __init__(self, core, form, on_cancel, on_send, kwargs):
Tab.__init__(self, core)
self._form = form
self._on_cancel = on_cancel
self._on_send = on_send

View file

@ -21,7 +21,7 @@ class ListTab(Tab):
plugin_commands = {}
plugin_keys = {}
def __init__(self, name, help_message, header_text, cols):
def __init__(self, core, name, help_message, header_text, cols):
"""Parameters:
name: The name of the tab
help_message: The default help message displayed instead of the
@ -31,7 +31,7 @@ class ListTab(Tab):
cols: a tuple of 2-tuples. e.g. (('column1_name', number),
('column2_name', number))
"""
Tab.__init__(self)
Tab.__init__(self, core)
self.state = 'normal'
self.name = name
columns = collections.OrderedDict()

View file

@ -19,8 +19,8 @@ class MucListTab(ListTab):
plugin_commands = {}
plugin_keys = {}
def __init__(self, server):
ListTab.__init__(self, server,
def __init__(self, core, server):
ListTab.__init__(self, core, server,
"“j”: join room.",
'Chatroom list on server %s (Loading)' % server,
(('node-part', 0), ('name', 2), ('users', 3)))

View file

@ -53,9 +53,9 @@ class MucTab(ChatTab):
message_type = 'groupchat'
plugin_commands = {}
plugin_keys = {}
def __init__(self, jid, nick, password=None):
def __init__(self, core, jid, nick, password=None):
self.joined = False
ChatTab.__init__(self, jid)
ChatTab.__init__(self, core, jid)
if self.joined == False:
self._state = 'disconnected'
self.own_nick = nick

View file

@ -35,8 +35,8 @@ class PrivateTab(OneToOneTab):
plugin_commands = {}
additional_informations = {}
plugin_keys = {}
def __init__(self, name, nick):
OneToOneTab.__init__(self, name)
def __init__(self, core, name, nick):
OneToOneTab.__init__(self, core, name)
self.own_nick = nick
self.name = name
self.text_win = windows.TextWin()

View file

@ -35,8 +35,8 @@ class RosterInfoTab(Tab):
"""
plugin_commands = {}
plugin_keys = {}
def __init__(self):
Tab.__init__(self)
def __init__(self, core):
Tab.__init__(self, core)
self.name = "Roster"
self.v_separator = windows.VerticalSeparator()
self.information_win = windows.TextWin()

View file

@ -54,8 +54,8 @@ MATCHERS_MAPPINGS = {
}
class XMLTab(Tab):
def __init__(self):
Tab.__init__(self)
def __init__(self, core):
Tab.__init__(self, core)
self.state = 'normal'
self.name = 'XMLTab'
self.filters = []