From 8383f773413cee8529ad4fdc05f092286d6dd377 Mon Sep 17 00:00:00 2001
From: mathieui <mathieui@mathieui.net>
Date: Thu, 30 Jun 2016 23:57:12 +0200
Subject: Use a "core" parameter for each tab object instead of a singleton

fixes the circular import issue
---
 poezio/core/commands.py            |  8 ++++----
 poezio/core/core.py                | 22 +++++++++++-----------
 poezio/tabs/adhoc_commands_list.py |  4 ++--
 poezio/tabs/basetabs.py            | 16 ++++++----------
 poezio/tabs/bookmarkstab.py        |  4 ++--
 poezio/tabs/conversationtab.py     |  4 ++--
 poezio/tabs/data_forms.py          |  4 ++--
 poezio/tabs/listtab.py             |  4 ++--
 poezio/tabs/muclisttab.py          |  4 ++--
 poezio/tabs/muctab.py              |  4 ++--
 poezio/tabs/privatetab.py          |  4 ++--
 poezio/tabs/rostertab.py           |  4 ++--
 poezio/tabs/xmltab.py              |  4 ++--
 13 files changed, 41 insertions(+), 45 deletions(-)

diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index 40f0182b..c36afc90 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -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,
diff --git a/poezio/core/core.py b/poezio/core/core.py
index b8c4f5cf..c6d83ad5 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -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)
diff --git a/poezio/tabs/adhoc_commands_list.py b/poezio/tabs/adhoc_commands_list.py
index 4d396d84..6db654c9 100644
--- a/poezio/tabs/adhoc_commands_list.py
+++ b/poezio/tabs/adhoc_commands_list.py
@@ -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)))
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index 9f1e09e7..b0bebfec 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -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()
 
-
diff --git a/poezio/tabs/bookmarkstab.py b/poezio/tabs/bookmarkstab.py
index 2eb138b3..053e45dd 100644
--- a/poezio/tabs/bookmarkstab.py
+++ b/poezio/tabs/bookmarkstab.py
@@ -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 = []
diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py
index 686e2d5c..70eed405 100644
--- a/poezio/tabs/conversationtab.py
+++ b/poezio/tabs/conversationtab.py
@@ -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'
diff --git a/poezio/tabs/data_forms.py b/poezio/tabs/data_forms.py
index 82c0f128..0edf9e89 100644
--- a/poezio/tabs/data_forms.py
+++ b/poezio/tabs/data_forms.py
@@ -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
diff --git a/poezio/tabs/listtab.py b/poezio/tabs/listtab.py
index 3e290aee..ddb8b58e 100644
--- a/poezio/tabs/listtab.py
+++ b/poezio/tabs/listtab.py
@@ -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()
diff --git a/poezio/tabs/muclisttab.py b/poezio/tabs/muclisttab.py
index ec60d245..5a860b6b 100644
--- a/poezio/tabs/muclisttab.py
+++ b/poezio/tabs/muclisttab.py
@@ -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)))
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py
index b55c1141..f91cf2b1 100644
--- a/poezio/tabs/muctab.py
+++ b/poezio/tabs/muctab.py
@@ -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
diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py
index 8dc1b18e..c8c80f19 100644
--- a/poezio/tabs/privatetab.py
+++ b/poezio/tabs/privatetab.py
@@ -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()
diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py
index c5475bee..b9b0c228 100644
--- a/poezio/tabs/rostertab.py
+++ b/poezio/tabs/rostertab.py
@@ -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()
diff --git a/poezio/tabs/xmltab.py b/poezio/tabs/xmltab.py
index e6faed4d..937ab0f9 100644
--- a/poezio/tabs/xmltab.py
+++ b/poezio/tabs/xmltab.py
@@ -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 = []
-- 
cgit v1.2.3