Bläddra i källkod

还需要修正deadline时间计算的部分

Zhilong Li 5 år sedan
förälder
incheckning
5636abd144
1 ändrade filer med 50 tillägg och 18 borttagningar
  1. 50 18
      Jt.py

+ 50 - 18
Jt.py

@@ -1,7 +1,7 @@
 from hashlib import md5
 from os import listdir
 import pickle
-
+import sys
 import random
 import time
 
@@ -18,10 +18,14 @@ class Base:
 
 
 class Entry(Base):
-    def __init__(self):
+    def __init__(self, title: str = "未命名事项"):
         Base.__init__(self)
-        self.title: str = "未命名事项" + self.str_time[4:8]
-        Base.__gene_id(self)
+
+        if title == "未命名事项":
+            self.title: str = title + self.str_time[4:8]
+        else:
+            self.title: str = title
+
         self.content: str = "在这里输入事项内容"
         self.set_priority()
         self.set_deadline()
@@ -37,7 +41,7 @@ class Entry(Base):
             priority = 10.0
         self.priority: float = priority
 
-    def set_deadline(self, deadline_date: time.struct_time = time.localtime()):
+    def set_deadline(self, deadline_date: time.struct_time = time.localtime(time.time()+time.mktime(time.strptime("7", "%d")))):
         if deadline_date < time.localtime():
             print("\033[1;31mERROR: Let it RIP if it's dead already\033[0m")
             return 1
@@ -95,28 +99,29 @@ class Interface:
             "ls": self.__list_coord,
             "show": self.__show_now_coord,
             "entry": self.__new_entry,
+            "chcrd": self.__coord_changer,
         }
 
     def start(self):
-        print("Welcome to Jt mission manager")
-        print("Please open a coordinate")
-        self.__list_coord()
-        coord_file = self.files[
-            int(input("\033[1;32mType in the number of coordinate:\033[0m"))
-        ]
-        self.__open_coord("coord/" + coord_file)
+        print(
+            "*******************************\n*Welcome to Jt mission manager*\n*******************************\n"
+        )
+        self.__coord_changer([])
         while not (self.exit):
             command = input("\033[1;32m> \033[0m").split()
-            func_name = command[0]
             try:
-                func = self.func_dict[func_name]
-                func(command[1:])
-            except KeyError:
-                print("\033[1;31mERROR: Command not found\033[0m")
+                func_name = command[0]
+                try:
+                    func = self.func_dict[func_name]
+                    func(command[1:])
+                except KeyError:
+                    print("\033[1;31mERROR: Command not found\033[0m")
+            except IndexError:
+                pass
 
     def __open_coord(self, coord_file: str):
         with open(coord_file, "rb") as f:
-            self.now_coord = pickle.load(f)
+            self.now_coord: Coordinate = pickle.load(f)
 
     def __list_coord(self):
         self.files = listdir("coord")
@@ -126,6 +131,33 @@ class Interface:
                 print(i, f)
                 i += 1
 
+    def __save_now_coord(self):
+        save_or_not: str = input("Save the opened coordinate? Y/n")
+        if save_or_not in ["Y", "y", "1"]:
+            self.now_coord.save_coord()
+            return 0
+        elif save_or_not in ["N", "n", "0"]:
+            return 0
+        else:
+            self.__save_now_coord()
+
+    def __coord_changer(self, arg: list):
+        try:
+            self.now_coord
+            self.__save_now_coord()
+        except AttributeError:
+            pass
+        print("Select a coordinate to open:")
+        self.__list_coord()
+        coord_file = self.files[
+            int(input("\033[1;32mType in the coordinate number:\033[0m"))
+        ]
+        self.__open_coord("coord/" + coord_file)
+
+    def __new_entry(self, arg: list):
+        e = Entry(arg[0])
+        e.content = sys.stdin.readlines()
+
     def __new_coord(self, arg: list):
         c = Coordinate()
         c.name = arg[0]