Repository: psychopy/psychopy

Issue:
Line/Column values invalid for unsaved document in coder.

Closing a panel should emit an event and update the state of the menu checkbox.



Discussion:

Resolving patch:
diff --git a/psychopy/app/builder/builder.py b/psychopy/app/builder/builder.py
--- a/psychopy/app/builder/builder.py
+++ b/psychopy/app/builder/builder.py
@@ -2093,6 +2093,10 @@ def addComponentButton(self, name, panel):
         shortName = name
         for redundant in ['component', 'Component', "ButtonBox"]:
             shortName = shortName.replace(redundant, "")
+        # Convert from CamelCase to Title Case for button label
+        label = shortName
+        for c in "".join(c if c.isupper() else "" for c in name[1:]):
+            label = label.replace(c, "\n"+c)
         # set size
         size = 48
         # get tooltip
@@ -2103,7 +2107,7 @@ def addComponentButton(self, name, panel):
         btn = iconCache.getComponentButton(
                 parent=self,
                 name=name,
-                label=shortName,
+                label=label,
                 size=size,
                 tip=thisTip,
         )
@@ -2620,12 +2624,8 @@ def clearMode(self, event=None):
         self.draw()
         self.frame.SetStatusText("")
         self.btnInsertRoutine.SetLabel(_translate('Insert Routine'))
-        self.btnInsertRoutine.SetLabelColor(wx.Colour(cs['text']))
-        self.btnInsertRoutine.SetBackgroundColour(wx.Colour(cs['frame_bg']))
         self.btnInsertRoutine.Update()
         self.btnInsertLoop.SetLabel(_translate('Insert Loop'))
-        self.btnInsertLoop.SetLabelColor(wx.Colour(cs['text']))
-        self.btnInsertLoop.SetBackgroundColour(wx.Colour(cs['frame_bg']))
         self.btnInsertRoutine.Update()
 
     def ConvertEventCoords(self, event):
diff --git a/psychopy/app/coder/codeEditorBase.py b/psychopy/app/coder/codeEditorBase.py
--- a/psychopy/app/coder/codeEditorBase.py
+++ b/psychopy/app/coder/codeEditorBase.py
@@ -79,6 +79,10 @@ def __init__(self, parent, ID, pos, size, style):
         self.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERMIDTAIL,
                           wx.stc.STC_MARK_TCORNER, "white", "#808080")
 
+        # Set what kind of events will trigger a modified event
+        self.SetModEventMask(wx.stc.STC_MOD_DELETETEXT |
+                             wx.stc.STC_MOD_INSERTTEXT)
+
         # Bind context menu
         self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)
 
