def OnUpdateCursor(self, *ignore): if self._can_update: p = self.popup offset = wpf.get_position(self.tbx) pos, end, line = utils.get_current_line(self.tbx) sz = wpf.measure_string(self.tbx.Text[end-len(line):pos], self.tbx.FontFamily, self.tbx.FontSize) x = offset.X + sz.Width y = offset.Y + self.tbx.Text[:pos].count('\n') * sz.Height if x != p.HorizontalOffset: p.HorizontalOffset = x if y != p.VerticalOffset: p.VerticalOffset = y # Check if the cursor is out of bounds or if the textbox is hidden cursor_pos = wpf.Point(x, y) bounds = wpf.Rect(wpf.get_position(self.bounding_sv), wpf.Size(self.bounding_sv.ViewportWidth, self.bounding_sv.ViewportHeight)) if bounds.Contains(wpf.Point(cursor_pos.X, cursor_pos.Y + self.cursor.ActualHeight/2)) and bounds.Contains(offset): if not p.IsOpen: self.show() else: if p.IsOpen: self.hide()
def initialize(self): self._can_update = False p = self.popup = wpf.Popup() if sys.platform == 'cli': p.PlacementTarget = wpf.get_root_visual() p.Placement = wpf.PlacementMode.Relative self.cursor = wpf.Rectangle() sz = wpf.measure_string('|', Preferences.FontFamily, Preferences.FontSize) self.cursor.Width = 2 self.cursor.Height = sz.Height self.cursor.Fill = wpf.brush('#ffffff') p.Child = self.cursor self.sb = wpf.Storyboard() self.sb.AutoReverse = True self.sb.RepeatBehavior = wpf.RepeatBehavior.Forever anim = Preferences.CursorAnimation if sys.platform == 'silverlight': wpf.Storyboard.SetTarget(anim, self.cursor) self.sb.Children.Add(anim) self.popup.Opened += self.OnPopupOpened
def OnFirstLayout(self, sender, e): p = self.popup if p.IsOpen: child = p.Child rv = wpf.get_root_visual() pos, end, line = utils.get_current_line(self.tbx) offset = wpf.get_position(self.tbx) sz = wpf.measure_string(self._prefix, self.tbx.FontFamily, self.tbx.FontSize) desired_sz = wpf.measure(child) p.VerticalOffset = offset.Y + (self.tbx.Text[:pos].count('\n')+1) * sz.Height if p.VerticalOffset > rv.ActualHeight/2: # Display above the line p.VerticalOffset -= desired_sz.Height + sz.Height if p.VerticalOffset < 10: child.MaxHeight = desired_sz.Height - (10 - p.VerticalOffset) p.VerticalOffset = 10 elif p.VerticalOffset + desired_sz.Height + 10 > rv.ActualHeight: child.MaxHeight = rv.ActualHeight - p.VerticalOffset - 10 p.HorizontalOffset = offset.X + sz.Width if p.HorizontalOffset + desired_sz.Width > rv.ActualWidth-10: # Display further left p.HorizontalOffset = rv.ActualWidth - 10 - desired_sz.Width if p.Child is self.member_lbx: start = end - len(line) self.update_member_list(line[:pos-start])