Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
--- a/PLCOpenEditor.py Mon Apr 30 16:27:25 2012 +0200
+++ b/PLCOpenEditor.py Wed May 02 00:32:15 2012 +0200
@@ -833,6 +833,33 @@
self.RefreshEditor()
event.Skip()
+ def GetProjectConfiguration(self):
+ if self.Config.HasEntry("projects"):
+ projects = cPickle.loads(str(self.Config.Read("projects")))
+ else:
+ projects = {}
+
+ return projects.setdefault(os.path.realpath(self.Controler.GetFilePath()), {})
+
+ def SavePageState(self, page):
+ state = page.GetState()
+ if state is not None:
+ if self.Config.HasEntry("projects"):
+ projects = cPickle.loads(str(self.Config.Read("projects")))
+ else:
+ projects = {}
+
+ project_infos = projects.setdefault(os.path.realpath(self.Controler.GetFilePath()), {})
+ editors_state = project_infos.setdefault("editors_state", {})
+
+ if page.IsDebugging():
+ editors_state[page.GetInstancePath()] = state
+ else:
+ editors_state[page.GetTagName()] = state
+
+ self.Config.Write("projects", cPickle.dumps(projects))
+ self.Config.Flush()
+
def GetTabInfos(self, tab):
if isinstance(tab, EditorPanel):
if tab.IsDebugging():
@@ -844,7 +871,7 @@
if page_ref == tab:
return ("main", page_name)
return None
-
+
def SaveTabOrganization(self, notebook):
tabs = []
for child in notebook.GetChildren():
@@ -974,6 +1001,9 @@
self.SaveProjectOrganization()
+ for i in xrange(self.TabsOpened.GetPageCount()):
+ self.SavePageState(self.TabsOpened.GetPage(i))
+
self.Config.Flush()
def SaveProjectOrganization(self):
@@ -985,14 +1015,11 @@
else:
projects = {}
- project_infos = {
- "tabs": self.SaveTabOrganization(self.TabsOpened)
- }
+ project_infos = projects.setdefault(os.path.realpath(self.Controler.GetFilePath()), {})
+ project_infos["tabs"] = self.SaveTabOrganization(self.TabsOpened)
if self.EnableDebug:
project_infos["debug_vars"] = self.DebugVariablePanel.GetDebugVariables()
- projects[os.path.realpath(self.Controler.GetFilePath())] = project_infos
-
self.Config.Write("projects", cPickle.dumps(projects))
self.Config.Flush()
@@ -1034,6 +1061,10 @@
## Callback function when AUINotebook Page closed with CloseButton
# @param event AUINotebook Event.
def OnPageClose(self, event):
+ selected = self.TabsOpened.GetSelection()
+ if selected > -1:
+ self.SavePageState(self.TabsOpened.GetPage(selected))
+
# Refresh all window elements that have changed
wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
wx.CallAfter(self.RefreshTabCtrlEvent)
@@ -1909,6 +1940,12 @@
new_window = element
self.AddPage(element, "")
if new_window is not None:
+ project_infos = self.GetProjectConfiguration()
+ if project_infos.has_key("editors_state"):
+ state = project_infos["editors_state"].get(tagname)
+ if state is not None:
+ wx.CallAfter(new_window.SetState, state)
+
openedidx = self.IsOpened(tagname)
old_selected = self.TabsOpened.GetSelection()
if old_selected != openedidx:
@@ -2163,6 +2200,12 @@
else:
new_window.SetKeywords(ST_KEYWORDS)
if new_window is not None:
+ project_infos = self.GetProjectConfiguration()
+ if project_infos.has_key("editors_state"):
+ state = project_infos["editors_state"].get(instance_path)
+ if state is not None:
+ wx.CallAfter(new_window.SetState, state)
+
if instance_category in [ITEM_FUNCTIONBLOCK, ITEM_PROGRAM]:
pou_type = self.Controler.GetEditedElementType(instance_type, True)[1].upper()
icon = self.GenerateBitmap(pou_type, bodytype)
--- a/TextViewer.py Mon Apr 30 16:27:25 2012 +0200
+++ b/TextViewer.py Wed May 02 00:32:15 2012 +0200
@@ -243,6 +243,12 @@
def GetCurrentPos(self):
return self.Editor.GetCurrentPos()
+ def GetState(self):
+ return {"cursor_pos": self.Editor.GetCurrentPos()}
+
+ def SetState(self, state):
+ self.Editor.GotoPos(state["cursor_pos"])
+
def OnModification(self, event):
if not self.DisableEvents:
mod_type = event.GetModificationType()
--- a/Viewer.py Mon Apr 30 16:27:25 2012 +0200
+++ b/Viewer.py Wed May 02 00:32:15 2012 +0200
@@ -686,6 +686,15 @@
def GetViewScale(self):
return self.ViewScale
+ def GetState(self):
+ return {"position": self.Editor.GetViewStart(),
+ "zoom": self.CurrentScale}
+
+ def SetState(self, state):
+ self.SetScale(state["zoom"])
+ self.Scroll(*state["position"])
+ self.RefreshVisibleElements()
+
def GetLogicalDC(self, buffered=False):
if buffered:
bitmap = wx.EmptyBitmap(*self.Editor.GetClientSize())
--- a/controls/EditorPanel.py Mon Apr 30 16:27:25 2012 +0200
+++ b/controls/EditorPanel.py Wed May 02 00:32:15 2012 +0200
@@ -93,6 +93,12 @@
def SetIcon(self, icon):
self.Icon = icon
+ def GetState(self):
+ return None
+
+ def SetState(self, state):
+ pass
+
def IsViewing(self, tagname):
return self.TagName == tagname