示例#1
0
    def pasteWidgets(self, pos = (0,0), logicals = False):
        """Pastes widgets from the clipboard."""
        clipFormat = wx.CustomDataFormat(StoryPanel.CLIPBOARD_FORMAT)
        clipData = wx.CustomDataObject(clipFormat)

        if wx.TheClipboard.Open():
            gotData = wx.TheClipboard.IsSupported(clipFormat) and wx.TheClipboard.GetData(clipData)
            wx.TheClipboard.Close()

            if gotData:
                data = pickle.loads(clipData.GetData())

                self.eachWidget(lambda w: w.setSelected(False, False))

                if not pos: pos = StoryPanel.INSET
                if not logicals: pos = self.toLogical(pos)

                for widget in data:
                    newPassage = PassageWidget(self, self.app, state = widget, pos = pos, title = self.untitledName(widget['passage'].title))
                    newPassage.findSpace()
                    newPassage.setSelected(True, False)
                    self.widgetDict[newPassage.passage.title] = newPassage
                    self.snapWidget(newPassage, False)

                self.parent.setDirty(True, action = 'Paste')
                self.resize()
                self.Refresh()
示例#2
0
    def newWidget(self,
                  title=None,
                  text='',
                  tags=(),
                  pos=None,
                  quietly=False,
                  logicals=False):
        """Adds a new widget to the container."""

        # defaults

        if not title:
            if tags and tags[0] in TiddlyWiki.INFO_TAGS:
                type = "Untitled " + tags[0].capitalize()
            else:
                type = "Untitled Passage"
            title = self.untitledName(type)
        if not pos: pos = StoryPanel.INSET
        if not logicals: pos = self.toLogical(pos)

        new = PassageWidget(self,
                            self.app,
                            title=title,
                            text=text,
                            tags=tags,
                            pos=pos)
        self.widgetDict[new.passage.title] = new
        self.snapWidget(new, quietly)
        self.resize()
        self.Refresh()
        if not quietly: self.parent.setDirty(True, action='New Passage')
        return new
示例#3
0
    def __init__(self, parent, app, id=wx.ID_ANY, state=None):
        wx.ScrolledWindow.__init__(self, parent, id)
        self.app = app
        self.parent = parent

        # inner state

        self.snapping = self.app.config.ReadBool('storyPanelSnap')
        self.widgets = []
        self.draggingMarquee = False
        self.draggingWidgets = False
        self.scrolling = False
        self.undoStack = []
        self.undoPointer = -1
        self.lastSearchRegexp = None
        self.lastSearchFlags = None
        self.trackinghover = None
        self.tooltipcounter = 0
        self.tooltipplace = ''
        self.tooltipobj = None

        if (state):
            self.scale = state['scale']
            for widget in state['widgets']:
                self.widgets.append(PassageWidget(self, self.app,
                                                  state=widget))
            if (hasattr(state, 'snapping')) and state['snapping']:
                self.snapping = True
        else:
            self.scale = 1
            self.newWidget(title=StoryPanel.FIRST_TITLE,
                           text=StoryPanel.FIRST_TEXT,
                           quietly=True)

        self.pushUndo(action='')
        self.undoPointer -= 1

        # cursors

        self.dragCursor = wx.StockCursor(wx.CURSOR_SIZING)
        self.badDragCursor = wx.StockCursor(wx.CURSOR_NO_ENTRY)
        self.scrollCursor = wx.StockCursor(wx.CURSOR_SIZING)
        self.defaultCursor = wx.StockCursor(wx.CURSOR_ARROW)
        self.SetCursor(self.defaultCursor)

        # events

        self.SetDropTarget(StoryPanelDropTarget(self))
        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: e)
        self.Bind(wx.EVT_PAINT, self.paint)
        self.Bind(wx.EVT_SIZE, self.resize)
        self.Bind(wx.EVT_LEFT_DOWN, self.handleClick)
        self.Bind(wx.EVT_LEFT_DCLICK, self.handleDoubleClick)
        self.Bind(wx.EVT_RIGHT_UP, self.handleRightClick)
        self.Bind(wx.EVT_MIDDLE_UP, self.handleMiddleClick)
        self.Bind(wx.EVT_ENTER_WINDOW, self.handleHoverStart)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.handleHoverStop)
        self.Bind(wx.EVT_MOTION, self.handleHover)
示例#4
0
 def undo(self):
     """
     Restores the undo state at self.undoPointer to the current view, then
     decreases self.undoPointer by 1.
     """
     self.widgets = []
     state = self.undoStack[self.undoPointer]
     for widget in state['widgets']:
         self.widgets.append(PassageWidget(self, self.app, state=widget))
     self.undoPointer -= 1
     self.Refresh()
示例#5
0
 def pasteWidgets (self):
     """Pastes widgets into the clipboard."""
     format = wx.CustomDataFormat(StoryPanel.CLIPBOARD_FORMAT)
     
     if wx.TheClipboard.Open() and wx.TheClipboard.IsSupported(format):
         clipData = wx.CustomDataObject(format)
         wx.TheClipboard.GetData(clipData)
         wx.TheClipboard.Close()
         data = pickle.loads(clipData.GetData())
                     
         self.eachWidget(lambda w: w.setSelected(False, False))
         
         for widget in data:
             newPassage = PassageWidget(self, self.app, state = widget)
             newPassage.findSpace()
             newPassage.setSelected(True, False)
             self.widgets.append(newPassage)
             
         self.parent.setDirty(True, action = 'Paste')
         self.Refresh()
示例#6
0
    def pasteWidgets(self, pos=(0, 0), logicals=False):
        """Pastes widgets from the clipboard."""
        clipFormat = wx.DataFormat(StoryPanel.CLIPBOARD_FORMAT)
        clipData = wx.CustomDataObject(clipFormat)

        if wx.TheClipboard.Open():
            gotData = wx.TheClipboard.IsSupported(
                clipFormat) and wx.TheClipboard.GetData(clipData)
            wx.TheClipboard.Close()

            if gotData:
                data = pickle.loads(clipData.GetData())

                self.eachWidget(lambda w: w.setSelected(False, False))

                if not pos: pos = StoryPanel.INSET
                if not logicals: pos = self.toLogical(pos)

                for widget in data:
                    newPassage = PassageWidget(self,
                                               self.app,
                                               state=widget,
                                               pos=pos,
                                               title=self.untitledName(
                                                   widget['passage'].title))
                    newPassage.findSpace()
                    newPassage.setSelected(True, False)
                    self.widgetDict[newPassage.passage.title] = newPassage
                    self.snapWidget(newPassage, False)

                self.parent.setDirty(True, action='Paste')
                self.resize()
                self.Refresh()
示例#7
0
 def undo(self):
     """
     Restores the undo state at self.undoPointer to the current view, then
     decreases self.undoPointer by 1.
     """
     self.widgetDict = dict()
     self.visibleWidgets = None
     state = self.undoStack[self.undoPointer]
     for widgetState in state['widgets']:
         widget = PassageWidget(self, self.app, state=widgetState)
         self.widgetDict[widget.passage.title] = widget
     self.undoPointer -= 1
     self.Refresh()
示例#8
0
    def pasteWidgets(self):
        """Pastes widgets from the clipboard."""
        clipFormat = wx.CustomDataFormat(StoryPanel.CLIPBOARD_FORMAT)
        clipData = wx.CustomDataObject(clipFormat)

        if wx.TheClipboard.Open():
            gotData = wx.TheClipboard.IsSupported(clipFormat) and wx.TheClipboard.GetData(clipData)
            wx.TheClipboard.Close()

            if gotData:
                data = pickle.loads(clipData.GetData())

                self.eachWidget(lambda w: w.setSelected(False, False))

                for widget in data:
                    newPassage = PassageWidget(self, self.app, state = widget, title = self.untitledName(widget['passage'].title))
                    newPassage.findSpace()
                    newPassage.setSelected(True, False)
                    self.widgets.append(newPassage)

                self.parent.setDirty(True, action = 'Paste')
                self.Refresh()
示例#9
0
    def newWidget(self, title=None, text='', pos=None, quietly=False):
        """Adds a new widget to the container."""

        # defaults

        if not title: title = self.untitledName()
        if not pos: pos = StoryPanel.INSET

        pos = self.toLogical(pos)
        new = PassageWidget(self, self.app, title=title, text=text, pos=pos)
        self.widgets.append(new)
        self.snapWidget(new)
        self.Refresh()
        self.resize()
        if not quietly: self.parent.setDirty(True, action='New Passage')
        return new
示例#10
0
    def pasteWidgets(self):
        """Pastes widgets into the clipboard."""
        format = wx.CustomDataFormat(StoryPanel.CLIPBOARD_FORMAT)

        if wx.TheClipboard.Open() and wx.TheClipboard.IsSupported(format):
            clipData = wx.CustomDataObject(format)
            wx.TheClipboard.GetData(clipData)
            wx.TheClipboard.Close()
            data = pickle.loads(clipData.GetData())

            self.eachWidget(lambda w: w.setSelected(False, False))

            for widget in data:
                newPassage = PassageWidget(self, self.app, state=widget)
                newPassage.findSpace()
                newPassage.setSelected(True, False)
                self.widgets.append(newPassage)

            self.parent.setDirty(True, action='Paste')
            self.Refresh()
示例#11
0
    def __init__(self, parent, app, id=wx.ID_ANY, state=None):
        wx.ScrolledWindow.__init__(self, parent, id)
        self.app = app
        self.parent = parent

        # inner state

        self.snapping = self.app.config.ReadBool('storyPanelSnap')
        self.overlapping = self.app.config.ReadBool('storyPanelOverlap')
        self.widgetDict = dict()
        self.visibleWidgets = None
        self.includedPassages = set()
        self.draggingMarquee = False
        self.draggingWidgets = []
        self.notDraggingWidgets = []
        self.undoStack = []
        self.undoPointer = -1
        self.lastSearchRegexp = None
        self.lastSearchFlags = None
        self.lastScrollPos = -1
        self.trackinghover = None
        self.tooltiptimer = wx.PyTimer(self.tooltipShow)
        self.tooltipplace = None
        self.tooltipobj = None
        self.textDragSource = None

        if state:
            self.scale = state['scale']
            try:
                self.storywidth = state['storywidth']
                self.storyheight = state['storyheight']
            except:
                self.storywidth = self.parent.GetSize()[0]
                self.storyheight = self.parent.GetSize()[1]
            for widget in state['widgets']:
                pw = PassageWidget(self, self.app, state=widget)
                self.widgetDict[pw.passage.title] = pw
            if 'snapping' in state:
                self.snapping = state['snapping']
        else:
            self.scale = 1
            self.storywidth = self.parent.GetSize()[0]
            self.storyheight = self.parent.GetSize()[1]
            for title in ('Start', 'StoryTitle', 'StoryAuthor'):
                self.newWidget(title=title,
                               text=self.parent.defaultTextForPassage(title),
                               quietly=True)

        self.pushUndo(action='')
        self.undoPointer -= 1

        # cursors

        self.dragCursor = wx.Cursor(wx.CURSOR_SIZING)
        self.badDragCursor = wx.Cursor(wx.CURSOR_NO_ENTRY)
        self.scrollCursor = wx.Cursor(wx.CURSOR_SIZING)
        self.defaultCursor = wx.Cursor(wx.CURSOR_ARROW)
        self.SetCursor(self.defaultCursor)

        # events

        self.SetDropTarget(StoryPanelDropTarget(self))
        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: e)
        self.Bind(wx.EVT_PAINT, self.paint)
        self.Bind(wx.EVT_SIZE, self.resize)
        self.Bind(wx.EVT_LEFT_DOWN, self.handleClick)
        self.Bind(wx.EVT_LEFT_DCLICK, self.handleDoubleClick)
        self.Bind(wx.EVT_RIGHT_UP, self.handleRightClick)
        self.Bind(wx.EVT_MIDDLE_UP, self.handleMiddleClick)
        self.Bind(wx.EVT_ENTER_WINDOW, self.handleHoverStart)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.handleHoverStop)
        self.Bind(wx.EVT_MOTION, self.handleHover)