Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /newedit/src/

newedit
Discussion topic

Back to topic list

CVS update: /newedit/src/

Reply

Author limodou
Full name limodou
Date 2004-05-08 07:23:09 PDT
Message User: limodou
Date: 04/05/08 07:23:09

Added:
 /newedit/src/
  Accelerator.py, ChangeLog.txt, Debug.py, Id.py, Mixin.py, NewEdit.py,
  NewEdit.pyw, PrefDialog.py, Preference.py, makemenu.py, maketoolbar.py,
  py.ico

Log:
 Issue number:
 Obtained from:
 Submitted by:
 Reviewed by:

File Changes:

Directory: /newedit/src/
========================

File [added]: Accelerator.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/Accelera​tor.py?rev=1.1&c​ontent-type=text/vnd​.viewcvs-markup
Added lines: 90
---------------
import wx
import Id
from Debug import *
import re

keylist = {
'BACK' :wx.WXK_BACK,
'TAB' :wx.WXK_TAB,
'RETURN' :wx.WXK_RETURN,
'ESCAPE' :wx.WXK_ESCAPE,
'SPACE' :wx.WXK_SPACE,
'DELETE' :wx.WXK_DELETE,
'PRIOR' :wx.WXK_PRIOR,
'NEXT' :wx.WXK_NEXT,
'END' :wx.WXK_END,
'HOME' :wx.WXK_HOME,
'LEFT' :wx.WXK_LEFT,
'UP' :wx.WXK_UP,
'RIGHT' :wx.WXK_RIGHT,
'DOWN' :wx.WXK_DOWN,
'PRINT' :wx.WXK_PRINT,
'INSERT' :wx.WXK_INSERT,
'HELP' :wx.WXK_HELP,
'NUMPAD0' :wx.WXK_NUMPAD0,
'NUMPAD1' :wx.WXK_NUMPAD1,
'NUMPAD2' :wx.WXK_NUMPAD2,
'NUMPAD3' :wx.WXK_NUMPAD3,
'NUMPAD4' :wx.WXK_NUMPAD4,
'NUMPAD5' :wx.WXK_NUMPAD5,
'NUMPAD6' :wx.WXK_NUMPAD6,
'NUMPAD7' :wx.WXK_NUMPAD7,
'NUMPAD8' :wx.WXK_NUMPAD8,
'NUMPAD9' :wx.WXK_NUMPAD9,
'ADD' :wx.WXK_ADD,
'SEPARATOR' :wx.WXK_SEPARATOR,
'SUBTRACT' :wx.WXK_SUBTRACT,
'DECIMAL' :wx.WXK_DECIMAL,
'DIVIDE' :wx.WXK_DIVIDE,
'F1' :wx.WXK_F1,
'F2' :wx.WXK_F2,
'F3' :wx.WXK_F3,
'F4' :wx.WXK_F4,
'F5' :wx.WXK_F5,
'F6' :wx.WXK_F6,
'F7' :wx.WXK_F7,
'F8' :wx.WXK_F8,
'F9' :wx.WXK_F9,
'F10' :wx.WXK_F10,
'F11' :wx.WXK_F11,
'F12' :wx.WXK_F12,
'F13' :wx.WXK_F13,
'F14' :wx.WXK_F14,
'F15' :wx.WXK_F15,
'F16' :wx.WXK_F16,
'F17' :wx.WXK_F17,
'F18' :wx.WXK_F18,
'F19' :wx.WXK_F19,
'F20' :wx.WXK_F20,
'F21' :wx.WXK_F21,
'F22' :wx.WXK_F22,
'F23' :wx.WXK_F23,
'F24' :wx.WXK_F24,
'NUMLOCK' :wx.WXK_NUMLOCK,
}

