eclipse workbench usage(EditReference ViewReference etc)

1. Only one Workbench
IWorkbench wb = PlatformUI.getWorkbench();
2. A workbench has one or more main windows(always one)
IWorkbenchWindow[] wbWindows = PlatformUI.getWorkbench()getWorkbenchWindows();
IWorkbenchWindow wbWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();

//others
Display display =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay();
display.syncExec(Runnable); //串行
display.asyncExec(Runnable); //并行

3. Each workbench window has a collection of pages(always one)
IWorkbenchPage[] pages =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
Composite composite = page.getClientComposite();

4.Each workbench page has a collection of workbench parts, of which there are
two kinds: views and editors.
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
IEditorPart[] editors = page.getEditors();

IViewReference[] viewRefs = page.getViewReferences();
IViewPart[] views = page.getViews();

//you can also get perspective from WorkbenchPage
Perspective perspective = page.getActivePerspective();

5. LayoutPart and its child class PartPane PartPlaceholder PartSashContainer
PartStack, jsut layout. for example: zoom in/out, specified size, drag/drop.
6. Editors shared one Action Bars, Views has his own Action Bars.
Editor: getSite().getActionBars();
editors[0].getEditorSite().getActionBars();
View: views[0].getViewSite().getActionBars();

7. Get contorl from editor/view:
Composite composite = views[0].getPane().getControl();
Composite composite = editors[0].getPane().getControl();

8. What’s Site
PartSite is the general implementation for an IWorkbenchPartSite. A site
maintains the context for a part, including the part, its pane, active
contributions, selection provider, etc. Together, these components make up the
complete behavior for a part as if it was implemented by one person. The
PartSite lifecycle is as follows ..

1. a site is constructed
2. a part is constructed and stored in the part
3. the site calls part.init()
4. a pane is constructed and stored in the site
5. the action bars for a part are constructed and stored in the site
6. the pane is added to a presentation
7. the SWT widgets for the pane and part are created
8. the site is activated, causing the actions to become visible

http://www.eclipse.org/articles/Article-UI-Workbench/workbench.html

使用python脚本下载www.wuxia.net.cn上的书籍,并且将它们合并成一个文件

如题,太累了,直接贴上source,应该能看明白,不明白的话,请给我回复,我会及时回复。

# -*- coding: cp936 -*-
import sgmllib
import urllib2
import HTMLParser
import codecs

class BookParser(sgmllib.SGMLParser):
    def __init__(self):

        # inherit from the SGMLParser class
        sgmllib.SGMLParser.__init__(self)

        # create a list this will store all the links found
        self.links = []
        self.bookNames = []
        self.inside_a_element = 0
        self.count = 0;

    def unknown_starttag(self, tag, attrs):
        #print "unknown tag start " + tag
        for key, value in attrs:
            if key.lower() == "href":
                if "/book/" in value and ".html" in value:
                    self.links.append(value)
                    self.inside_a_element = 1


    def unknown_endtag(self, tag):
        #print "in end tag"
        if self.inside_a_element:
            self.inside_a_element = 0
            self.count += 1

    def handle_data(self, text):
        #print text
        if self.inside_a_element:
            text = unicode(text, 'utf-8')
            text = text + str(self.count) + ".txt"
            self.bookNames.append(text)
            codecs.open(text, 'a', "utf-8")

class PageParser(sgmllib.SGMLParser):
    def __init__(self):

        # inherit from the SGMLParser class
        sgmllib.SGMLParser.__init__(self)

        # create a list this will store all the links found
        self.links = []

    def unknown_starttag(self, tag, attrs):
        #print "unknown tag start " + tag
        for key, value in attrs:
            if key.lower() == "href":
                if "/book/" in value and ".html" in value:
                    self.links.append(value)


class ContentParser(sgmllib.SGMLParser):
    def __init__(self, bookNames):

        # inherit from the SGMLParser class
        sgmllib.SGMLParser.__init__(self)

        # create a list this will store all the divs(page content) found
        self.divs = []
        # create a list this will store all the h1(title) found
        self.headone = []
        print " in content parser " + bookNames
        self.logfile = codecs.open(bookNames, 'a', "utf-8")
        self.inside_a_element = 0
        self.h = HTMLParser.HTMLParser()

    # this function is called once an anchor tag is found

    def unknown_starttag(self, tag, attrs):
        #print "unknown tag start " + tag
        if tag.lower() == "h1":
            self.inside_a_element = 1
        if tag.lower() == "p":
            self.inside_a_element = 2

    def unknown_endtag(self, tag):
        if self.inside_a_element:
            self.inside_a_element = 0
            self.logfile.write("\n")

    def handle_data(self, text):
        #print "handle data "  + text
        if self.inside_a_element == 1:
            text = unicode(text, 'utf-8')
            self.logfile.write(text + "\n\n")

        if self.inside_a_element == 2:
            text = unicode(text, 'utf-8')
            self.logfile.write(text)

    def handle_charref(self, ref):
        print "#############"
        print "chart is " + ref
        print self.h("&#%(ref)")
    def handle_entityref(self, ref):
        self.logfile.write(self.h.unescape("&"+ref+";"))
        #print "#############"
        #print "enttity is + " + ref
        #print self.h.unescape("&"+ref+";")