diff --git a/psychopy/app/coder/coder.py b/psychopy/app/coder/coder.py
--- a/psychopy/app/coder/coder.py
+++ b/psychopy/app/coder/coder.py
@@ -559,8 +559,15 @@ def __init__(self, parent, ID, frame,
         # caret info, these are updated by calling updateCaretInfo()
         self.indentSize = self.GetIndent()
         self.caretCurrentPos = self.GetCurrentPos()
-        self.caretVisible, self.caretColumn, self.caretLine = \
-            self.PositionToXY(self.caretCurrentPos)
+        self.caretVisible, caretColumn, caretLine = self.PositionToXY(
+            self.caretCurrentPos)
+
+        if self.caretVisible:
+            self.caretColumn = caretColumn
+            self.caretLine = caretLine
+        else:
+            self.caretLine = self.GetCurrentLine()
+            self.caretColumn = self.GetLineLength(self.caretLine)
 
         # where does the line text start?
         self.caretLineIndentCol = \
@@ -869,8 +876,16 @@ def updateCaretInfo(self):
         """
         self.indentSize = self.GetIndent()
         self.caretCurrentPos = self.GetCurrentPos()
-        self.caretVisible, self.caretColumn, self.caretLine = \
-            self.PositionToXY(self.caretCurrentPos)
+        self.caretVisible, caretColumn, caretLine = self.PositionToXY(
+            self.caretCurrentPos)
+
+        if self.caretVisible:
+            self.caretColumn = caretColumn
+            self.caretLine = caretLine
+        else:
+            self.caretLine = self.GetCurrentLine()
+            self.caretColumn = self.GetLineLength(self.caretLine)
+
         self.caretLineIndentCol = \
             self.GetColumn(self.GetLineIndentPosition(self.caretLine))
         self.caretLineIndentLevel = self.caretLineIndentCol / self.indentSize
@@ -1115,21 +1130,27 @@ def __init__(self, parent, ID, title, files=(), app=None):
         # Create menus and status bar
         self.makeMenus()
         self.makeStatusBar()
-        #self.statusBar.SetStatusText("PsychoPy v{}".format(psychopy.__version__), 3)
         self.fileMenu = self.editMenu = self.viewMenu = None
         self.helpMenu = self.toolsMenu = None
 
         # Create source assistant notebook
-        self.sourceAsst = aui.AuiNotebook(self.pnlMain, wx.ID_ANY, agwStyle=aui.AUI_NB_CLOSE_ON_ALL_TABS)
-        #self.sourceAsst.SetArtProvider(PsychopyTabArt())
+        self.sourceAsst = aui.AuiNotebook(
+            self.pnlMain,
+            wx.ID_ANY,
+            size = wx.Size(350, 600),
+            agwStyle=aui.AUI_NB_CLOSE_ON_ALL_TABS |
+                     aui.AUI_NB_TAB_SPLIT |
+                     aui.AUI_NB_TAB_MOVE)
+
         self.structureWindow = SourceTreePanel(self.sourceAsst, self)
         self.fileBrowserWindow = FileBrowserPanel(self.sourceAsst, self)
         # Add source assistant panel
         self.paneManager.AddPane(self.sourceAsst,
                                  aui.AuiPaneInfo().
-                                 BestSize((600, 600)).
-                                 Floatable(True).
-                                 BottomDockable(True).TopDockable(True).
+                                 BestSize((350, 600)).
+                                 FloatingSize((350, 600)).
+                                 Floatable(False).
+                                 BottomDockable(False).TopDockable(False).
                                  CloseButton(False).PaneBorder(False).
                                  Name("SourceAsst").
                                  Caption(_translate("Source Assistant")).
@@ -1147,13 +1168,18 @@ def __init__(self, parent, ID, title, files=(), app=None):
 
         # Create editor notebook
         #todo: Why is editor default background not same as usual frame backgrounds?
-        self.notebook = aui.AuiNotebook(self.pnlMain, -1, size=wx.Size(480, 600))
+        self.notebook = aui.AuiNotebook(
+            self.pnlMain, -1, size=wx.Size(480, 600),
+            agwStyle=aui.AUI_NB_TAB_MOVE | aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
+
         #self.notebook.SetArtProvider(PsychopyTabArt())
         # Add editor panel
         self.paneManager.AddPane(self.notebook, aui.AuiPaneInfo().
                                  Name("Editor").
                                  Caption(_translate("Editor")).
-                                 BestSize((600,600)).
+                                 BestSize((480, 600)).
+                                 Floatable(False).
+                                 Movable(False).
                                  Center().PaneBorder(False).  # 'center panes' expand
                                  CloseButton(False).
                                  MaximizeButton(True))
@@ -1211,7 +1237,8 @@ def __init__(self, parent, ID, title, files=(), app=None):
                                  Name("Shelf").
                                  Caption(_translate("Shelf")).
                                  BestSize((600, 250)).PaneBorder(False).
-                                 Floatable(True).
+                                 Floatable(False).
+                                 Movable(True).
                                  BottomDockable(True).TopDockable(True).
                                  CloseButton(False).
                                  Bottom().Show(self.prefs['showOutput']))
@@ -2488,6 +2515,7 @@ def setOutputWindow(self, event=None, value=None):
         # show/hide the output window (from the view menu control)
         if value is None:
             value = self.outputChk.IsChecked()
+        self.outputChk.Check(value)
         if value:
             # show the pane
             self.prefs['showOutput'] = True
@@ -2651,6 +2679,7 @@ def _applyAppTheme(self, target=None):
         # updating sourceAsst will incl fileBrowser and sourcetree
         ThemeMixin._applyAppTheme(self.sourceAsst)
         ThemeMixin._applyAppTheme(self.notebook)
+        self.notebook.Refresh()
         if hasattr(self, 'shelf'):
             ThemeMixin._applyAppTheme(self.shelf)
         self.Update()


Test patch: