Python Web Site Process Bus v1.0 - 翻译
triple_des(des3) 算法 - php,python 实现

python 拖拉桌面小程序. :)

TLHL28 posted @ Mon, 14 Mar 2011 14:06:14 +0800 in 随笔 with tags python , 2354 readers

descript: 拖拉两个xls文件到此小程序中, 自动进行比对并输出比对结果(xls)

 

# -*- coding: utf-8 -*-

# Import wx.Python
import wx
import xlrd,xlwt
import os.path

# Declare GUI Constants
DRAG_SOURCE    = wx.NewId()

#=====================================
def encoding(s,coding=None):
    cl = ['utf8', 'gb2312','gb18030']
    if coding:
        cl.append(coding)
    for a in cl:
        try:
            s.decode(a)
            return a
        except UnicodeEncodeError:
            pass
    return 'unknown'

def toUnicode(s,coding=None):
    if isinstance(s,unicode):
        return s
    return s.decode(encoding(s,coding))
#=================================================

# Define File Drop Target class
class FileDropTarget(wx.FileDropTarget):
    """ This object implements Drop Target functionality for Files """
    def __init__(self, obj):
        """ Initialize the Drop Target, passing in the Object Reference to
          indicate what should receive the dropped files """
        # Initialize the wxFileDropTarget Object
        wx.FileDropTarget.__init__(self)
        # Store the Object Reference for dropped files
        self.obj = obj
        self._initContent()

    def _initContent(self):
        self.content = {'same':[],'diff':[]}

    def _log(self,string):
        self.obj.WriteText(toUnicode(string))

    def _analyze(self,xls={}):

        def combine_rows(sheet):
            rows = []
            for rownum in range(sheet.nrows):
                rows.append("-".join([toUnicode(str(row) if isinstance(row,float) else row) \
                        for row in sheet.row_values(rownum)]))
            return rows

        #FIXME optime
        name = xls.keys()
        self._log(u"正在比对 "+name[0]+u" , "+name[1]+u" 中...... \n")
        rows = []
        for sheet in xls.values():
            rows.append(combine_rows(sheet))
        same_rows = list(set(rows[0]) & set(rows[1]))
        file1_rows = list(set(rows[0]) - set(rows[1]))
        file2_rows = list(set(rows[1]) - set(rows[0]))
        self.content['same'].extend(same_rows)
        self.content['diff'].extend(\
                [{'name':name[0],'rows':file1_rows},
                {'name':name[1],'rows':file2_rows}])
        self._log("比对完成 \n")
        return 1

    def _dumpToXls(self,path):
        self._log("生成比对结果中...... \n")
        xls = xlwt.Workbook()
        sheet_same = xls.add_sheet(u'相同数据',cell_overwrite_ok=True)
        same_rows = self.content['same']
        def write_rows(sheet,rows):
            for r in range(len(rows)):
                cells = rows[r].split('-')
                for c in range(len(cells)):
                    sheet.write(r,c,cells[c])
        write_rows(sheet_same,same_rows)

        sheet_diff = {}
        for diff in self.content['diff']:
            name = diff.get('name','default')
            rows = diff.get('rows',[])
            sheet_diff[name] = xls.add_sheet(name+u"独有",cell_overwrite_ok=True)
            write_rows(sheet_diff[name],rows)
        result = os.path.join(path,u" 和 ".join(sheet_diff.keys())+u'的比对结果.xls')
        xls.save(result)
        self._log(u"生成比对结果如下:\n%s\n" % (result,))
        self._initContent()

    def _compare(self,filenames):
        filenames = filenames if isinstance(filenames,list) else list(filenames)
        #for mutiple files
        xls={}
        try:
            for file in filenames:
                name = os.path.basename(file).split('.')[0]
                xls[name] = xlrd.open_workbook(file).sheets()[0]
        except xlrd.biffh.XLRDError,e:
            self._log("请载入xls格式文件")
            return False
        #filenames.sort(self._analyze)
        self._analyze(xls)
        self._dumpToXls(os.path.dirname(filenames[0]))

    def OnDropFiles(self, x, y, filenames):
        """ Implement File Drop """
        # For Demo purposes, this function appends a list of the files dropped at the end of the widget's text
        # Move Insertion Point to the end of the widget's text
        self.obj.SetInsertionPointEnd()
        # append a list of the file names dropped
        self._log("\n加载了 %d 个文件:\n" % (len(filenames)))
        if len(filenames) != 2:
            self._log("只能比对两个文件\n")
            return False
        self._compare(filenames)

class MainWindow(wx.Frame):
    """ This window displays the GUI Widgets. """
    def __init__(self,parent,id,title):
        #wx.Frame.__init__(self,parent,-4, title, size = (430,270), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
        wx.Frame.__init__(self,parent,-4, title, size = (430,270), \
                style=wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN )
        self.SetBackgroundColour(wx.WHITE)

        wx.StaticText(self, -1, u"请将要比对的EXCEL文件拖拉进下面区域进行比对",(3,0))
        self.text = wx.TextCtrl(self, -1, "", pos=(2,15),size=(418,220), style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY)

        dt = FileDropTarget(self.text)
        self.text.SetDropTarget(dt)

        # Display the Window
        self.Show(True)

    def CloseWindow(self, event):
        """ Close the Window """
        self.Close()

    def OnDragInit(self, event):
        """ Begin a Drag Operation """
        # Create a Text Data Object, which holds the text that is to be dragged
        tdo = wx.PyTextDataObject(self.text.GetStringSelection())
        # Create a Drop Source Object, which enables the Drag operation
        tds = wx.DropSource(self.text)
        # Associate the Data to be dragged with the Drop Source Object
        tds.SetData(tdo)
        # Intiate the Drag Operation
        tds.DoDragDrop(True)

class MyApp(wx.App):
    """ Define the Drag and Drop Example Application """
    def OnInit(self):
        """ Initialize the Application """
        # Declare the Main Application Window
        frame = MainWindow(None, -1, u"Excel文件比对小程序")
        # Show the Application as the top window
        self.SetTopWindow(frame)
        return True

# Declare the Application and start the Main Loop
app = MyApp(0)
app.MainLoop()

 

Rylan Landon said:
Thu, 03 Jan 2019 18:33:52 +0800

This is the wonderful content, Cheers pertaining to supplying us this info. Preserve putting up. Tax Accountants

Benjamin Ford said:
Fri, 20 Sep 2019 22:02:37 +0800

I prefer merely excellent resources - you will see these people in: phone forwarding

Kevin Richardson said:
Mon, 04 Nov 2019 02:32:43 +0800

   Gives you the best website address       I know there alone you'll find how easy it is. 바카라사이트

Kevin Richardson said:
Sat, 09 Nov 2019 16:06:30 +0800

   I prefer merely excellent resources - you will see these people in: детски стаи стара загора

Kevin Richardson said:
Sat, 09 Nov 2019 23:58:53 +0800

   You ought to basically fantastic not to mention solid advice, which means notice: медиатори в училище

Kevin Richardson said:
Mon, 11 Nov 2019 23:09:36 +0800

On that website page, you'll see your description, why not read through this. convert ai to jpg

Kevin Richardson said:
Mon, 11 Nov 2019 23:15:06 +0800

These things are very important, good think so - I think so too...  convert png to jpg

Kevin Richardson said:
Mon, 11 Nov 2019 23:19:56 +0800

I exploit solely premium quality products -- you will observe these individuals on: convert bmp to jpg

Kevin Richardson said:
Mon, 11 Nov 2019 23:23:47 +0800

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. convert pdf to jpg

Kevin Richardson said:
Tue, 19 Nov 2019 20:10:24 +0800

Glad to chat your blog, I seem to be forward to more reliable articles and I think we all wish to thank so many good articles, blog to share with us.  https://www.militarywifejob.com/halki-diabetes-remedy-review-scam-or-legit/

Kevin Richardson said:
Tue, 19 Nov 2019 21:10:16 +0800

What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up. the lost ways book

Kevin Richardson said:
Fri, 20 Dec 2019 21:29:52 +0800

Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing... 바카라사이트

Amrita Spa said:
Sat, 22 Feb 2020 13:59:23 +0800

Thank you for sharing your knowledge and experience with me.
<a href="https://www.amritaspa.in/">full body massage service in malviya nagar</a>
<a href="https://www.lispa.in/">full body to body massage in delhi</a>
<a href="https://www.amritabodyspa.com/">best spa in malviya nagar</a>
<a href="https://www.omegaspa.in/">body to body massage female to male in lajpat nagar</a>
<a href="https://www.mylespa.com/">full body massage centre in jasola</a>
<a href="https://www.geetanjalispa.in/">full body to body massage parlour in mahipalpur</a>
<a href="https://www.fullbodytobodymassage.com/">body spa in lajpat nagar</a>
<a href="https://www.bodytobodymassage.co.in/">body to body massage with happy ending in malviya nagar</a>
<a href="https://nurumassagedelhi.com/">female to male body to body massage center in delhi</a>
<a href="https://www.body-massage.co.in/">body massage centre in gurgaon</a>
<a href="https://www.book2spa.com/">body to body massage parlour in gurgaon</a>
<a href="https://www.elisiondayspa.com/">body massage service in ludhiana</a>
<a href="https://www.mourinhodayspa.com/">female to male body massage in malviya nagar</a>
<a href="https://www.lotusspa.in/">body massage in gurgaon</a>
<a href="https://www.massagecenteringurgaon.com/">female to male full body massage center in gurgaon</a>
<a href="https://www.massagecenterindelhi.co.in/">female to male full body massage parlour in delhi</a>
<a href="https://www.lispa.in/body-2-body-massage-in-delhi-ncr">body massage price in delhi</a>
<a href="https://www.amritabodyspa.com/body-2-body-massage-in-delhi-ncr.html">spa in delhi</a>
<a href="https://www.amritaspa.in/full-body-to-body-massage-delhi.htm">massage in delhi</a>
<a href="https://www.mylespa.com/body-2-body-massage-delhi-faridabad-noida">female to male full body to body massage in delhi</a>
<a href="https://delhi.in.locan.to/ID_1332417206/Pay-Rs-999-Full-Body-Massage-By-Female-to-Male-at-Malviya-Nagar.html">erotic massage in malviya nagar</a>
<a href="https://delhi.in.locan.to/ID_912092337/Female-to-Male-Full-Body-to-Body-Massage-in-Lajpat-Nagar.html">nuru massage in lajpat nagar</a>
<a href="https://www.bookamassage.in/">massage spa in delhi</a>
<a href="https://www.bodymassageservices.com/">sandwich massage in delhi</a>
<a href="https://www.fullbodymassage.info/">female to male full body massage in delhi</a>
<a href="https://delhi.in.locan.to/ID_1167718098/Female-to-Male-Full-Body-to-Body-Massage-Center-in-Mahipalpur.html">spa center in mahipalpur</a>
<a href="https://ludhiana.in.locan.to/ID_4134170594/Female-to-Male-Full-Body-to-Body-Massage-in-Ludhiana.html">full body massage in ludhiana</a>
<a href="https://gurgaon.in.locan.to/ID_193025517/Female-to-Male-Full-body-Massage-Parlour-in-Gurgaon.html">full body massage for men in gurgaon</a>
<a href="https://delhi.in.locan.to/ID_1566893969/Pay-999-Full-Body-Massage-Parlour-in-Saket-Select-City-Walk-Mall.html">b 2 b massage in delhi</a>
<a href="https://delhi.in.locan.to/ID_213678440/Female-to-Male-Full-Body-to-Body-Massage-Parlour-in-Hauz-Khas.html">body massage center in hauz khas</a>
<a href="https://delhi.in.locan.to/ID_2720733429/Full-Body-to-Body-Massage-in-Jasola-Faridabad-by-Female-to-Male.html">full body to body massage services in jasola</a>
<a href="http://spamalviyanagar.ultimatefreehost.in/">massage parlour for men in malviya nagar</a>
<a href="http://bodytobodymassagemalviyanagardelhi.rf.gd/">body with body massage in malviya nagar</a>
<a href="https://www.facebook.com/pages/category/Massage-Service/Full-Body-to-Body-Massage-Centre-in-Malviya-Nagar-Delhi-09971655238-108611530585494/">female to male massage in malviya nagar</a>
<a href="http://amritaspa.hstn.me/">full body with body massage in malviya nagar</a>
<a href="http://bspamalviyanagar.byethost33.com/">body massage parlour in malviya nagar</a>
<a href="https://nurumassagedelhincr.wordpress.com/">full body massage parlour in malviya nagar</a>
<a href="http://nurubodymassagedelhi.unaux.com/">full body massage by female to male in malviya nagar</a>
<a href="http://bodytobodymassageinmalviyanagardelhi.atwebpages.com/">female to male body massage in malviya nagar</a>
<a href="http://spainmalviyanagar.onlinewebshop.net/">full body massage by female in malviya nagar</a>
<a href="http://amritaspadelhi.ihostfull.com/">best body massage in malviya nagar</a>
<a href="http://bodymassagemalviyanagar.000a.biz/">body on body massage in malviya nagar</a>
<a href="http://bodymassagemalviyanagar.eu5.org/">body to body massage in malviya nagar</a>
<a href="http://spainmalviyanagar.c1.biz/">massage center in malviya nagar</a>
<a href="http://spainmalviyanagar.125mb.com/">body message in malviya nagar</a>
<a href="http://amritaspadelhi.mipropia.com/">body massage parlour for male by female in malviya nagar</a>
<a href="http://spamalviyanagar.freegiga.in/">massage service in malviya nagar</a>
<a href="https://amrita-spa.constantcontactsites.com/">full body to body massage by female in malviya nagar</a>

Amrita Spa said:
Sat, 22 Feb 2020 13:59:46 +0800

Thank you for sharing your knowledge and experience with me.
[url=https://www.amritaspa.in/]female to male body massage in malviya nagar[/url]
[url=https://www.lispa.in/]body to body massage parlour in delhi[/url]
[url=https://www.amritabodyspa.com/]body massage parlour for male by female in malviya nagar[/url]
[url=https://www.omegaspa.in/]sensual massage in lajpat nagar[/url]
[url=https://www.mylespa.com/]happy ending massage in jasola[/url]
[url=https://www.geetanjalispa.in/]full body to body massage services in mahipalpur[/url]
[url=https://www.fullbodytobodymassage.com/]full body massage service in lajpat nagar[/url]
[url=https://www.bodytobodymassage.co.in/]body message in malviya nagar[/url]
[url=https://nurumassagedelhi.com/]body with body massage in delhi[/url]
[url=https://www.body-massage.co.in/]body spa in gurgaon[/url]
[url=https://www.book2spa.com/]best massage spa in gurgaon[/url]
[url=https://www.elisiondayspa.com/]body massage spa in ludhiana[/url]
[url=https://www.mourinhodayspa.com/]best massage in malviya nagar[/url]
[url=https://www.lotusspa.in/]full body to body massage in gurgaon[/url]
[url=https://www.massagecenteringurgaon.com/]best body massage in gurgaon[/url]
[url=https://www.massagecenterindelhi.co.in/]body on body massage in delhi[/url]
[url=https://www.lispa.in/body-2-body-massage-in-delhi-ncr]full body massage by female to male in delhi[/url]
[url=https://www.amritabodyspa.com/body-2-body-massage-in-delhi-ncr.html]b2b massage in delhi[/url]
[url=https://www.amritaspa.in/full-body-to-body-massage-delhi.htm]body to body massage with happy ending in delhi[/url]
[url=https://www.mylespa.com/body-2-body-massage-delhi-faridabad-noida]female to male full body to body massage in delhi[/url]
[url=https://delhi.in.locan.to/ID_1332417206/Pay-Rs-999-Full-Body-Massage-By-Female-to-Male-at-Malviya-Nagar.html]full body massage in malviya nagar[/url]
[url=https://delhi.in.locan.to/ID_912092337/Female-to-Male-Full-Body-to-Body-Massage-in-Lajpat-Nagar.html]female to male full body massage in lajpat nagar[/url]
[url=https://www.bookamassage.in/]full body massage centre in delhi[/url]
[url=https://www.bodymassageservices.com/]erotic massage in delhi[/url]
[url=https://www.fullbodymassage.info/]spa in delhi[/url]
[url=https://delhi.in.locan.to/ID_1167718098/Female-to-Male-Full-Body-to-Body-Massage-Center-in-Mahipalpur.html]full body to body massage by female in mahipalpur[/url]
[url=https://ludhiana.in.locan.to/ID_4134170594/Female-to-Male-Full-Body-to-Body-Massage-in-Ludhiana.html]spa center in ludhiana[/url]
[url=https://gurgaon.in.locan.to/ID_193025517/Female-to-Male-Full-body-Massage-Parlour-in-Gurgaon.html]body massage center in gurgaon[/url]
[url=https://delhi.in.locan.to/ID_1566893969/Pay-999-Full-Body-Massage-Parlour-in-Saket-Select-City-Walk-Mall.html]female to male massage in delhi[/url]
[url=https://delhi.in.locan.to/ID_213678440/Female-to-Male-Full-Body-to-Body-Massage-Parlour-in-Hauz-Khas.html]body massage service in hauz khas[/url]
[url=https://delhi.in.locan.to/ID_2720733429/Full-Body-to-Body-Massage-in-Jasola-Faridabad-by-Female-to-Male.html]full body massage parlour in jasola[/url]
[url=http://spamalviyanagar.ultimatefreehost.in/]massage in malviya nagar[/url]
[url=http://bodytobodymassagemalviyanagardelhi.rf.gd/]best spa in malviya nagar[/url]
[url=https://www.facebook.com/pages/category/Massage-Service/Full-Body-to-Body-Massage-Centre-in-Malviya-Nagar-Delhi-09971655238-108611530585494/]female to male full body massage parlour in malviya nagar[/url]
[url=http://amritaspa.hstn.me/]female to male body massage in malviya nagar[/url]
[url=http://bspamalviyanagar.byethost33.com/]massage service in malviya nagar[/url]
[url=https://nurumassagedelhincr.wordpress.com/]body to body massage in malviya nagar[/url]
[url=http://nurubodymassagedelhi.unaux.com/]body massage parlour in malviya nagar[/url]
[url=http://bodytobodymassageinmalviyanagardelhi.atwebpages.com/]full body with body massage in malviya nagar[/url]
[url=http://spainmalviyanagar.onlinewebshop.net/]female to male body to body massage in malviya nagar[/url]
[url=http://amritaspadelhi.ihostfull.com/]full body massage in malviya nagar[/url]
[url=http://bodymassagemalviyanagar.000a.biz/]spa for men in malviya nagar[/url]
[url=http://bodymassagemalviyanagar.eu5.org/]massage center in malviya nagar[/url]
[url=http://spainmalviyanagar.c1.biz/]female to male full body massage center in malviya nagar[/url]
[url=http://spainmalviyanagar.125mb.com/]best body to body massage in malviya nagar[/url]
[url=http://amritaspadelhi.mipropia.com/]body 2 body massage in malviya nagar[/url]
[url=http://spamalviyanagar.freegiga.in/]body to body massage female to male in malviya nagar[/url]
[url=https://amrita-spa.constantcontactsites.com/]b 2 b massage in malviya nagar[/url]

Amrita Spa said:
Sat, 22 Feb 2020 13:59:58 +0800

Thank you for sharing your knowledge and experience with me.
https://www.amritaspa.in/
https://www.lispa.in/
https://www.amritabodyspa.com/
https://www.omegaspa.in/
https://www.mylespa.com/
https://www.geetanjalispa.in/
https://www.fullbodytobodymassage.com/
https://www.bodytobodymassage.co.in/
https://nurumassagedelhi.com/
https://www.body-massage.co.in/
https://www.book2spa.com/
https://www.elisiondayspa.com/
https://www.mourinhodayspa.com/
https://www.lotusspa.in/
https://www.massagecenteringurgaon.com/
https://www.massagecenterindelhi.co.in/
https://www.lispa.in/body-2-body-massage-in-delhi-ncr
https://www.amritabodyspa.com/body-2-body-massage-in-delhi-ncr.html
https://www.amritaspa.in/full-body-to-body-massage-delhi.htm
https://www.mylespa.com/body-2-body-massage-delhi-faridabad-noida
https://delhi.in.locan.to/ID_1332417206/Pay-Rs-999-Full-Body-Massage-By-Female-to-Male-at-Malviya-Nagar.html
https://delhi.in.locan.to/ID_912092337/Female-to-Male-Full-Body-to-Body-Massage-in-Lajpat-Nagar.html
https://www.bookamassage.in/
https://www.bodymassageservices.com/
https://www.fullbodymassage.info/
https://delhi.in.locan.to/ID_1167718098/Female-to-Male-Full-Body-to-Body-Massage-Center-in-Mahipalpur.html
https://ludhiana.in.locan.to/ID_4134170594/Female-to-Male-Full-Body-to-Body-Massage-in-Ludhiana.html
https://gurgaon.in.locan.to/ID_193025517/Female-to-Male-Full-body-Massage-Parlour-in-Gurgaon.html
https://delhi.in.locan.to/ID_1566893969/Pay-999-Full-Body-Massage-Parlour-in-Saket-Select-City-Walk-Mall.html
https://delhi.in.locan.to/ID_213678440/Female-to-Male-Full-Body-to-Body-Massage-Parlour-in-Hauz-Khas.html
https://delhi.in.locan.to/ID_2720733429/Full-Body-to-Body-Massage-in-Jasola-Faridabad-by-Female-to-Male.html
http://spamalviyanagar.ultimatefreehost.in/
http://bodytobodymassagemalviyanagardelhi.rf.gd/
https://www.facebook.com/pages/category/Massage-Service/Full-Body-to-Body-Massage-Centre-in-Malviya-Nagar-Delhi-09971655238-108611530585494/
http://amritaspa.hstn.me/
http://bspamalviyanagar.byethost33.com/
https://nurumassagedelhincr.wordpress.com/
http://nurubodymassagedelhi.unaux.com/
http://bodytobodymassageinmalviyanagardelhi.atwebpages.com/
http://spainmalviyanagar.onlinewebshop.net/
http://amritaspadelhi.ihostfull.com/
http://bodymassagemalviyanagar.000a.biz/
http://bodymassagemalviyanagar.eu5.org/
http://spainmalviyanagar.c1.biz/
http://spainmalviyanagar.125mb.com/
http://amritaspadelhi.mipropia.com/
http://spamalviyanagar.freegiga.in/
https://amrita-spa.constantcontactsites.com/


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter