Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
[Allgemein] -  C# vs Python
#15
Auch dies möchte ich sehr gerne sehen.

Zitat:Perfekt! Dann erweitern wir das Task-Management-Framework, sodass es nun alle erledigten Aufgaben automatisch archiviert, und die GUI zeigt nur offene Aufgaben an.
Damit hast du ein voll funktionsfähiges Echtzeit-System:
  • Python-Skripte erzeugen automatisch Aufgaben
  • Perl Tk GUI zeigt nur offene Aufgaben
  • Erledigte Aufgaben werden in einer separaten Datei archiviert

1️⃣ Projektstruktur
Code:
TaskManagerArchive/

├─ tasks_gui_archive.pl      ← Perl Tk GUI mit Live-Refresh & Archiv
├─ tasks_update_1.py         ← Python Skript 1
├─ tasks_update_2.py         ← Python Skript 2
├─ tasks.json                ← Offene Aufgaben
├─ tasks_archive.json        ← Archivierte Aufgaben
├─ run_task_manager.bat      ← Batch-Datei zum Starten
└─ README.md

2️⃣
Code:
tasks_gui_archive.pl
– GUI mit Archivfunktion
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use JSON;
use File::Spec;
my $json_file    = File::Spec->catfile(".", "tasks.json");
my $archive_file = File::Spec->catfile(".", "tasks_archive.json");
sub load_tasks {
    open my $fh, "<", $json_file or return [];
    local $/;
    my $json_text = <$fh>;
    close $fh;
    return decode_json($json_text);
}
sub save_tasks {
    my ($tasks_ref) = @_;
    open my $fh, ">", $json_file or die "Kann Datei nicht schreiben: $!";
    print $fh encode_json($tasks_ref);
    close $fh;
}
sub load_archive {
    open my $fh, "<", $archive_file or return [];
    local $/;
    my $json_text = <$fh>;
    close $fh;
    return decode_json($json_text);
}
sub save_archive {
    my ($archive_ref) = @_;
    open my $fh, ">", $archive_file or die "Kann Archiv nicht schreiben: $!";
    print $fh encode_json($archive_ref);
    close $fh;
}
my $mw = MainWindow->new;
$mw->title("Task Manager mit Archiv");
my $frame = $mw->Frame()->pack(-side => 'top', -fill => 'both', -expand => 1);
my $listbox = $frame->Scrolled("Listbox", -scrollbars => 'e')->pack(-side => 'left', -fill => 'both', -expand => 1);
my $tasks = load_tasks();
my $archive = load_archive();
sub refresh_list {
    $tasks = load_tasks();
    $listbox->delete(0, 'end');
    for my $i (0..$#$tasks) {
        my $t = $tasks->[$i];
        my $status = $t->{done} ? "✓" : "✗";
        $listbox->insert('end', "$status $t->{task}") unless $t->{done};
    }
}
refresh_list();
my $entry = $mw->Entry()->pack(-side => 'top', -fill => 'x', -padx => 5, -pady => 5);
# Neue Aufgabe hinzufügen
$mw->Button(-text => "Aufgabe hinzufügen",
    -command => sub {
        my $text = $entry->get;
        return unless $text;
        push @$tasks, { task => $text, done => 0 };
        save_tasks($tasks);
        $entry->delete(0, 'end');
        refresh_list();
    })->pack(-side => 'top', -fill => 'x', -padx => 5, -pady => 5);
# Aufgabe erledigen und archivieren
$mw->Button(-text => "Ausgewählte Aufgabe erledigen",
    -command => sub {
        my $idx = $listbox->curselection;
        return unless defined $idx->[0];
        my $task_done = $tasks->[$idx->[0]];
        $task_done->{done} = 1;
        # In Archiv verschieben
        push @$archive, $task_done;
        save_archive($archive);
        # Aus Aufgabenliste entfernen
        splice @$tasks, $idx->[0], 1;
        save_tasks($tasks);
        refresh_list();
    })->pack(-side => 'top', -fill => 'x', -padx => 5, -pady => 5);
# Live-Refresh alle 2 Sekunden
$mw->repeat(2000 => \&refresh_list);
MainLoop;
Erklärung:
  • Nur offene Aufgaben werden in der ListBox angezeigt
  • Wenn Aufgabe als erledigt markiert wird, wandert sie ins Archiv (
    Code:
    tasks_archive.json
    )
  • GUI bleibt interaktiv, Python-Skripte können weiterhin Aufgaben hinzufügen

3️⃣ Python-Skripte
Code:
tasks_update_1.py
import json, os, datetime, time
json_file = "tasks.json"
while True:
    if not os.path.exists(json_file):
        tasks = []
    else:
        with open(json_file, "r") as f:
            tasks = json.load(f)
   
    timestamp = datetime.datetime.now().strftime("%H:%M:%S")
    tasks.append({"task": f"AutoTask1 {timestamp}", "done": False})
   
    with open(json_file, "w") as f:
        json.dump(tasks, f, indent=4)
    time.sleep(10)
tasks_update_2.py
import json, os, datetime, time
json_file = "tasks.json"
while True:
    if not os.path.exists(json_file):
        tasks = []
    else:
        with open(json_file, "r") as f:
            tasks = json.load(f)
   
    timestamp = datetime.datetime.now().strftime("%H:%M:%S")
    tasks.append({"task": f"ReminderTask {timestamp}", "done": False})
   
    with open(json_file, "w") as f:
        json.dump(tasks, f, indent=4)
    time.sleep(15)

4️⃣
Code:
run_task_manager.bat
@echo off
REM Starte Python-Skripte im Hintergrund
start python "%~dp0tasks_update_1.py"
start python "%~dp0tasks_update_2.py"
REM Starte Perl Tk GUI
perl "%~dp0tasks_gui_archive.pl"
pause
  • Python-Skripte laufen parallel
  • GUI startet sofort und zeigt nur offene Aufgaben
  • Erledigte Aufgaben werden automatisch archiviert

5️⃣ Vorteile des erweiterten Frameworks
  • Live-Integration: Python-Skripte erzeugen Aufgaben, GUI zeigt sie automatisch
  • Archivierung: erledigte Aufgaben gehen in
    Code:
    tasks_archive.json

  • Interaktiv: neue Aufgaben hinzufügen, Aufgaben abhaken
  • Erweiterbar: mehrere Python-Skripte, Filter, Prioritäten, Logging
  • Plattformübergreifend: JSON als zentraler Speicher

Wenn du willst, kann ich als Nächstes noch eine Version bauen, die zusätzlich eine Historie visualisiert und GUI farblich markiert, welche Aufgaben alt oder neu sind – quasi eine vollwertige Task-Management-Anwendung in Echtzeit unter Windows.
Willst du, dass ich das erstelle?
Zitieren Return to top


Nachrichten in diesem Thema
C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste