diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b78c77b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: build + +on: [push, pull_request] + +jobs: + build: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.10 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pyinstaller==6.4.0 + + - name: Build package + run: | + pyinstaller DesktopNote.spec + + - name: Upload build artifact + uses: actions/upload-artifact@v2 + with: + name: DesktopNote-build + path: | + dist/ \ No newline at end of file diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..043b001 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,34 @@ +name: format + +on: [push, pull_request] + +jobs: + format: + + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.10 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install autopep8 + + - name: Format code + run: | + autopep8 . + + - name: Check code changes + run: | + git diff --exit-code + if ( $LASTEXITCODE -ne 0 ) + { + exit 1 + } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4fa54d6..3e94e62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ __pycache__/ +build/ +dist/ *.dat *exe \ No newline at end of file diff --git a/DesktopNote.py b/DesktopNote.py index cfb4d39..653d589 100644 --- a/DesktopNote.py +++ b/DesktopNote.py @@ -15,77 +15,71 @@ def screen(self): for _i, _x in enumerate(TEXT): if _i == self.y: if TEXT[self.y] == '': - print(str(_i)+'>', '><') + print(str(_i) + '>', '><') else: print( - str(_i)+'>', + str(_i) + '>', ( TEXT[self.y][:self.x] - + '>'+TEXT[self.y][self.x]+'<' - + TEXT[self.y][self.x+1:] + + '>' + TEXT[self.y][self.x] + '<' + + TEXT[self.y][self.x + 1:] ) ) else: - print(str(_i)+'>', _x) + print(str(_i) + '>', _x) def do_mv(self, arg): - '''Move to a location\ - \n=====\ - \nmv ''' + '''Move to a location + mv ''' arg = [int(x) for x in arg.split()] self.x = arg[1] self.y = arg[0] self.screen() def do_r(self, arg): - '''Right move\ - \n=====\ - \nr ''' + '''Right move + r ''' self.x += int(arg) self.screen() def do_l(self, arg): - '''Left move\ - \n=====\ - \nl ''' + '''Left move + l ''' self.x -= int(arg) self.screen() def do_u(self, arg): - '''Up move\ - \n=====\ - \nu ''' + '''Up move + u ''' self.y -= int(arg) self.screen() def do_d(self, arg): - '''Down move\ - \n=====\ - \nd ''' + '''Down move + d ''' self.y += int(arg) self.screen() def do_rm(self, arg): - '''Delete a char or chars\ - \n=====\ - \nrm [[ []] | []]''' + '''Delete a char or chars + rm [[ []] | []]''' arg = [int(x) for x in arg.split()] _leng = len(arg) # Delete string if _leng == 0: - TEXT[self.y] = TEXT[self.y][:self.x]+TEXT[self.y][self.x+1:] + TEXT[self.y] = TEXT[self.y][:self.x] + TEXT[self.y][self.x + 1:] elif _leng == 1: _l = arg[0] - TEXT[self.y] = TEXT[self.y][:self.x]+TEXT[self.y][self.x+_l:] + TEXT[self.y] = TEXT[self.y][:self.x] + TEXT[self.y][self.x + _l:] elif _leng == 2: _x = arg[1] _y = arg[0] - TEXT[_y] = TEXT[_y][:_x]+TEXT[_y][_x+1:] + TEXT[_y] = TEXT[_y][:_x] + TEXT[_y][_x + 1:] elif _leng == 3: _x = arg[1] _y = arg[0] _l = arg[2] - TEXT[_y] = TEXT[_y][:_x]+TEXT[_y][_x+_l:] + TEXT[_y] = TEXT[_y][:_x] + TEXT[_y][_x + _l:] # Move pointer if _leng == 2 or _leng == 3: self.x = _x @@ -95,23 +89,22 @@ def do_rm(self, arg): if _leng_s == 0: self.x = 0 else: - self.x = _leng_s-1 + self.x = _leng_s - 1 self.screen() def do_ad(self, arg): - '''Add a string on the right side\ - \n=====\ - \nad [ ]''' + '''Add a string on the right side + ad [ ]''' arg = [int(x) for x in arg.split()] _leng = len(arg) # Add string _s = input('Added string: ') if _leng == 0: - TEXT[self.y] = TEXT[self.y][:self.x+1]+_s+TEXT[self.y][self.x+1:] + TEXT[self.y] = TEXT[self.y][:self.x + 1] + _s + TEXT[self.y][self.x + 1:] elif _leng == 2: _x = arg[1] _y = arg[0] - TEXT[_y] = TEXT[_y][:_x+1]+_s+TEXT[_y][_x+1:] + TEXT[_y] = TEXT[_y][:_x + 1] + _s + TEXT[_y][_x + 1:] # Move pointer _leng_s = len(_s) if _leng == 2: @@ -121,27 +114,26 @@ def do_ad(self, arg): self.screen() def do_rv(self, arg): # (x, y)或无, 将一个字符修改; (x, y, l)或l, 将 l 个字符修改 - '''Revise a char or chars\ - \n=====\ - \nrv [[ []] | []]''' + '''Revise a char or chars + rv [[ []] | []]''' arg = [int(x) for x in arg.split()] _leng = len(arg) # Revise string _s = input('New string: ') if _leng == 0: - TEXT[self.y] = TEXT[self.y][:self.x]+_s+TEXT[self.y][self.x+1:] + TEXT[self.y] = TEXT[self.y][:self.x] + _s + TEXT[self.y][self.x + 1:] elif _leng == 1: _l = arg[0] - TEXT[self.y] = TEXT[self.y][:self.x]+_s+TEXT[self.y][self.x+_l:] + TEXT[self.y] = TEXT[self.y][:self.x] + _s + TEXT[self.y][self.x + _l:] elif _leng == 2: _x = arg[1] _y = arg[0] - TEXT[_y] = TEXT[_y][:_x]+_s+TEXT[_y][_x+1:] + TEXT[_y] = TEXT[_y][:_x] + _s + TEXT[_y][_x + 1:] elif _leng == 3: _x = arg[1] _y = arg[0] _l = arg[2] - TEXT[_y] = TEXT[_y][:_x]+_s+TEXT[_y][_x+_l:] + TEXT[_y] = TEXT[_y][:_x] + _s + TEXT[_y][_x + _l:] # Move pointer _leng_s = len(_s) if _leng == 2 or _leng == 3: @@ -152,15 +144,14 @@ def do_rv(self, arg): # (x, y)或无, 将一个字符修改; (x, y, l)或l, 将 if _leng_ss == 0: self.x = 0 else: - self.x = _leng_ss-1 + self.x = _leng_ss - 1 else: - self.x += _leng_s-1 + self.x += _leng_s - 1 self.screen() def do_ex(self, arg): - '''Exit revising shell\ - \n=====\ - \nex''' + '''Exit revising shell + ex''' return True @@ -172,7 +163,7 @@ class Note(cmd.Cmd): prompt = '' try: fnote = open('note.dat', 'rb') - except: + except BaseException: fnote = open('note.dat', 'wb') pickle.dump([], fnote) fnote.close() @@ -181,9 +172,8 @@ class Note(cmd.Cmd): fnote.close() def do_show(self, arg): - '''Show the notes\ - \n=====\ - \nshow []''' + '''Show the notes + show []''' os.system('cls') print(' ==========================================================') try: @@ -191,20 +181,19 @@ def do_show(self, arg): print('Title:', arg, self.note[arg][0]) print('Text:') for i, s in enumerate(self.note[arg][1]): - print(str(i)+'>', s) + print(str(i) + '>', s) print(' ==========================================================') - except: + except BaseException: for i, x in enumerate(self.note): print('Title:', i, x[0]) print('Text:') for j, s in enumerate(x[1]): - print(str(j)+'>', s) + print(str(j) + '>', s) print(' ==========================================================') def do_write(self, arg): - '''Write a new note\ - \n=====\ - \nwrite''' + '''Write a new note + write''' temp_title = input('New note title: ') temp_text: list[str] = [] print('New note text(end with END):') @@ -216,9 +205,8 @@ def do_write(self, arg): self.fnote.close() def do_revise(self, arg): - '''Revise a note\ - \n=====\ - \nrevise ''' + '''Revise a note + revise ''' arg = int(arg) global TEXT TEXT = self.note[arg][1] @@ -227,8 +215,8 @@ def do_revise(self, arg): if x == '': print('0>', '><') else: - print('0>', '>'+x[0]+'<'+x[1:]) - print(str(i)+'>', x) + print('0>', '>' + x[0] + '<' + x[1:]) + print(str(i) + '>', x) TextRevise().cmdloop() self.note[arg][1] = TEXT self.fnote = open('note.dat', 'wb') @@ -236,9 +224,8 @@ def do_revise(self, arg): self.fnote.close() def do_delete(self, arg): - '''Delete a note\ - \n=====\ - \ndelete ''' + '''Delete a note + delete ''' arg = int(arg) self.note.pop(arg) self.fnote = open('note.dat', 'wb') @@ -246,10 +233,9 @@ def do_delete(self, arg): self.fnote.close() def do_exit(self, arg): - '''Exit DesktopNote\ - \n=====\ - \nexit''' - exit(0) + '''Exit DesktopNote + exit''' + return exit() def postcmd(self, stop: bool, line: str) -> bool: return False diff --git a/DesktopNote.spec b/DesktopNote.spec new file mode 100644 index 0000000..dad2426 --- /dev/null +++ b/DesktopNote.spec @@ -0,0 +1,37 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['DesktopNote.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name='DesktopNote', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3484fb0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[tool.autopep8] +max_line_length = 120 +aggressive = true +in-place = true +recursive = true \ No newline at end of file