Coverage for src/robotide/ui/notebook.py: 73%

76 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-06 10:40 +0100

1# Copyright 2008-2015 Nokia Networks 

2# Copyright 2016- Robot Framework Foundation 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15 

16try: 1ac

17 import wx.lib.agw.aui.auibook as aui 1ac

18except ImportError: 

19 import wx.lib.agw.aui as aui 

20 

21from ..publish import RideNotebookTabChanging, RideNotebookTabChanged 1ac

22 

23 

24class NoteBook(aui.AuiNotebook): 1ac

25 

26 def __init__(self, parent, app, style): 1ac

27 self.app = app 1ab

28 self._notebook_style = style 1ab

29 # style = fnb.FNB_NODRAG|fnb.FNB_HIDE_ON_SINGLE_TAB|fnb.FNB_VC8 

30 # fnb.FlatNotebook.__init__(self, parent, style=style) 

31 # default style=0, experiment others 

32 aui.AuiNotebook.__init__(self, parent, style=3, agwStyle=self._notebook_style) 1ab

33 self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.on_tab_closing) 1ab

34 self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGING, self.on_tab_changing) 1ab

35 self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_tab_changed) 1ab

36 self._tab_closing = False 1ab

37 self._tab_state = None 1ab

38 self._uncloseable = [] 1ab

39 

40 def add_tab(self, tab, title, allow_closing=True): 1ac

41 if not allow_closing: 1ab

42 self._uncloseable.append(tab) 

43 self.AddPage(tab, title.strip()) 1ab

44 

45 def show_tab(self, tab): 1ac

46 """Shows the notebook page that contains the given tab.""" 

47 if not self.tab_is_visible(tab): 1ab

48 page = self.GetPageIndex(tab) 

49 if page >= 0: 49 ↛ exitline 49 didn't return from function 'show_tab' because the condition on line 49 was always true

50 self.SetSelection(page) 

51 

52 def delete_tab(self, tab): 1ac

53 if tab in self._uncloseable: 53 ↛ 54line 53 didn't jump to line 54 because the condition on line 53 was never true1b

54 self._uncloseable.remove(tab) 

55 page = self.GetPageIndex(tab) 1b

56 self.DeletePage(page) 1b

57 

58 def rename_tab(self, tab, new_name): 1ac

59 self.SetPageText(self.GetPageIndex(tab), new_name) 

60 

61 def allow_closing(self, tab): 1ac

62 if tab in self._uncloseable: 

63 self._uncloseable.remove(tab) 

64 

65 def disallow_closing(self, tab): 1ac

66 if tab not in self._uncloseable: 

67 self._uncloseable.append(tab) 

68 

69 def tab_is_visible(self, tab): 1ac

70 return tab == self.GetCurrentPage() 1ab

71 

72 @property 1ac

73 def current_page_title(self): 1ac

74 return self.GetPageText(self.GetSelection()) 1ade

75 

76 def on_tab_closing(self, event): 1ac

77 if self.GetPage(event.GetSelection()) in self._uncloseable: 

78 event.Veto() 

79 return 

80 self._tab_closing = True 

81 

82 def on_tab_changing(self, event): 1ac

83 if not self._tab_changed(): 83 ↛ 84line 83 didn't jump to line 84 because the condition on line 83 was never true1ab

84 return 

85 oldselect = event.GetOldSelection() 1ab

86 try: 1ab

87 oldtitle = self.GetPageText(oldselect) 1ab

88 except Exception: 1ab

89 oldtitle = "" 1ab

90 newindex = event.GetSelection() 1ab

91 newtitle = self.GetPageText(event.GetSelection()) 1ab

92 if self._tab_state is not None: 1ab

93 if self._tab_state == oldtitle + newtitle + str(newindex): 

94 return 

95 else: 

96 self._tab_state = oldtitle + newtitle + str(newindex) 

97 else: 

98 self._tab_state = newtitle + str(newindex) 1ab

99 self.GetPage(event.GetSelection()).SetFocus() 1ab

100 RideNotebookTabChanging(oldtab=oldtitle, newtab=newtitle).publish() 1ab

101 event.Skip() 1ab

102 

103 def on_tab_changed(self, event): 1ac

104 __ = event 1ab

105 if not self._tab_changed(): 105 ↛ 106line 105 didn't jump to line 106 because the condition on line 105 was never true1ab

106 self._tab_closing = False 

107 return 

108 RideNotebookTabChanged().publish() 1ab

109 

110 def _tab_changed(self): 1ac

111 """Change event is sent even when no tab available or tab is closed""" 

112 if not self.GetPageCount() or self._tab_closing: 112 ↛ 113line 112 didn't jump to line 113 because the condition on line 112 was never true1ab

113 return False 

114 return True 1ab