mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 07:23:03 +08:00
Compare commits
18 Commits
59c06b3a19
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d05d4c7cb | |||
| 01f4ccaa0e | |||
| 0bad34d7a8 | |||
| 61d1b44402 | |||
| 72301c63fd | |||
| 609850ab60 | |||
| 8e14d45b71 | |||
| f6ef9af39d | |||
| 72dce83c55 | |||
| c337904010 | |||
| 779aad13b8 | |||
| f3360423e5 | |||
| bea12d5f0c | |||
| b24f39456e | |||
| bb63ee6f03 | |||
| 3ebebe015f | |||
| 02b3a62868 | |||
| d7e19dcd52 |
@@ -4,6 +4,9 @@ name: Build Test
|
||||
# It is triggered when a pull request is opened, synchronized, or reopened against the main branch.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
@@ -45,12 +48,12 @@ jobs:
|
||||
with:
|
||||
python-version: '3.13'
|
||||
cache: 'pip'
|
||||
cache-dependency-path: requirement.txt
|
||||
cache-dependency-path: requirements.txt
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirement.txt
|
||||
pip install -r requirements.txt
|
||||
|
||||
- name: Solve ddddocr compatibility and copy model files
|
||||
run: |
|
||||
@@ -209,13 +212,283 @@ jobs:
|
||||
|
||||
- name: Upload build summary
|
||||
run: |
|
||||
Write-Host "## Build Test Summary" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
Write-Host "" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "========================================" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "✓ Pull request build test completed successfully!" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Version: ${{ steps.get_version.outputs.VERSION }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Tag: ${{ steps.get_version.outputs.TAG_NAME }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Pull Request #${{ github.event.pull_request.number || 'N/A' }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Branch: ${{ github.event.pull_request.head.ref || github.ref }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Event: ${{ github.event_name }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"## Build Test Summary" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
"" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"========================================" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"✓ Pull request build test completed successfully!" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Version: ${{ steps.get_version.outputs.VERSION }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Tag: ${{ steps.get_version.outputs.TAG_NAME }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Pull Request #${{ github.event.pull_request.number || 'N/A' }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Branch: ${{ github.event.pull_request.head.ref || github.ref }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Event: ${{ github.event_name }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
shell: pwsh
|
||||
|
||||
#
|
||||
# Build macOS
|
||||
#
|
||||
|
||||
build-macos:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
|
||||
- name: Get version info
|
||||
id: get_version
|
||||
run: |
|
||||
version="pr-test"
|
||||
tag_name="pr-test"
|
||||
echo "✓ Mode: Pull Request Test Build"
|
||||
echo "✓ Tag: $tag_name"
|
||||
echo "✓ Version: $version"
|
||||
echo "VERSION=$version" >> $GITHUB_OUTPUT
|
||||
echo "TAG_NAME=$tag_name" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.13'
|
||||
cache: 'pip'
|
||||
cache-dependency-path: requirements.txt
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
|
||||
- name: Solve ddddocr compatibility and copy model files
|
||||
run: |
|
||||
ddddocr_path=$(python -c "import ddddocr, os; print(os.path.dirname(ddddocr.__file__))")
|
||||
echo "ddddocr package location: $ddddocr_path"
|
||||
|
||||
init_file="$ddddocr_path/__init__.py"
|
||||
if [ -f "$init_file" ]; then
|
||||
echo "Fixing ddddocr compatibility in: $init_file"
|
||||
# macOS 使用 BSD sed,要求 -i 后跟备份后缀名(空字符串 = 不备份)
|
||||
sed -i '' 's/Image\.ANTIALIAS/Image.Resampling.LANCZOS/g' "$init_file"
|
||||
echo "✓ Fixed: Image.ANTIALIAS -> Image.Resampling.LANCZOS"
|
||||
else
|
||||
echo "✗ ddddocr __init__.py not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p models
|
||||
echo "✓ Created models directory"
|
||||
|
||||
# 多路径 fallback 搜索 ONNX 模型,提升 ddddocr 版本兼容性
|
||||
onnx_source=""
|
||||
onnx_dest="models/common.onnx"
|
||||
candidate_paths=(
|
||||
"$ddddocr_path/common.onnx"
|
||||
"$ddddocr_path/models/common.onnx"
|
||||
"$ddddocr_path/ddddocr/common.onnx"
|
||||
)
|
||||
for candidate in "${candidate_paths[@]}"; do
|
||||
if [ -f "$candidate" ]; then
|
||||
onnx_source="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
# 若以上候选均未命中,回退到全包搜索
|
||||
if [ -z "$onnx_source" ]; then
|
||||
echo "⚠ 未在已知路径找到 ONNX 模型,回退到全包搜索..."
|
||||
onnx_source=$(find "$ddddocr_path" -name "*.onnx" -type f 2>/dev/null | head -1)
|
||||
fi
|
||||
|
||||
if [ -n "$onnx_source" ] && [ -f "$onnx_source" ]; then
|
||||
cp "$onnx_source" "$onnx_dest"
|
||||
echo "✓ ONNX model copied: $onnx_source -> $onnx_dest"
|
||||
else
|
||||
echo "✗ ONNX model not found in ddddocr package"
|
||||
echo " Searched directory: $ddddocr_path"
|
||||
ls -la "$ddddocr_path/" || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$onnx_dest" ]; then
|
||||
file_size=$(du -h "$onnx_dest" | cut -f1)
|
||||
echo "✓ Model file verified: $onnx_dest (Size: $file_size)"
|
||||
else
|
||||
echo "✗ Failed to copy model file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Compile Qt Resource files
|
||||
run: |
|
||||
cd batchs
|
||||
bash compile_rc.sh
|
||||
|
||||
- name: Compile Qt UI files
|
||||
run: |
|
||||
cd batchs
|
||||
bash compile_ui.sh
|
||||
|
||||
- name: Generate 'Main.spec'
|
||||
env:
|
||||
APP_VERSION: ${{ steps.get_version.outputs.VERSION }}
|
||||
run: |
|
||||
version="$APP_VERSION"
|
||||
exe_name="AutoLibrary-$version"
|
||||
echo "Generating Main.spec for version: $version"
|
||||
echo "App name: $exe_name"
|
||||
|
||||
printf '%s\n' \
|
||||
'# -*- mode: python ; coding: utf-8 -*-' \
|
||||
'' \
|
||||
'a = Analysis(' \
|
||||
" ['src/Main.py']," \
|
||||
' pathex=[],' \
|
||||
' binaries=[],' \
|
||||
' datas=[' \
|
||||
" ('models/common.onnx', 'ddddocr')," \
|
||||
" ('src/gui/resources/icons/AutoLibrary_Logo_64.ico', 'gui/resources/icons')," \
|
||||
' ],' \
|
||||
' hiddenimports=[],' \
|
||||
' hookspath=[],' \
|
||||
' hooksconfig={},' \
|
||||
' runtime_hooks=[],' \
|
||||
' excludes=[],' \
|
||||
' noarchive=False,' \
|
||||
' optimize=0,' \
|
||||
')' \
|
||||
'pyz = PYZ(a.pure)' \
|
||||
'' \
|
||||
'exe = EXE(' \
|
||||
' pyz,' \
|
||||
' a.scripts,' \
|
||||
' [],' \
|
||||
' exclude_binaries=True,' \
|
||||
" name='AutoLibrary'," \
|
||||
' debug=False,' \
|
||||
' bootloader_ignore_signals=False,' \
|
||||
' strip=False,' \
|
||||
' upx=True,' \
|
||||
' upx_exclude=[],' \
|
||||
' runtime_tmpdir=None,' \
|
||||
' console=False,' \
|
||||
' disable_windowed_traceback=False,' \
|
||||
' argv_emulation=False,' \
|
||||
' target_arch=None,' \
|
||||
' codesign_identity=None,' \
|
||||
' entitlements_file=None,' \
|
||||
" icon=['src/gui/resources/icons/AutoLibrary_Logo_64.ico']," \
|
||||
')' \
|
||||
'' \
|
||||
'coll = COLLECT(' \
|
||||
' exe,' \
|
||||
' a.binaries,' \
|
||||
' a.zipfiles,' \
|
||||
' a.datas,' \
|
||||
' strip=False,' \
|
||||
' upx=True,' \
|
||||
' upx_exclude=[],' \
|
||||
" name='${exe_name}'," \
|
||||
')' \
|
||||
'' \
|
||||
'app = BUNDLE(' \
|
||||
' coll,' \
|
||||
" name='AutoLibrary.app'," \
|
||||
" icon='src/gui/resources/icons/AutoLibrary_Logo.icns'," \
|
||||
" bundle_identifier='com.kenanzhu.autolibrary'," \
|
||||
' info_plist={' \
|
||||
" 'NSHighResolutionCapable': 'True'," \
|
||||
" 'CFBundleName': 'AutoLibrary'," \
|
||||
" 'CFBundleDisplayName': 'AutoLibrary'," \
|
||||
" 'CFBundleShortVersionString': '${version}'," \
|
||||
" 'CFBundleVersion': '${version}'," \
|
||||
" 'CFBundleExecutable': 'AutoLibrary'," \
|
||||
" 'NSPrincipalClass': 'NSApplication'," \
|
||||
" 'LSMinimumSystemVersion': '11.0'," \
|
||||
" 'NSRequiresAquaSystemAppearance': 'False'," \
|
||||
" 'NSHumanReadableCopyright': 'Copyright 2025 - 2026 KenanZhu. All rights reserved.'," \
|
||||
' },' \
|
||||
')' \
|
||||
> Main.spec
|
||||
|
||||
echo "✓ Main.spec generated successfully"
|
||||
echo ""
|
||||
echo "========================================"
|
||||
echo "Generated Main.spec"
|
||||
echo "========================================"
|
||||
cat Main.spec
|
||||
echo "========================================"
|
||||
|
||||
- name: Build with PyInstaller
|
||||
run: |
|
||||
python -m PyInstaller Main.spec
|
||||
|
||||
- name: Create DMG
|
||||
run: |
|
||||
tag_name="${{ steps.get_version.outputs.TAG_NAME }}"
|
||||
dmg_name="AutoLibrary.$tag_name-macos-arm64.dmg"
|
||||
app_path="dist/AutoLibrary.app"
|
||||
|
||||
if [ ! -d "$app_path" ]; then
|
||||
echo "✗ App bundle not found: $app_path"
|
||||
echo "Files in dist directory:"
|
||||
ls -la dist/
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Creating DMG from: $app_path"
|
||||
xattr -cr "$app_path" 2>/dev/null || true
|
||||
|
||||
tmp_dmg_dir=$(mktemp -d)
|
||||
cp -R "$app_path" "$tmp_dmg_dir/"
|
||||
ln -s /Applications "$tmp_dmg_dir/Applications"
|
||||
|
||||
hdiutil create \
|
||||
-volname "AutoLibrary $tag_name" \
|
||||
-srcfolder "$tmp_dmg_dir" \
|
||||
-ov \
|
||||
-format UDZO \
|
||||
"$dmg_name"
|
||||
|
||||
rm -rf "$tmp_dmg_dir"
|
||||
|
||||
if [ -f "$dmg_name" ]; then
|
||||
dmg_size=$(du -h "$dmg_name" | cut -f1)
|
||||
echo "✓ DMG created: $dmg_name (Size: $dmg_size)"
|
||||
else
|
||||
echo "✗ Failed to create DMG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ Artifacts ready:"
|
||||
echo " - $dmg_name"
|
||||
echo " - $app_path"
|
||||
|
||||
- name: Archive artifacts
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: AutoLibrary.${{ steps.get_version.outputs.TAG_NAME }}-macos-arm64
|
||||
path: |
|
||||
AutoLibrary.${{ steps.get_version.outputs.TAG_NAME }}-macos-arm64.dmg
|
||||
dist/AutoLibrary.app/**
|
||||
retention-days: 7
|
||||
|
||||
- name: Upload build summary
|
||||
run: |
|
||||
tag_name="${{ steps.get_version.outputs.TAG_NAME }}"
|
||||
version="${{ steps.get_version.outputs.VERSION }}"
|
||||
dmg_name="AutoLibrary.$tag_name-macos-arm64.dmg"
|
||||
|
||||
{
|
||||
echo "## Build Test Summary (macOS)"
|
||||
echo ""
|
||||
echo "========================================"
|
||||
echo "✓ Pull request build test completed successfully!"
|
||||
echo "- Version: $version"
|
||||
echo "- Tag: $tag_name"
|
||||
echo "- Pull Request #${{ github.event.pull_request.number || 'N/A' }}"
|
||||
echo "- Branch: ${{ github.event.pull_request.head.ref || github.ref }}"
|
||||
echo "- Event: ${{ github.event_name }}"
|
||||
echo "- DMG: $dmg_name"
|
||||
echo ""
|
||||
echo "### How to test on macOS"
|
||||
echo '1. Download the DMG artifact'
|
||||
echo '2. Open the DMG and drag AutoLibrary.app to /Applications'
|
||||
echo '3. Right-click → Open the app (to bypass Gatekeeper)'
|
||||
} >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
+313
-12
@@ -1,7 +1,10 @@
|
||||
name: Build
|
||||
|
||||
# This workflow compiles the application for Windows platform using PyInstaller, and
|
||||
# archives the built artifacts as 'AutoLibrary.<tag_name>-windows-x86_64.zip'.
|
||||
# This workflow compiles the application for Windows and macOS platforms using
|
||||
# PyInstaller, and archives the built artifacts.
|
||||
#
|
||||
# - Windows: AutoLibrary.<tag_name>-windows-x86_64.zip
|
||||
# - macOS: AutoLibrary.<tag_name>-macos-arm64.dmg
|
||||
#
|
||||
# It is triggered when called by the release workflow.
|
||||
|
||||
@@ -86,12 +89,12 @@ jobs:
|
||||
with:
|
||||
python-version: '3.13'
|
||||
cache: 'pip'
|
||||
cache-dependency-path: requirement.txt
|
||||
cache-dependency-path: requirements.txt
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirement.txt
|
||||
pip install -r requirements.txt
|
||||
|
||||
- name: Solve ddddocr compatibility and copy model files
|
||||
run: |
|
||||
@@ -251,12 +254,310 @@ jobs:
|
||||
- name: Upload build summary
|
||||
if: ${{ inputs.is_test == 'true' }}
|
||||
run: |
|
||||
Write-Host "## Build Summary" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
Write-Host "" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "========================================" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "✓ Build test completed successfully!" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Version: ${{ steps.get_version.outputs.VERSION }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Tag: ${{ steps.get_version.outputs.TAG_NAME }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Event: ${{ github.event_name }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
Write-Host "- Ref: ${{ github.ref }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"## Build Summary" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
"" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"========================================" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"✓ Build test completed successfully!" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Version: ${{ steps.get_version.outputs.VERSION }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Tag: ${{ steps.get_version.outputs.TAG_NAME }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Event: ${{ github.event_name }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
"- Ref: ${{ github.ref }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
||||
shell: pwsh
|
||||
|
||||
#
|
||||
# Build macOS
|
||||
#
|
||||
|
||||
build-macos:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
|
||||
- name: Download build version of ALVersionInfo.py
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: updated-version-info-for-build
|
||||
path: src/gui/
|
||||
|
||||
- name: Get version info
|
||||
id: get_version
|
||||
run: |
|
||||
is_test="${{ inputs.is_test }}"
|
||||
if [ "$is_test" = "true" ]; then
|
||||
version="test"
|
||||
tag_name="test"
|
||||
echo "✓ Mode: Test Build"
|
||||
else
|
||||
version="${{ inputs.version }}"
|
||||
tag_name="${{ inputs.tag_name }}"
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
version="test"
|
||||
tag_name="test"
|
||||
echo "✓ Mode: Independent Build (No inputs provided)"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "✓ Tag: $tag_name"
|
||||
echo "✓ Version: $version"
|
||||
|
||||
echo "VERSION=$version" >> $GITHUB_OUTPUT
|
||||
echo "TAG_NAME=$tag_name" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Verify 'ALVersionInfo.py' was updated
|
||||
run: |
|
||||
version_info_file="src/gui/ALVersionInfo.py"
|
||||
echo "Verifying $version_info_file content:"
|
||||
echo "========================================"
|
||||
cat "$version_info_file"
|
||||
echo "========================================"
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.13'
|
||||
cache: 'pip'
|
||||
cache-dependency-path: requirements.txt
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
|
||||
- name: Solve ddddocr compatibility and copy model files
|
||||
run: |
|
||||
ddddocr_path=$(python -c "import ddddocr, os; print(os.path.dirname(ddddocr.__file__))")
|
||||
echo "ddddocr package location: $ddddocr_path"
|
||||
|
||||
init_file="$ddddocr_path/__init__.py"
|
||||
if [ -f "$init_file" ]; then
|
||||
echo "Fixing ddddocr compatibility in: $init_file"
|
||||
# macOS 使用 BSD sed,要求 -i 后跟备份后缀名(空字符串 = 不备份)
|
||||
sed -i '' 's/Image\.ANTIALIAS/Image.Resampling.LANCZOS/g' "$init_file"
|
||||
echo "✓ Fixed: Image.ANTIALIAS -> Image.Resampling.LANCZOS"
|
||||
else
|
||||
echo "✗ ddddocr __init__.py not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p models
|
||||
echo "✓ Created models directory"
|
||||
|
||||
# 多路径 fallback 搜索 ONNX 模型,提升 ddddocr 版本兼容性
|
||||
onnx_source=""
|
||||
onnx_dest="models/common.onnx"
|
||||
candidate_paths=(
|
||||
"$ddddocr_path/common.onnx"
|
||||
"$ddddocr_path/models/common.onnx"
|
||||
"$ddddocr_path/ddddocr/common.onnx"
|
||||
)
|
||||
for candidate in "${candidate_paths[@]}"; do
|
||||
if [ -f "$candidate" ]; then
|
||||
onnx_source="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
# 若以上候选均未命中,回退到全包搜索
|
||||
if [ -z "$onnx_source" ]; then
|
||||
echo "⚠ 未在已知路径找到 ONNX 模型,回退到全包搜索..."
|
||||
onnx_source=$(find "$ddddocr_path" -name "*.onnx" -type f 2>/dev/null | head -1)
|
||||
fi
|
||||
|
||||
if [ -n "$onnx_source" ] && [ -f "$onnx_source" ]; then
|
||||
cp "$onnx_source" "$onnx_dest"
|
||||
echo "✓ ONNX model copied: $onnx_source -> $onnx_dest"
|
||||
else
|
||||
echo "✗ ONNX model not found in ddddocr package"
|
||||
echo " Searched directory: $ddddocr_path"
|
||||
ls -la "$ddddocr_path/" || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$onnx_dest" ]; then
|
||||
file_size=$(du -h "$onnx_dest" | cut -f1)
|
||||
echo "✓ Model file verified: $onnx_dest (Size: $file_size)"
|
||||
else
|
||||
echo "✗ Failed to copy model file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Compile Qt Resource files
|
||||
run: |
|
||||
cd batchs
|
||||
bash compile_rc.sh
|
||||
|
||||
- name: Compile Qt UI files
|
||||
run: |
|
||||
cd batchs
|
||||
bash compile_ui.sh
|
||||
|
||||
- name: Generate 'Main.spec'
|
||||
env:
|
||||
APP_VERSION: ${{ steps.get_version.outputs.VERSION }}
|
||||
run: |
|
||||
version="$APP_VERSION"
|
||||
exe_name="AutoLibrary-$version"
|
||||
echo "Generating Main.spec for version: $version"
|
||||
echo "App name: $exe_name"
|
||||
|
||||
printf '%s\n' \
|
||||
'# -*- mode: python ; coding: utf-8 -*-' \
|
||||
'' \
|
||||
'a = Analysis(' \
|
||||
" ['src/Main.py']," \
|
||||
' pathex=[],' \
|
||||
' binaries=[],' \
|
||||
' datas=[' \
|
||||
" ('models/common.onnx', 'ddddocr')," \
|
||||
" ('src/gui/resources/icons/AutoLibrary_Logo_64.ico', 'gui/resources/icons')," \
|
||||
' ],' \
|
||||
' hiddenimports=[],' \
|
||||
' hookspath=[],' \
|
||||
' hooksconfig={},' \
|
||||
' runtime_hooks=[],' \
|
||||
' excludes=[],' \
|
||||
' noarchive=False,' \
|
||||
' optimize=0,' \
|
||||
')' \
|
||||
'pyz = PYZ(a.pure)' \
|
||||
'' \
|
||||
'exe = EXE(' \
|
||||
' pyz,' \
|
||||
' a.scripts,' \
|
||||
' [],' \
|
||||
' exclude_binaries=True,' \
|
||||
" name='AutoLibrary'," \
|
||||
' debug=False,' \
|
||||
' bootloader_ignore_signals=False,' \
|
||||
' strip=False,' \
|
||||
' upx=True,' \
|
||||
' upx_exclude=[],' \
|
||||
' runtime_tmpdir=None,' \
|
||||
' console=False,' \
|
||||
' disable_windowed_traceback=False,' \
|
||||
' argv_emulation=False,' \
|
||||
' target_arch=None,' \
|
||||
' codesign_identity=None,' \
|
||||
' entitlements_file=None,' \
|
||||
" icon=['src/gui/resources/icons/AutoLibrary_Logo_64.ico']," \
|
||||
')' \
|
||||
'' \
|
||||
'coll = COLLECT(' \
|
||||
' exe,' \
|
||||
' a.binaries,' \
|
||||
' a.zipfiles,' \
|
||||
' a.datas,' \
|
||||
' strip=False,' \
|
||||
' upx=True,' \
|
||||
' upx_exclude=[],' \
|
||||
" name='${exe_name}'," \
|
||||
')' \
|
||||
'' \
|
||||
'app = BUNDLE(' \
|
||||
' coll,' \
|
||||
" name='AutoLibrary.app'," \
|
||||
" icon='src/gui/resources/icons/AutoLibrary_Logo.icns'," \
|
||||
" bundle_identifier='com.kenanzhu.autolibrary'," \
|
||||
' info_plist={' \
|
||||
" 'NSHighResolutionCapable': 'True'," \
|
||||
" 'CFBundleName': 'AutoLibrary'," \
|
||||
" 'CFBundleDisplayName': 'AutoLibrary'," \
|
||||
" 'CFBundleShortVersionString': '${version}'," \
|
||||
" 'CFBundleVersion': '${version}'," \
|
||||
" 'CFBundleExecutable': 'AutoLibrary'," \
|
||||
" 'NSPrincipalClass': 'NSApplication'," \
|
||||
" 'LSMinimumSystemVersion': '11.0'," \
|
||||
" 'NSRequiresAquaSystemAppearance': 'False'," \
|
||||
" 'NSHumanReadableCopyright': 'Copyright 2025 - 2026 KenanZhu. All rights reserved.'," \
|
||||
' },' \
|
||||
')' \
|
||||
> Main.spec
|
||||
|
||||
echo "✓ Main.spec generated successfully"
|
||||
echo ""
|
||||
echo "========================================"
|
||||
echo "Generated Main.spec"
|
||||
echo "========================================"
|
||||
cat Main.spec
|
||||
echo "========================================"
|
||||
|
||||
- name: Build with PyInstaller
|
||||
run: |
|
||||
python -m PyInstaller Main.spec
|
||||
|
||||
- name: Create DMG
|
||||
run: |
|
||||
tag_name="${{ steps.get_version.outputs.TAG_NAME }}"
|
||||
dmg_name="AutoLibrary.$tag_name-macos-arm64.dmg"
|
||||
app_path="dist/AutoLibrary.app"
|
||||
|
||||
if [ ! -d "$app_path" ]; then
|
||||
echo "✗ App bundle not found: $app_path"
|
||||
echo "Files in dist directory:"
|
||||
ls -la dist/
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Creating DMG from: $app_path"
|
||||
xattr -cr "$app_path" 2>/dev/null || true
|
||||
|
||||
tmp_dmg_dir=$(mktemp -d)
|
||||
cp -R "$app_path" "$tmp_dmg_dir/"
|
||||
ln -s /Applications "$tmp_dmg_dir/Applications"
|
||||
|
||||
hdiutil create \
|
||||
-volname "AutoLibrary $tag_name" \
|
||||
-srcfolder "$tmp_dmg_dir" \
|
||||
-ov \
|
||||
-format UDZO \
|
||||
"$dmg_name"
|
||||
|
||||
rm -rf "$tmp_dmg_dir"
|
||||
|
||||
if [ -f "$dmg_name" ]; then
|
||||
dmg_size=$(du -h "$dmg_name" | cut -f1)
|
||||
echo "✓ DMG created: $dmg_name (Size: $dmg_size)"
|
||||
else
|
||||
echo "✗ Failed to create DMG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ Artifacts ready:"
|
||||
echo " - $dmg_name"
|
||||
echo " - $app_path"
|
||||
|
||||
- name: Archive artifacts
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: AutoLibrary.${{ steps.get_version.outputs.TAG_NAME }}-macos-arm64
|
||||
path: |
|
||||
AutoLibrary.${{ steps.get_version.outputs.TAG_NAME }}-macos-arm64.dmg
|
||||
dist/AutoLibrary.app/**
|
||||
retention-days: ${{ inputs.is_test == 'true' && 7 || 90 }}
|
||||
|
||||
- name: Upload build summary
|
||||
if: ${{ inputs.is_test == 'true' }}
|
||||
run: |
|
||||
tag_name="${{ steps.get_version.outputs.TAG_NAME }}"
|
||||
version="${{ steps.get_version.outputs.VERSION }}"
|
||||
dmg_name="AutoLibrary.$tag_name-macos-arm64.dmg"
|
||||
|
||||
{
|
||||
echo "## Build Summary (macOS)"
|
||||
echo ""
|
||||
echo "========================================"
|
||||
echo "✓ Build test completed successfully!"
|
||||
echo "- Version: $version"
|
||||
echo "- Tag: $tag_name"
|
||||
echo "- Event: ${{ github.event_name }}"
|
||||
echo "- Ref: ${{ github.ref }}"
|
||||
echo "- DMG: $dmg_name"
|
||||
echo ""
|
||||
echo "### How to test on macOS"
|
||||
echo '1. Download the DMG artifact'
|
||||
echo '2. Open the DMG and drag AutoLibrary.app to /Applications'
|
||||
echo '3. Right-click → Open the app (to bypass Gatekeeper)'
|
||||
} >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
@@ -21,8 +21,10 @@ name: Release
|
||||
# Commits version changes to release branch and creates the release tag.
|
||||
|
||||
# 4. Build:
|
||||
# Compiles the application for Windows platform using PyInstaller, and
|
||||
# archives the built artifacts as 'AutoLibrary.<tag_name>-windows-x86_64.zip'.
|
||||
# Compiles the application for Windows and macOS platforms using PyInstaller, and
|
||||
# archives the built artifacts.
|
||||
# - Windows: AutoLibrary.<tag_name>-windows-x86_64.zip
|
||||
# - macOS: AutoLibrary.<tag_name>-macos-arm64.dmg
|
||||
|
||||
# 5. Release:
|
||||
# Creates GitHub release with generated artifacts and release notes
|
||||
@@ -181,12 +183,18 @@ jobs:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
- name: Download Windows artifacts
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: AutoLibrary.${{ needs.extract-version.outputs.tag_name }}-windows-x86_64
|
||||
path: artifacts/
|
||||
|
||||
- name: Download macOS artifacts
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: AutoLibrary.${{ needs.extract-version.outputs.tag_name }}-macos-arm64
|
||||
path: artifacts/
|
||||
|
||||
- name: Create release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v2
|
||||
@@ -195,6 +203,7 @@ jobs:
|
||||
name: AutoLibrary ${{ needs.extract-version.outputs.tag_name }}
|
||||
files: |
|
||||
artifacts/AutoLibrary.${{ needs.extract-version.outputs.tag_name }}-windows-x86_64.zip
|
||||
artifacts/AutoLibrary.${{ needs.extract-version.outputs.tag_name }}-macos-arm64.dmg
|
||||
draft: false
|
||||
prerelease: ${{ needs.extract-version.outputs.is_rc == 'true' }}
|
||||
generate_release_notes: true
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
6. 定时任务 - 使用内置定时任务管理,添加定时任务,指定时间后按当前预约信息自动运行,支持设置重复任务
|
||||
7. 驱动管理 - 内置浏览器驱动自动管理,支持自动检测浏览器版本并下载对应驱动,无需手动下载
|
||||
|
||||
*具体操作方法和注意事项请访问我们的 [帮助手册](https://www.autolibrary.kenanzhu.com/manuals)*
|
||||
*具体操作方法和注意事项请访问我们的 [帮助手册](https://manuals.autolibrary.kenanzhu.com)*
|
||||
|
||||
### 如何使用
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
This folder is used to store the manuals.
|
||||
|
||||
Our manuals are available at https://manuals.autolibrary.kenanzhu.com
|
||||
@@ -1,3 +0,0 @@
|
||||
This folder is used to store the manuals.
|
||||
|
||||
Our manuals are available at https://www.autolibrary.kenanzhu.com/manuals
|
||||
Binary file not shown.
@@ -0,0 +1,39 @@
|
||||
attrs==26.1.0
|
||||
certifi==2026.2.25
|
||||
cffi==2.0.0
|
||||
charset-normalizer==3.4.6
|
||||
ddddocr==1.0.6
|
||||
flatbuffers==25.12.19
|
||||
h11==0.16.0
|
||||
idna==3.11
|
||||
lupa==2.8
|
||||
mpmath==1.3.0
|
||||
numpy==2.4.3
|
||||
onnxruntime==1.24.4
|
||||
outcome==1.3.0.post0
|
||||
packaging==26.0
|
||||
pefile==2024.8.26
|
||||
pillow==12.1.1
|
||||
protobuf==7.34.0
|
||||
pybrowsers==1.3.2
|
||||
pycparser==3.0
|
||||
pyinstaller==6.19.0
|
||||
pyinstaller-hooks-contrib==2026.3
|
||||
PySide6==6.10.2
|
||||
PySide6_Addons==6.10.2
|
||||
PySide6_Essentials==6.10.2
|
||||
PySocks==1.7.1
|
||||
pywin32-ctypes==0.2.3
|
||||
requests==2.32.5
|
||||
selenium==4.38.0
|
||||
setuptools==82.0.1
|
||||
shiboken6==6.10.2
|
||||
sniffio==1.3.1
|
||||
sortedcontainers==2.4.0
|
||||
sympy==1.14.0
|
||||
trio==0.33.0
|
||||
trio-websocket==0.12.2
|
||||
typing_extensions==4.15.0
|
||||
urllib3==2.6.3
|
||||
websocket-client==1.9.0
|
||||
wsproto==1.3.2
|
||||
@@ -9,6 +9,7 @@ See the LICENSE file for details.
|
||||
"""
|
||||
from .ASEngine import ASEngine
|
||||
|
||||
__version__ = "1.0.0" # autoscript version
|
||||
|
||||
_TARGET_VAR_DEFS = [
|
||||
("USERNAME", "String", ["username"], "用户名"),
|
||||
|
||||
+81
-31
@@ -16,11 +16,16 @@ from PySide6.QtCore import (
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication,
|
||||
QDialog
|
||||
QDialog,
|
||||
QTabWidget,
|
||||
QTextBrowser
|
||||
)
|
||||
|
||||
from gui.ALVersionInfo import (
|
||||
AL_VERSION, AL_COMMIT_SHA, AL_COMMIT_DATE, AL_BUILD_DATE
|
||||
AL_VERSION,
|
||||
AL_COMMIT_SHA,
|
||||
AL_COMMIT_DATE,
|
||||
AL_BUILD_DATE
|
||||
)
|
||||
from gui.resources.ui.Ui_ALAboutDialog import Ui_ALAboutDialog
|
||||
from gui.resources import ALResource
|
||||
@@ -43,12 +48,23 @@ class ALAboutDialog(QDialog, Ui_ALAboutDialog):
|
||||
):
|
||||
|
||||
self.LogoIconLabel.setPixmap(QIcon(":/res/icons/AutoLibrary_Logo_64.svg").pixmap(48, 48))
|
||||
info_text = self.generateAboutText()
|
||||
self.AboutInfoBrowser.setHtml(info_text)
|
||||
browser_font = self.AboutInfoBrowser.font()
|
||||
browser_font.setFamily("Courier New")
|
||||
self.AboutInfoBrowser.setFont(browser_font)
|
||||
self.AboutInfoBrowser.setTextInteractionFlags(Qt.TextBrowserInteraction)
|
||||
self.TabWidget = QTabWidget()
|
||||
self.TabWidget.setDocumentMode(True)
|
||||
AboutBrowser = QTextBrowser()
|
||||
AboutBrowser.setHtml(self.generateAboutText())
|
||||
AboutBrowser.setOpenExternalLinks(True)
|
||||
AboutBrowser.setLineWrapMode(QTextBrowser.LineWrapMode.NoWrap)
|
||||
AboutBrowser.setTextInteractionFlags(Qt.TextBrowserInteraction)
|
||||
BrowserFont = AboutBrowser.font()
|
||||
BrowserFont.setFamilies(["Courier New", "Consolas", "Menlo", "DejaVu Sans Mono", "monospace"])
|
||||
AboutBrowser.setFont(BrowserFont)
|
||||
self.TabWidget.addTab(AboutBrowser, "关于")
|
||||
LicenseBrowser = QTextBrowser()
|
||||
LicenseBrowser.setHtml(self.generateLicenseText())
|
||||
LicenseBrowser.setOpenExternalLinks(True)
|
||||
LicenseBrowser.setTextInteractionFlags(Qt.TextBrowserInteraction)
|
||||
self.TabWidget.addTab(LicenseBrowser, "许可证")
|
||||
self.AboutInfoLayout.addWidget(self.TabWidget)
|
||||
|
||||
def connectSignals(
|
||||
self
|
||||
@@ -61,33 +77,57 @@ class ALAboutDialog(QDialog, Ui_ALAboutDialog):
|
||||
) -> str:
|
||||
|
||||
os_info = self.getOSInfo()
|
||||
run_on = f"{os_info['system']} {os_info['version']} {os_info['architecture']}"
|
||||
selenium_ver = self.getSeleniumVersion()
|
||||
about_text = f"""
|
||||
<h4>Version Information:</h4>
|
||||
Version: {AL_VERSION}<br>
|
||||
<b style="font-size:14px;">VERSION: {AL_VERSION}</b><br>
|
||||
Commit SHA: {AL_COMMIT_SHA}<br>
|
||||
Commit date: {AL_COMMIT_DATE}<br>
|
||||
Build date: {AL_BUILD_DATE}<br>
|
||||
Python version: {platform.python_version()}<br>
|
||||
Qt version: {self.getQtVersion()}<br>
|
||||
|
||||
<h4>System Information:</h4>
|
||||
<br>
|
||||
<b style="font-size:14px;">SYSTEM</b><br>
|
||||
Running on: {run_on}<br>
|
||||
Processor: {platform.processor()}<br>
|
||||
Operating system: {os_info['system']}<br>
|
||||
System version: {os_info['version']}<br>
|
||||
System architecture: {os_info['architecture']}<br>
|
||||
|
||||
<h4>Project Information:</h4>
|
||||
License: MIT License<br>
|
||||
Project repository: <a href="https://www.github.com/KenanZhu/AutoLibrary" style="text-decoration: none;">https://www.github.com/KenanZhu/AutoLibrary</a><br>
|
||||
Project website: <a href="https://www.autolibrary.kenanzhu.com" style="text-decoration: none;">https://www.autolibrary.kenanzhu.com</a><br>
|
||||
|
||||
<h4>Author Information:</h4>
|
||||
Developer: KenanZhu<br>
|
||||
Contact: nanoki_zh@163.com<br>
|
||||
GitHub: <a href="https://www.github.com/KenanZhu" style="text-decoration: none;">https://www.github.com/KenanZhu</a><br>
|
||||
<br>
|
||||
<b style="font-size:14px;">DEPENDENCIES</b><br>
|
||||
Python: {platform.python_version()}<br>
|
||||
Qt(PySide6): {self.getQtVersion()}<br>
|
||||
Selenium: {selenium_ver}<br>
|
||||
<br>
|
||||
<b style="font-size:14px;">PROJECT</b><br>
|
||||
Website: <a href="https://www.autolibrary.kenanzhu.com" style="text-decoration:none;">https://www.autolibrary.kenanzhu.com</a><br>
|
||||
Repository: <a href="https://www.github.com/KenanZhu/AutoLibrary" style="text-decoration:none;">https://www.github.com/KenanZhu/AutoLibrary</a><br>
|
||||
<br>
|
||||
<b style="font-size:14px;">AUTHOR</b><br>
|
||||
Developer/Maintainer: KenanZhu<br>
|
||||
Contact: <a href="mailto:nanoki_zh@163.com">nanoki_zh@163.com</a><br>
|
||||
GitHub: <a href="https://www.github.com/KenanZhu" style="text-decoration:none;">https://www.github.com/KenanZhu</a><br>
|
||||
"""
|
||||
return about_text
|
||||
|
||||
def generateLicenseText(
|
||||
self
|
||||
) -> str:
|
||||
|
||||
return """
|
||||
<b>MIT License</b>
|
||||
<p>Copyright © 2025 - 2026 KenanZhu</p>
|
||||
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:</p>
|
||||
<p>The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.</p>
|
||||
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.</p>"""
|
||||
|
||||
def getOSInfo(
|
||||
self
|
||||
):
|
||||
@@ -129,13 +169,23 @@ GitHub: <a href="https://www.github.com/KenanZhu" style="text-decoration: none;"
|
||||
except:
|
||||
return "Unknown"
|
||||
|
||||
def getSeleniumVersion(
|
||||
self
|
||||
):
|
||||
|
||||
try:
|
||||
import selenium
|
||||
return selenium.__version__
|
||||
except Exception:
|
||||
return "Unknown"
|
||||
|
||||
def copyAboutInfo(
|
||||
self
|
||||
):
|
||||
|
||||
about_text = self.AboutInfoBrowser.toPlainText()
|
||||
clipboard = QApplication.clipboard()
|
||||
clipboard.setText(about_text)
|
||||
about_text = self.TabWidget.currentWidget().toPlainText()
|
||||
Clipboard = QApplication.clipboard()
|
||||
Clipboard.setText(about_text)
|
||||
original_text = self.CopyButton.text()
|
||||
self.CopyButton.setText("已复制")
|
||||
QTimer.singleShot(2000, lambda: self.CopyButton.setText(original_text))
|
||||
QTimer.singleShot(2000, lambda: self.CopyButton.setText(original_text))
|
||||
|
||||
+237
-237
@@ -74,54 +74,54 @@ class ALScriptHighlighter(QSyntaxHighlighter):
|
||||
super().__init__(parent)
|
||||
self._rules = []
|
||||
|
||||
keywordFmt = QTextCharFormat()
|
||||
keywordFmt.setForeground(QColor("#569CD6"))
|
||||
keywordFmt.setFontWeight(QFont.Weight.Bold)
|
||||
KeywordFmt = QTextCharFormat()
|
||||
KeywordFmt.setForeground(QColor("#569CD6"))
|
||||
KeywordFmt.setFontWeight(QFont.Weight.Bold)
|
||||
for kw in [
|
||||
"if", "elseif", "else", "end", "then",
|
||||
"and", "or", "not",
|
||||
"local", "function", "return", "nil",
|
||||
]:
|
||||
self._rules.append((r"\b" + kw + r"\b", keywordFmt))
|
||||
boolFmt = QTextCharFormat()
|
||||
boolFmt.setForeground(QColor("#4FC1FF"))
|
||||
boolFmt.setFontWeight(QFont.Weight.Bold)
|
||||
self._rules.append((r"\btrue\b", boolFmt))
|
||||
self._rules.append((r"\bfalse\b", boolFmt))
|
||||
cmpFmt = QTextCharFormat()
|
||||
cmpFmt.setForeground(QColor("#C586C0"))
|
||||
cmpFmt.setFontWeight(QFont.Weight.Normal)
|
||||
self._rules.append((r"\b" + kw + r"\b", KeywordFmt))
|
||||
BoolFmt = QTextCharFormat()
|
||||
BoolFmt.setForeground(QColor("#4FC1FF"))
|
||||
BoolFmt.setFontWeight(QFont.Weight.Bold)
|
||||
self._rules.append((r"\btrue\b", BoolFmt))
|
||||
self._rules.append((r"\bfalse\b", BoolFmt))
|
||||
CmpFmt = QTextCharFormat()
|
||||
CmpFmt.setForeground(QColor("#C586C0"))
|
||||
CmpFmt.setFontWeight(QFont.Weight.Normal)
|
||||
for op in [r"==", r"~=", r">=", r"<=", r">", r"<"]:
|
||||
self._rules.append((op, cmpFmt))
|
||||
arithFmt = QTextCharFormat()
|
||||
arithFmt.setForeground(QColor("#C586C0"))
|
||||
arithFmt.setFontWeight(QFont.Weight.Normal)
|
||||
self._rules.append((op, CmpFmt))
|
||||
ArithFmt = QTextCharFormat()
|
||||
ArithFmt.setForeground(QColor("#C586C0"))
|
||||
ArithFmt.setFontWeight(QFont.Weight.Normal)
|
||||
for op in [r"\+", r"-", r"\*", r"/", r"\.\."]:
|
||||
self._rules.append((op, arithFmt))
|
||||
funcFmt = QTextCharFormat()
|
||||
funcFmt.setForeground(QColor("#DCDCAA"))
|
||||
funcFmt.setFontWeight(QFont.Weight.Normal)
|
||||
self._rules.append((op, ArithFmt))
|
||||
FuncFmt = QTextCharFormat()
|
||||
FuncFmt.setForeground(QColor("#DCDCAA"))
|
||||
FuncFmt.setFontWeight(QFont.Weight.Normal)
|
||||
for fn in [ "time", "date", "datenow", "timenow", "dateadd", "timeadd"]:
|
||||
self._rules.append((r"\b" + fn + r"\b", funcFmt))
|
||||
varFmt = QTextCharFormat()
|
||||
varFmt.setForeground(QColor("#9CDCFE"))
|
||||
varFmt.setFontWeight(QFont.Weight.Normal)
|
||||
self._rules.append((r"\b" + fn + r"\b", FuncFmt))
|
||||
VarFmt = QTextCharFormat()
|
||||
VarFmt.setForeground(QColor("#9CDCFE"))
|
||||
VarFmt.setFontWeight(QFont.Weight.Normal)
|
||||
var_names = [name for _, (name, _) in createAllVariablesTable().items()]
|
||||
for var in var_names:
|
||||
self._rules.append((r"\b" + var + r"\b", varFmt))
|
||||
strFmt = QTextCharFormat()
|
||||
strFmt.setForeground(QColor("#CE9178"))
|
||||
strFmt.setFontWeight(QFont.Weight.Normal)
|
||||
self._rules.append((r'"[^"]*"', strFmt))
|
||||
self._rules.append((r"'[^']*'", strFmt))
|
||||
numFmt = QTextCharFormat()
|
||||
numFmt.setForeground(QColor("#B5CEA8"))
|
||||
numFmt.setFontWeight(QFont.Weight.Normal)
|
||||
self._rules.append((r"\b\d+(?:\.\d+)?\b", numFmt))
|
||||
commentFmt = QTextCharFormat()
|
||||
commentFmt.setForeground(QColor("#6A9955"))
|
||||
commentFmt.setFontItalic(True)
|
||||
self._rules.append((r"--[^\n]*", commentFmt))
|
||||
self._rules.append((r"\b" + var + r"\b", VarFmt))
|
||||
StrFmt = QTextCharFormat()
|
||||
StrFmt.setForeground(QColor("#CE9178"))
|
||||
StrFmt.setFontWeight(QFont.Weight.Normal)
|
||||
self._rules.append((r'"[^"]*"', StrFmt))
|
||||
self._rules.append((r"'[^']*'", StrFmt))
|
||||
NumFmt = QTextCharFormat()
|
||||
NumFmt.setForeground(QColor("#B5CEA8"))
|
||||
NumFmt.setFontWeight(QFont.Weight.Normal)
|
||||
self._rules.append((r"\b\d+(?:\.\d+)?\b", NumFmt))
|
||||
CommentFmt = QTextCharFormat()
|
||||
CommentFmt.setForeground(QColor("#6A9955"))
|
||||
CommentFmt.setFontItalic(True)
|
||||
self._rules.append((r"--[^\n]*", CommentFmt))
|
||||
|
||||
def highlightBlock(
|
||||
self,
|
||||
@@ -147,22 +147,22 @@ class _DebugResultDialog(QDialog):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle("调试运行结果 - AutoLibrary")
|
||||
self.setMinimumSize(600, 200)
|
||||
layout = QVBoxLayout(self)
|
||||
table = QTableWidget(len(changes), 3)
|
||||
table.setHorizontalHeaderLabels(["目标变量", "原始数据", "运行后数据"])
|
||||
table.horizontalHeader().setStretchLastSection(True)
|
||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
table.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
|
||||
DbgLayout = QVBoxLayout(self)
|
||||
DbgTable = QTableWidget(len(changes), 3)
|
||||
DbgTable.setHorizontalHeaderLabels(["目标变量", "原始数据", "运行后数据"])
|
||||
DbgTable.horizontalHeader().setStretchLastSection(True)
|
||||
DbgTable.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
DbgTable.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
|
||||
for row, (display_name, name, var_type, before_val, after_val) in enumerate(changes):
|
||||
label = f"{display_name}: {name}({var_type})"
|
||||
table.setItem(row, 0, QTableWidgetItem(label))
|
||||
table.setItem(row, 1, QTableWidgetItem(str(before_val)))
|
||||
table.setItem(row, 2, QTableWidgetItem(str(after_val)))
|
||||
layout.addWidget(table)
|
||||
btnBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
|
||||
btnBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定")
|
||||
btnBox.accepted.connect(self.accept)
|
||||
layout.addWidget(btnBox)
|
||||
DbgTable.setItem(row, 0, QTableWidgetItem(label))
|
||||
DbgTable.setItem(row, 1, QTableWidgetItem(str(before_val)))
|
||||
DbgTable.setItem(row, 2, QTableWidgetItem(str(after_val)))
|
||||
DbgLayout.addWidget(DbgTable)
|
||||
DbgBtnBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
|
||||
DbgBtnBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定")
|
||||
DbgBtnBox.accepted.connect(self.accept)
|
||||
DbgLayout.addWidget(DbgBtnBox)
|
||||
|
||||
|
||||
class _TabToSpacesEditor(QPlainTextEdit):
|
||||
@@ -193,9 +193,9 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
|
||||
self.setupUi()
|
||||
self.connectSignals()
|
||||
self.textEdit.setPlainText(script)
|
||||
self._highlighter = ALScriptHighlighter(
|
||||
self.textEdit.document()
|
||||
self.TextEdit.setPlainText(script)
|
||||
self._Highlighter = ALScriptHighlighter(
|
||||
self.TextEdit.document()
|
||||
)
|
||||
if mockData:
|
||||
self.setMockData(mockData)
|
||||
@@ -206,80 +206,80 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
|
||||
self.setWindowTitle("AutoScript 编辑 - AutoLibrary")
|
||||
self.setMinimumSize(660, 600)
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSpacing(3)
|
||||
layout.setContentsMargins(3, 3, 3, 3)
|
||||
toolbarLayout = QHBoxLayout()
|
||||
self.zoomInBtn = QPushButton("+")
|
||||
self.zoomInBtn.setFixedSize(25, 25)
|
||||
self.zoomOutBtn = QPushButton("-")
|
||||
self.zoomOutBtn.setFixedSize(25, 25)
|
||||
self.zoomResetBtn = QPushButton("")
|
||||
self.zoomResetBtn.setIcon(QIcon(":/res/icons/Reset.svg"))
|
||||
self.zoomResetBtn.setIconSize(QSize(20, 20))
|
||||
self.zoomResetBtn.setFixedSize(25, 25)
|
||||
self.zoomResetBtn.setToolTip("重置缩放")
|
||||
self.zoomLabel = QLabel(f"{self._fontSize}px")
|
||||
self.zoomLabel.setFixedHeight(25)
|
||||
self.orchBtn = QPushButton("编排")
|
||||
self.orchBtn.setFixedHeight(25)
|
||||
self.orchBtn.setToolTip("可视化生成 AutoScript 代码并插入到光标位置")
|
||||
toolbarLayout.addWidget(self.orchBtn)
|
||||
self.debugBtn = QPushButton("▶ 调试运行")
|
||||
self.debugBtn.setFixedHeight(25)
|
||||
self.debugBtn.setToolTip("使用右侧模拟数据执行脚本,查看目标变量变化")
|
||||
toolbarLayout.addWidget(self.debugBtn)
|
||||
sep = QFrame()
|
||||
sep.setFrameShape(QFrame.Shape.VLine)
|
||||
sep.setFrameShadow(QFrame.Shadow.Sunken)
|
||||
sep.setFixedWidth(1)
|
||||
toolbarLayout.addWidget(sep)
|
||||
toolbarLayout.addWidget(self.zoomInBtn)
|
||||
toolbarLayout.addWidget(self.zoomOutBtn)
|
||||
toolbarLayout.addWidget(self.zoomResetBtn)
|
||||
toolbarLayout.addWidget(self.zoomLabel)
|
||||
toolbarLayout.addStretch()
|
||||
self.copyBtn = QPushButton("")
|
||||
self.copyBtn.setIcon(QIcon(":/res/icons/Copy.svg"))
|
||||
self.copyBtn.setIconSize(QSize(20, 20))
|
||||
self.copyBtn.setFixedSize(25, 25)
|
||||
self.copyBtn.setToolTip("复制脚本")
|
||||
toolbarLayout.addWidget(self.copyBtn)
|
||||
layout.addLayout(toolbarLayout)
|
||||
self.textEdit = _TabToSpacesEditor(self)
|
||||
self.textEdit.setTabStopDistance(40)
|
||||
self.textEdit.setLineWrapMode(
|
||||
Layout = QVBoxLayout(self)
|
||||
Layout.setSpacing(3)
|
||||
Layout.setContentsMargins(3, 3, 3, 3)
|
||||
ToolbarLayout = QHBoxLayout()
|
||||
self.ZoomInBtn = QPushButton("+")
|
||||
self.ZoomInBtn.setFixedSize(25, 25)
|
||||
self.ZoomOutBtn = QPushButton("-")
|
||||
self.ZoomOutBtn.setFixedSize(25, 25)
|
||||
self.ZoomResetBtn = QPushButton("")
|
||||
self.ZoomResetBtn.setIcon(QIcon(":/res/icons/Reset.svg"))
|
||||
self.ZoomResetBtn.setIconSize(QSize(20, 20))
|
||||
self.ZoomResetBtn.setFixedSize(25, 25)
|
||||
self.ZoomResetBtn.setToolTip("重置缩放")
|
||||
self.ZoomLabel = QLabel(f"{self._fontSize}px")
|
||||
self.ZoomLabel.setFixedHeight(25)
|
||||
self.OrchBtn = QPushButton("编排")
|
||||
self.OrchBtn.setFixedHeight(25)
|
||||
self.OrchBtn.setToolTip("可视化生成 AutoScript 代码并插入到光标位置")
|
||||
ToolbarLayout.addWidget(self.OrchBtn)
|
||||
self.DebugBtn = QPushButton("▶ 调试运行")
|
||||
self.DebugBtn.setFixedHeight(25)
|
||||
self.DebugBtn.setToolTip("使用右侧模拟数据执行脚本,查看目标变量变化")
|
||||
ToolbarLayout.addWidget(self.DebugBtn)
|
||||
Sep = QFrame()
|
||||
Sep.setFrameShape(QFrame.Shape.VLine)
|
||||
Sep.setFrameShadow(QFrame.Shadow.Sunken)
|
||||
Sep.setFixedWidth(1)
|
||||
ToolbarLayout.addWidget(Sep)
|
||||
ToolbarLayout.addWidget(self.ZoomInBtn)
|
||||
ToolbarLayout.addWidget(self.ZoomOutBtn)
|
||||
ToolbarLayout.addWidget(self.ZoomResetBtn)
|
||||
ToolbarLayout.addWidget(self.ZoomLabel)
|
||||
ToolbarLayout.addStretch()
|
||||
self.CopyBtn = QPushButton("")
|
||||
self.CopyBtn.setIcon(QIcon(":/res/icons/Copy.svg"))
|
||||
self.CopyBtn.setIconSize(QSize(20, 20))
|
||||
self.CopyBtn.setFixedSize(25, 25)
|
||||
self.CopyBtn.setToolTip("复制脚本")
|
||||
ToolbarLayout.addWidget(self.CopyBtn)
|
||||
Layout.addLayout(ToolbarLayout)
|
||||
self.TextEdit = _TabToSpacesEditor(self)
|
||||
self.TextEdit.setTabStopDistance(40)
|
||||
self.TextEdit.setLineWrapMode(
|
||||
QPlainTextEdit.LineWrapMode.NoWrap
|
||||
)
|
||||
self.textEdit.setStyleSheet(
|
||||
self.TextEdit.setStyleSheet(
|
||||
"QPlainTextEdit {"
|
||||
" font-family: 'Courier New', 'Consolas', monospace;"
|
||||
f" font-size: {self._fontSize}px;"
|
||||
"}"
|
||||
)
|
||||
layout.addWidget(self.textEdit)
|
||||
self.createButtonPanel(layout)
|
||||
self.btnBox = QDialogButtonBox(
|
||||
Layout.addWidget(self.TextEdit)
|
||||
self.createButtonPanel(Layout)
|
||||
self.BtnBox = QDialogButtonBox(
|
||||
QDialogButtonBox.StandardButton.Ok |
|
||||
QDialogButtonBox.StandardButton.Cancel
|
||||
)
|
||||
self.btnBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定")
|
||||
self.btnBox.button(QDialogButtonBox.StandardButton.Cancel).setText("取消")
|
||||
layout.addWidget(self.btnBox)
|
||||
self.BtnBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定")
|
||||
self.BtnBox.button(QDialogButtonBox.StandardButton.Cancel).setText("取消")
|
||||
Layout.addWidget(self.BtnBox)
|
||||
|
||||
def createButtonPanel(
|
||||
self,
|
||||
parent_layout
|
||||
ParentLayout
|
||||
):
|
||||
|
||||
splitter = QSplitter(Qt.Orientation.Horizontal)
|
||||
tabWidget = QTabWidget()
|
||||
tabWidget.setMaximumHeight(150)
|
||||
basicWidget = QWidget()
|
||||
basicLayout = QGridLayout(basicWidget)
|
||||
basicLayout.setSpacing(4)
|
||||
basicLayout.setContentsMargins(4, 4, 4, 4)
|
||||
basicLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
Splitter = QSplitter(Qt.Orientation.Horizontal)
|
||||
TabWidget = QTabWidget()
|
||||
TabWidget.setMaximumHeight(150)
|
||||
BasicWidget = QWidget()
|
||||
BasicLayout = QGridLayout(BasicWidget)
|
||||
BasicLayout.setSpacing(4)
|
||||
BasicLayout.setContentsMargins(4, 4, 4, 4)
|
||||
BasicLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
controlButtons = [
|
||||
("如果 (if...)", "if then\n \nend"),
|
||||
("再如果 (elseif...)", "elseif then\n "),
|
||||
@@ -287,22 +287,22 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
("结束 (end)", "end"),
|
||||
("跳过 (pass)", "-- pass"),
|
||||
]
|
||||
self.addButtonsToGrid(basicLayout, controlButtons, 0, 0, 3)
|
||||
self.addButtonsToGrid(BasicLayout, controlButtons, 0, 0, 3)
|
||||
assignButtons = [
|
||||
("赋值 (=)", " = "),
|
||||
]
|
||||
self.addButtonsToGrid(basicLayout, assignButtons, 1, 2, 3)
|
||||
tabWidget.addTab(basicWidget, "基本语法")
|
||||
operatorWidget = QWidget()
|
||||
operatorLayout = QGridLayout(operatorWidget)
|
||||
operatorLayout.setSpacing(4)
|
||||
operatorLayout.setContentsMargins(4, 4, 4, 4)
|
||||
operatorLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
self.addButtonsToGrid(BasicLayout, assignButtons, 1, 2, 3)
|
||||
TabWidget.addTab(BasicWidget, "基本语法")
|
||||
OperatorWidget = QWidget()
|
||||
OperatorLayout = QGridLayout(OperatorWidget)
|
||||
OperatorLayout.setSpacing(4)
|
||||
OperatorLayout.setContentsMargins(4, 4, 4, 4)
|
||||
OperatorLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
arithmeticButtons = [
|
||||
("加 (+)", " + "),
|
||||
("减 (-)", " - "),
|
||||
]
|
||||
self.addButtonsToGrid(operatorLayout, arithmeticButtons, 0, 0, 3)
|
||||
self.addButtonsToGrid(OperatorLayout, arithmeticButtons, 0, 0, 3)
|
||||
compareButtons = [
|
||||
("等于 (==)", " == "),
|
||||
("不等于 (~=)", " ~= "),
|
||||
@@ -311,50 +311,50 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
("大于等于 (>=)", " >= "),
|
||||
("小于等于 (<=)", " <= "),
|
||||
]
|
||||
self.addButtonsToGrid(operatorLayout, compareButtons, 1, 0, 3)
|
||||
self.addButtonsToGrid(OperatorLayout, compareButtons, 1, 0, 3)
|
||||
logic_buttons = [
|
||||
("且 (and)", " and "),
|
||||
("或 (or)", " or "),
|
||||
]
|
||||
self.addButtonsToGrid(operatorLayout, logic_buttons, 2, 0, 3)
|
||||
tabWidget.addTab(operatorWidget, "运算符")
|
||||
literalWidget = QWidget()
|
||||
literalLayout = QGridLayout(literalWidget)
|
||||
literalLayout.setSpacing(4)
|
||||
literalLayout.setContentsMargins(4, 4, 4, 4)
|
||||
literalLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
self.addButtonsToGrid(OperatorLayout, logic_buttons, 2, 0, 3)
|
||||
TabWidget.addTab(OperatorWidget, "运算符")
|
||||
LiteralWidget = QWidget()
|
||||
LiteralLayout = QGridLayout(LiteralWidget)
|
||||
LiteralLayout.setSpacing(4)
|
||||
LiteralLayout.setContentsMargins(4, 4, 4, 4)
|
||||
LiteralLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
bool_buttons = [
|
||||
("真 (true)", "true"),
|
||||
("假 (false)", "false"),
|
||||
]
|
||||
self.addButtonsToGrid(literalLayout, bool_buttons, 0, 0, 3)
|
||||
self.addButtonsToGrid(LiteralLayout, bool_buttons, 0, 0, 3)
|
||||
dateTimeButtons = [
|
||||
("日期", 'date(2026, 1, 1)'),
|
||||
("时间", 'time(0, 0)'),
|
||||
]
|
||||
self.addButtonsToGrid(literalLayout, dateTimeButtons, 1, 0, 3)
|
||||
self.addButtonsToGrid(LiteralLayout, dateTimeButtons, 1, 0, 3)
|
||||
hintButtons = [
|
||||
("字符串", '"请输入文本"'),
|
||||
("数字", "123"),
|
||||
("注释", "-- 请输入注释"),
|
||||
]
|
||||
self.addButtonsToGrid(literalLayout, hintButtons, 2, 0, 3)
|
||||
tabWidget.addTab(literalWidget, "字面量")
|
||||
varWidget = QWidget()
|
||||
varLayout = QGridLayout(varWidget)
|
||||
varLayout.setSpacing(4)
|
||||
varLayout.setContentsMargins(4, 4, 4, 4)
|
||||
varLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
self.addButtonsToGrid(LiteralLayout, hintButtons, 2, 0, 3)
|
||||
TabWidget.addTab(LiteralWidget, "字面量")
|
||||
VarWidget = QWidget()
|
||||
VarLayout = QGridLayout(VarWidget)
|
||||
VarLayout.setSpacing(4)
|
||||
VarLayout.setContentsMargins(4, 4, 4, 4)
|
||||
VarLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
varButtons = [
|
||||
(display_name, name) for display_name, (name, _) in createAllVariablesTable().items()
|
||||
]
|
||||
self.addButtonsToGrid(varLayout, varButtons, 0, 0, 3)
|
||||
tabWidget.addTab(varWidget, "变量")
|
||||
funcWidget = QWidget()
|
||||
funcLayout = QGridLayout(funcWidget)
|
||||
funcLayout.setSpacing(4)
|
||||
funcLayout.setContentsMargins(4, 4, 4, 4)
|
||||
funcLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
self.addButtonsToGrid(VarLayout, varButtons, 0, 0, 3)
|
||||
TabWidget.addTab(VarWidget, "变量")
|
||||
FuncWidget = QWidget()
|
||||
FuncLayout = QGridLayout(FuncWidget)
|
||||
FuncLayout.setSpacing(4)
|
||||
FuncLayout.setContentsMargins(4, 4, 4, 4)
|
||||
FuncLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
funcButtons = [
|
||||
("datenow()", "datenow()", "返回当前日期的 Unix 时间戳"),
|
||||
("timenow()", "timenow()", "返回当前时间在一天中的分钟数"),
|
||||
@@ -362,22 +362,22 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
("timeadd(time, n)", "timeadd(, )", "时间偏移: timeadd(分钟数, 分钟数)"),
|
||||
]
|
||||
for i, (text, template, tooltip) in enumerate(funcButtons):
|
||||
btn = QPushButton(text)
|
||||
btn.setProperty("template", template)
|
||||
btn.clicked.connect(self.insertTemplate)
|
||||
btn.setFixedWidth(100)
|
||||
btn.setFixedHeight(25)
|
||||
btn.setToolTip(tooltip)
|
||||
funcLayout.addWidget(btn, i // 2, i % 2)
|
||||
tabWidget.addTab(funcWidget, "工具函数")
|
||||
mockPanel = self.createMockPanel()
|
||||
mockPanel.setMinimumWidth(260)
|
||||
splitter.addWidget(tabWidget)
|
||||
splitter.addWidget(mockPanel)
|
||||
splitter.setStretchFactor(0, 1)
|
||||
splitter.setStretchFactor(1, 1)
|
||||
splitter.setSizes([530, 530])
|
||||
parent_layout.addWidget(splitter)
|
||||
Btn = QPushButton(text)
|
||||
Btn.setProperty("template", template)
|
||||
Btn.clicked.connect(self.insertTemplate)
|
||||
Btn.setFixedWidth(100)
|
||||
Btn.setFixedHeight(25)
|
||||
Btn.setToolTip(tooltip)
|
||||
FuncLayout.addWidget(Btn, i // 2, i % 2)
|
||||
TabWidget.addTab(FuncWidget, "工具函数")
|
||||
MockPanel = self.createMockPanel()
|
||||
MockPanel.setMinimumWidth(260)
|
||||
Splitter.addWidget(TabWidget)
|
||||
Splitter.addWidget(MockPanel)
|
||||
Splitter.setStretchFactor(0, 1)
|
||||
Splitter.setStretchFactor(1, 1)
|
||||
Splitter.setSizes([530, 530])
|
||||
ParentLayout.addWidget(Splitter)
|
||||
|
||||
def addButtonsToGrid(
|
||||
self,
|
||||
@@ -392,13 +392,13 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
row = start_row
|
||||
|
||||
for btn_text, template in buttons:
|
||||
btn = QPushButton(btn_text)
|
||||
btn.setProperty("template", template)
|
||||
btn.clicked.connect(self.insertTemplate)
|
||||
btn.setFixedWidth(100)
|
||||
btn.setFixedHeight(25)
|
||||
btn.setToolTip(f"插入: {template}")
|
||||
grid_layout.addWidget(btn, row, col)
|
||||
Btn = QPushButton(btn_text)
|
||||
Btn.setProperty("template", template)
|
||||
Btn.clicked.connect(self.insertTemplate)
|
||||
Btn.setFixedWidth(100)
|
||||
Btn.setFixedHeight(25)
|
||||
Btn.setToolTip(f"插入: {template}")
|
||||
grid_layout.addWidget(Btn, row, col)
|
||||
col += 1
|
||||
if col >= start_col + max_columns:
|
||||
col = start_col
|
||||
@@ -408,10 +408,10 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
self
|
||||
) -> QGroupBox:
|
||||
|
||||
group = QGroupBox("模拟目标数据")
|
||||
form = QFormLayout(group)
|
||||
form.setSpacing(4)
|
||||
form.setContentsMargins(5, 10, 5, 5)
|
||||
Group = QGroupBox("模拟目标数据")
|
||||
Form = QFormLayout(Group)
|
||||
Form.setSpacing(4)
|
||||
Form.setContentsMargins(5, 10, 5, 5)
|
||||
self._mockWidgets = {}
|
||||
mockData = createMockTargetData()
|
||||
for name, var_type, key_path, display_name in createTargetVarDefs():
|
||||
@@ -419,11 +419,11 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
for key in key_path:
|
||||
d = d[key]
|
||||
default = d
|
||||
widget = self.makeMockInput(var_type, default)
|
||||
label = QLabel(f"{display_name}: {name}({var_type})")
|
||||
form.addRow(label, widget)
|
||||
self._mockWidgets[name] = (widget, var_type, key_path)
|
||||
return group
|
||||
Widget = self.makeMockInput(var_type, default)
|
||||
Label = QLabel(f"{display_name}: {name}({var_type})")
|
||||
Form.addRow(Label, Widget)
|
||||
self._mockWidgets[name] = (Widget, var_type, key_path)
|
||||
return Group
|
||||
|
||||
def makeMockInput(
|
||||
self,
|
||||
@@ -432,41 +432,41 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
) -> QWidget:
|
||||
|
||||
if var_type == "String":
|
||||
w = QLineEdit()
|
||||
w.setText(str(default))
|
||||
return w
|
||||
W = QLineEdit()
|
||||
W.setText(str(default))
|
||||
return W
|
||||
if var_type == "Boolean":
|
||||
w = QComboBox()
|
||||
w.addItems(["是", "否"])
|
||||
w.setCurrentIndex(0 if default else 1)
|
||||
return w
|
||||
W = QComboBox()
|
||||
W.addItems(["是", "否"])
|
||||
W.setCurrentIndex(0 if default else 1)
|
||||
return W
|
||||
if var_type == "Date":
|
||||
w = QDateEdit()
|
||||
w.setCalendarPopup(True)
|
||||
w.setDisplayFormat("yyyy-MM-dd")
|
||||
w.setDate(QDate.fromString(str(default), "yyyy-MM-dd"))
|
||||
return w
|
||||
W = QDateEdit()
|
||||
W.setCalendarPopup(True)
|
||||
W.setDisplayFormat("yyyy-MM-dd")
|
||||
W.setDate(QDate.fromString(str(default), "yyyy-MM-dd"))
|
||||
return W
|
||||
if var_type == "Time":
|
||||
w = QTimeEdit()
|
||||
w.setDisplayFormat("HH:mm")
|
||||
w.setTime(QTime.fromString(str(default), "HH:mm"))
|
||||
return w
|
||||
W = QTimeEdit()
|
||||
W.setDisplayFormat("HH:mm")
|
||||
W.setTime(QTime.fromString(str(default), "HH:mm"))
|
||||
return W
|
||||
if var_type == "Int":
|
||||
w = QSpinBox()
|
||||
w.setMinimum(-999999)
|
||||
w.setMaximum(999999)
|
||||
w.setValue(int(default) if default else 0)
|
||||
return w
|
||||
W = QSpinBox()
|
||||
W.setMinimum(-999999)
|
||||
W.setMaximum(999999)
|
||||
W.setValue(int(default) if default else 0)
|
||||
return W
|
||||
if var_type == "Float":
|
||||
w = QDoubleSpinBox()
|
||||
w.setMinimum(-999999.0)
|
||||
w.setMaximum(999999.0)
|
||||
w.setDecimals(2)
|
||||
w.setValue(float(default) if default else 0.0)
|
||||
return w
|
||||
w = QLineEdit()
|
||||
w.setText(str(default))
|
||||
return w
|
||||
W = QDoubleSpinBox()
|
||||
W.setMinimum(-999999.0)
|
||||
W.setMaximum(999999.0)
|
||||
W.setDecimals(2)
|
||||
W.setValue(float(default) if default else 0.0)
|
||||
return W
|
||||
W = QLineEdit()
|
||||
W.setText(str(default))
|
||||
return W
|
||||
|
||||
def getMockData(
|
||||
self
|
||||
@@ -541,45 +541,45 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
self
|
||||
):
|
||||
|
||||
self.btnBox.accepted.connect(self.accept)
|
||||
self.btnBox.rejected.connect(self.reject)
|
||||
self.orchBtn.clicked.connect(self.onOpenOrchDialog)
|
||||
self.debugBtn.clicked.connect(self.onDebugRun)
|
||||
self.zoomInBtn.clicked.connect(self.onZoomIn)
|
||||
self.zoomOutBtn.clicked.connect(self.onZoomOut)
|
||||
self.zoomResetBtn.clicked.connect(self.onZoomReset)
|
||||
self.copyBtn.clicked.connect(self.onCopy)
|
||||
self.BtnBox.accepted.connect(self.accept)
|
||||
self.BtnBox.rejected.connect(self.reject)
|
||||
self.OrchBtn.clicked.connect(self.onOpenOrchDialog)
|
||||
self.DebugBtn.clicked.connect(self.onDebugRun)
|
||||
self.ZoomInBtn.clicked.connect(self.onZoomIn)
|
||||
self.ZoomOutBtn.clicked.connect(self.onZoomOut)
|
||||
self.ZoomResetBtn.clicked.connect(self.onZoomReset)
|
||||
self.CopyBtn.clicked.connect(self.onCopy)
|
||||
|
||||
def getScript(
|
||||
self
|
||||
) -> str:
|
||||
|
||||
return self.textEdit.toPlainText()
|
||||
return self.TextEdit.toPlainText()
|
||||
|
||||
def updateFontSize(
|
||||
self
|
||||
):
|
||||
|
||||
self.textEdit.setStyleSheet(
|
||||
self.TextEdit.setStyleSheet(
|
||||
"QPlainTextEdit {"
|
||||
" font-family: 'Courier New', 'Consolas', monospace;"
|
||||
f" font-size: {self._fontSize}px;"
|
||||
"}"
|
||||
)
|
||||
self.zoomLabel.setText(f"{self._fontSize}px")
|
||||
self.ZoomLabel.setText(f"{self._fontSize}px")
|
||||
|
||||
@Slot()
|
||||
def insertTemplate(
|
||||
self
|
||||
):
|
||||
|
||||
btn = self.sender()
|
||||
if not isinstance(btn, QPushButton):
|
||||
Btn = self.sender()
|
||||
if not isinstance(Btn, QPushButton):
|
||||
return
|
||||
template = btn.property("template")
|
||||
template = Btn.property("template")
|
||||
if not template:
|
||||
return
|
||||
cursor = self.textEdit.textCursor()
|
||||
cursor = self.TextEdit.textCursor()
|
||||
cursor.insertText(template)
|
||||
|
||||
@Slot()
|
||||
@@ -611,11 +611,11 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
self
|
||||
):
|
||||
|
||||
clipboard = QApplication.clipboard()
|
||||
clipboard.setText(self.textEdit.toPlainText())
|
||||
self.copyBtn.setEnabled(False)
|
||||
Clipboard = QApplication.clipboard()
|
||||
Clipboard.setText(self.TextEdit.toPlainText())
|
||||
self.CopyBtn.setEnabled(False)
|
||||
QTimer.singleShot(2000, lambda: (
|
||||
self.copyBtn.setEnabled(True)
|
||||
self.CopyBtn.setEnabled(True)
|
||||
))
|
||||
|
||||
@Slot()
|
||||
@@ -624,20 +624,20 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
):
|
||||
|
||||
from gui.ALAutoScriptOrchDialog import ALAutoScriptOrchDialog
|
||||
dlg = ALAutoScriptOrchDialog(self)
|
||||
if dlg.exec() == QDialog.DialogCode.Accepted:
|
||||
script = dlg.getScript()
|
||||
Dlg = ALAutoScriptOrchDialog(self)
|
||||
if Dlg.exec() == QDialog.DialogCode.Accepted:
|
||||
script = Dlg.getScript()
|
||||
if script:
|
||||
cursor = self.textEdit.textCursor()
|
||||
cursor = self.TextEdit.textCursor()
|
||||
cursor.insertText(script)
|
||||
dlg.deleteLater()
|
||||
Dlg.deleteLater()
|
||||
|
||||
@Slot()
|
||||
def onDebugRun(
|
||||
self
|
||||
):
|
||||
|
||||
script = self.textEdit.toPlainText().strip()
|
||||
script = self.TextEdit.toPlainText().strip()
|
||||
if not script:
|
||||
QMessageBox.warning(self, "提示", "脚本内容为空。")
|
||||
return
|
||||
@@ -664,6 +664,6 @@ class ALAutoScriptEditDialog(QDialog):
|
||||
if not changes:
|
||||
QMessageBox.information(self, "调试运行", "目标变量未发生变化。")
|
||||
return
|
||||
dlg = _DebugResultDialog(changes, self)
|
||||
dlg.exec()
|
||||
dlg.deleteLater()
|
||||
Dlg = _DebugResultDialog(changes, self)
|
||||
Dlg.exec()
|
||||
Dlg.deleteLater()
|
||||
|
||||
@@ -57,81 +57,81 @@ class ConditionalBlock(QGroupBox):
|
||||
"margin-top: 5px; padding-top: 5px; }"
|
||||
)
|
||||
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
||||
mainLayout = QVBoxLayout(self)
|
||||
mainLayout.setSpacing(6)
|
||||
mainLayout.setContentsMargins(8, 8, 8, 8)
|
||||
headerLayout = QHBoxLayout()
|
||||
headerLayout.setSpacing(8)
|
||||
self.typeCombo = QComboBox(self)
|
||||
self.typeCombo.addItem("IF", "IF")
|
||||
self.typeCombo.addItem("ELSE IF", "ELSE IF")
|
||||
self.typeCombo.addItem("ELSE", "ELSE")
|
||||
self.typeCombo.setFixedHeight(25)
|
||||
MainLayout = QVBoxLayout(self)
|
||||
MainLayout.setSpacing(6)
|
||||
MainLayout.setContentsMargins(8, 8, 8, 8)
|
||||
HeaderLayout = QHBoxLayout()
|
||||
HeaderLayout.setSpacing(8)
|
||||
self.TypeCombo = QComboBox(self)
|
||||
self.TypeCombo.addItem("IF", "IF")
|
||||
self.TypeCombo.addItem("ELSE IF", "ELSE IF")
|
||||
self.TypeCombo.addItem("ELSE", "ELSE")
|
||||
self.TypeCombo.setFixedHeight(25)
|
||||
if self.blockIndex == 0:
|
||||
self.typeCombo.setEnabled(False)
|
||||
headerLayout.addWidget(QLabel("类型:", self))
|
||||
headerLayout.addWidget(self.typeCombo)
|
||||
headerLayout.addStretch()
|
||||
self.deleteBlockBtn = QPushButton("删除此块", self)
|
||||
self.deleteBlockBtn.setStyleSheet("color: red;")
|
||||
self.deleteBlockBtn.setFixedHeight(25)
|
||||
headerLayout.addWidget(self.deleteBlockBtn)
|
||||
mainLayout.addLayout(headerLayout)
|
||||
self.conditionWidget = QWidget(self)
|
||||
self.conditionWidget.setSizePolicy(
|
||||
self.TypeCombo.setEnabled(False)
|
||||
HeaderLayout.addWidget(QLabel("类型:", self))
|
||||
HeaderLayout.addWidget(self.TypeCombo)
|
||||
HeaderLayout.addStretch()
|
||||
self.DeleteBlockBtn = QPushButton("删除此块", self)
|
||||
self.DeleteBlockBtn.setStyleSheet("color: red;")
|
||||
self.DeleteBlockBtn.setFixedHeight(25)
|
||||
HeaderLayout.addWidget(self.DeleteBlockBtn)
|
||||
MainLayout.addLayout(HeaderLayout)
|
||||
self.ConditionWidget = QWidget(self)
|
||||
self.ConditionWidget.setSizePolicy(
|
||||
QSizePolicy.Preferred, QSizePolicy.Preferred
|
||||
)
|
||||
condLayout = QVBoxLayout(self.conditionWidget)
|
||||
condLayout.setContentsMargins(4, 4, 4, 4)
|
||||
condLayout.setSpacing(6)
|
||||
self.condRowsLayout = QVBoxLayout()
|
||||
self.condRowsLayout.setSpacing(4)
|
||||
condLayout.addLayout(self.condRowsLayout)
|
||||
self.addCondBtn = QPushButton("+ 添加条件", self.conditionWidget)
|
||||
self.addCondBtn.setFixedHeight(25)
|
||||
condLayout.addWidget(self.addCondBtn)
|
||||
mainLayout.addWidget(self.conditionWidget)
|
||||
self.actionLabel = QLabel("执行步骤:", self)
|
||||
self.actionLabel.setFixedHeight(25)
|
||||
mainLayout.addWidget(self.actionLabel)
|
||||
self.actionsLayout = QVBoxLayout()
|
||||
self.actionsLayout.setSpacing(4)
|
||||
mainLayout.addLayout(self.actionsLayout)
|
||||
self.addActionBtn = QPushButton("+ 添加执行步骤", self)
|
||||
self.addActionBtn.setFixedHeight(25)
|
||||
mainLayout.addWidget(self.addActionBtn)
|
||||
CondLayout = QVBoxLayout(self.ConditionWidget)
|
||||
CondLayout.setContentsMargins(4, 4, 4, 4)
|
||||
CondLayout.setSpacing(6)
|
||||
self.CondRowsLayout = QVBoxLayout()
|
||||
self.CondRowsLayout.setSpacing(4)
|
||||
CondLayout.addLayout(self.CondRowsLayout)
|
||||
self.AddCondBtn = QPushButton("+ 添加条件", self.ConditionWidget)
|
||||
self.AddCondBtn.setFixedHeight(25)
|
||||
CondLayout.addWidget(self.AddCondBtn)
|
||||
MainLayout.addWidget(self.ConditionWidget)
|
||||
self.ActionLabel = QLabel("执行步骤:", self)
|
||||
self.ActionLabel.setFixedHeight(25)
|
||||
MainLayout.addWidget(self.ActionLabel)
|
||||
self.ActionsLayout = QVBoxLayout()
|
||||
self.ActionsLayout.setSpacing(4)
|
||||
MainLayout.addLayout(self.ActionsLayout)
|
||||
self.AddActionBtn = QPushButton("+ 添加执行步骤", self)
|
||||
self.AddActionBtn.setFixedHeight(25)
|
||||
MainLayout.addWidget(self.AddActionBtn)
|
||||
self.setUpdatesEnabled(True)
|
||||
|
||||
def connectSignals(
|
||||
self
|
||||
):
|
||||
|
||||
self.typeCombo.currentIndexChanged.connect(self.onTypeChanged)
|
||||
self.addCondBtn.clicked.connect(self.addConditionRow)
|
||||
self.addActionBtn.clicked.connect(self.addActionStep)
|
||||
self.TypeCombo.currentIndexChanged.connect(self.onTypeChanged)
|
||||
self.AddCondBtn.clicked.connect(self.addConditionRow)
|
||||
self.AddActionBtn.clicked.connect(self.addActionStep)
|
||||
|
||||
def addInitialConditionRow(
|
||||
self
|
||||
):
|
||||
|
||||
row = ConditionRowFrame(
|
||||
Row = ConditionRowFrame(
|
||||
self._varMgr, self.blockIndex,
|
||||
isFirst=True, parent=self
|
||||
)
|
||||
self._conditionRows.append(row)
|
||||
self.condRowsLayout.addWidget(row)
|
||||
self._conditionRows.append(Row)
|
||||
self.CondRowsLayout.addWidget(Row)
|
||||
|
||||
def addConditionRow(
|
||||
self
|
||||
):
|
||||
|
||||
row = ConditionRowFrame(
|
||||
Row = ConditionRowFrame(
|
||||
self._varMgr, self.blockIndex,
|
||||
isFirst=False, parent=self
|
||||
)
|
||||
row.deleteBtn.clicked.connect(lambda: self.removeConditionRow(row))
|
||||
self._conditionRows.append(row)
|
||||
self.condRowsLayout.addWidget(row)
|
||||
Row.DeleteBtn.clicked.connect(lambda: self.removeConditionRow(Row))
|
||||
self._conditionRows.append(Row)
|
||||
self.CondRowsLayout.addWidget(Row)
|
||||
|
||||
def removeConditionRow(
|
||||
self,
|
||||
@@ -140,7 +140,7 @@ class ConditionalBlock(QGroupBox):
|
||||
|
||||
if row in self._conditionRows and len(self._conditionRows) > 1:
|
||||
self._conditionRows.remove(row)
|
||||
self.condRowsLayout.removeWidget(row)
|
||||
self.CondRowsLayout.removeWidget(row)
|
||||
row.hide()
|
||||
row.deleteLater()
|
||||
|
||||
@@ -148,10 +148,10 @@ class ConditionalBlock(QGroupBox):
|
||||
self
|
||||
):
|
||||
|
||||
step = ActionStepFrame(self._varMgr, self.blockIndex, parent=self)
|
||||
step.deleteBtn.clicked.connect(lambda: self.removeActionStep(step))
|
||||
self._actionWidgets.append(step)
|
||||
self.actionsLayout.addWidget(step)
|
||||
Step = ActionStepFrame(self._varMgr, self.blockIndex, parent=self)
|
||||
Step.DeleteBtn.clicked.connect(lambda: self.removeActionStep(Step))
|
||||
self._actionWidgets.append(Step)
|
||||
self.ActionsLayout.addWidget(Step)
|
||||
|
||||
def removeActionStep(
|
||||
self,
|
||||
@@ -160,7 +160,7 @@ class ConditionalBlock(QGroupBox):
|
||||
|
||||
if step in self._actionWidgets:
|
||||
self._actionWidgets.remove(step)
|
||||
self.actionsLayout.removeWidget(step)
|
||||
self.ActionsLayout.removeWidget(step)
|
||||
step.hide()
|
||||
step.deleteLater()
|
||||
|
||||
@@ -168,7 +168,7 @@ class ConditionalBlock(QGroupBox):
|
||||
self
|
||||
) -> str:
|
||||
|
||||
return self.typeCombo.currentData()
|
||||
return self.TypeCombo.currentData()
|
||||
|
||||
def getConditionRows(
|
||||
self
|
||||
@@ -239,18 +239,18 @@ class ConditionalBlock(QGroupBox):
|
||||
prevType: str | None
|
||||
):
|
||||
|
||||
model = self.typeCombo.model()
|
||||
model = self.TypeCombo.model()
|
||||
if model is None:
|
||||
return
|
||||
for data in ("ELSE IF", "ELSE"):
|
||||
idx = self.typeCombo.findData(data)
|
||||
idx = self.TypeCombo.findData(data)
|
||||
if idx < 0:
|
||||
continue
|
||||
item = model.item(idx)
|
||||
shouldEnable = prevType != "ELSE"
|
||||
item.setEnabled(shouldEnable)
|
||||
if prevType == "ELSE" and self.typeCombo.currentData() in ("ELSE IF", "ELSE"):
|
||||
self.typeCombo.setCurrentIndex(0)
|
||||
if prevType == "ELSE" and self.TypeCombo.currentData() in ("ELSE IF", "ELSE"):
|
||||
self.TypeCombo.setCurrentIndex(0)
|
||||
|
||||
@Slot(int)
|
||||
def onTypeChanged(
|
||||
@@ -258,8 +258,8 @@ class ConditionalBlock(QGroupBox):
|
||||
_idx
|
||||
):
|
||||
|
||||
isCond = self.typeCombo.currentData() in ("IF", "ELSE IF")
|
||||
self.conditionWidget.setVisible(isCond)
|
||||
self.actionLabel.setText(
|
||||
isCond = self.TypeCombo.currentData() in ("IF", "ELSE IF")
|
||||
self.ConditionWidget.setVisible(isCond)
|
||||
self.ActionLabel.setText(
|
||||
"执行步骤:" if isCond else "ELSE 执行步骤:"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ class ALAutoScriptOrchDialog(QDialog):
|
||||
self.setupUi()
|
||||
self.connectSignals()
|
||||
self.addBlock()
|
||||
self.scrollLayout.addStretch()
|
||||
self.ScrollLayout.addStretch()
|
||||
|
||||
def setupUi(
|
||||
self
|
||||
@@ -49,33 +49,33 @@ class ALAutoScriptOrchDialog(QDialog):
|
||||
self.setWindowTitle("AutoScript 指令编排 - AutoLibrary")
|
||||
self.setMinimumSize(640, 600)
|
||||
self.setModal(True)
|
||||
mainLayout = QVBoxLayout(self)
|
||||
scroll = QScrollArea()
|
||||
scroll.setWidgetResizable(True)
|
||||
scroll.setFrameShape(QFrame.NoFrame)
|
||||
scrollContent = QWidget()
|
||||
self.scrollLayout = QVBoxLayout(scrollContent)
|
||||
self.scrollLayout.setSpacing(5)
|
||||
scroll.setWidget(scrollContent)
|
||||
mainLayout.addWidget(scroll)
|
||||
self.addBlockBtn = QPushButton("+ 添加判断块")
|
||||
self.addBlockBtn.setFixedHeight(25)
|
||||
mainLayout.addWidget(self.addBlockBtn)
|
||||
self.btnBox = QDialogButtonBox(
|
||||
MainLayout = QVBoxLayout(self)
|
||||
Scroll = QScrollArea()
|
||||
Scroll.setWidgetResizable(True)
|
||||
Scroll.setFrameShape(QFrame.NoFrame)
|
||||
ScrollContent = QWidget()
|
||||
self.ScrollLayout = QVBoxLayout(ScrollContent)
|
||||
self.ScrollLayout.setSpacing(5)
|
||||
Scroll.setWidget(ScrollContent)
|
||||
MainLayout.addWidget(Scroll)
|
||||
self.AddBlockBtn = QPushButton("+ 添加判断块")
|
||||
self.AddBlockBtn.setFixedHeight(25)
|
||||
MainLayout.addWidget(self.AddBlockBtn)
|
||||
self.BtnBox = QDialogButtonBox(
|
||||
QDialogButtonBox.StandardButton.Ok |
|
||||
QDialogButtonBox.StandardButton.Cancel
|
||||
)
|
||||
self.btnBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定")
|
||||
self.btnBox.button(QDialogButtonBox.StandardButton.Cancel).setText("取消")
|
||||
mainLayout.addWidget(self.btnBox)
|
||||
self.BtnBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定")
|
||||
self.BtnBox.button(QDialogButtonBox.StandardButton.Cancel).setText("取消")
|
||||
MainLayout.addWidget(self.BtnBox)
|
||||
|
||||
def connectSignals(
|
||||
self
|
||||
):
|
||||
|
||||
self.btnBox.accepted.connect(self.onAccept)
|
||||
self.btnBox.rejected.connect(self.reject)
|
||||
self.addBlockBtn.clicked.connect(self.addBlock)
|
||||
self.BtnBox.accepted.connect(self.onAccept)
|
||||
self.BtnBox.rejected.connect(self.reject)
|
||||
self.AddBlockBtn.clicked.connect(self.addBlock)
|
||||
|
||||
def updateBlockTypeRestrictions(
|
||||
self
|
||||
@@ -90,24 +90,24 @@ class ALAutoScriptOrchDialog(QDialog):
|
||||
self
|
||||
):
|
||||
|
||||
block = ConditionalBlock(
|
||||
Block = ConditionalBlock(
|
||||
len(self._blocks), self._varMgr, parent=self
|
||||
)
|
||||
block.deleteBlockBtn.clicked.connect(lambda: self.removeBlock(block))
|
||||
block.typeCombo.currentIndexChanged.connect(self.updateBlockTypeRestrictions)
|
||||
block.addActionStep()
|
||||
self._blocks.append(block)
|
||||
Block.DeleteBlockBtn.clicked.connect(lambda: self.removeBlock(Block))
|
||||
Block.TypeCombo.currentIndexChanged.connect(self.updateBlockTypeRestrictions)
|
||||
Block.addActionStep()
|
||||
self._blocks.append(Block)
|
||||
self.updateBlockTypeRestrictions()
|
||||
if self.scrollLayout.count() > 0:
|
||||
lastItem = self.scrollLayout.itemAt(
|
||||
self.scrollLayout.count() - 1
|
||||
if self.ScrollLayout.count() > 0:
|
||||
lastItem = self.ScrollLayout.itemAt(
|
||||
self.ScrollLayout.count() - 1
|
||||
)
|
||||
if lastItem and lastItem.spacerItem():
|
||||
self.scrollLayout.insertWidget(
|
||||
self.scrollLayout.count() - 1, block
|
||||
self.ScrollLayout.insertWidget(
|
||||
self.ScrollLayout.count() - 1, Block
|
||||
)
|
||||
return
|
||||
self.scrollLayout.addWidget(block)
|
||||
self.ScrollLayout.addWidget(Block)
|
||||
|
||||
def removeBlock(
|
||||
self,
|
||||
@@ -119,16 +119,16 @@ class ALAutoScriptOrchDialog(QDialog):
|
||||
return
|
||||
if block in self._blocks:
|
||||
self._blocks.remove(block)
|
||||
self.scrollLayout.removeWidget(block)
|
||||
self.ScrollLayout.removeWidget(block)
|
||||
block.hide()
|
||||
block.deleteLater()
|
||||
for i, blk in enumerate(self._blocks):
|
||||
blk.blockIndex = i
|
||||
if i == 0:
|
||||
blk.typeCombo.setEnabled(False)
|
||||
blk.typeCombo.setCurrentIndex(0)
|
||||
blk.TypeCombo.setEnabled(False)
|
||||
blk.TypeCombo.setCurrentIndex(0)
|
||||
else:
|
||||
blk.typeCombo.setEnabled(True)
|
||||
blk.TypeCombo.setEnabled(True)
|
||||
blk.refreshVarCombos()
|
||||
self.updateBlockTypeRestrictions()
|
||||
|
||||
|
||||
@@ -110,39 +110,39 @@ class _DateInputContainer(QWidget):
|
||||
self
|
||||
):
|
||||
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(4)
|
||||
self._modeCombo = QComboBox(self)
|
||||
self._modeCombo.addItem("相对日期", "relative")
|
||||
self._modeCombo.addItem("绝对日期", "absolute")
|
||||
self._modeCombo.setFixedHeight(25)
|
||||
self._stack = QStackedWidget(self)
|
||||
self._relCombo = QComboBox(self)
|
||||
Layout = QHBoxLayout(self)
|
||||
Layout.setContentsMargins(0, 0, 0, 0)
|
||||
Layout.setSpacing(4)
|
||||
self._ModeCombo = QComboBox(self)
|
||||
self._ModeCombo.addItem("相对日期", "relative")
|
||||
self._ModeCombo.addItem("绝对日期", "absolute")
|
||||
self._ModeCombo.setFixedHeight(25)
|
||||
self._Stack = QStackedWidget(self)
|
||||
self._RelCombo = QComboBox(self)
|
||||
for display, data in DATE_OPTIONS:
|
||||
self._relCombo.addItem(display, data)
|
||||
self._relCombo.setFixedHeight(25)
|
||||
self._stack.addWidget(self._relCombo)
|
||||
self._dateEdit = QDateEdit(self)
|
||||
self._dateEdit.setDisplayFormat("yyyy-MM-dd")
|
||||
self._dateEdit.setCalendarPopup(True)
|
||||
self._dateEdit.setFixedHeight(25)
|
||||
self._stack.addWidget(self._dateEdit)
|
||||
self._modeCombo.currentIndexChanged.connect(
|
||||
lambda i: self._stack.setCurrentIndex(i)
|
||||
self._RelCombo.addItem(display, data)
|
||||
self._RelCombo.setFixedHeight(25)
|
||||
self._Stack.addWidget(self._RelCombo)
|
||||
self._DateEdit = QDateEdit(self)
|
||||
self._DateEdit.setDisplayFormat("yyyy-MM-dd")
|
||||
self._DateEdit.setCalendarPopup(True)
|
||||
self._DateEdit.setFixedHeight(25)
|
||||
self._Stack.addWidget(self._DateEdit)
|
||||
self._ModeCombo.currentIndexChanged.connect(
|
||||
lambda i: self._Stack.setCurrentIndex(i)
|
||||
)
|
||||
layout.addWidget(self._modeCombo)
|
||||
layout.addWidget(self._stack)
|
||||
layout.addStretch()
|
||||
Layout.addWidget(self._ModeCombo)
|
||||
Layout.addWidget(self._Stack)
|
||||
Layout.addStretch()
|
||||
|
||||
def getValue(
|
||||
self
|
||||
) -> str:
|
||||
|
||||
mode = self._modeCombo.currentData()
|
||||
mode = self._ModeCombo.currentData()
|
||||
if mode == "relative":
|
||||
return self._relCombo.currentText()
|
||||
return self._dateEdit.date().toString("yyyy-MM-dd")
|
||||
return self._RelCombo.currentText()
|
||||
return self._DateEdit.date().toString("yyyy-MM-dd")
|
||||
|
||||
|
||||
class _TimeInputContainer(QWidget):
|
||||
@@ -153,19 +153,19 @@ class _TimeInputContainer(QWidget):
|
||||
):
|
||||
|
||||
super().__init__(parent)
|
||||
self._timeEdit = QTimeEdit(self)
|
||||
self._timeEdit.setDisplayFormat("HH:mm")
|
||||
self._timeEdit.setFixedHeight(25)
|
||||
self._TimeEdit = QTimeEdit(self)
|
||||
self._TimeEdit.setDisplayFormat("HH:mm")
|
||||
self._TimeEdit.setFixedHeight(25)
|
||||
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.addWidget(self._timeEdit)
|
||||
Layout = QHBoxLayout(self)
|
||||
Layout.setContentsMargins(0, 0, 0, 0)
|
||||
Layout.addWidget(self._TimeEdit)
|
||||
|
||||
def getValue(
|
||||
self
|
||||
) -> str:
|
||||
|
||||
return self._timeEdit.time().toString("HH:mm")
|
||||
return self._TimeEdit.time().toString("HH:mm")
|
||||
|
||||
|
||||
class _DateOffsetContainer(QWidget):
|
||||
@@ -176,20 +176,20 @@ class _DateOffsetContainer(QWidget):
|
||||
):
|
||||
|
||||
super().__init__(parent)
|
||||
self._spinBox = QSpinBox(self)
|
||||
self._spinBox.setRange(0, 99999)
|
||||
self._spinBox.setFixedHeight(25)
|
||||
self._unitCombo = QComboBox(self)
|
||||
self._SpinBox = QSpinBox(self)
|
||||
self._SpinBox.setRange(0, 99999)
|
||||
self._SpinBox.setFixedHeight(25)
|
||||
self._UnitCombo = QComboBox(self)
|
||||
for display, data in DATE_OFFSET_OPTIONS:
|
||||
self._unitCombo.addItem(display, data)
|
||||
self._unitCombo.setFixedHeight(25)
|
||||
self._UnitCombo.addItem(display, data)
|
||||
self._UnitCombo.setFixedHeight(25)
|
||||
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(4)
|
||||
layout.addWidget(self._spinBox)
|
||||
layout.addWidget(self._unitCombo)
|
||||
layout.addStretch()
|
||||
Layout = QHBoxLayout(self)
|
||||
Layout.setContentsMargins(0, 0, 0, 0)
|
||||
Layout.setSpacing(4)
|
||||
Layout.addWidget(self._SpinBox)
|
||||
Layout.addWidget(self._UnitCombo)
|
||||
Layout.addStretch()
|
||||
|
||||
def getValue(
|
||||
self
|
||||
@@ -201,8 +201,8 @@ class _DateOffsetContainer(QWidget):
|
||||
self
|
||||
) -> int:
|
||||
|
||||
val = self._spinBox.value()
|
||||
unit = self._unitCombo.currentData()
|
||||
val = self._SpinBox.value()
|
||||
unit = self._UnitCombo.currentData()
|
||||
if unit == "weeks":
|
||||
return val*7
|
||||
if unit == "months":
|
||||
@@ -220,14 +220,14 @@ class _TimeOffsetContainer(QWidget):
|
||||
):
|
||||
|
||||
super().__init__(parent)
|
||||
self._spinBox = QSpinBox(self)
|
||||
self._spinBox.setRange(0, 99999)
|
||||
self._spinBox.setSuffix(" 小时")
|
||||
self._spinBox.setFixedHeight(25)
|
||||
self._SpinBox = QSpinBox(self)
|
||||
self._SpinBox.setRange(0, 99999)
|
||||
self._SpinBox.setSuffix(" 小时")
|
||||
self._SpinBox.setFixedHeight(25)
|
||||
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.addWidget(self._spinBox)
|
||||
Layout = QHBoxLayout(self)
|
||||
Layout.setContentsMargins(0, 0, 0, 0)
|
||||
Layout.addWidget(self._SpinBox)
|
||||
|
||||
def getValue(
|
||||
self
|
||||
@@ -239,7 +239,7 @@ class _TimeOffsetContainer(QWidget):
|
||||
self
|
||||
) -> int:
|
||||
|
||||
return self._spinBox.value()
|
||||
return self._SpinBox.value()
|
||||
|
||||
|
||||
class VariableManager(QObject):
|
||||
@@ -364,11 +364,11 @@ def makeVarRefCombo(
|
||||
parent: QWidget = None
|
||||
) -> QComboBox:
|
||||
|
||||
cb = QComboBox(parent)
|
||||
cb.setFixedHeight(25)
|
||||
cb.setMinimumWidth(120)
|
||||
cb.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
return cb
|
||||
Cb = QComboBox(parent)
|
||||
Cb.setFixedHeight(25)
|
||||
Cb.setMinimumWidth(120)
|
||||
Cb.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
return Cb
|
||||
|
||||
def makeComboWidget(
|
||||
items,
|
||||
@@ -376,12 +376,12 @@ def makeComboWidget(
|
||||
parent: QWidget = None
|
||||
) -> QComboBox:
|
||||
|
||||
cb = QComboBox(parent)
|
||||
Cb = QComboBox(parent)
|
||||
for display, data in items:
|
||||
cb.addItem(display, data)
|
||||
cb.setFixedHeight(25)
|
||||
cb.setMinimumWidth(min_width)
|
||||
return cb
|
||||
Cb.addItem(display, data)
|
||||
Cb.setFixedHeight(25)
|
||||
Cb.setMinimumWidth(min_width)
|
||||
return Cb
|
||||
|
||||
def makeLabel(
|
||||
text: str,
|
||||
@@ -389,11 +389,11 @@ def makeLabel(
|
||||
width: int = None
|
||||
) -> QLabel:
|
||||
|
||||
lbl = QLabel(text, parent)
|
||||
lbl.setFixedHeight(25)
|
||||
Lbl = QLabel(text, parent)
|
||||
Lbl.setFixedHeight(25)
|
||||
if width:
|
||||
lbl.setFixedWidth(width)
|
||||
return lbl
|
||||
Lbl.setFixedWidth(width)
|
||||
return Lbl
|
||||
|
||||
def getValueFromWidget(
|
||||
w: QWidget
|
||||
|
||||
@@ -66,42 +66,42 @@ class ConditionRowFrame(QFrame):
|
||||
self.setFrameShape(QFrame.StyledPanel)
|
||||
self.setFrameShadow(QFrame.Raised)
|
||||
self.setFixedHeight(32)
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(2, 2, 2, 2)
|
||||
layout.setSpacing(4)
|
||||
Layout = QHBoxLayout(self)
|
||||
Layout.setContentsMargins(2, 2, 2, 2)
|
||||
Layout.setSpacing(4)
|
||||
if self._isFirst:
|
||||
self.logicCombo = None
|
||||
self.LogicCombo = None
|
||||
else:
|
||||
self.logicCombo = makeComboWidget(LOGIC_OPTIONS, min_width=110, parent=self)
|
||||
layout.addWidget(self.logicCombo)
|
||||
self.leftVarCombo = QComboBox(self)
|
||||
self.leftVarCombo.setFixedHeight(25)
|
||||
self.leftVarCombo.setMinimumWidth(120)
|
||||
self.leftVarCombo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
self.LogicCombo = makeComboWidget(LOGIC_OPTIONS, min_width=110, parent=self)
|
||||
Layout.addWidget(self.LogicCombo)
|
||||
self.LeftVarCombo = QComboBox(self)
|
||||
self.LeftVarCombo.setFixedHeight(25)
|
||||
self.LeftVarCombo.setMinimumWidth(120)
|
||||
self.LeftVarCombo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
self.populateLeftVarCombo()
|
||||
layout.addWidget(self.leftVarCombo)
|
||||
self.opCombo = makeComboWidget(COMPARE_OPTIONS, min_width=80, parent=self)
|
||||
layout.addWidget(self.opCombo)
|
||||
self._compTypeCombo = makeComboWidget([
|
||||
Layout.addWidget(self.LeftVarCombo)
|
||||
self.OpCombo = makeComboWidget(COMPARE_OPTIONS, min_width=80, parent=self)
|
||||
Layout.addWidget(self.OpCombo)
|
||||
self._CompTypeCombo = makeComboWidget([
|
||||
("特定值", "literal"),
|
||||
("变量", "variable"),
|
||||
], min_width=70, parent=self)
|
||||
layout.addWidget(self._compTypeCombo)
|
||||
self.rhsStack = QStackedWidget(self)
|
||||
self.rhsStack.setFixedHeight(25)
|
||||
Layout.addWidget(self._CompTypeCombo)
|
||||
self.RhsStack = QStackedWidget(self)
|
||||
self.RhsStack.setFixedHeight(25)
|
||||
self.initLiteralStack()
|
||||
self.rhsVarCombo = makeVarRefCombo(self)
|
||||
self.rhsStack.addWidget(self.rhsVarCombo)
|
||||
self.rhsStack.setCurrentIndex(0)
|
||||
layout.addWidget(self.rhsStack)
|
||||
self.RhsVarCombo = makeVarRefCombo(self)
|
||||
self.RhsStack.addWidget(self.RhsVarCombo)
|
||||
self.RhsStack.setCurrentIndex(0)
|
||||
Layout.addWidget(self.RhsStack)
|
||||
if not self._isFirst:
|
||||
self.deleteBtn = QPushButton("×", self)
|
||||
self.deleteBtn.setFixedSize(25, 25)
|
||||
self.deleteBtn.setStyleSheet("color: red; font-weight: bold;")
|
||||
layout.addWidget(self.deleteBtn)
|
||||
self.DeleteBtn = QPushButton("×", self)
|
||||
self.DeleteBtn.setFixedSize(25, 25)
|
||||
self.DeleteBtn.setStyleSheet("color: red; font-weight: bold;")
|
||||
Layout.addWidget(self.DeleteBtn)
|
||||
else:
|
||||
self.deleteBtn = None
|
||||
layout.addStretch()
|
||||
self.DeleteBtn = None
|
||||
Layout.addStretch()
|
||||
self.setUpdatesEnabled(True)
|
||||
|
||||
def populateLeftVarCombo(
|
||||
@@ -111,53 +111,53 @@ class ConditionRowFrame(QFrame):
|
||||
wasBool = self._isBoolMode
|
||||
boolName = None
|
||||
if wasBool:
|
||||
data = self.leftVarCombo.currentData()
|
||||
data = self.LeftVarCombo.currentData()
|
||||
if data:
|
||||
boolName = data[0]
|
||||
self._varMgr.populateCombo(self.leftVarCombo)
|
||||
self._varMgr.populateCombo(self.LeftVarCombo)
|
||||
# Append boolean literal sentinels at the end
|
||||
self.leftVarCombo.insertSeparator(self.leftVarCombo.count())
|
||||
self.leftVarCombo.addItem("true", ("true", "Boolean"))
|
||||
self.leftVarCombo.addItem("false", ("false", "Boolean"))
|
||||
self.LeftVarCombo.insertSeparator(self.LeftVarCombo.count())
|
||||
self.LeftVarCombo.addItem("true", ("true", "Boolean"))
|
||||
self.LeftVarCombo.addItem("false", ("false", "Boolean"))
|
||||
if wasBool and boolName:
|
||||
for ci in range(self.leftVarCombo.count()):
|
||||
d = self.leftVarCombo.itemData(ci)
|
||||
for ci in range(self.LeftVarCombo.count()):
|
||||
d = self.LeftVarCombo.itemData(ci)
|
||||
if d and d[0] == boolName:
|
||||
self.leftVarCombo.setCurrentIndex(ci)
|
||||
self.LeftVarCombo.setCurrentIndex(ci)
|
||||
break
|
||||
|
||||
def populateRHSVarCombo(
|
||||
self
|
||||
):
|
||||
|
||||
self._varMgr.populateCombo(self.rhsVarCombo)
|
||||
self._varMgr.populateCombo(self.RhsVarCombo)
|
||||
|
||||
def initLiteralStack(
|
||||
self
|
||||
):
|
||||
|
||||
self.literalStack = QStackedWidget(self)
|
||||
self.literalStack.setFixedHeight(25)
|
||||
self.LiteralStack = QStackedWidget(self)
|
||||
self.LiteralStack.setFixedHeight(25)
|
||||
self._literalWidgets = {}
|
||||
for vt in getTypeOrder():
|
||||
w = makeValueWidget(vt, self.literalStack)
|
||||
self._literalWidgets[vt] = w
|
||||
self.literalStack.addWidget(w)
|
||||
self.literalStack.setCurrentWidget(self._literalWidgets.get("String"))
|
||||
self.rhsStack.addWidget(self.literalStack)
|
||||
W = makeValueWidget(vt, self.LiteralStack)
|
||||
self._literalWidgets[vt] = W
|
||||
self.LiteralStack.addWidget(W)
|
||||
self.LiteralStack.setCurrentWidget(self._literalWidgets.get("String"))
|
||||
self.RhsStack.addWidget(self.LiteralStack)
|
||||
|
||||
def connectSignals(
|
||||
self
|
||||
):
|
||||
|
||||
self.leftVarCombo.currentIndexChanged.connect(self.onLeftVarChanged)
|
||||
self._compTypeCombo.currentIndexChanged.connect(self.onCompTypeChanged)
|
||||
self.LeftVarCombo.currentIndexChanged.connect(self.onLeftVarChanged)
|
||||
self._CompTypeCombo.currentIndexChanged.connect(self.onCompTypeChanged)
|
||||
|
||||
def getLogic(
|
||||
self
|
||||
) -> str:
|
||||
|
||||
return self.logicCombo.currentData() if self.logicCombo else ""
|
||||
return self.LogicCombo.currentData() if self.LogicCombo else ""
|
||||
|
||||
def updateRHSLiteralWidget(
|
||||
self,
|
||||
@@ -166,13 +166,13 @@ class ConditionRowFrame(QFrame):
|
||||
|
||||
if vartype not in self._literalWidgets:
|
||||
vartype = "String"
|
||||
self.literalStack.setCurrentWidget(self._literalWidgets[vartype])
|
||||
self.LiteralStack.setCurrentWidget(self._literalWidgets[vartype])
|
||||
|
||||
def toScript(
|
||||
self
|
||||
) -> str:
|
||||
|
||||
data = self.leftVarCombo.currentData()
|
||||
data = self.LeftVarCombo.currentData()
|
||||
if self._isBoolMode and data:
|
||||
return data[0]
|
||||
if not data:
|
||||
@@ -183,12 +183,12 @@ class ConditionRowFrame(QFrame):
|
||||
name = "datenow()"
|
||||
elif name == "CURRENT_TIME":
|
||||
name = "timenow()"
|
||||
opSym = self.opCombo.currentData()
|
||||
opSym = self.OpCombo.currentData()
|
||||
if self._rawRhsExpr:
|
||||
return f"{name} {opSym} {self._rawRhsExpr}"
|
||||
isVarRef = (self._compTypeCombo.currentData() == "variable")
|
||||
isVarRef = (self._CompTypeCombo.currentData() == "variable")
|
||||
if isVarRef:
|
||||
rd = self.rhsVarCombo.currentData()
|
||||
rd = self.RhsVarCombo.currentData()
|
||||
if rd:
|
||||
rhsName = rd[0]
|
||||
if rhsName == "CURRENT_DATE":
|
||||
@@ -196,7 +196,7 @@ class ConditionRowFrame(QFrame):
|
||||
elif rhsName == "CURRENT_TIME":
|
||||
rhsName = "timenow()"
|
||||
return f"{name} {opSym} {rhsName}"
|
||||
rhsText = self.rhsVarCombo.currentText().strip()
|
||||
rhsText = self.RhsVarCombo.currentText().strip()
|
||||
if rhsText:
|
||||
return f"{name} {opSym} {rhsText}"
|
||||
return ""
|
||||
@@ -223,15 +223,15 @@ class ConditionRowFrame(QFrame):
|
||||
self._rawRhsExpr = ""
|
||||
if idx < 0:
|
||||
return
|
||||
data = self.leftVarCombo.itemData(idx)
|
||||
data = self.LeftVarCombo.itemData(idx)
|
||||
if not data:
|
||||
return
|
||||
name, vartype = data
|
||||
isBool = name in ("true", "false")
|
||||
self._isBoolMode = isBool
|
||||
self.opCombo.setVisible(not isBool)
|
||||
self._compTypeCombo.setVisible(not isBool)
|
||||
self.rhsStack.setVisible(not isBool)
|
||||
self.OpCombo.setVisible(not isBool)
|
||||
self._CompTypeCombo.setVisible(not isBool)
|
||||
self.RhsStack.setVisible(not isBool)
|
||||
if not isBool:
|
||||
self.updateRHSLiteralWidget(vartype)
|
||||
|
||||
@@ -242,8 +242,8 @@ class ConditionRowFrame(QFrame):
|
||||
):
|
||||
|
||||
self._rawRhsExpr = ""
|
||||
isVar = (self._compTypeCombo.currentData() == "variable")
|
||||
self.rhsStack.setCurrentIndex(1 if isVar else 0)
|
||||
isVar = (self._CompTypeCombo.currentData() == "variable")
|
||||
self.RhsStack.setCurrentIndex(1 if isVar else 0)
|
||||
if isVar:
|
||||
self.populateRHSVarCombo()
|
||||
|
||||
@@ -273,52 +273,52 @@ class ActionStepFrame(QFrame):
|
||||
self.setFrameShape(QFrame.StyledPanel)
|
||||
self.setFrameShadow(QFrame.Raised)
|
||||
self.setFixedHeight(35)
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(2, 2, 2, 2)
|
||||
layout.setSpacing(4)
|
||||
self.opTypeCombo = makeComboWidget(ACTION_OPTIONS, min_width=70, parent=self)
|
||||
layout.addWidget(self.opTypeCombo)
|
||||
layout.addWidget(makeLabel("设置", self))
|
||||
self.targetCombo = QComboBox(self)
|
||||
self.targetCombo.setFixedHeight(25)
|
||||
self.targetCombo.setMinimumWidth(120)
|
||||
Layout = QHBoxLayout(self)
|
||||
Layout.setContentsMargins(2, 2, 2, 2)
|
||||
Layout.setSpacing(4)
|
||||
self.OpTypeCombo = makeComboWidget(ACTION_OPTIONS, min_width=70, parent=self)
|
||||
Layout.addWidget(self.OpTypeCombo)
|
||||
Layout.addWidget(makeLabel("设置", self))
|
||||
self.TargetCombo = QComboBox(self)
|
||||
self.TargetCombo.setFixedHeight(25)
|
||||
self.TargetCombo.setMinimumWidth(120)
|
||||
self.populateTargetCombo()
|
||||
layout.addWidget(self.targetCombo)
|
||||
layout.addWidget(makeLabel("为", self))
|
||||
self.valueSrcCombo = makeComboWidget([
|
||||
Layout.addWidget(self.TargetCombo)
|
||||
Layout.addWidget(makeLabel("为", self))
|
||||
self.ValueSrcCombo = makeComboWidget([
|
||||
("特定值", "literal"),
|
||||
("变量", "variable"),
|
||||
], min_width=70, parent=self)
|
||||
layout.addWidget(self.valueSrcCombo)
|
||||
self.valueStack = QStackedWidget(self)
|
||||
self.valueStack.setFixedHeight(25)
|
||||
Layout.addWidget(self.ValueSrcCombo)
|
||||
self.ValueStack = QStackedWidget(self)
|
||||
self.ValueStack.setFixedHeight(25)
|
||||
self.initValueStacks()
|
||||
layout.addWidget(self.valueStack)
|
||||
self.existingVarCombo = makeVarRefCombo(self)
|
||||
self.existingVarCombo.setVisible(False)
|
||||
layout.addWidget(self.existingVarCombo)
|
||||
self.deleteBtn = QPushButton("×", self)
|
||||
self.deleteBtn.setFixedSize(25, 25)
|
||||
self.deleteBtn.setStyleSheet("color: red; font-weight: bold;")
|
||||
layout.addWidget(self.deleteBtn)
|
||||
Layout.addWidget(self.ValueStack)
|
||||
self.ExistingVarCombo = makeVarRefCombo(self)
|
||||
self.ExistingVarCombo.setVisible(False)
|
||||
Layout.addWidget(self.ExistingVarCombo)
|
||||
self.DeleteBtn = QPushButton("×", self)
|
||||
self.DeleteBtn.setFixedSize(25, 25)
|
||||
self.DeleteBtn.setStyleSheet("color: red; font-weight: bold;")
|
||||
Layout.addWidget(self.DeleteBtn)
|
||||
self.setUpdatesEnabled(True)
|
||||
|
||||
def populateTargetCombo(
|
||||
self
|
||||
):
|
||||
|
||||
self.targetCombo.blockSignals(True)
|
||||
self.targetCombo.clear()
|
||||
self.TargetCombo.blockSignals(True)
|
||||
self.TargetCombo.clear()
|
||||
for p in getPresetVars():
|
||||
if p["name"] in ("CURRENT_TIME", "CURRENT_DATE"):
|
||||
continue
|
||||
info = self._varMgr.getInfoByName(p["name"])
|
||||
if info:
|
||||
self.targetCombo.addItem(
|
||||
self.TargetCombo.addItem(
|
||||
info["display"],
|
||||
(info["name"], info["type"])
|
||||
)
|
||||
self.targetCombo.blockSignals(False)
|
||||
self.TargetCombo.blockSignals(False)
|
||||
|
||||
def initValueStacks(
|
||||
self
|
||||
@@ -327,45 +327,45 @@ class ActionStepFrame(QFrame):
|
||||
self._literalWidgets = {}
|
||||
self._offsetWidgets = {}
|
||||
for vt in getTypeOrder():
|
||||
self._literalWidgets[vt] = makeValueWidget(vt, self.valueStack)
|
||||
self.valueStack.addWidget(self._literalWidgets[vt])
|
||||
self._literalWidgets[vt] = makeValueWidget(vt, self.ValueStack)
|
||||
self.ValueStack.addWidget(self._literalWidgets[vt])
|
||||
if getArithType(vt):
|
||||
self._offsetWidgets[vt] = makeOffsetWidget(vt, self.valueStack)
|
||||
self.valueStack.addWidget(self._offsetWidgets[vt])
|
||||
self._offsetWidgets[vt] = makeOffsetWidget(vt, self.ValueStack)
|
||||
self.ValueStack.addWidget(self._offsetWidgets[vt])
|
||||
else:
|
||||
lbl = QLabel("(不支持该操作)", self.valueStack)
|
||||
lbl.setFixedHeight(25)
|
||||
self._offsetWidgets[vt] = lbl
|
||||
self.valueStack.addWidget(lbl)
|
||||
Lbl = QLabel("(不支持该操作)", self.ValueStack)
|
||||
Lbl.setFixedHeight(25)
|
||||
self._offsetWidgets[vt] = Lbl
|
||||
self.ValueStack.addWidget(Lbl)
|
||||
|
||||
def connectSignals(
|
||||
self
|
||||
):
|
||||
|
||||
self.opTypeCombo.currentIndexChanged.connect(self.onOpTypeChanged)
|
||||
self.targetCombo.currentIndexChanged.connect(self.onTargetChanged)
|
||||
self.valueSrcCombo.currentIndexChanged.connect(self.onValueSrcChanged)
|
||||
self.OpTypeCombo.currentIndexChanged.connect(self.onOpTypeChanged)
|
||||
self.TargetCombo.currentIndexChanged.connect(self.onTargetChanged)
|
||||
self.ValueSrcCombo.currentIndexChanged.connect(self.onValueSrcChanged)
|
||||
|
||||
def getTargetName(
|
||||
self
|
||||
) -> str:
|
||||
|
||||
data = self.targetCombo.currentData()
|
||||
data = self.TargetCombo.currentData()
|
||||
return data[0] if data else ""
|
||||
|
||||
def updateValueWidget(
|
||||
self
|
||||
):
|
||||
|
||||
op = self.opTypeCombo.currentData()
|
||||
op = self.OpTypeCombo.currentData()
|
||||
isArith = (op in ("add", "sub"))
|
||||
actualType = self._currentTargetType
|
||||
if isArith and actualType in self._offsetWidgets:
|
||||
self.valueStack.setCurrentWidget(self._offsetWidgets[actualType])
|
||||
self.ValueStack.setCurrentWidget(self._offsetWidgets[actualType])
|
||||
elif actualType in self._literalWidgets:
|
||||
self.valueStack.setCurrentWidget(self._literalWidgets[actualType])
|
||||
self.ValueStack.setCurrentWidget(self._literalWidgets[actualType])
|
||||
else:
|
||||
self.valueStack.setCurrentWidget(self._literalWidgets.get("String"))
|
||||
self.ValueStack.setCurrentWidget(self._literalWidgets.get("String"))
|
||||
|
||||
def toScript(
|
||||
self
|
||||
@@ -375,7 +375,7 @@ class ActionStepFrame(QFrame):
|
||||
"""
|
||||
|
||||
target = self.getTargetName()
|
||||
op = self.opTypeCombo.currentData()
|
||||
op = self.OpTypeCombo.currentData()
|
||||
if op == "pass":
|
||||
return " -- pass"
|
||||
if not target:
|
||||
@@ -386,19 +386,19 @@ class ActionStepFrame(QFrame):
|
||||
encoded = encodeValueStr(rawVal, vartype)
|
||||
return f" {target} = {encoded}"
|
||||
elif op == "add":
|
||||
if vartype == "Date" and hasattr(self.valueStack.currentWidget(), "getOffsetDays"):
|
||||
days = self.valueStack.currentWidget().getOffsetDays()
|
||||
if vartype == "Date" and hasattr(self.ValueStack.currentWidget(), "getOffsetDays"):
|
||||
days = self.ValueStack.currentWidget().getOffsetDays()
|
||||
return f" {target} = dateadd({target}, {days})"
|
||||
if vartype == "Time" and hasattr(self.valueStack.currentWidget(), "getOffsetHours"):
|
||||
hours = self.valueStack.currentWidget().getOffsetHours()
|
||||
if vartype == "Time" and hasattr(self.ValueStack.currentWidget(), "getOffsetHours"):
|
||||
hours = self.ValueStack.currentWidget().getOffsetHours()
|
||||
return f" {target} = timeadd({target}, {hours})"
|
||||
return f" {target} = {target} + {rawVal}"
|
||||
elif op == "sub":
|
||||
if vartype == "Date" and hasattr(self.valueStack.currentWidget(), "getOffsetDays"):
|
||||
days = self.valueStack.currentWidget().getOffsetDays()
|
||||
if vartype == "Date" and hasattr(self.ValueStack.currentWidget(), "getOffsetDays"):
|
||||
days = self.ValueStack.currentWidget().getOffsetDays()
|
||||
return f" {target} = dateadd({target}, -{days})"
|
||||
if vartype == "Time" and hasattr(self.valueStack.currentWidget(), "getOffsetHours"):
|
||||
hours = self.valueStack.currentWidget().getOffsetHours()
|
||||
if vartype == "Time" and hasattr(self.ValueStack.currentWidget(), "getOffsetHours"):
|
||||
hours = self.ValueStack.currentWidget().getOffsetHours()
|
||||
return f" {target} = timeadd({target}, -{hours})"
|
||||
return f" {target} = {target} - {rawVal}"
|
||||
return ""
|
||||
@@ -407,10 +407,10 @@ class ActionStepFrame(QFrame):
|
||||
self
|
||||
) -> str:
|
||||
|
||||
if self.valueSrcCombo.currentData() == "variable":
|
||||
data = self.existingVarCombo.currentData()
|
||||
if self.ValueSrcCombo.currentData() == "variable":
|
||||
data = self.ExistingVarCombo.currentData()
|
||||
return data[0] if data else ""
|
||||
w = self.valueStack.currentWidget()
|
||||
w = self.ValueStack.currentWidget()
|
||||
if w:
|
||||
return getValueFromWidget(w)
|
||||
return ""
|
||||
@@ -419,15 +419,15 @@ class ActionStepFrame(QFrame):
|
||||
self
|
||||
):
|
||||
|
||||
currentData = self.targetCombo.currentData()
|
||||
currentData = self.TargetCombo.currentData()
|
||||
self.populateTargetCombo()
|
||||
if currentData:
|
||||
for i in range(self.targetCombo.count()):
|
||||
d = self.targetCombo.itemData(i)
|
||||
for i in range(self.TargetCombo.count()):
|
||||
d = self.TargetCombo.itemData(i)
|
||||
if d and d[0] == currentData[0]:
|
||||
self.targetCombo.setCurrentIndex(i)
|
||||
self.TargetCombo.setCurrentIndex(i)
|
||||
break
|
||||
self._varMgr.populateCombo(self.existingVarCombo)
|
||||
self._varMgr.populateCombo(self.ExistingVarCombo)
|
||||
|
||||
@Slot(int)
|
||||
def onTargetChanged(
|
||||
@@ -437,13 +437,13 @@ class ActionStepFrame(QFrame):
|
||||
|
||||
if idx < 0:
|
||||
return
|
||||
data = self.targetCombo.itemData(idx)
|
||||
data = self.TargetCombo.itemData(idx)
|
||||
if not data:
|
||||
return
|
||||
_, vartype = data
|
||||
self._currentTargetType = vartype
|
||||
self.updateValueWidget()
|
||||
self.onValueSrcChanged(self.valueSrcCombo.currentIndex())
|
||||
self.onValueSrcChanged(self.ValueSrcCombo.currentIndex())
|
||||
|
||||
@Slot(int)
|
||||
def onOpTypeChanged(
|
||||
@@ -459,10 +459,10 @@ class ActionStepFrame(QFrame):
|
||||
idx
|
||||
):
|
||||
|
||||
isVar = (self.valueSrcCombo.currentData() == "variable")
|
||||
self.valueStack.setVisible(not isVar)
|
||||
self.existingVarCombo.setVisible(isVar)
|
||||
isVar = (self.ValueSrcCombo.currentData() == "variable")
|
||||
self.ValueStack.setVisible(not isVar)
|
||||
self.ExistingVarCombo.setVisible(isVar)
|
||||
if isVar:
|
||||
self._varMgr.populateCombo(self.existingVarCombo)
|
||||
self._varMgr.populateCombo(self.ExistingVarCombo)
|
||||
else:
|
||||
self.updateValueWidget()
|
||||
|
||||
+100
-100
@@ -386,18 +386,18 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
|
||||
user_config = self.defaultUserConfig()
|
||||
for i in range(self.UserTreeWidget.topLevelItemCount()):
|
||||
group_item = self.UserTreeWidget.topLevelItem(i)
|
||||
GroupItem = self.UserTreeWidget.topLevelItem(i)
|
||||
group_config = {
|
||||
"name": group_item.text(0),
|
||||
"enabled": group_item.checkState(1) == Qt.CheckState.Checked,
|
||||
"name": GroupItem.text(0),
|
||||
"enabled": GroupItem.checkState(1) == Qt.CheckState.Checked,
|
||||
"users": []
|
||||
}
|
||||
for j in range(group_item.childCount()):
|
||||
user_item = group_item.child(j)
|
||||
user = user_item.data(0, Qt.UserRole)
|
||||
for j in range(GroupItem.childCount()):
|
||||
UserItem = GroupItem.child(j)
|
||||
user = UserItem.data(0, Qt.UserRole)
|
||||
if not user:
|
||||
continue
|
||||
user["enabled"] = user_item.checkState(1) == Qt.CheckState.Checked
|
||||
user["enabled"] = UserItem.checkState(1) == Qt.CheckState.Checked
|
||||
group_config["users"].append(user)
|
||||
user_config["groups"].append(group_config)
|
||||
return user_config
|
||||
@@ -453,18 +453,18 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
try:
|
||||
if "groups" in users:
|
||||
for group_config in users["groups"]:
|
||||
group_item = QTreeWidgetItem(self.UserTreeWidget, ALUserTreeItemType.GROUP.value)
|
||||
group_item.setText(0, group_config["name"])
|
||||
group_item.setFlags(group_item.flags() | Qt.ItemIsEditable)
|
||||
group_item.setCheckState(1, Qt.Checked if group_config.get("enabled", True) else Qt.Unchecked)
|
||||
GroupItem = QTreeWidgetItem(self.UserTreeWidget, ALUserTreeItemType.GROUP.value)
|
||||
GroupItem.setText(0, group_config["name"])
|
||||
GroupItem.setFlags(GroupItem.flags() | Qt.ItemIsEditable)
|
||||
GroupItem.setCheckState(1, Qt.Checked if group_config.get("enabled", True) else Qt.Unchecked)
|
||||
for user_config in group_config["users"]:
|
||||
user_item = QTreeWidgetItem(group_item, ALUserTreeItemType.USER.value)
|
||||
user_item.setText(0, user_config["username"])
|
||||
user_item.setText(1, "" if user_config.get("enabled", True) else "跳过")
|
||||
user_item.setData(0, Qt.UserRole, user_config)
|
||||
user_item.setCheckState(1, Qt.Checked if user_config.get("enabled", True) else Qt.Unchecked)
|
||||
user_item.setDisabled(not group_config.get("enabled", True))
|
||||
group_item.setExpanded(True)
|
||||
UserItem = QTreeWidgetItem(GroupItem, ALUserTreeItemType.USER.value)
|
||||
UserItem.setText(0, user_config["username"])
|
||||
UserItem.setText(1, "" if user_config.get("enabled", True) else "跳过")
|
||||
UserItem.setData(0, Qt.UserRole, user_config)
|
||||
UserItem.setCheckState(1, Qt.Checked if user_config.get("enabled", True) else Qt.Unchecked)
|
||||
UserItem.setDisabled(not group_config.get("enabled", True))
|
||||
GroupItem.setExpanded(True)
|
||||
except KeyError as e:
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
@@ -638,43 +638,43 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
) -> QTreeWidgetItem:
|
||||
|
||||
self.UserTreeWidget.itemChanged.disconnect(self.onUserTreeWidgetItemChanged)
|
||||
group_item = QTreeWidgetItem(self.UserTreeWidget, ALUserTreeItemType.GROUP.value)
|
||||
GroupItem = QTreeWidgetItem(self.UserTreeWidget, ALUserTreeItemType.GROUP.value)
|
||||
if not group_name:
|
||||
group_name = f"新分组-{self.UserTreeWidget.topLevelItemCount()}"
|
||||
group_item.setText(0, group_name)
|
||||
group_item.setFlags(group_item.flags() | Qt.ItemIsEditable)
|
||||
group_item.setCheckState(1, Qt.Checked)
|
||||
self.UserTreeWidget.setCurrentItem(group_item)
|
||||
GroupItem.setText(0, group_name)
|
||||
GroupItem.setFlags(GroupItem.flags() | Qt.ItemIsEditable)
|
||||
GroupItem.setCheckState(1, Qt.Checked)
|
||||
self.UserTreeWidget.setCurrentItem(GroupItem)
|
||||
self.UserTreeWidget.itemChanged.connect(self.onUserTreeWidgetItemChanged)
|
||||
return group_item
|
||||
return GroupItem
|
||||
|
||||
def delGroup(
|
||||
self,
|
||||
group_item: QTreeWidgetItem = None
|
||||
GroupItem: QTreeWidgetItem = None
|
||||
):
|
||||
|
||||
if group_item is None:
|
||||
if GroupItem is None:
|
||||
return
|
||||
if group_item.type() != ALUserTreeItemType.GROUP.value:
|
||||
if GroupItem.type() != ALUserTreeItemType.GROUP.value:
|
||||
return
|
||||
index = self.UserTreeWidget.indexOfTopLevelItem(group_item)
|
||||
index = self.UserTreeWidget.indexOfTopLevelItem(GroupItem)
|
||||
self.UserTreeWidget.takeTopLevelItem(index)
|
||||
|
||||
def addUser(
|
||||
self,
|
||||
group_item: QTreeWidgetItem = None
|
||||
GroupItem: QTreeWidgetItem = None
|
||||
) -> QTreeWidgetItem:
|
||||
|
||||
if group_item is None:
|
||||
current_item = self.UserTreeWidget.currentItem()
|
||||
if current_item is None:
|
||||
group_item = self.addGroup()
|
||||
if group_item.type() == ALUserTreeItemType.USER.value:
|
||||
group_item = group_item.parent()
|
||||
if group_item.checkState(1) == Qt.CheckState.Unchecked:
|
||||
if GroupItem is None:
|
||||
CurrentItem = self.UserTreeWidget.currentItem()
|
||||
if CurrentItem is None:
|
||||
GroupItem = self.addGroup()
|
||||
if GroupItem.type() == ALUserTreeItemType.USER.value:
|
||||
GroupItem = GroupItem.parent()
|
||||
if GroupItem.checkState(1) == Qt.CheckState.Unchecked:
|
||||
return None
|
||||
new_user = {
|
||||
"username": f"新用户-{group_item.childCount()}",
|
||||
"username": f"新用户-{GroupItem.childCount()}",
|
||||
"password": "000000",
|
||||
"enabled": True,
|
||||
"reserve_info": {
|
||||
@@ -703,30 +703,30 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
}
|
||||
}
|
||||
self.UserTreeWidget.itemChanged.disconnect(self.onUserTreeWidgetItemChanged)
|
||||
user_item = QTreeWidgetItem(group_item, ALUserTreeItemType.USER.value)
|
||||
user_item.setText(0, new_user["username"])
|
||||
user_item.setText(1, "")
|
||||
user_item.setData(0, Qt.UserRole, new_user)
|
||||
user_item.setCheckState(1, Qt.CheckState.Checked)
|
||||
group_item.setExpanded(True)
|
||||
self.UserTreeWidget.setCurrentItem(user_item)
|
||||
UserItem = QTreeWidgetItem(GroupItem, ALUserTreeItemType.USER.value)
|
||||
UserItem.setText(0, new_user["username"])
|
||||
UserItem.setText(1, "")
|
||||
UserItem.setData(0, Qt.UserRole, new_user)
|
||||
UserItem.setCheckState(1, Qt.CheckState.Checked)
|
||||
GroupItem.setExpanded(True)
|
||||
self.UserTreeWidget.setCurrentItem(UserItem)
|
||||
self.setUserToWidget(new_user)
|
||||
self.UserTreeWidget.itemChanged.connect(self.onUserTreeWidgetItemChanged)
|
||||
return user_item
|
||||
return UserItem
|
||||
|
||||
def delUser(
|
||||
self,
|
||||
user_item: QTreeWidgetItem = None
|
||||
UserItem: QTreeWidgetItem = None
|
||||
):
|
||||
|
||||
if user_item is None:
|
||||
if UserItem is None:
|
||||
return
|
||||
if user_item.type() != ALUserTreeItemType.USER.value:
|
||||
if UserItem.type() != ALUserTreeItemType.USER.value:
|
||||
return
|
||||
parent_item = user_item.parent()
|
||||
index = parent_item.indexOfChild(user_item)
|
||||
parent_item.takeChild(index)
|
||||
if parent_item.childCount() == 0:
|
||||
ParentItem = UserItem.parent()
|
||||
index = ParentItem.indexOfChild(UserItem)
|
||||
ParentItem.takeChild(index)
|
||||
if ParentItem.childCount() == 0:
|
||||
self.UserTreeWidget.setCurrentItem(None)
|
||||
|
||||
def renameItem(
|
||||
@@ -787,19 +787,19 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
room = self.RoomComboBox.currentText()
|
||||
floor_idx = self.__floor_rmap[floor]
|
||||
room_idx = self.__room_rmap[room]
|
||||
dialog = ALSeatMapSelectDialog(
|
||||
Dialog = ALSeatMapSelectDialog(
|
||||
self,
|
||||
floor,
|
||||
room,
|
||||
ALSeatMapTable[floor_idx][room_idx]
|
||||
)
|
||||
dialog.selectSeats(self.SeatIDEdit.text().split(","))
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
selected_seats = dialog.getSelectedSeats()
|
||||
Dialog.selectSeats(self.SeatIDEdit.text().split(","))
|
||||
if Dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
selected_seats = Dialog.getSelectedSeats()
|
||||
if len(selected_seats) == 0:
|
||||
self.SeatIDEdit.clear()
|
||||
return
|
||||
self.SeatIDEdit.setText(",".join(dialog.getSelectedSeats()))
|
||||
self.SeatIDEdit.setText(",".join(Dialog.getSelectedSeats()))
|
||||
|
||||
@Slot()
|
||||
def onUserTreeWidgetCurrentItemChanged(
|
||||
@@ -844,10 +844,10 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
if item.type() == ALUserTreeItemType.GROUP.value:
|
||||
is_checked = item.checkState(1) == Qt.CheckState.Checked
|
||||
for i in range(item.childCount()):
|
||||
child = item.child(i)
|
||||
if self.UserTreeWidget.currentItem() == child:
|
||||
Child = item.child(i)
|
||||
if self.UserTreeWidget.currentItem() == Child:
|
||||
self.UserTreeWidget.setCurrentItem(item)
|
||||
child.setDisabled(not is_checked)
|
||||
Child.setDisabled(not is_checked)
|
||||
else:
|
||||
is_checked = item.checkState(1) == Qt.CheckState.Checked
|
||||
item.setText(1, "" if is_checked else "跳过")
|
||||
@@ -857,41 +857,41 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
menu: QMenu
|
||||
):
|
||||
|
||||
add_group_action = QAction("添加分组", menu)
|
||||
add_group_action.triggered.connect(self.addGroup)
|
||||
menu.addAction(add_group_action)
|
||||
AddGroupAction = QAction("添加分组", menu)
|
||||
AddGroupAction.triggered.connect(self.addGroup)
|
||||
menu.addAction(AddGroupAction)
|
||||
|
||||
def showGroupMenu(
|
||||
self,
|
||||
menu: QMenu,
|
||||
group_item: QTreeWidgetItem = None
|
||||
GroupItem: QTreeWidgetItem = None
|
||||
):
|
||||
|
||||
add_user_action = QAction("添加用户", menu)
|
||||
rename_group_action = QAction("重命名分组", menu)
|
||||
del_group_action = QAction("删除分组", menu)
|
||||
add_user_action.triggered.connect(lambda: self.addUser(group_item))
|
||||
rename_group_action.triggered.connect(lambda: self.renameItem(group_item))
|
||||
del_group_action.triggered.connect(lambda: self.delGroup(group_item))
|
||||
menu.addAction(add_user_action)
|
||||
AddUserAction = QAction("添加用户", menu)
|
||||
RenameGroupAction = QAction("重命名分组", menu)
|
||||
DelGroupAction = QAction("删除分组", menu)
|
||||
AddUserAction.triggered.connect(lambda: self.addUser(GroupItem))
|
||||
RenameGroupAction.triggered.connect(lambda: self.renameItem(GroupItem))
|
||||
DelGroupAction.triggered.connect(lambda: self.delGroup(GroupItem))
|
||||
menu.addAction(AddUserAction)
|
||||
menu.addSeparator()
|
||||
menu.addAction(rename_group_action)
|
||||
menu.addAction(del_group_action)
|
||||
if group_item.checkState(1) == Qt.CheckState.Unchecked:
|
||||
add_user_action.setEnabled(False)
|
||||
menu.addAction(RenameGroupAction)
|
||||
menu.addAction(DelGroupAction)
|
||||
if GroupItem.checkState(1) == Qt.CheckState.Unchecked:
|
||||
AddUserAction.setEnabled(False)
|
||||
|
||||
def showUserMenu(
|
||||
self,
|
||||
menu: QMenu,
|
||||
user_item: QTreeWidgetItem = None
|
||||
UserItem: QTreeWidgetItem = None
|
||||
):
|
||||
|
||||
rename_user_action = QAction("重命名用户", menu)
|
||||
del_user_action = QAction("删除用户", menu)
|
||||
rename_user_action.triggered.connect(lambda: self.renameItem(user_item))
|
||||
del_user_action.triggered.connect(lambda: self.delUser(user_item))
|
||||
menu.addAction(rename_user_action)
|
||||
menu.addAction(del_user_action)
|
||||
RenameUserAction = QAction("重命名用户", menu)
|
||||
DelUserAction = QAction("删除用户", menu)
|
||||
RenameUserAction.triggered.connect(lambda: self.renameItem(UserItem))
|
||||
DelUserAction.triggered.connect(lambda: self.delUser(UserItem))
|
||||
menu.addAction(RenameUserAction)
|
||||
menu.addAction(DelUserAction)
|
||||
|
||||
@Slot()
|
||||
def onUserTreeWidgetContextMenu(
|
||||
@@ -899,31 +899,31 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
pos
|
||||
):
|
||||
|
||||
current_item = self.UserTreeWidget.itemAt(pos)
|
||||
menu = QMenu(self.UserTreeWidget)
|
||||
if current_item is None:
|
||||
self.showTreeMenu(menu)
|
||||
elif current_item.type() == ALUserTreeItemType.GROUP.value:
|
||||
self.showGroupMenu(menu, current_item)
|
||||
CurrentItem = self.UserTreeWidget.itemAt(pos)
|
||||
Menu = QMenu(self.UserTreeWidget)
|
||||
if CurrentItem is None:
|
||||
self.showTreeMenu(Menu)
|
||||
elif CurrentItem.type() == ALUserTreeItemType.GROUP.value:
|
||||
self.showGroupMenu(Menu, CurrentItem)
|
||||
else:
|
||||
self.showUserMenu(menu, current_item)
|
||||
menu.exec_(self.UserTreeWidget.mapToGlobal(pos))
|
||||
self.showUserMenu(Menu, CurrentItem)
|
||||
Menu.exec_(self.UserTreeWidget.mapToGlobal(pos))
|
||||
|
||||
@Slot()
|
||||
def onAddUserButtonClicked(
|
||||
self
|
||||
):
|
||||
|
||||
current_item = self.UserTreeWidget.currentItem()
|
||||
self.addUser(current_item)
|
||||
CurrentItem = self.UserTreeWidget.currentItem()
|
||||
self.addUser(CurrentItem)
|
||||
|
||||
@Slot()
|
||||
def onDelUserButtonClicked(
|
||||
self
|
||||
):
|
||||
|
||||
current_item = self.UserTreeWidget.currentItem()
|
||||
self.delUser(current_item)
|
||||
CurrentItem = self.UserTreeWidget.currentItem()
|
||||
self.delUser(CurrentItem)
|
||||
|
||||
@Slot()
|
||||
def onBrowseBrowserDriverButtonClicked(
|
||||
@@ -944,10 +944,10 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
self
|
||||
):
|
||||
|
||||
dialog = ALWebDriverDownloadDialog(self)
|
||||
dialog.show()
|
||||
dialog.exec_()
|
||||
selected_driver_info = dialog.getSelectedDriverInfo()
|
||||
Dialog = ALWebDriverDownloadDialog(self)
|
||||
Dialog.show()
|
||||
Dialog.exec_()
|
||||
selected_driver_info = Dialog.getSelectedDriverInfo()
|
||||
if selected_driver_info and selected_driver_info.driver_path:
|
||||
self.BrowserTypeComboBox.setCurrentText(selected_driver_info.driver_type.value)
|
||||
self.BrowseBrowserDriverEdit.setText(QDir.toNativeSeparators(str(selected_driver_info.driver_path)))
|
||||
@@ -1133,8 +1133,8 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
self
|
||||
):
|
||||
|
||||
current_item = self.UserTreeWidget.currentItem()
|
||||
if current_item and current_item.type() == ALUserTreeItemType.USER.value:
|
||||
CurrentItem = self.UserTreeWidget.currentItem()
|
||||
if CurrentItem and CurrentItem.type() == ALUserTreeItemType.USER.value:
|
||||
self.UserTreeWidget.setCurrentItem(None)
|
||||
if self.saveConfigs(
|
||||
self.__config_paths["run"],
|
||||
|
||||
@@ -76,8 +76,8 @@ class ALMainWindow(MsgBase, QMainWindow, Ui_ALMainWindow):
|
||||
self
|
||||
):
|
||||
|
||||
self.icon = QIcon(":/res/icons/AutoLibrary_Logo_64.svg")
|
||||
self.setWindowIcon(self.icon)
|
||||
self.Icon = QIcon(":/res/icons/AutoLibrary_Logo_64.svg")
|
||||
self.setWindowIcon(self.Icon)
|
||||
self.MessageIOTextEdit.setFont(QFont("Courier New", 10))
|
||||
self.ManualAction.triggered.connect(self.onManualActionTriggered)
|
||||
self.AboutAction.triggered.connect(self.onAboutActionTriggered)
|
||||
@@ -106,15 +106,15 @@ class ALMainWindow(MsgBase, QMainWindow, Ui_ALMainWindow):
|
||||
self
|
||||
):
|
||||
|
||||
about_dialog = ALAboutDialog(self)
|
||||
about_dialog.exec()
|
||||
AboutDialog = ALAboutDialog(self)
|
||||
AboutDialog.exec()
|
||||
|
||||
def onManualActionTriggered(
|
||||
self
|
||||
):
|
||||
|
||||
url = QUrl("https://www.autolibrary.kenanzhu.com/manuals")
|
||||
QDesktopServices.openUrl(url)
|
||||
Url = QUrl("https://www.autolibrary.kenanzhu.com/manuals")
|
||||
QDesktopServices.openUrl(Url)
|
||||
|
||||
def setupTray(
|
||||
self
|
||||
@@ -123,7 +123,7 @@ class ALMainWindow(MsgBase, QMainWindow, Ui_ALMainWindow):
|
||||
if not QSystemTrayIcon.isSystemTrayAvailable():
|
||||
self._showTrace("操作系统不支持系统托盘功能, 无法创建系统托盘图标", self.TraceLevel.WARNING)
|
||||
return
|
||||
self.TrayIcon = QSystemTrayIcon(self.icon, self)
|
||||
self.TrayIcon = QSystemTrayIcon(self.Icon, self)
|
||||
self.TrayIcon.setToolTip("AutoLibrary")
|
||||
|
||||
self.TrayMenu = QMenu()
|
||||
|
||||
@@ -103,15 +103,15 @@ class ALSeatMapView(QGraphicsView):
|
||||
seats_number = [seat.strip() for seat in row.split(",")]
|
||||
for seat_number in seats_number:
|
||||
if seat_number:
|
||||
seat_widget = ALSeatFrame(seat_number)
|
||||
seat_widget.clicked.connect(self.onSeatClicked)
|
||||
self.SeatsContainerLayout.addWidget(seat_widget, row_idx, col_idx)
|
||||
self.__seat_frames[seat_number] = seat_widget
|
||||
SeatWidget = ALSeatFrame(seat_number)
|
||||
SeatWidget.clicked.connect(self.onSeatClicked)
|
||||
self.SeatsContainerLayout.addWidget(SeatWidget, row_idx, col_idx)
|
||||
self.__seat_frames[seat_number] = SeatWidget
|
||||
else:
|
||||
spacer = QFrame()
|
||||
spacer.setFixedSize(20, 30)
|
||||
spacer.setStyleSheet("background-color: transparent; border: none;")
|
||||
self.SeatsContainerLayout.addWidget(spacer, row_idx, col_idx)
|
||||
Spacer = QFrame()
|
||||
Spacer.setFixedSize(20, 30)
|
||||
Spacer.setStyleSheet("background-color: transparent; border: none;")
|
||||
self.SeatsContainerLayout.addWidget(Spacer, row_idx, col_idx)
|
||||
col_idx += 1
|
||||
self.SeatsContainerLayout.setSpacing(20)
|
||||
self.SeatsContainerLayout.setContentsMargins(20, 20, 20, 20)
|
||||
|
||||
+67
-68
@@ -56,7 +56,6 @@ class ALStatusLabel(QLabel):
|
||||
|
||||
self.setFixedSize(36, 36)
|
||||
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
self.RunningAnimation = QPropertyAnimation(self, b"iconAngle")
|
||||
self.RunningAnimation.setDuration(1000)
|
||||
self.RunningAnimation.setStartValue(0)
|
||||
@@ -119,35 +118,35 @@ class ALStatusLabel(QLabel):
|
||||
event
|
||||
):
|
||||
|
||||
painter = QPainter(self)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
Painter = QPainter(self)
|
||||
Painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
center_x = self.width()/2
|
||||
center_y = self.height()/2
|
||||
radius = min(center_x, center_y) - 3
|
||||
match self.__status:
|
||||
case self.Status.WAITING:
|
||||
pen = painter.pen()
|
||||
pen.setWidth(2)
|
||||
pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
pen.setColor(QColor("#969696")) # grey
|
||||
painter.setPen(pen)
|
||||
painter.drawEllipse(
|
||||
Pen = Painter.pen()
|
||||
Pen.setWidth(2)
|
||||
Pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
Pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
Pen.setColor(QColor("#969696")) # grey
|
||||
Painter.setPen(Pen)
|
||||
Painter.drawEllipse(
|
||||
int(center_x - radius),
|
||||
int(center_y - radius),
|
||||
int(radius*2),
|
||||
int(radius*2)
|
||||
)
|
||||
case self.Status.RUNNING:
|
||||
gradient = QConicalGradient(center_x, center_y, self.__icon_angle)
|
||||
gradient.setColorAt(0.0, QColor("#2294FF" if self.isDarkMode() else "#0094FF"))
|
||||
gradient.setColorAt(1.0, QColor("#2294FF00"))
|
||||
pen = painter.pen()
|
||||
pen.setWidth(3)
|
||||
pen.setBrush(gradient)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
painter.setPen(pen)
|
||||
painter.drawEllipse(
|
||||
Gradient = QConicalGradient(center_x, center_y, self.__icon_angle)
|
||||
Gradient.setColorAt(0.0, QColor("#2294FF" if self.isDarkMode() else "#0094FF"))
|
||||
Gradient.setColorAt(1.0, QColor("#2294FF00"))
|
||||
Pen = Painter.pen()
|
||||
Pen.setWidth(3)
|
||||
Pen.setBrush(Gradient)
|
||||
Pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
Painter.setPen(Pen)
|
||||
Painter.drawEllipse(
|
||||
int(center_x - radius),
|
||||
int(center_y - radius),
|
||||
int(radius*2),
|
||||
@@ -155,102 +154,102 @@ class ALStatusLabel(QLabel):
|
||||
)
|
||||
case self.Status.SUCCESS:
|
||||
# draw the success green circle
|
||||
pen = painter.pen()
|
||||
pen.setWidth(2)
|
||||
pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
pen.setColor(QColor("#4CAF50" if self.isDarkMode() else "#00AF50")) # green
|
||||
painter.setPen(pen)
|
||||
painter.drawEllipse(
|
||||
Pen = Painter.pen()
|
||||
Pen.setWidth(2)
|
||||
Pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
Pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
Pen.setColor(QColor("#4CAF50" if self.isDarkMode() else "#00AF50")) # green
|
||||
Painter.setPen(Pen)
|
||||
Painter.drawEllipse(
|
||||
int(center_x - radius),
|
||||
int(center_y - radius),
|
||||
int(radius*2),
|
||||
int(radius*2)
|
||||
)
|
||||
# draw the success check mark '✓'
|
||||
painter.setPen(Qt.PenStyle.SolidLine)
|
||||
pen = painter.pen()
|
||||
pen.setWidth(3)
|
||||
pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
Painter.setPen(Qt.PenStyle.SolidLine)
|
||||
Pen = Painter.pen()
|
||||
Pen.setWidth(3)
|
||||
Pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
Pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
# white when dark mode, black when light mode
|
||||
pen.setColor(self.getMarkColor())
|
||||
painter.setPen(pen)
|
||||
Pen.setColor(self.getMarkColor())
|
||||
Painter.setPen(Pen)
|
||||
mark_size = radius/2
|
||||
mark_path = [
|
||||
(center_x - mark_size, center_y),
|
||||
(center_x - mark_size/3, center_y + mark_size/2),
|
||||
(center_x + mark_size, center_y - mark_size/2)
|
||||
]
|
||||
painter.drawLine(
|
||||
Painter.drawLine(
|
||||
int(mark_path[0][0]),int(mark_path[0][1]),
|
||||
int(mark_path[1][0]),int(mark_path[1][1])
|
||||
)
|
||||
painter.drawLine(
|
||||
Painter.drawLine(
|
||||
int(mark_path[1][0]),int(mark_path[1][1]),
|
||||
int(mark_path[2][0]),int(mark_path[2][1])
|
||||
)
|
||||
case self.Status.WARNING:
|
||||
# draw the warning orange circle
|
||||
pen = painter.pen()
|
||||
pen.setWidth(2)
|
||||
pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
pen.setColor(QColor("#FF9800")) # orange
|
||||
painter.setPen(pen)
|
||||
painter.drawEllipse(
|
||||
Pen = Painter.pen()
|
||||
Pen.setWidth(2)
|
||||
Pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
Pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
Pen.setColor(QColor("#FF9800")) # orange
|
||||
Painter.setPen(Pen)
|
||||
Painter.drawEllipse(
|
||||
int(center_x - radius),
|
||||
int(center_y - radius),
|
||||
int(radius*2),
|
||||
int(radius*2)
|
||||
)
|
||||
# draw the warning exclamation mark '!'
|
||||
painter.setPen(Qt.PenStyle.SolidLine)
|
||||
pen = painter.pen()
|
||||
pen.setWidth(3)
|
||||
pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
Painter.setPen(Qt.PenStyle.SolidLine)
|
||||
Pen = Painter.pen()
|
||||
Pen.setWidth(3)
|
||||
Pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
Pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
# white when dark mode, black when light mode
|
||||
pen.setColor(self.getMarkColor())
|
||||
painter.setPen(pen)
|
||||
painter.drawLine(
|
||||
Pen.setColor(self.getMarkColor())
|
||||
Painter.setPen(Pen)
|
||||
Painter.drawLine(
|
||||
int(center_x), int(center_y - radius/2),
|
||||
int(center_x), int(center_y + radius/6)
|
||||
)
|
||||
painter.drawPoint(
|
||||
Painter.drawPoint(
|
||||
int(center_x), int(center_y + radius/2)
|
||||
)
|
||||
case self.Status.FAILURE:
|
||||
# draw the failure red circle
|
||||
pen = painter.pen()
|
||||
pen.setWidth(2)
|
||||
pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
pen.setColor(QColor("#DC0000")) # red
|
||||
painter.setPen(pen)
|
||||
painter.drawEllipse(
|
||||
Pen = Painter.pen()
|
||||
Pen.setWidth(2)
|
||||
Pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
Pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
Pen.setColor(QColor("#DC0000")) # red
|
||||
Painter.setPen(Pen)
|
||||
Painter.drawEllipse(
|
||||
int(center_x - radius),
|
||||
int(center_y - radius),
|
||||
int(radius*2),
|
||||
int(radius*2)
|
||||
)
|
||||
# draw the failure cross mark '✗'
|
||||
painter.setPen(Qt.PenStyle.SolidLine)
|
||||
pen = painter.pen()
|
||||
pen.setWidth(3)
|
||||
pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
Painter.setPen(Qt.PenStyle.SolidLine)
|
||||
Pen = Painter.pen()
|
||||
Pen.setWidth(3)
|
||||
Pen.setBrush(Qt.BrushStyle.NoBrush)
|
||||
Pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
# white when dark mode, black when light mode
|
||||
pen.setColor(self.getMarkColor())
|
||||
painter.setPen(pen)
|
||||
Pen.setColor(self.getMarkColor())
|
||||
Painter.setPen(Pen)
|
||||
mark_size = radius/3
|
||||
painter.drawLine(
|
||||
Painter.drawLine(
|
||||
int(center_x - mark_size), int(center_y - mark_size),
|
||||
int(center_x + mark_size), int(center_y + mark_size)
|
||||
)
|
||||
painter.drawLine(
|
||||
Painter.drawLine(
|
||||
int(center_x + mark_size), int(center_y - mark_size),
|
||||
int(center_x - mark_size), int(center_y + mark_size)
|
||||
)
|
||||
painter.end()
|
||||
Painter.end()
|
||||
super().paintEvent(event)
|
||||
|
||||
@@ -80,7 +80,6 @@ class ALTimerTaskAddDialog(QDialog, Ui_ALTimerTaskAddDialog):
|
||||
self.SpecificDateTimeEdit.setDateTime(QDateTime.currentDateTime().addSecs(60))
|
||||
self.SpecificTimerLayout.addWidget(self.SpecificDateTimeEdit)
|
||||
self.TimerConfigLayout.addWidget(self.SpecificTimerWidget)
|
||||
|
||||
self.RelativeTimerWidget = QWidget()
|
||||
self.RelativeTimerLayout = QHBoxLayout(self.RelativeTimerWidget)
|
||||
self.RelativeTimerLayout.setContentsMargins(0, 0, 0, 0)
|
||||
@@ -108,17 +107,16 @@ class ALTimerTaskAddDialog(QDialog, Ui_ALTimerTaskAddDialog):
|
||||
self.RelativeTimerLayout.addWidget(self.RelativeSecondSpinBox)
|
||||
self.TimerConfigLayout.addWidget(self.RelativeTimerWidget)
|
||||
self.RelativeTimerWidget.setVisible(False)
|
||||
|
||||
self.AutoScriptGroupBox = QGroupBox("AutoScript 指令")
|
||||
self.AutoScriptLayout = QVBoxLayout(self.AutoScriptGroupBox)
|
||||
self.AutoScriptLayout.setContentsMargins(3, 3, 3, 3)
|
||||
self.AutoScriptLayout.setSpacing(3)
|
||||
autoScriptBtnLayout = QHBoxLayout()
|
||||
AutoScriptBtnLayout = QHBoxLayout()
|
||||
self.AutoScriptEditButton = QPushButton("编辑")
|
||||
self.AutoScriptEditButton.setMinimumHeight(25)
|
||||
self.AutoScriptEditButton.setFixedWidth(80)
|
||||
autoScriptBtnLayout.addWidget(self.AutoScriptEditButton)
|
||||
autoScriptBtnLayout.addStretch()
|
||||
AutoScriptBtnLayout.addWidget(self.AutoScriptEditButton)
|
||||
AutoScriptBtnLayout.addStretch()
|
||||
self.AutoScriptHelpButton = QPushButton("?")
|
||||
self.AutoScriptHelpButton.setFixedSize(20, 20)
|
||||
self.AutoScriptHelpButton.setToolTip(
|
||||
@@ -132,12 +130,12 @@ class ALTimerTaskAddDialog(QDialog, Ui_ALTimerTaskAddDialog):
|
||||
"font-weight: bold; color: #555; }"
|
||||
"QPushButton:hover { background-color: #E0E0E0; }"
|
||||
)
|
||||
autoScriptBtnLayout.addWidget(self.AutoScriptHelpButton)
|
||||
AutoScriptBtnLayout.addWidget(self.AutoScriptHelpButton)
|
||||
self.AutoScriptStatusLabel = QLabel("未设置")
|
||||
self.AutoScriptStatusLabel.setStyleSheet("color: #969696;")
|
||||
self.AutoScriptStatusLabel.setFixedHeight(25)
|
||||
autoScriptBtnLayout.addWidget(self.AutoScriptStatusLabel)
|
||||
self.AutoScriptLayout.addLayout(autoScriptBtnLayout)
|
||||
AutoScriptBtnLayout.addWidget(self.AutoScriptStatusLabel)
|
||||
self.AutoScriptLayout.addLayout(AutoScriptBtnLayout)
|
||||
self.ALAddTimerTaskLayout.insertWidget(
|
||||
self.ALAddTimerTaskLayout.indexOf(self.TaskConfigGroupBox) + 1,
|
||||
self.AutoScriptGroupBox
|
||||
@@ -305,18 +303,18 @@ class ALTimerTaskAddDialog(QDialog, Ui_ALTimerTaskAddDialog):
|
||||
@Slot()
|
||||
def onPreviewAutoScript(self):
|
||||
from gui.ALAutoScriptEditDialog import ALAutoScriptEditDialog
|
||||
dlg = ALAutoScriptEditDialog(self, self.__auto_script, self.__mock_target_data)
|
||||
if dlg.exec() == QDialog.DialogCode.Accepted:
|
||||
script = dlg.getScript()
|
||||
Dlg = ALAutoScriptEditDialog(self, self.__auto_script, self.__mock_target_data)
|
||||
if Dlg.exec() == QDialog.DialogCode.Accepted:
|
||||
script = Dlg.getScript()
|
||||
self.__auto_script = script
|
||||
self.__mock_target_data = dlg.getMockData()
|
||||
self.__mock_target_data = Dlg.getMockData()
|
||||
if script:
|
||||
self.AutoScriptStatusLabel.setText("已设置")
|
||||
self.AutoScriptStatusLabel.setStyleSheet("color: #4CAF50;")
|
||||
else:
|
||||
self.AutoScriptStatusLabel.setText("未设置")
|
||||
self.AutoScriptStatusLabel.setStyleSheet("color: #969696;")
|
||||
dlg.deleteLater()
|
||||
Dlg.deleteLater()
|
||||
|
||||
@Slot()
|
||||
def onAutoScriptHelp(
|
||||
|
||||
@@ -41,7 +41,6 @@ class ALTimerTaskHistoryDialog(QDialog):
|
||||
self.setWindowTitle("定时任务执行历史 - AutoLibrary")
|
||||
self.setMinimumSize(300, 300)
|
||||
self.setMaximumSize(500, 400)
|
||||
|
||||
MainLayout = QVBoxLayout(self)
|
||||
InfoLayout = QGridLayout()
|
||||
TaskNameLabel = QLabel(f"任务: {self.__task_data.get('name', '未命名')}")
|
||||
@@ -51,7 +50,6 @@ class ALTimerTaskHistoryDialog(QDialog):
|
||||
TaskUUIDLabel.setStyleSheet("color: #969696; font-size: 11px;")
|
||||
InfoLayout.addWidget(TaskUUIDLabel, 1, 0)
|
||||
InfoLayout.setColumnStretch(0, 1)
|
||||
|
||||
if self.__task_data.get("repeat", False):
|
||||
RepeatLabel = QLabel("可重复性任务")
|
||||
RepeatLabel.setStyleSheet("color: #2294FF; font-size: 12px;")
|
||||
@@ -68,7 +66,6 @@ class ALTimerTaskHistoryDialog(QDialog):
|
||||
self.HistoryTableWidget.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectRows)
|
||||
self.loadHistory()
|
||||
MainLayout.addWidget(self.HistoryTableWidget)
|
||||
|
||||
ButtonLayout = QHBoxLayout()
|
||||
ButtonLayout.addStretch()
|
||||
self.CloseButton = QPushButton("关闭")
|
||||
|
||||
@@ -173,20 +173,20 @@ class ALTimerTaskItemWidget(QWidget):
|
||||
pos
|
||||
):
|
||||
|
||||
menu = QMenu(self)
|
||||
edit_action = QAction("编辑", self)
|
||||
edit_action.triggered.connect(
|
||||
Menu = QMenu(self)
|
||||
EditAction = QAction("编辑", self)
|
||||
EditAction.triggered.connect(
|
||||
lambda: self.editRequested.emit(self.__timer_task)
|
||||
)
|
||||
menu.addAction(edit_action)
|
||||
Menu.addAction(EditAction)
|
||||
if self.__timer_task["status"] != ALTimerTaskStatus.RUNNING\
|
||||
and self.__timer_task["status"] != ALTimerTaskStatus.READY:
|
||||
delete_action = QAction("删除", self)
|
||||
delete_action.triggered.connect(
|
||||
DeleteAction = QAction("删除", self)
|
||||
DeleteAction.triggered.connect(
|
||||
lambda: self.__manage_widget.deleteTask(self.__timer_task)
|
||||
)
|
||||
menu.addAction(delete_action)
|
||||
menu.exec(self.mapToGlobal(pos))
|
||||
Menu.addAction(DeleteAction)
|
||||
Menu.exec(self.mapToGlobal(pos))
|
||||
|
||||
|
||||
class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
@@ -209,7 +209,7 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
super().__init__(parent)
|
||||
self.__cfg_mgr: ConfigProvider = ConfigManager.instance()
|
||||
self.__timer_tasks = []
|
||||
self.__check_timer = None
|
||||
self.__CheckTimer = None
|
||||
self.__sort_policy = self.SortPolicy.BY_EXECUTE_TIME
|
||||
self.__sort_order = Qt.SortOrder.AscendingOrder
|
||||
|
||||
@@ -233,9 +233,9 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
self
|
||||
):
|
||||
|
||||
self.__check_timer = QTimer(self)
|
||||
self.__check_timer.timeout.connect(self.checkTasks)
|
||||
self.__check_timer.start(500)
|
||||
self.__CheckTimer = QTimer(self)
|
||||
self.__CheckTimer.timeout.connect(self.checkTasks)
|
||||
self.__CheckTimer.start(500)
|
||||
|
||||
def initializeTimerTasks(
|
||||
self
|
||||
@@ -386,28 +386,28 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
self.TimerTasksListWidget.clear()
|
||||
self.sortTimerTasks(self.__sort_policy, self.__sort_order)
|
||||
for timer_task in self.__timer_tasks:
|
||||
item = QListWidgetItem()
|
||||
item.setData(Qt.UserRole, timer_task)
|
||||
widget = ALTimerTaskItemWidget(self, timer_task)
|
||||
widget.DeleteButton.clicked.connect(
|
||||
Item = QListWidgetItem()
|
||||
Item.setData(Qt.UserRole, timer_task)
|
||||
Widget = ALTimerTaskItemWidget(self, timer_task)
|
||||
Widget.DeleteButton.clicked.connect(
|
||||
lambda _, task = timer_task: self.deleteTask(task)
|
||||
)
|
||||
if timer_task.get("repeat", False) and hasattr(widget, "HistoryButton"):
|
||||
widget.HistoryButton.clicked.connect(
|
||||
if timer_task.get("repeat", False) and hasattr(Widget, "HistoryButton"):
|
||||
Widget.HistoryButton.clicked.connect(
|
||||
lambda _, task = timer_task: self.showTaskHistory(task)
|
||||
)
|
||||
widget.editRequested.connect(self.editTask)
|
||||
item.setSizeHint(widget.size())
|
||||
self.TimerTasksListWidget.addItem(item)
|
||||
self.TimerTasksListWidget.setItemWidget(item, widget)
|
||||
Widget.editRequested.connect(self.editTask)
|
||||
Item.setSizeHint(Widget.size())
|
||||
self.TimerTasksListWidget.addItem(Item)
|
||||
self.TimerTasksListWidget.setItemWidget(Item, Widget)
|
||||
|
||||
def addTask(
|
||||
self
|
||||
):
|
||||
|
||||
dialog = ALTimerTaskAddDialog(self)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
timer_task = dialog.getTimerTask()
|
||||
Dialog = ALTimerTaskAddDialog(self)
|
||||
if Dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
timer_task = Dialog.getTimerTask()
|
||||
self.__timer_tasks.append(timer_task)
|
||||
self.timerTasksChanged.emit()
|
||||
|
||||
@@ -416,9 +416,9 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
timer_task: dict
|
||||
):
|
||||
|
||||
dialog = ALTimerTaskAddDialog(self, timer_task)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
updated = dialog.getTimerTask()
|
||||
Dialog = ALTimerTaskAddDialog(self, timer_task)
|
||||
if Dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
updated = Dialog.getTimerTask()
|
||||
for i, task in enumerate(self.__timer_tasks):
|
||||
if task["uuid"] == updated["uuid"]:
|
||||
self.__timer_tasks[i] = updated
|
||||
@@ -449,19 +449,19 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
):
|
||||
|
||||
if timer_task["repeat"]: # when delete a repeat task
|
||||
msgbox = QMessageBox(self)
|
||||
msgbox.setIcon(QMessageBox.Icon.Question)
|
||||
msgbox.setWindowTitle("警告 - AutoLibrary")
|
||||
msgbox.setStandardButtons(
|
||||
MsgBox = QMessageBox(self)
|
||||
MsgBox.setIcon(QMessageBox.Icon.Question)
|
||||
MsgBox.setWindowTitle("警告 - AutoLibrary")
|
||||
MsgBox.setStandardButtons(
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||
)
|
||||
msgbox.setText("删除可重复性任务将同时删除所有已执行的记录 !\n是否继续 ?")
|
||||
msgbox.setDetailedText(
|
||||
MsgBox.setText("删除可重复性任务将同时删除所有已执行的记录 !\n是否继续 ?")
|
||||
MsgBox.setDetailedText(
|
||||
"以下可重复性任务将被删除:\n"\
|
||||
"\n"
|
||||
f"{self.getTimerTaskDetailMessage(timer_task)}"
|
||||
)
|
||||
result = msgbox.exec()
|
||||
result = MsgBox.exec()
|
||||
if result != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
task_uuid = timer_task["uuid"]
|
||||
@@ -506,13 +506,13 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
]
|
||||
repeat_tasks_count = len(repeat_tasks)
|
||||
if repeat_tasks_count > 0:
|
||||
msgbox = QMessageBox(self)
|
||||
msgbox.setIcon(QMessageBox.Icon.Question)
|
||||
msgbox.setWindowTitle("警告 - AutoLibrary")
|
||||
msgbox.setStandardButtons(
|
||||
MsgBox = QMessageBox(self)
|
||||
MsgBox.setIcon(QMessageBox.Icon.Question)
|
||||
MsgBox.setWindowTitle("警告 - AutoLibrary")
|
||||
MsgBox.setStandardButtons(
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||
)
|
||||
msgbox.setText(
|
||||
MsgBox.setText(
|
||||
f"存在 {repeat_tasks_count} 个可重复性任务,\n"
|
||||
"删除可重复性任务将同时删除所有已执行的记录 !\n"
|
||||
"是否继续 ?"
|
||||
@@ -520,12 +520,12 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
delete_msgs = [
|
||||
self.getTimerTaskDetailMessage(x) for x in repeat_tasks
|
||||
]
|
||||
msgbox.setDetailedText(
|
||||
MsgBox.setDetailedText(
|
||||
"以下可重复性任务将被删除:\n"\
|
||||
"\n"
|
||||
f"{"\n\n".join(delete_msgs)}"
|
||||
)
|
||||
result = msgbox.exec()
|
||||
result = MsgBox.exec()
|
||||
if result != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
# clear all tasks
|
||||
@@ -537,8 +537,8 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
task: dict
|
||||
):
|
||||
|
||||
dialog = ALTimerTaskHistoryDialog(self, task)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
Dialog = ALTimerTaskHistoryDialog(self, task)
|
||||
if Dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
self.timerTasksChanged.emit()
|
||||
|
||||
def checkTasks(
|
||||
|
||||
+15
-15
@@ -51,9 +51,9 @@ class ALUserTreeWidget(QTreeWidget):
|
||||
self
|
||||
):
|
||||
|
||||
__qtreewidgetitem = QTreeWidgetItem()
|
||||
__qtreewidgetitem.setText(0, u"\u5206\u7ec4/\u7528\u6237");
|
||||
self.setHeaderItem(__qtreewidgetitem)
|
||||
__QTreeWidgetItem = QTreeWidgetItem()
|
||||
__QTreeWidgetItem.setText(0, u"\u5206\u7ec4/\u7528\u6237");
|
||||
self.setHeaderItem(__QTreeWidgetItem)
|
||||
self.setObjectName(u"UserTreeWidget")
|
||||
self.setMinimumSize(QSize(230, 0))
|
||||
self.setMaximumSize(QSize(250, 16777215))
|
||||
@@ -81,8 +81,8 @@ class ALUserTreeWidget(QTreeWidget):
|
||||
self
|
||||
):
|
||||
|
||||
___qtreewidgetitem = self.headerItem()
|
||||
___qtreewidgetitem.setText(1, QCoreApplication.translate("ALConfigWidget", u"\u72b6\u6001", None));
|
||||
___QTreeWidgetItem = self.headerItem()
|
||||
___QTreeWidgetItem.setText(1, QCoreApplication.translate("ALConfigWidget", u"\u72b6\u6001", None));
|
||||
|
||||
@staticmethod
|
||||
def isDragPositionValid(
|
||||
@@ -109,27 +109,27 @@ class ALUserTreeWidget(QTreeWidget):
|
||||
|
||||
super().dragMoveEvent(event)
|
||||
|
||||
source_item = self.currentItem()
|
||||
target_item = self.itemAt(event.position().toPoint())
|
||||
if source_item is None:
|
||||
SourceItem = self.currentItem()
|
||||
TargetItem = self.itemAt(event.position().toPoint())
|
||||
if SourceItem is None:
|
||||
event.ignore()
|
||||
return
|
||||
if source_item.type() == ALUserTreeItemType.GROUP.value:
|
||||
if target_item is not None:
|
||||
if SourceItem.type() == ALUserTreeItemType.GROUP.value:
|
||||
if TargetItem is not None:
|
||||
event.ignore()
|
||||
return
|
||||
elif source_item.type() == ALUserTreeItemType.USER.value:
|
||||
if target_item is None:
|
||||
elif SourceItem.type() == ALUserTreeItemType.USER.value:
|
||||
if TargetItem is None:
|
||||
event.ignore()
|
||||
return
|
||||
if target_item.type() != ALUserTreeItemType.GROUP.value:
|
||||
if TargetItem.type() != ALUserTreeItemType.GROUP.value:
|
||||
event.ignore()
|
||||
return
|
||||
if target_item.checkState(1) == Qt.CheckState.Unchecked:
|
||||
if TargetItem.checkState(1) == Qt.CheckState.Unchecked:
|
||||
event.ignore()
|
||||
return
|
||||
if not self.isDragPositionValid(
|
||||
self.visualItemRect(target_item),
|
||||
self.visualItemRect(TargetItem),
|
||||
event.position().toPoint()
|
||||
):
|
||||
event.ignore()
|
||||
|
||||
@@ -182,14 +182,11 @@ class ALWebDriverDownloadDialog(QDialog):
|
||||
self.setMaximumHeight(240)
|
||||
self.setMinimumHeight(240)
|
||||
self.setWindowTitle("浏览器驱动下载 - AutoLibrary")
|
||||
|
||||
self.MainLayout = QVBoxLayout(self)
|
||||
self.MainLayout.setContentsMargins(5, 5, 5, 5)
|
||||
self.MainLayout.setSpacing(5)
|
||||
|
||||
self.BrowserCountLabel = QLabel("检测到 0 个可用浏览器:")
|
||||
self.MainLayout.addWidget(self.BrowserCountLabel)
|
||||
|
||||
self.DriverInfoLayout = QHBoxLayout()
|
||||
self.DriverInfoLayout.setSpacing(5)
|
||||
self.DriverComboBox = QComboBox()
|
||||
@@ -198,7 +195,6 @@ class ALWebDriverDownloadDialog(QDialog):
|
||||
self.StatusLabel.setFixedSize(32, 32)
|
||||
self.DriverInfoLayout.addWidget(self.StatusLabel)
|
||||
self.MainLayout.addLayout(self.DriverInfoLayout)
|
||||
|
||||
self.DetailLayout = QVBoxLayout()
|
||||
self.DetailLayout.setSpacing(5)
|
||||
self.DetailLayout.setContentsMargins(5, 5, 5, 5)
|
||||
@@ -211,7 +207,6 @@ class ALWebDriverDownloadDialog(QDialog):
|
||||
self.PathLabel.setText("路径:未安装")
|
||||
self.DetailLayout.addWidget(self.PathLabel)
|
||||
self.MainLayout.addLayout(self.DetailLayout)
|
||||
|
||||
self.Line = QFrame()
|
||||
self.Line.setFrameShape(QFrame.Shape.HLine)
|
||||
self.Line.setFrameShadow(QFrame.Shadow.Sunken)
|
||||
@@ -237,7 +232,6 @@ class ALWebDriverDownloadDialog(QDialog):
|
||||
self.ConfirmButton = QPushButton("确认")
|
||||
self.ConfirmButton.setFixedSize(80, 25)
|
||||
self.ConfirmButton.setEnabled(False)
|
||||
|
||||
self.ControlLayout.addWidget(self.RefreshButton)
|
||||
self.ControlLayout.addWidget(self.DownloadButton)
|
||||
self.ControlLayout.addWidget(self.DeleteButton)
|
||||
|
||||
Binary file not shown.
@@ -19,7 +19,7 @@
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>400</height>
|
||||
<height>600</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -103,53 +103,6 @@
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="AboutInfoSpaceFrame">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>56</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>56</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="AboutInfoBrowser">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::LineWrapMode::NoWrap</enum>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
@@ -360,6 +360,10 @@ class WebDriverDownloader:
|
||||
break
|
||||
if not driver_file:
|
||||
raise FileNotFoundError(f"未找到 web driver 文件 : {expected_name}")
|
||||
# Ensure executable permissions on Unix systems (zipfile
|
||||
# extraction does not preserve the execute bit).
|
||||
if os.name != 'nt':
|
||||
os.chmod(driver_file, 0o755)
|
||||
progress_callback(100, 100, 0.0, "解压完成")
|
||||
self.download_path.unlink()
|
||||
self._cleanup(driver_file)
|
||||
|
||||
@@ -111,6 +111,10 @@ class WebDriverManager:
|
||||
for driver_info in self.__driver_infos:
|
||||
driver_path = self._getDriverPath(driver_info)
|
||||
if driver_path and driver_path.exists() and driver_path.is_file():
|
||||
# Repair missing execute permission on Unix
|
||||
# (zip-extracted drivers from older versions).
|
||||
if os.name != 'nt' and not os.access(str(driver_path), os.X_OK):
|
||||
os.chmod(str(driver_path), 0o755)
|
||||
driver_info.driver_path = driver_path
|
||||
driver_info.driver_status = WebDriverStatus.INSTALLED
|
||||
|
||||
|
||||
+25
-18
@@ -10,6 +10,7 @@ See the LICENSE file for details.
|
||||
import os
|
||||
import queue
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.remote.webdriver import WebDriver
|
||||
from selenium.common.exceptions import (
|
||||
TimeoutException,
|
||||
WebDriverException,
|
||||
@@ -37,11 +38,11 @@ class AutoLib(MsgBase):
|
||||
output_queue: queue.Queue,
|
||||
run_config: dict,
|
||||
) -> None:
|
||||
super().__init__(input_queue, output_queue)
|
||||
|
||||
super().__init__(input_queue, output_queue)
|
||||
self.__run_config: dict = run_config
|
||||
self.__user_config: dict | None = None
|
||||
self.__driver = None
|
||||
self.__driver: WebDriver | None = None
|
||||
self.__driver_type: str = ""
|
||||
self.__driver_path: str = ""
|
||||
self.__login_page: LoginPage = None
|
||||
@@ -58,7 +59,7 @@ class AutoLib(MsgBase):
|
||||
else:
|
||||
if not self.__initDriverUrl():
|
||||
self.close()
|
||||
raise Exception("浏览器驱动URL初始化失败 !")
|
||||
raise Exception("浏览器驱动 URL 初始化失败 !")
|
||||
self.__initPagesServices()
|
||||
self.__initPagesFlows()
|
||||
|
||||
@@ -67,9 +68,10 @@ class AutoLib(MsgBase):
|
||||
) -> bool:
|
||||
|
||||
self._showTrace("正在初始化浏览器驱动......", no_log=True)
|
||||
web_driver_config: dict = self.__run_config.get("web_driver", None)
|
||||
self.__driver_type = web_driver_config.get("driver_type", "none")
|
||||
match self.__driver_type.lower():
|
||||
driver_config: dict = self.__run_config.get("web_driver", None)
|
||||
self.__driver_type = driver_config.get("driver_type", "none")
|
||||
self.__driver_type = self.__driver_type.lower()
|
||||
match self.__driver_type:
|
||||
case "edge":
|
||||
driver_options = webdriver.EdgeOptions()
|
||||
case "chrome":
|
||||
@@ -82,10 +84,10 @@ class AutoLib(MsgBase):
|
||||
self.TraceLevel.WARNING,
|
||||
)
|
||||
return False
|
||||
if not web_driver_config:
|
||||
if not driver_config:
|
||||
self._showTrace("未配置浏览器驱动参数 !", self.TraceLevel.ERROR)
|
||||
return False
|
||||
if web_driver_config.get("headless", False):
|
||||
if driver_config.get("headless", False):
|
||||
driver_options.add_argument("--headless")
|
||||
driver_options.add_argument("--disable-gpu")
|
||||
driver_options.add_argument("--no-sandbox")
|
||||
@@ -110,11 +112,11 @@ class AutoLib(MsgBase):
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "\
|
||||
"Chrome/120.0.0.0 "\
|
||||
"Safari/537.36"
|
||||
if self.__driver_type.lower() == "edge":
|
||||
if self.__driver_type == "edge":
|
||||
user_agent += " Edg/120.0.0.0"
|
||||
|
||||
# set options for firefox
|
||||
elif self.__driver_type.lower() == "firefox":
|
||||
elif self.__driver_type == "firefox":
|
||||
driver_options.set_preference("dom.webdriver.enabled", False)
|
||||
driver_options.set_preference("useAutomationExtension", False)
|
||||
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) "\
|
||||
@@ -122,14 +124,14 @@ class AutoLib(MsgBase):
|
||||
driver_options.add_argument(f"user-agent={user_agent}")
|
||||
|
||||
# init browser driver
|
||||
self.__driver_path = web_driver_config.get("driver_path", "")
|
||||
self.__driver_path = driver_config.get("driver_path", "")
|
||||
if not self.__driver_path:
|
||||
self._showTrace("未配置浏览器驱动路径 !", self.TraceLevel.WARNING)
|
||||
return False
|
||||
try:
|
||||
self.__driver_path = os.path.abspath(self.__driver_path)
|
||||
service = None
|
||||
match self.__driver_type.lower():
|
||||
match self.__driver_type:
|
||||
case "edge":
|
||||
service = EdgeService(executable_path=self.__driver_path)
|
||||
self.__driver = webdriver.Edge(service=service, options=driver_options)
|
||||
@@ -161,7 +163,7 @@ class AutoLib(MsgBase):
|
||||
self._showTrace("未配置图书馆参数 !", self.TraceLevel.ERROR)
|
||||
return False
|
||||
url: str = lib_config.get("host_url") + lib_config.get("login_url")
|
||||
self.__login_page = LoginPage(self.__driver, tracer=self._showTrace)
|
||||
self.__login_page = LoginPage(self._input_queue, self._output_queue, self.__driver)
|
||||
self.__driver.set_page_load_timeout(5)
|
||||
try:
|
||||
self.__driver.get(url)
|
||||
@@ -233,6 +235,7 @@ class AutoLib(MsgBase):
|
||||
|
||||
# result : -1 - terminate, 0 - success, 1 - failed, 2 - passed
|
||||
result: int = 2
|
||||
|
||||
# login
|
||||
auto_captcha: bool = login_config.get("auto_captcha", True)
|
||||
if not self.__login_page.login(
|
||||
@@ -249,10 +252,11 @@ class AutoLib(MsgBase):
|
||||
"auto_checkin": run_mode_raw & 0x2,
|
||||
"auto_renewal": run_mode_raw & 0x4,
|
||||
}
|
||||
|
||||
# reserve
|
||||
if run_mode["auto_reserve"]:
|
||||
if self.__record_checker.canReserve(self.__shell, reserve_info["date"]):
|
||||
if self.__reserve_checker.check(reserve_info):
|
||||
if self.__reserve_checker.check(reserve_info):
|
||||
if self.__record_checker.canReserve(self.__shell, reserve_info["date"]):
|
||||
ctx = ReserveContext(
|
||||
username=username,
|
||||
date=reserve_info["date"],
|
||||
@@ -273,10 +277,10 @@ class AutoLib(MsgBase):
|
||||
else:
|
||||
result = 1
|
||||
else:
|
||||
result = 1
|
||||
self._showTrace(f"用户 {username} 无法预约, 已跳过")
|
||||
result = 2
|
||||
else:
|
||||
self._showTrace(f"用户 {username} 无法预约, 已跳过")
|
||||
result = 2
|
||||
result = 1
|
||||
|
||||
# checkin
|
||||
last_result: int = result
|
||||
@@ -317,8 +321,11 @@ class AutoLib(MsgBase):
|
||||
|
||||
# logout
|
||||
if not self.__shell.logout():
|
||||
self._showTrace(f"用户 {username} 退出登录失败, 尝试直接重载页面")
|
||||
if not self.__initDriverUrl():
|
||||
self._showTrace(f"用户 {username} 重载页面失败, 无法继续操作, 该任务已终止 !")
|
||||
return -1
|
||||
self._showTrace(f"用户 {username} 已退出登录")
|
||||
return result
|
||||
|
||||
def run(
|
||||
|
||||
+13
-19
@@ -7,7 +7,8 @@ This software is provided "as is", without any warranty of any kind.
|
||||
You may use, modify, and distribute this file under the terms of the MIT License.
|
||||
See the LICENSE file for details.
|
||||
"""
|
||||
from typing import Callable, Optional
|
||||
import queue
|
||||
from typing import Callable
|
||||
|
||||
from selenium.common.exceptions import (
|
||||
ElementNotInteractableException,
|
||||
@@ -19,8 +20,10 @@ from selenium.webdriver.remote.webdriver import WebDriver
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
from base.MsgBase import MsgBase
|
||||
|
||||
class LoginPage:
|
||||
|
||||
class LoginPage(MsgBase):
|
||||
|
||||
USERNAME_INPUT = (By.NAME, "username")
|
||||
PASSWORD_INPUT = (By.NAME, "password")
|
||||
@@ -36,22 +39,13 @@ class LoginPage:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
input_queue: queue.Queue,
|
||||
output_queue: queue.Queue,
|
||||
driver: WebDriver,
|
||||
tracer: Optional[Callable[..., None]] = None,
|
||||
) -> None:
|
||||
|
||||
super().__init__(input_queue, output_queue)
|
||||
self._driver: WebDriver = driver
|
||||
self._tracer: Optional[Callable[..., None]] = tracer
|
||||
|
||||
def _trace(
|
||||
self,
|
||||
msg: str,
|
||||
level: int = 20,
|
||||
no_log: bool = False,
|
||||
) -> None:
|
||||
|
||||
if self._tracer:
|
||||
self._tracer(msg, level, no_log)
|
||||
|
||||
def navigate(
|
||||
self,
|
||||
@@ -185,7 +179,7 @@ class LoginPage:
|
||||
) -> bool:
|
||||
|
||||
for attempt in range(max_attempts):
|
||||
self._trace(
|
||||
self._showTrace(
|
||||
f"用户 {username} 第 {attempt + 1} 次尝试登录......",
|
||||
no_log=True,
|
||||
)
|
||||
@@ -196,16 +190,16 @@ class LoginPage:
|
||||
continue
|
||||
if not self.fillCaptcha(captcha_text):
|
||||
continue
|
||||
self._trace("尝试登录...", no_log=True)
|
||||
self._showTrace("尝试登录...", no_log=True)
|
||||
if not self.clickLogin():
|
||||
continue
|
||||
if self.waitLoginSuccess():
|
||||
self._trace(f"用户 {username} 第 {attempt + 1} 次登录成功 !")
|
||||
self._showTrace(f"用户 {username} 第 {attempt + 1} 次登录成功 !")
|
||||
return True
|
||||
else:
|
||||
self._trace(
|
||||
self._showTrace(
|
||||
"登录页面加载失败 ! : "
|
||||
"用户账号或者密码错误/验证码错误, 具体以页面提示为准",
|
||||
level=40,
|
||||
level=self.TraceLevel.ERROR,
|
||||
)
|
||||
return False
|
||||
|
||||
@@ -35,7 +35,7 @@ class CheckinFlow(MsgBase):
|
||||
self._driver: WebDriver = driver
|
||||
self._shell: MainShell = shell
|
||||
|
||||
def execute(
|
||||
def _ensureCheckinButton(
|
||||
self,
|
||||
username: str,
|
||||
) -> bool:
|
||||
@@ -49,7 +49,13 @@ class CheckinFlow(MsgBase):
|
||||
self._showTrace(f"签到按钮启用失败 !", self.TraceLevel.ERROR)
|
||||
return False
|
||||
self._showTrace("签到按钮已启用")
|
||||
self._shell.clickCheckinButton()
|
||||
return True
|
||||
|
||||
def _processCheckinDialog(
|
||||
self,
|
||||
username: str,
|
||||
) -> bool:
|
||||
|
||||
try:
|
||||
with CheckinResultDialog(self._driver) as dialog:
|
||||
result_msg = dialog.getResultMessage()
|
||||
@@ -87,3 +93,13 @@ class CheckinFlow(MsgBase):
|
||||
except (TimeoutException, NoSuchElementException, ElementNotInteractableException):
|
||||
self._showTrace("签到时发生未知错误 !", self.TraceLevel.ERROR)
|
||||
return False
|
||||
|
||||
def execute(
|
||||
self,
|
||||
username: str,
|
||||
) -> bool:
|
||||
|
||||
if not self._ensureCheckinButton(username):
|
||||
return False
|
||||
self._shell.clickCheckinButton()
|
||||
return self._processCheckinDialog(username)
|
||||
|
||||
@@ -61,19 +61,23 @@ class RenewFlow(MsgBase):
|
||||
)
|
||||
return True
|
||||
|
||||
def execute(
|
||||
def _computeRenewTarget(
|
||||
self,
|
||||
username: str,
|
||||
record: dict,
|
||||
renew_info: dict,
|
||||
) -> bool:
|
||||
):
|
||||
|
||||
max_diff = renew_info.get("max_diff", 30)
|
||||
prefer_earlier = renew_info.get("prefer_early", True)
|
||||
end_time = record["time"]["end"]
|
||||
target_renew_mins = timeStrToMins(end_time) + renew_info.get("expect_duration", 2) * 60
|
||||
if not self._validateRenewTime(end_time, target_renew_mins):
|
||||
return False
|
||||
return None
|
||||
return target_renew_mins
|
||||
|
||||
def _ensureExtendButton(
|
||||
self,
|
||||
username: str,
|
||||
) -> bool:
|
||||
|
||||
if not self._shell.waitExtendButton():
|
||||
self._showTrace(f"用户 {username} 续约界面加载失败 !", self.TraceLevel.ERROR)
|
||||
return False
|
||||
@@ -83,7 +87,17 @@ class RenewFlow(MsgBase):
|
||||
f"请连接图书馆网络后重试"
|
||||
)
|
||||
return False
|
||||
self._shell.clickExtendButton()
|
||||
return True
|
||||
|
||||
def _processRenewDialog(
|
||||
self,
|
||||
username: str,
|
||||
record: dict,
|
||||
target_renew_mins: int,
|
||||
max_diff: int,
|
||||
prefer_earlier: bool,
|
||||
) -> bool:
|
||||
|
||||
try:
|
||||
with RenewDialog(self._driver) as dialog:
|
||||
if not dialog.waitUntilReady():
|
||||
@@ -132,3 +146,22 @@ class RenewFlow(MsgBase):
|
||||
self._showTrace(f"用户 {username} 续约失败 ! : {e}", self.TraceLevel.ERROR)
|
||||
self._shell.refresh()
|
||||
return False
|
||||
|
||||
def execute(
|
||||
self,
|
||||
username: str,
|
||||
record: dict,
|
||||
renew_info: dict,
|
||||
) -> bool:
|
||||
|
||||
max_diff = renew_info.get("max_diff", 30)
|
||||
prefer_earlier = renew_info.get("prefer_early", True)
|
||||
target_renew_mins = self._computeRenewTarget(record, renew_info)
|
||||
if target_renew_mins is None:
|
||||
return False
|
||||
if not self._ensureExtendButton(username):
|
||||
return False
|
||||
self._shell.clickExtendButton()
|
||||
return self._processRenewDialog(
|
||||
username, record, target_renew_mins, max_diff, prefer_earlier,
|
||||
)
|
||||
|
||||
+103
-35
@@ -58,40 +58,105 @@ class ReserveFlow(MsgBase):
|
||||
self._driver: WebDriver = driver
|
||||
self._shell: MainShell = shell
|
||||
|
||||
def execute(
|
||||
def _loadReserveView(
|
||||
self,
|
||||
) -> ReserveView | None:
|
||||
|
||||
try:
|
||||
return self._shell.gotoReserveView()
|
||||
except (TimeoutException, ElementNotInteractableException) as e:
|
||||
self._showTrace(f"加载预约选座页面失败 ! : {e}", self.TraceLevel.ERROR)
|
||||
return None
|
||||
|
||||
def _selectDate(
|
||||
self,
|
||||
view: ReserveView,
|
||||
ctx: ReserveContext,
|
||||
) -> bool:
|
||||
|
||||
submit_reserve = False
|
||||
reserve_success = False
|
||||
have_hover_on_page = False
|
||||
|
||||
try:
|
||||
view = self._shell.gotoReserveView()
|
||||
except (TimeoutException, ElementNotInteractableException) as e:
|
||||
self._showTrace(f"加载预约选座页面失败 ! : {e}", self.TraceLevel.ERROR)
|
||||
return False
|
||||
if not view.selectDate(ctx.date):
|
||||
self._showTrace(f"选择日期失败 ! : {ctx.date} 不可用", self.TraceLevel.ERROR)
|
||||
return False
|
||||
self._showTrace(f"日期 {ctx.date} 选择成功 !")
|
||||
return True
|
||||
|
||||
def _selectPlace(
|
||||
self,
|
||||
view: ReserveView,
|
||||
) -> bool:
|
||||
|
||||
if not view.selectPlace("1"):
|
||||
self._showTrace("选择预约场所失败 ! : 图书馆 不可用", self.TraceLevel.ERROR)
|
||||
return False
|
||||
self._showTrace("预约场所 图书馆 选择成功 !")
|
||||
return True
|
||||
|
||||
def _selectFloor(
|
||||
self,
|
||||
view: ReserveView,
|
||||
ctx: ReserveContext,
|
||||
) -> bool:
|
||||
|
||||
if not view.selectFloor(ctx.floor):
|
||||
display_floor = ReserveView.FLOOR_MAP.get(ctx.floor, ctx.floor)
|
||||
self._showTrace(f"选择楼层失败 ! : {display_floor} 不可用", self.TraceLevel.ERROR)
|
||||
return False
|
||||
self._showTrace(f"楼层 {ReserveView.FLOOR_MAP.get(ctx.floor)} 选择成功 !")
|
||||
return True
|
||||
|
||||
def _selectRoom(
|
||||
self,
|
||||
view: ReserveView,
|
||||
ctx: ReserveContext,
|
||||
):
|
||||
|
||||
seat_map = view.selectRoom(ctx.room)
|
||||
if seat_map is None:
|
||||
display_room = ReserveView.ROOM_MAP.get(ctx.room, ctx.room)
|
||||
self._showTrace(f"选择房间失败 ! : {display_room} 不可用", self.TraceLevel.ERROR)
|
||||
return False
|
||||
return None
|
||||
self._showTrace(f"房间 {ReserveView.ROOM_MAP.get(ctx.room)} 选择成功 !")
|
||||
have_hover_on_page = True
|
||||
return seat_map
|
||||
|
||||
def _processReserveResult(
|
||||
self,
|
||||
) -> bool:
|
||||
|
||||
with ReserveResultDialog(self._driver) as result:
|
||||
if result.isFailure():
|
||||
self._showTrace("预约失败", self.TraceLevel.ERROR)
|
||||
elif result.isSuccess():
|
||||
details = result.getDetailTexts()
|
||||
if len(details) >= 6:
|
||||
self._showTrace(
|
||||
f"\n"
|
||||
f" 预约成功 !\n"
|
||||
f" {details[1]}\n"
|
||||
f" {details[2]}\n"
|
||||
f" {details[3]}\n"
|
||||
f" 签到时间 :{details[5]}"
|
||||
)
|
||||
else:
|
||||
self._showTrace(
|
||||
"\n"
|
||||
" 预约成功 !\n"
|
||||
" 未找获取到详细信息"
|
||||
)
|
||||
return True
|
||||
else:
|
||||
self._showTrace("预约结果加载失败 !", self.TraceLevel.ERROR)
|
||||
return False
|
||||
|
||||
def _selectSeatAndSubmit(
|
||||
self,
|
||||
view: ReserveView,
|
||||
seat_map,
|
||||
ctx: ReserveContext,
|
||||
) -> tuple[bool, bool]:
|
||||
|
||||
submit_reserve = False
|
||||
reserve_success = False
|
||||
|
||||
seat_status = seat_map.selectSeat(ctx.seat_id)
|
||||
if seat_status is None:
|
||||
self._showTrace(
|
||||
@@ -111,31 +176,34 @@ class ReserveFlow(MsgBase):
|
||||
try:
|
||||
view.submitReserve()
|
||||
submit_reserve = True
|
||||
with ReserveResultDialog(self._driver) as result:
|
||||
if result.isFailure():
|
||||
self._showTrace("预约失败", self.TraceLevel.ERROR)
|
||||
elif result.isSuccess():
|
||||
details = result.getDetailTexts()
|
||||
if len(details) >= 6:
|
||||
self._showTrace(
|
||||
f"\n"
|
||||
f" 预约成功 !\n"
|
||||
f" {details[1]}\n"
|
||||
f" {details[2]}\n"
|
||||
f" {details[3]}\n"
|
||||
f" 签到时间 :{details[5]}"
|
||||
)
|
||||
else:
|
||||
self._showTrace(
|
||||
"\n"
|
||||
" 预约成功 !\n"
|
||||
" 未找获取到详细信息"
|
||||
)
|
||||
reserve_success = True
|
||||
else:
|
||||
self._showTrace("预约结果加载失败 !", self.TraceLevel.ERROR)
|
||||
reserve_success = self._processReserveResult()
|
||||
except (TimeoutException, ElementNotInteractableException):
|
||||
self._showTrace("预约提交失败 !", self.TraceLevel.ERROR)
|
||||
return submit_reserve, reserve_success
|
||||
|
||||
def execute(
|
||||
self,
|
||||
ctx: ReserveContext,
|
||||
) -> bool:
|
||||
|
||||
# reserve flow pipeline:
|
||||
# date > place > floor > room > seat (begin/end time) > submit > result
|
||||
view = self._loadReserveView()
|
||||
if view is None:
|
||||
return False
|
||||
if not self._selectDate(view, ctx):
|
||||
return False
|
||||
if not self._selectPlace(view):
|
||||
return False
|
||||
if not self._selectFloor(view, ctx):
|
||||
return False
|
||||
seat_map = self._selectRoom(view, ctx)
|
||||
if seat_map is None:
|
||||
return False
|
||||
have_hover_on_page = True
|
||||
submit_reserve, reserve_success = self._selectSeatAndSubmit(
|
||||
view, seat_map, ctx,
|
||||
)
|
||||
if not submit_reserve and have_hover_on_page:
|
||||
view.refresh()
|
||||
if reserve_success:
|
||||
|
||||
Reference in New Issue
Block a user