def initaccelerator(win, acceleratorlist):
    accelist = []
    ikey = 0

    for keys, idname in acceleratorlist:
        f=wx.ACCEL_NORMAL
        for k in re.split('[\+-]', keys):
            uk = k.upper()
            if uk == 'CTRL':
                f |= wx.ACCEL_CTRL
            elif uk == 'ALT':
                f |= wx.ACCEL_ALT
            elif uk == 'SHIFT':
                f |= wx.ACCEL_SHIFT
            elif keylist.has_key(uk):
                ikey = keylist[uk]
            elif len(uk) == 1:
                ikey = ord(uk)
            else:
                debugput("[accelerator] Error: Undefined char [%s]" % uk)
        id = Id.makeid(win, idname)
        accelist.append((f, ikey, id))
    
    aTable = wx.AcceleratorTable(accelist)
    win.SetAcceleratorTable(aTable)

File [added]: ChangeLog.txt
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/ChangeLo​g.txt?rev=1.1&co​ntent-type=text/vnd.​viewcvs-markup
Added lines: 23
---------------
[2004/05/03]
OnModified.py Ôö¼ÓÎĵµÐ޸ĺónotebo​okºÍ´°ÌåµÄ±êÌâ±ä»¯
EditCtrl.py Ôö¼ÓtabÇл»ºó±êÌâµÄ±ä»¯

[2004/05/02]
EditorCtrl.py Ôö¼ÓOnFileNewºÍOnFileOpen²Ëµ¥

[2004/05/01]
MainSubFrame.py ÐÞ¸ÄMainSubFrameÀ࣬ÐÞ¸Ämixin OnSashDragºÍOnSize£¬​Ôö¼ÓÏàÓ¦µÄplugin
Mixin.py ÐÞ¸Äinitmixin·½·¨£¬µ​±ÎÞ¶ÔÓ¦µÄmixinʵÏÖʱ​£¬²åÈë¿Õ__plugins__
Debug.py Ôö¼Ó³õʼ»¯´úÂ룬ÐÅÏ¢​Êä³öΪ¼´Ê±¸üÐÂ
EditCtrl.py Notebook½á¹¹ÓÃÓÚ±£´æÿ¸öÎĵµ
Editor.py Ôö¼Ó±à¼­Îĵµ¿Ø¼þ

[2004/04/25]
Debug.py Ôö¼ÓDebugÄ£¿é£¬ÓÃÓÚÐÅÏ¢Êä³ö
Mixin.py ÐÞ¸ÄMixinÄ£¿éÐÅÏ¢Êä³ö
NewEdit.py ½«ËùÓÐÉú³ÉMainFrameµ​Ä´úÂë¼ò´úΪһ¸öinit½​Ó¿Ú£¬É¾³ýÔ­getMainFr​ame½Ó¿Ú
MainFrame.py ɾ³ýÔ­getMainFrame½Ó​¿Ú£¬Ôö¼Óinit½Ó¿Ú£¬ÓÃ​ÓÚÕû¸ömainframeµÄÉú³​É
StatusBar.py ½«×´Ì¬Ìõ´úÂë·ÖÀë³öÀ´

[2004/04/22]
NewEdit³õʼ¿ò¼Ü´î½¨

File [added]: Debug.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/Debug.py​?rev=1.1&content​-type=text/vnd.viewc​vs-markup
Added lines: 19
---------------
DEBUG = True
import sys

#out = sys.stdout
debugfilename=''

def debuginit(filename):
    global debugfilename

    debugfilename = filename
    open(debugfilename, 'w')

def debugput(*argv):
    if DEBUG:
        out = open(debugfilename, 'a')
        for i in argv:
            out.write(str(i))
        out.write("\n")
        out.close()

File [added]: Id.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/Id.py?re​v=1.1&content-ty​pe=text/vnd.viewcvs-​markup
Added lines: 12
---------------
import wx

def makeidlist(win, idlist):
    for idname in idlist:
        makeid(win, idname)

def makeid(win, idname):
    if not hasattr(win, idname):
        id=wx.NewId()
        setattr(win, idname, id)

    return getattr(win, idname)

File [added]: Mixin.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/Mixin.py​?rev=1.1&content​-type=text/vnd.viewc​vs-markup
Added lines: 104
----------------
import types
from Debug import debugput

__mixinset__ = {} #used to collect all mixins and plugins

class Mixin:
    __mixinname__ = '' #mixin interface name, all subclass need define its own __mixinname__

    def __init__(self):
        self.initmixin()

    def initmixin(self):
        debugput('[Mixin] Dealing class [%s]' % self.__class__.__name__)
        if self.__class__.__name__ == 'Mixin': #don't dealing Mixin class itself
            return
        if hasattr(self.__class__, '__mixinflag__'):
            if self.__class__.__mixinflag__ >= 1: #having executed mixin
                return
            else:
                self.__class__.__mixinflag__ = 1
        else:
            setattr(self.__class__, '__mixinflag__', 1)
        if not self.__mixinname__:
            debugput('[Mixin] The class [%s] has not a mixinname defined' % self.__class__.__name__)
            return
        if __mixinset__.has_key​(self.__mixinname__)​:
            debugput('[Mixin] Mixinning class [%s]' % self.__class__.__name__)
            mixins, plugins = __mixinset__[self.__​mixinname__]
            for name in mixins.keys():
                setattr(self.__class__, name, mixins[name])
            setattr(self.__class__, '__plugins__', plugins)
        else:
            setattr(self.__class__, '__plugins__', {})

    def callplugin(self, name, *argv, **argkv):
        if not self.__plugins__.has_key(name):
            debugput('[Mixin] The plugin [%s] has not been implemented yet!' % name)
            return

        for f in self.__plugins__[name]:
            debugput("[Mixin] Call plugin [%s]" % name)
            f(*argv, **argkv)

    def execplugin(self, name, *argv, **argkv):
        if not self.__plugins__.has_key(name):
            debugput('[Mixin] The plugin [%s] has not been implemented yet!' % name)
            return

        if len(self.__plugins__​[name])>1:
            debugput('[Mixin] There should be only one plug-in [%s]!' % name)
            return

        f = self.__plugins__[name][0]
        return f(*argv, **argkv)

def searchpackage(packagename):
    module=__import__(packagename)
    if hasattr(module, '__all__'):
        for i in module.__all__:
            debugput('[Mixin] Dealing module [%s]' % i)
            __import__(packagename+'.'+i)

def setMixin(mixinname, name, value):
    if __mixinset__.has_key​(mixinname):
        mixins = __mixinset__[mixinname][0]
    else:
        __mixinset__[mixinname] = ({}, {})
        mixins = __mixinset__[mixinname][0]

    t = type(value)
    if t in (types.DictType, types.TupleType, types.ListType):
        if mixins.has_key(name):
            if t == types.DictType :
                mixins[name].update(value)
            else:
                mixins[name].extend(value)
        else:
            mixins[name] = value
    else:
        mixins[name] = value

def setPlugin(mixinname, name, value):
    if __mixinset__.has_key​(mixinname):
        plugins = __mixinset__[mixinname][1]
    else:
        __mixinset__[mixinname] = ({}, {})
        plugins = __mixinset__[mixinname][1]

    if plugins.has_key(name):
        plugins[name].append(value)
    else:
        plugins[name] = [value]

def printMixin():
    debugput("[Mixin] Printing mixin set...")
    for name, value in __mixinset__.items():
        mixins, plugins = value
        debugput("\tname=%s" % name)
        debugput("\t |----mixin")
        for k in mixins.keys():
            debugput("\t |%s" % k)
        debugput("\t |----plugin")
        for k in plugins.keys():
            debugput("\t |%s" % k)

File [added]: NewEdit.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/NewEdit.​py?rev=1.1&conte​nt-type=text/vnd.vie​wcvs-markup
Added lines: 0
--------------

File [added]: NewEdit.pyw
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/NewEdit.​pyw?rev=1.1&cont​ent-type=text/vnd.vi​ewcvs-markup
Added lines: 1
--------------
import NewEdit

File [added]: PrefDialog.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/PrefDial​og.py?rev=1.1&co​ntent-type=text/vnd.​viewcvs-markup
Added lines: 49
---------------
import wx
import Preference

