Ich habe die folgenden Scripte geschrieben und sie laufen bei mir auch wunderbar.
Nachdem ich nicht auf jedem Rechner Python + alles Libs installen will, habe ich einfach meine Installation auf ein Netzlaufwerk kopiert und rufe sie in einem .bat über die pythonw.exe dort auf. Das Problem ist nun das sich auf allen anderen Rechnern (ausser auf dem Entwicklungsrechner) einfach nix tut. Kein Fehler, aber auch keine Anwendung.
Hat jemand eine Idee dazu ?
Danke schon mal !
PS(Ich bin noch recht gründ hinter den Ohren also bitte nicht gleich ausfallend werden wenn ich nicht alles Konventionen einhalte ^^...darauf hingewiesen werde ich aber natürich gerne.)
Code: Alles auswählen
# -*- coding: utf-8 -*-
import wx, os, win32com.client as win32, traceback, word_test, time
from lxml import etree
from threading import Thread
from wx.lib.pubsub import setupv1 as psv1
from wx.lib.pubsub import Publisher
import pythoncom
class MainWindow(wx.Frame):
def __init__(self, parent, title):
self.checkson = word_test.CheckOr()
# A "-1" in the size parameter instructs wxWidgets to use the default size.
# In this case, we select 200px width and the default height.
wx.Frame.__init__(self, parent, title=title)
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.HSCROLL)
self.control.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL))
self.Statusbar = self.CreateStatusBar() # A Statusbar in the bottom of the window
self.Statusbar.SetStatusText("LexisNexis | DCM 2012 (c)")
self.Button1 = wx.Button(self, -1, "Check'em", size=(100,50))
self.Button2 = wx.Button(self, -1, "Clear", size=(100,50))
self.ChoiceList = wx.Choice(self,1,choices=self.checkson.getJournals())
self.Label1 = wx.StaticText(self,1, label="Zeitschrift: ")
dt = MyFileDropTarget(self.control)
self.control.SetDropTarget(dt)
Publisher.subscribe(self.updateDisplay, "update")
ib = wx.IconBundle()
ib.AddIconFromFile("check.ico", wx.BITMAP_TYPE_ANY)
self.SetIcons(ib)
# Setting up the menu.
filemenu= wx.Menu()
#menuOpen = filemenu.Append(wx.ID_OPEN, "&Open"," Open a file to edit")
menuAbout= filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
# Events.
#self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
self.Bind(wx.EVT_BUTTON, self.OnCheck, self.Button1)
self.Bind(wx.EVT_BUTTON, self.OnClear, self.Button2)
# Use some sizers to see layout options
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.control, 1, wx.EXPAND)
self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.sizer2, 0, wx.EXPAND)
self.sizer2.Add(self.Button1, 1,wx.EXPAND)
self.sizer2.Add(self.Button2, 1,wx.EXPAND)
self.sizer3 = wx.BoxSizer(wx.VERTICAL)
self.sizer2.Add(self.sizer3, 2,wx.EXPAND)
self.sizer3.Add(self.Label1, 0)
self.sizer3.Add(self.ChoiceList, 0,wx.EXPAND)
self.SetBackgroundColour("#FFFFF")
#Layout sizers
self.SetSizer(self.sizer)
self.MinSize = (700,500)
self.Fit()
self.Show()
def OnAbout(self,e):
# Create a message dialog box
dlg = wx.MessageDialog(self, "This Tool checks for troubles in Word-documents.\n (c)Patrick Szabo, LexisNexis 2012", "About", wx.OK)
dlg.ShowModal() # Shows it
dlg.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(True) # Close the frame.
def OnClear(self,e):
self.control.Clear()
def OnCheck(self, file):
files = []
for line in range(0,self.control.GetNumberOfLines()-1):
files.append(self.control.GetLineText(line))
self.control.Clear()
for i in range(0,len(files)):
self.control.AppendText(" \n")
self.control.Clear()
CheckThread(files)
#for file in files:
# self.control.AppendText("Working on %s...\n" % file)
# for error in self.checkson.main(file):
# self.control.AppendText(" Unknown: '%s' at '%s'(%i)\n" % (error[2],error[1],error[0]))
# self.control.AppendText("Done...\n")
#self.control.AppendText("\n")
#self.control.AppendText("Finished!\n")
def updateDisplay(self, msg):
"""
Receives data from thread and updates the display
"""
t = msg.data
self.control.AppendText(t)
class MyFileDropTarget(wx.FileDropTarget):
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):
for file in filenames:
self.window.AppendText("%s\n" % file)
class CheckThread(Thread):
"""Test Worker Thread Class."""
def __init__(self, files):
"""Init Worker Thread Class."""
Thread.__init__(self)
self.checkson = word_test.CheckOr()
self.files = files
self.start() # start the thread
def run(self):
pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
"""Run Worker Thread."""
# This is the code executing in the new thread.
for file in self.files:
self.postTime("Working on %s...\n" % file)
for error in self.checkson.main(file):
self.postTime(" Unknown: '%s' at '%s'(%i)\n" % (error[2],error[1],error[0]))
self.postTime("Done...\n")
self.postTime("\n")
self.postTime("\n")
self.postTime("Finished!\n")
pythoncom.CoUninitialize(pythoncom.COINIT_APARTMENTTHREADED)
def postTime(self, amt):
Publisher.sendMessage("update", amt)
app = wx.App(False)
frame = MainWindow(None, "ChecktO_ol")
app.MainLoop()
Code: Alles auswählen
# -*- coding: utf-8 -*-
'''
Created on 03.02.2012
@author: szabop
'''
import win32com.client as win32, traceback
from lxml import etree
class CheckOr():
def __init__(self):
self.zeitschrift ="ZFR"
self.parser = etree.XMLParser(recover=True, resolve_entities=True, load_dtd=True)
self.formats_file = "formats.xml"
self.formats = etree.ElementTree(etree.XML(open(self.formats_file, 'r').read(),self.parser))
self.root = self.formats.getroot()
self.common_formats = [x.lower().strip() for x in self.zeichen(self.root.xpath('common/text()')[0]).split(',')]
self.numbered_formats = [x.lower().strip() for x in self.zeichen(self.root.xpath('numbered/text()')[0]).split(',')]
self.specific_formats = {}
for zs in self.root.xpath('zs'):
self.specific_formats[zs.xpath("zs_name/text()")[0]] = self.zeichen(zs.xpath("zs_formats/text()")[0]).split(',')
self.final_formats = self.common_formats + self.specific_formats[self.zeitschrift]
for i in range(1,20):
for item in self.numbered_formats:
self.final_formats.append(item + " %i" %i)
def zeichen(self, s):
return s.replace(u"ü","ue").replace(u"ä", "ae").replace(u"ß", "ss")
def main(self, file):
word = win32.gencache.EnsureDispatch('Word.Application')
doc = word.Documents.Open(file)
errors = []
p = 0
for par in doc.Paragraphs:
print
if not(self.zeichen(unicode(par.Format.Style)).lower().strip() in self.final_formats):
#print "WRONG: %s" % self.zeichen(str(par.Format.Style)).lower()
#print "P%i: %s" % (p+1,par)
errors.append([p+1,unicode(par).strip(),self.zeichen(unicode(par.Format.Style)).lower()])
p+=1
doc.Close()
word.Application.Quit(-1)
return errors
def getJournals(self):
return self.specific_formats.keys()
#checker = CheckOr()
#checker.main("I:\\_zeitschriften\RdW\\produktion\\06a-Word_ueberarbeitet_aufsatz\\0201_2012_2_zorn_korr.doc")