def getBookList(url):
    bookDict = {}
    sock = urllib2.urlopen(url)
    # make sure the string that is going to be parsed is 8-bit ascii
    if sock.info().dict['content-type'] == 'text/html':
        parser = BookParser()
        parser.feed(sock.read())
        bookDic = dict(zip(parser.links, parser.bookNames))
    return bookDic


def getPageList(bookUrl):
    pageList = []
    sock = urllib2.urlopen(bookUrl)
    # make sure the string that is going to be parsed is 8-bit ascii
    if sock.info().dict['content-type'] == 'text/html':
        parser = PageParser()
        parser.feed(sock.read())
        pageList = parser.links

    return pageList

def getPageContent(pageUrl, bookNames):
    sock = urllib2.urlopen(pageUrl)
    # make sure the string that is going to be parsed is 8-bit ascii
    if True:
        parser = ContentParser(bookNames)
        parser.feed(sock.read())
        # print out links
        for link in parser.divs:
            print link


def main(wuxiaUrl):
    bookDic = getBookList(wuxiaUrl)
    print type(bookDic)
    print bookDic
    for link, bookNames in bookDic.iteritems():
        print "link is " + link
        print "bookNames is " + bookNames
        pageList = getPageList("http://www.wuxia.net.cn" + link)
        for page in pageList:
            getPageContent("http://www.wuxia.net.cn" + page, bookNames)


if __name__ == '__main__':
    # this str is author's page
    main("http://www.wuxia.net.cn/author/shiweihan.html")
    #if len(sys.argv) < 2:
    #    print("Usage: %s xuxiaurl"%sys.argv[0])
    #else:
    #    main(sys.argv[1])

The road of iTour

I have this idea few years ago, But I have not enough time to make it. So I
write it down.
iTour’s basic function is: User can add his/her tour’s location, stay time,
picture, comment, video etc to the map with time order, when the tour
finished, User can see the tour line actively in the map.

iTour’s other functions:
1. User can shares his/her tour’s info;
2. User can adds his/her tour’s location, stay time, picture, comment, video
etc to the map with time order;
3. User can views the iTour line in the map with different perspective(time,
location , compare perspective);
4. More deep develope, User can adds his/her work or life’ line to the map,
then System can give user some advice about eat/traffic with user’s supplied
info;
5. If user’s phone have location function, the iTour line can automaticly
produced;
6. User can adds the tour which have passed;
7. User can add some things(like World Cup, Premier League, NBA etc) or
famous person or animals(Polar Bear etc) and share with the world;
8. It’s better user can add iTour anonymous, Google, Facebook, twitter’s
account can login;
9. iTour can produce flash, let user live over again his/her tour;
10. User can download all the info which He/She added.

iTour之路

这个想法是我很久以前的想法,但是一直没有时间和精力去搞。 所以写下来,以免以后忘记了。

iTour的基本功能就是可以让用户在地图上将自己的旅行地点和照片,视频等资料以时间的先后顺序标注出来,最后用户可以在地图上看到自己的旅行线路。

它具有以下功能:
1. 用户可以share自己的旅行线路和风景照片;
2. 用户可以iTour的某一点上添加图片,文字,链接,视频,音频,在这一点上的停留时间等资料;
3. 用户可以以时间,地点等视图查看自己的iTour;
4. 更进一步的,用户可以将自己的日常生活,工作等的线路描述出来,这是可以依据用户的资料给出用户的出行,用餐等建议;
5. 如果用户的手机具有定位功能的话,在iTour上可以自动添加iTour point,时间一长可以自动产生一条iTour;
6. 用户可以添加自己过去的某段时间的iTour;
7. 用户可以添加某一事件(世界杯,欧冠等)或某一著名人物或者某类生物(北极熊等)的iTour和大家分享;
8. 用户注册功能最好不需要,用户可以使用现存的社交网站的帐号登录iTour;
9. 用户可以匿名添加iTour;
10. iTour可以生产动态的重放效果,使用和可以重温自己的旅行或者别人的旅行;
11. 用户的所有信息都可以下载。

便携式马桶

如果你家里只有一个厕所,但是家里有好多人,是不是清朝上厕所很是煎熬啊?

以下是我设想的便携式马桶所具有的功能:
1. 可以折叠,便于携带和安放;
2. 大便可以拉在纸袋或塑料袋,方便处理;
3. 便于冲洗;
4. 大小不能太大