class PrefDialog(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, -1, title="Preference...", size=wx.Size(600, 400), style=wx.DEFAULT_DIALOG_STYLE)

        self.box1 = wx.BoxSizer(wx.VERTICAL)

        self.box2 = wx.BoxSizer(wx.HORIZONTAL)

        self.box3 = wx.BoxSizer(wx.VERTICAL)
        label = wx.StaticText(self, -1, "Catalog")
        self.box3.Add(label, 0, wx.ALIGN_LEFT|wx.BOT​TOM|wx.LEFT, 2)
        self.tree = wx.TreeCtrl(self, -1, size=(150, 100), style=wx.TR_HAS_BUTTONS | wx.TR_HIDE_ROOT)
        self.addCatalog(self.tree)
        self.box3.Add(self.tree, 1, wx.EXPAND|wx.ALL)
        self.box2.Add(self.box3, 0, wx.EXPAND|wx.ALL, 5)

        self.box4 = wx.BoxSizer(wx.VERTICAL)
        self.notebook = wx.Notebook(self, -1, style=wx.CLIP_CHILDREN)
        self.panel = wx.Panel(self.notebook, -1, style=wx.CLIP_CHILDREN)
        self.notebook.AddPag​e(self.panel, 'test')
        self.box4.Add(self.notebook, 1, wx.EXPAND|wx.ALL)
        self.box2.Add(self.box4, 1, wx.EXPAND|wx.ALL, 5)

        self.box1.Add(self.box2, 1, wx.EXPAND|wx.ALL)

        line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
        self.box1.Add(line, 0, wx.EXPAND|wx.ALIGN_C​ENTER_VERTICAL|wx.LE​FT|wx.RIGHT|wx.TOP, 5)

        self.box5 = wx.BoxSizer(wx.HORIZONTAL)

        self.btnok = wx.Button(self, wx.ID_OK, " OK ")
        self.btnok.SetDefault()
        self.box5.Add(self.btnok, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
        self.btncancel = wx.Button(self, wx.ID_CANCEL, " Cancel ")
        self.box5.Add(self.btncancel, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        self.box1.Add(self.box5, 0, wx.EXPAND|wx.ALL, 5)

        self.SetSizer(self.box1)
        self.SetAutoLayout(True)
# self.box1.Fit(self)

    def addCatalog(self, tree):
        self.root = tree.AddRoot('')
        tree.AppendItem(self.root, 'test1')


File [added]: Preference.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/Preferen​ce.py?rev=1.1&co​ntent-type=text/vnd.​viewcvs-markup
Added lines: 42
---------------
import Mixin
import Debug
import copy
import pickle

class Preference(Mixin.Mixin):
    __mixinname__ = 'preference'
    preflist = [('generic', 100, 'wildcard', 'All files (*.*)|*', None),
    ]
    defaultfile = 'newedit.opt'

    def __init__(self):
        self.initmixin()

        self.initpref()

    def clone(self):
        return copy.copy(self)

    def save(self, filename=''):
        if not filename:
            filename = self.defaultfile
        pickle.dump(self, open(filename, 'w'))

    def load(self, filename=''):
        if not filename:
            filename = self.defaultfile
        return pickle.load(open(filename))

    def initpref(self):
        for catalog, order, name, value, extern in self.preflist:
            setattr(self, name, value)

if __name__ == '__main__':
    Debug.debuginit('out.txt')
    p = Preference()
    print p.__dict__
    p.wildcard = 'aaa'
    p.save()
    p = p.load()
    print p.__dict__
    print p.wildcard, p.__mixinname__

File [added]: makemenu.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/makemenu​.py?rev=1.1&cont​ent-type=text/vnd.vi​ewcvs-markup
Added lines: 92
---------------
from Debug import *
import types
import wx
import Id

def makesubmenu(win, mlist, accel=None):
    menu = wx.Menu()
    for m in mlist:
        order, idname, caption, kind, func, obj = m
        if type(obj) == types.ListType:
            submenu = makesubmenu(obj)
            menu.AppendMenu(id, caption, submenu)
        else:
            if kind == wx.ITEM_SEPARATOR:
                menu.AppendSeparator()
            else:
                id = Id.makeid(win, idname)
                menu.Append(id, caption, obj, kind)

            if kind in (wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO):
                if func:
                    try:
                        f = getattr(win, func)
                        wx.EVT_MENU(win, id, f)
                    except:
                        debugput("[makemenu] Can't find function [%s] in class %s" % (func, win.__class__.__name__))
    return menu

def makepopmenu(win, popmenu, accel=None):
    mlist = mergemenu(popmenu)
    makeaccelerator(mlist, accel)
    menu = makesubmenu(win, mlist)
    return menu

def makemenu(win, menulist, accel=None):
    menuBar = wx.MenuBar()

    mlist = mergemenu(menulist)
    printmenu(mlist)
    makeaccelerator(mlist, accel)

    for m in mlist:
        order, idname, caption, kind, func, obj = m
        menu = makesubmenu(win, obj, accel)
        menuBar.Append(menu, caption)

    return menuBar

def mergemenu(menulist):
    menulist.sort()
    m = []
    level = 0

    for parentmenuid, menu in menulist:
        if parentmenuid == 0:
            m.extend(menu)
            m.sort()
        else:
            appendsubmenu(m, parentmenuid, menu)

    return m
    
def appendsubmenu(m, porder, menu):
    for i in range(len(m)):
        order, idname, caption, kind, func, obj = m[i]
        if order == porder: #find
            if type(obj) == types.ListType:
                obj.extend(menu)
                obj.sort()
            else:
                m[i] = m[i][:-1] + (menu, )
        else:
            if type(obj) == types.ListType:
                appendsubmenu(obj, porder, menu)

def printmenu(m):
# for level, id, idname, caption, kind, func, message in m:
# print level, id,idname,caption, message
    debugput('[makemenu] Menu listing...')
    for order, idname, caption, kind, func, obj in m:
        debugput('\t%s %s %s' % (order, idname, caption))
        if type(obj) == types.ListType:
            printmenu(obj)

def makeaccelerator(m, accellist):
    for order, idname, caption, kind, func, obj in m:
        if accellist != None:
            pos = caption.find('\t')
            if pos>= 0:
                accellist.append((ca​ption[pos+1:], idname))
        if type(obj) == types.ListType:
            makeaccelerator(obj, accellist)

File [added]: maketoolbar.py
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/maketool​bar.py?rev=1.1&c​ontent-type=text/vnd​.viewcvs-markup
Added lines: 47
---------------
import wx
import Id
from Debug import *
import os.path

class EUnknowImageType(Exception): pass

def getimagetype(imagefile):
    ext = os.path.splitext(ima​gefile.lower())[1]
    if ext == '.bmp':
        type = wx.BITMAP_TYPE_BMP
    elif ext == '.png':
        type = wx.BITMAP_TYPE_PNG
    elif ext == '.jpg':
        type = wx.BITMAP_TYPE_JPEG
    elif ext == '.gif':
        type = wx.BITMAP_TYPE_GIF
    else:
        debugput("[maketoolbar] Unsupported image type [%s]" % ext)
        raise EUnknowImageType
    return type

def maketoolbar(win, toollist, toolbaritems):
    win.toolbar = win.CreateToolBar(wx​.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)

    #judge image size by the first item of the toolbar item list
    imagefile = toolbaritems.values()[0][1]
    image = wx.Image(imagefile, getimagetype(imagefile))
    size = wx.Size(image.GetWidth(), image.GetHeight())
    win.toolbar.SetToolB​itmapSize(size)

    toollist.sort()
    for order, name in toollist:
        if name == '|':
            win.toolbar.AddSeparator()
        else:
            idname, imagefile, shorttext, longtext, func = toolbaritems[name]
            id = Id.makeid(win, idname)
            win.toolbar.AddSimpleTool(id, wx.Image(imagefile, getimagetype(imagefi​le)).ConvertToBitmap​(), shorttext, longtext)
            if func:
                try:
                    f = getattr(win, func)
                    wx.EVT_TOOL(win, id, f)
                except:
                    debugput("[maketoolbar] Can't find function [%s] in class %s" % (func, win.__class__.__name__))
    win.toolbar.Realize()
    

File [added]: py.ico
Url: http://newedit.tigri​s.org/source/browse/​newedit/src/py.ico?r​ev=1.1&content-t​ype=text/vnd.viewcvs​-markup



--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe@newe​dit.tigris.org
For additional commands, e-mail: cvs-help at newedit dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /newedit/src/ limodou limodou 2004-05-08 07:23:09 PDT
Messages per page: