Seite 1 von 2

Der komplette Quelltext.

Verfasst: Freitag 14. Januar 2005, 16:16
von Psus82
Hier ist mein kompletter Quelltext.

Code: Alles auswählen

from Tkinter import *
import sys
import tkFileDialog
import tkSimpleDialog
import os,time

FolderToScan = None
EmailAdress = None

def ChangeFolder():
 FolderToScan = tkFileDialog.askdirectory()

def EmailAdress():
    Subwindow1 = Tk() 
    Subwindow1.geometry("200x100+0+0")
    Label1= Label(Subwindow1, text = "E-Mailadress :")
    Label1.place(x = 5, y = 10)
    EmailAdress = Entry(Subwindow1, width=30)
    EmailAdress.place(x = 5, y = 35)
    Subwindow1.mainloop()

def ChangeLogFolder():
 FolderToSaveLog = tkFileDialog.askdirectory()


def watch_directories (paths , func, delay = 1.0):
    all_files = {}

    def f (unused, dirname, files):

        for filename in files:
            path = os.path.join(dirname, filename)

            try:
                t = os.stat(path)

            except os.error:
                continue
            mtime = remaining_files.get(path)

            if mtime is not None:
                del remaining_files[path]
                if t.st_mtime > mtime:
                    changed_list.append(path)

            else:
                changed_list.append(path)
            all_files[path] = t.st_mtime
    rescan = False

    while true:
        changed_list = []
        remaining_files = all_files.copy()
        all_files = {}

        for path in paths:
            os.path.walk(path, f, None)
        removed_list = remaining_files.keys()

        if rescan:
            rescan = False

        elif changed_list or removed_list:
            rescan = func(changed_list, removed_list)
        time.sleep(delay)

    if _name_ == '_main_':

        def f (changed_files, removed_files):
            print changed_files
            print 'Removed', removed_files
        watch_directories([FolderToScan], f, 1)

        
Mainwindow = Tk()
Mainwindow.geometry("400x200+0+0")

#Logo = PhotoImage(file ="I:\Groups3\ELE HW\SYSTEMS_BENCH\PRAK\Patrick Waibel\Projekte\Projekt Folder Scanner\logo.jpg")
#Label2 = Label(image = Logo).pack()

RunScriptButton = Button(Mainwindow, text = "Run script", bg = "green", width = 25, height = 2, command = watch_directories)
RunScriptButton.place(x = 25, y = 30)

StopScriptButton = Button(Mainwindow, text = "Stop script",bg = "red", width = 25, height = 2, command = sys.exit)
StopScriptButton.place(x = 215, y = 30)

ChangeFolderButton = Button(Mainwindow, text = "Change folder to scan", width = 25, command = ChangeFolder)
ChangeFolderButton.place(x = 25, y = 100)

ChangeMailAdressButton = Button(Mainwindow, text = "Change mailadress", width = 25, command = EmailAdress)
ChangeMailAdressButton.place(x = 215, y = 100)

ChangeLogButton = Button(Mainwindow, text = "Change destination of logfile", width = 25, command = ChangeLogFolder)
ChangeLogButton.place(x = 25, y = 150)

del FolderToScan

mainloop()
Gruß
Psus82

Edit (Leonidas): Code in Python-Tags gesetzt.

Verfasst: Freitag 14. Januar 2005, 16:33
von mawe
Hi!

Na gut, schaun wir mal:

Code: Alles auswählen

....
def ChangeFolder():
    global FolderToScan   # Du erzeugst hier sonst eine neue lokale Variable mit gleichem Namen
    FolderToScan = tkFileDialog.askdirectory() 
....
while True:   # nich true 
...
#if _name_ == '_main_':  # unnötig
# auf die Einrückung achten, def f ist auf der selben Ebene wie def watch_directories
def f (changed_files, removed_files):
      print changed_files
      print 'Removed', removed_files
#watch_directories([FolderToScan], f, 1)  # unnötig

Code: Alles auswählen

RunScriptButton = Button(Mainwindow, text = "Run script", bg = "green", width = 25, height = 2, 
    command = watch_directories)
Hier rufst Du eigentlich watch_directories auf, und wie Du siehst: ohne Argumente :wink:
Schreibs so:

Code: Alles auswählen

RunScriptButton = Button(Mainwindow, text = "Run script", 
    bg = "green", width = 25, height = 2, 
    command = lambda: watch_directories[FolderToScan],f,1])
Gruß, mawe

Besten Dank.

Verfasst: Freitag 14. Januar 2005, 16:35
von Psus82
Hey danke noch mal für die schnelle Hilfe werde die Änderungen ausprobieren.

:D

Greetz
Psus82

Der zeigt mir eine invalid Syntax an.

Verfasst: Freitag 14. Januar 2005, 16:48
von Psus82
Beim RunscriptButton wird mir eine invalid Syntax angezeigt.
Liegt das am ] ?
Und def f muss genau unter def watch_directories liegen?
Erstes def f oder zweites?

Verfasst: Freitag 14. Januar 2005, 16:54
von mawe
Hi!

Bevors zu kompliziert wird, hier mal der Code so wie er bei mir funktioniert:

Code: Alles auswählen


from Tkinter import *
import sys
import tkFileDialog
import tkSimpleDialog
import os,time

FolderToScan = None
EmailAdress = None

def ChangeFolder():
    global FolderToScan
    FolderToScan = tkFileDialog.askdirectory()

def EmailAdress():
    Subwindow1 = Tk()
    Subwindow1.geometry("200x100+0+0")
    Label1= Label(Subwindow1, text = "E-Mailadress :")
    Label1.place(x = 5, y = 10)
    EmailAdress = Entry(Subwindow1, width=30)
    EmailAdress.place(x = 5, y = 35)
    Subwindow1.mainloop()

def ChangeLogFolder():
	FolderToSaveLog = tkFileDialog.askdirectory()


def watch_directories (paths , func, delay = 1.0):
    all_files = {}

    def f (unused, dirname, files):

        for filename in files:
            path = os.path.join(dirname, filename)

            try:
                t = os.stat(path)

            except os.error:
                continue
            mtime = remaining_files.get(path)

            if mtime is not None:
                del remaining_files[path]
                if t.st_mtime > mtime:
                    changed_list.append(path)

            else:
                changed_list.append(path)
            all_files[path] = t.st_mtime
    rescan = False

    while True:
        changed_list = []
        remaining_files = all_files.copy()
        all_files = {}

        for path in paths:
            os.path.walk(path, f, None)
        removed_list = remaining_files.keys()

        if rescan:
            rescan = False

        elif changed_list or removed_list:
            rescan = func(changed_list, removed_list)
        time.sleep(delay)

def f (changed_files, removed_files):
    print changed_files
    print 'Removed', removed_files
       
Mainwindow = Tk()
Mainwindow.geometry("400x200+0+0")

RunScriptButton = Button(Mainwindow, text = "Run script", bg = "green", width = 25, height = 2, 
	command = lambda:watch_directories([FolderToScan],f,1))
RunScriptButton.place(x = 25, y = 30)

StopScriptButton = Button(Mainwindow, text = "Stop script",bg = "red", width = 25, height = 2, command = sys.exit)
StopScriptButton.place(x = 215, y = 30)

ChangeFolderButton = Button(Mainwindow, text = "Change folder to scan", width = 25, command = ChangeFolder)
ChangeFolderButton.place(x = 25, y = 100)

ChangeMailAdressButton = Button(Mainwindow, text = "Change mailadress", width = 25, command = EmailAdress)
ChangeMailAdressButton.place(x = 215, y = 100)

ChangeLogButton = Button(Mainwindow, text = "Change destination of logfile", width = 25, command = ChangeLogFolder)
ChangeLogButton.place(x = 25, y = 150)

del FolderToScan

mainloop()
Gruß, mawe

Alles klar.

Verfasst: Freitag 14. Januar 2005, 16:57
von Psus82
Danke klappt jetzt.

Verfasst: Freitag 14. Januar 2005, 17:01
von mawe
Hast Du was anderes erwartet? :D

Doch noch ein Problem mit dem Script.

Verfasst: Freitag 21. Januar 2005, 14:00
von Psus82
Sobald ich einen Ordner ausgesucht habe und das Script starten will hängt sich Python komplett auf.
Ne idee was man da machen kann?

Greetz Psus82