workspace.py :  » IDE » PyPE » PyPE-2.9.1 » plugins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » PyPE 
PyPE » PyPE 2.9.1 » plugins » workspace.py

'''
This software is licensed under the GPL (GNU General Public License) version 2
as it appears here: http://www.gnu.org/copyleft/gpl.html
It is also included with this archive as `gpl.txt <gpl.txt>`_.
'''


#system imports
import os

#site-packages imports
import wx

#local imports
import filehistory

#Why should I use an object when a closure works just as well?
#God this is such a hack, but it makes me smile.
def WorkspaceMenu(parentmenu, parentwindow, workspaces, workspace_order):
    
    def OnCloseAll(event):
        self = parentwindow
        sel = self.control.GetSelection()
        cnt = self.control.GetPageCount()
        try:
            for i in xrange(cnt):
                win = self.control.GetPage(i).GetWindow1()
                
                #Yeah, I know that using a function that is placed in the
                #module's namespace AFTER import is bad form, but I do it
                #anyways.
                if isdirty(win):
                    self.control.SetSelection(i)
                    self.sharedsave(win)
        except cancelled:
            event.Skip()
            return
        self.starting = 1
        for i in xrange(cnt-1, -1, -1):
            self.OnClose(None, i, self.control.GetPage(i).GetWindow1())
        self.starting = 0
    
    def OnSave(event):
        #check for dirty and unnamed files...
        self = parentwindow
        sel = self.control.GetSelection()
        cnt = self.control.GetPageCount()
        d = 0
        l = []
        for i in xrange(cnt):
            win = self.control.GetPage(i).GetWindow1()
            data = os.path.join(win.dirname, win.filename).encode('ascii')
            d += win.dirty and data == ' '
            if data != ' ':
                l.append(data)
        
        if d:
            self.dialog("Cannot save workspace with\nmodified untitled documents.", "Workspace Save Aborted!")
            return
        
        #get the name of the workspace
        while 1:
        
            dlg = wx.TextEntryDialog(parentwindow, "What would you like this workspace to be called?", "Workspace name", pos=(0,0))
            if openmenu.last:
                dlg.SetValue(openmenu.last)
            rslt = dlg.ShowModal()
            workspacename = dlg.GetValue()
            dlg.Destroy()
            if rslt != wx.ID_OK:
                self.SetStatusText("Workspace save cancelled")
                return
            
            wn = workspacename.strip()
            
            #check for usable name
            if not wn:
                self.SetStatusText("Workspace save cancelled")
                return
            
            #check for unused name
            if wn.lower() in [i.lower() for i in workspace_order]:
                if self.dialog("Are you sure you want to replace\nthe pre-existing workspace:\n%s"%wn.lower(), "Duplicate Workspace", wx.YES_NO) != wx.ID_YES:
                    continue
            
            break
        
        #remove potential duplicates
        workspace_order[:] = [i for i in workspace_order if i.lower() != wn.lower() or openmenu.ItemRemove(i) or deletemenu.ItemRemove(i)]
        x = dict(workspaces)
        workspaces.clear()
        for i in workspace_order:
            workspaces[i] = x[i]
        
        #handle workspace ordering
        workspace_order.insert(0, wn)
        workspaces[wn] = l
        openmenu.ItemAdd(wn)
        deletemenu.ItemAdd(wn)
    
    def OnOpen(label):
        ## print "opening workspace"
        
        #handle ordering of workspaces
        if label in workspace_order:
            workspace_order.remove(label)
        
        workspace_order.insert(0, label)
        
        #fetch the workspace
        ws = workspaces.get(label, [])
        
        #open all documents in the workspace
        parentwindow.OnDrop(ws)
    
    def OnDelete(label):
        ## print "deleting workspace..."
        #delete the workspace and fix workspace order
        
        if label in workspace_order:
            workspace_order.remove(label)
        workspaces.pop(label, None)
    
    #code that actually modifies the menu
    if 1:
        closeall = wx.NewId()
        parentmenu.Append(closeall, "Close All Documents",
                        "Closes all open documents, asking to save changes on modified files")
        wx.EVT_MENU(parentwindow, closeall, OnCloseAll)
        parentmenu.AppendSeparator()
        nwksid = wx.NewId()
        parentmenu.Append(nwksid, "Save Workspace",
                        "Saves the current workspace, aborts if modified and unnamed files are open")
        wx.EVT_MENU(parentwindow, nwksid, OnSave)
        
        openmenu = filehistory.FileHistory(parentwindow, callback=[OnOpen], seq=workspace_order)
        deletemenu = filehistory.FileHistory(parentwindow, remove=1,
                                callback=[openmenu.ItemRemove, OnDelete],
                                seq=workspace_order,
                                delmsg=("Are you sure you want to delete the workspace:\n%s",
                                        "Delete Workspace?"))
        openmenu.callback.append(deletemenu.ItemAdd)
        parentmenu.AppendMenu(wx.NewId(), "Open Workspace", openmenu)
        parentmenu.AppendMenu(wx.NewId(), "Delete Workspace", deletemenu)
        parentmenu.AppendSeparator()

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.