21 # You should have received a copy of the GNU General Public License |
21 # You should have received a copy of the GNU General Public License |
22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 |
25 |
|
26 from functools import cmp_to_key |
|
27 from operator import eq |
26 import sys |
28 import sys |
27 import base64 |
29 import base64 |
28 |
30 |
29 import wx |
31 import wx |
30 import wx.grid |
32 import wx.grid |
153 |
155 |
154 def SimplifyTabLayout(tabs, rect): |
156 def SimplifyTabLayout(tabs, rect): |
155 for tab in tabs: |
157 for tab in tabs: |
156 if tab["pos"][0] == rect.x: |
158 if tab["pos"][0] == rect.x: |
157 others = [t for t in tabs if t != tab] |
159 others = [t for t in tabs if t != tab] |
158 others.sort(lambda x, y: cmp(x["pos"][0], y["pos"][0])) |
160 others.sort(key=cmp_to_key(lambda x, y: eq(x["pos"][0], |
|
161 y["pos"][0]))) |
159 for other in others: |
162 for other in others: |
160 if other["pos"][1] == tab["pos"][1] and \ |
163 if other["pos"][1] == tab["pos"][1] and \ |
161 other["size"][1] == tab["size"][1] and \ |
164 other["size"][1] == tab["size"][1] and \ |
162 other["pos"][0] == tab["pos"][0] + tab["size"][0] + TAB_BORDER: |
165 other["pos"][0] == tab["pos"][0] + tab["size"][0] + TAB_BORDER: |
163 |
166 |
168 if tab["size"][0] == rect.width: |
171 if tab["size"][0] == rect.width: |
169 return True |
172 return True |
170 |
173 |
171 elif tab["pos"][1] == rect.y: |
174 elif tab["pos"][1] == rect.y: |
172 others = [t for t in tabs if t != tab] |
175 others = [t for t in tabs if t != tab] |
173 others.sort(lambda x, y: cmp(x["pos"][1], y["pos"][1])) |
176 others.sort(key=cmp_to_key(lambda x, y: eq(x["pos"][1], |
|
177 y["pos"][1]))) |
174 for other in others: |
178 for other in others: |
175 if other["pos"][0] == tab["pos"][0] and \ |
179 if other["pos"][0] == tab["pos"][0] and \ |
176 other["size"][0] == tab["size"][0] and \ |
180 other["size"][0] == tab["size"][0] and \ |
177 other["pos"][1] == tab["pos"][1] + tab["size"][1] + TAB_BORDER: |
181 other["pos"][1] == tab["pos"][1] + tab["size"][1] + TAB_BORDER: |
178 |
182 |
805 tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1]) |
809 tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1]) |
806 tab_infos = self.GetTabInfos(page) |
810 tab_infos = self.GetTabInfos(page) |
807 if tab_infos is not None: |
811 if tab_infos is not None: |
808 tab["pages"].append((tab_infos, page_idx == child.GetActivePage())) |
812 tab["pages"].append((tab_infos, page_idx == child.GetActivePage())) |
809 tabs.append(tab) |
813 tabs.append(tab) |
810 tabs.sort(lambda x, y: cmp(x["pos"], y["pos"])) |
814 tabs.sort(key=cmp_to_key(lambda x, y: eq(x["pos"], y["pos"]))) |
811 size = notebook.GetSize() |
815 size = notebook.GetSize() |
812 return ComputeTabsLayout(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER)) |
816 return ComputeTabsLayout(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER)) |
813 |
817 |
814 def LoadTab(self, notebook, page_infos): |
818 def LoadTab(self, notebook, page_infos): |
815 if page_infos[0] == "main": |
819 if page_infos[0] == "main": |