Compare commits
19
Commits
610aa299ef
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19522e8538 | ||
|
|
814ffb9a8a | ||
|
|
6c50257f04 | ||
|
|
ab06f8f7de | ||
|
|
7f6b7b4901 | ||
|
|
9e4a243daa | ||
|
|
bc04aba0d7 | ||
|
|
82082911b3 | ||
|
|
8f64345335 | ||
|
|
c9fc7c8d80 | ||
|
|
d589700d7a | ||
|
|
76b89dc412 | ||
|
|
60b9d4038b | ||
|
|
a029a670a4 | ||
|
|
291cefc44f | ||
|
|
809e768cae | ||
|
|
caf64b9815 | ||
|
|
5375a4af9b | ||
|
|
6bb356948d |
@@ -0,0 +1,330 @@
|
|||||||
|
# Coding pattern preferences
|
||||||
|
|
||||||
|
- Always prefer simple solutions
|
||||||
|
- Avoid duplication of code whenever possible, which means checking for other areas of the codebase that might already have similar code and functionality
|
||||||
|
- Write code that takes into account the different environments: dev, test, and prod
|
||||||
|
- You are careful to only make changes that are requested or you are confident are well understood and related to the change being requested
|
||||||
|
- When fixing an issue or bug, do not introduce a new pattern or technology without first exhausting all options for the existing implementation. And if you finally do this, make sure to remove the old implementation afterwards so we don’t have duplicate logic.
|
||||||
|
- Keep the codebase very clean and organized
|
||||||
|
- Avoid having files over 500 lines of code. Refactor at that point.
|
||||||
|
- Mocking data is only needed for tests, never mock data for dev or prod
|
||||||
|
- Never add stubbing or fake data patterns to code that affects the dev or prod environments
|
||||||
|
- Never overwrite my .env file without first asking and confirming
|
||||||
|
- Never ask the user to provide the content of a specific file. Just open the file and check it yourself.
|
||||||
|
- Never create multiple files for sql execution. Always use a single file for all sql execution in a given migration.
|
||||||
|
- Never fix the symptoms of a problem, always fix the root cause of the problem.
|
||||||
|
|
||||||
|
# File Documentation Completion Requirements
|
||||||
|
|
||||||
|
**MANDATORY: When updating a file to "match the new copilot instructions", you MUST:**
|
||||||
|
|
||||||
|
1. **Complete the ENTIRE file** - Document every method, function, class, and significant code block
|
||||||
|
2. **Check for syntax errors** - Always verify the file compiles without errors after changes
|
||||||
|
3. **Test incrementally** - Use the get_errors tool after each major change to catch issues early
|
||||||
|
4. **Document systematically** - Go through the file from top to bottom, ensuring no method is left undocumented
|
||||||
|
5. **Maintain functionality** - Never break existing functionality while adding documentation
|
||||||
|
6. **Use proper comment syntax** - Always use the correct comment format for the programming language
|
||||||
|
7. **Validate completeness** - Before considering the task complete, review the entire file to ensure every function has documentation
|
||||||
|
|
||||||
|
**File Documentation Checklist:**
|
||||||
|
|
||||||
|
- [ ] File header with comprehensive description
|
||||||
|
- [ ] Every class documented with JSDoc
|
||||||
|
- [ ] Every method/function documented with JSDoc
|
||||||
|
- [ ] Every significant code block has educational comments
|
||||||
|
- [ ] Business context explained for complex logic
|
||||||
|
- [ ] Technical implementation details provided
|
||||||
|
- [ ] Error handling approaches documented
|
||||||
|
- [ ] Integration points with other modules explained
|
||||||
|
- [ ] No syntax errors remain in the file
|
||||||
|
- [ ] File compiles and functions properly
|
||||||
|
|
||||||
|
**If a file is large (>1000 lines):**
|
||||||
|
|
||||||
|
- Work in sections but complete ALL sections
|
||||||
|
- Add section dividers with clear documentation
|
||||||
|
- Use get_errors tool frequently to catch issues
|
||||||
|
- Test syntax after each major section
|
||||||
|
- Document the overall file architecture in the header
|
||||||
|
|
||||||
|
**Quality Standards:**
|
||||||
|
|
||||||
|
- Documentation should be educational and explain both WHAT and WHY
|
||||||
|
- Include business context for complex features
|
||||||
|
- Explain integration points and dependencies
|
||||||
|
- Use examples where helpful
|
||||||
|
- Write for developers who are new to the codebase
|
||||||
|
|
||||||
|
# Coding workflow preferences
|
||||||
|
|
||||||
|
- Focus on the areas of code relevant to the task
|
||||||
|
- Always use a surgical approach to code changes either removing or adding code while preserving all other functionalities.
|
||||||
|
- Do not touch code that is unrelated to the task
|
||||||
|
- Avoid making major changes to the patterns and architecture of how a feature works, after it has shown to work well, unless explicitly instructed
|
||||||
|
- Always think about what other methods and areas of code might be affected by code changes
|
||||||
|
|
||||||
|
## Configuration File Documentation
|
||||||
|
|
||||||
|
### For Configuration Files (package.json, tsconfig.json, etc.):
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
/**
|
||||||
|
* [Configuration Purpose]
|
||||||
|
* Author: Dario Pascoal
|
||||||
|
*
|
||||||
|
* Description: [What this configuration controls and its main purpose]
|
||||||
|
*
|
||||||
|
* Important Notes: [Any critical information about changes or compatibility]
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version Control Guidelines
|
||||||
|
|
||||||
|
### Commit Message Standards
|
||||||
|
|
||||||
|
Follow conventional commit format:
|
||||||
|
|
||||||
|
- **feat**: New features or functionality
|
||||||
|
- **fix**: Bug fixes and corrections
|
||||||
|
- **docs**: Documentation updates (README, comments, etc.)
|
||||||
|
- **style**: Code formatting and style changes
|
||||||
|
- **refactor**: Code restructuring without functionality changes
|
||||||
|
- **test**: Adding or updating tests
|
||||||
|
- **chore**: Maintenance tasks, dependency updates
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
- `feat: add SAP connection configuration panel`
|
||||||
|
- `fix: resolve memory leak in VBS process management`
|
||||||
|
- `docs: update README with new installation requirements`
|
||||||
|
|
||||||
|
# Code Documentation Requirements
|
||||||
|
|
||||||
|
## File Headers
|
||||||
|
|
||||||
|
Every source code file should include a comprehensive header:
|
||||||
|
|
||||||
|
### For TypeScript/JavaScript files:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
/**
|
||||||
|
* [File Purpose/Component Name]
|
||||||
|
* Author: Dario Pascoal
|
||||||
|
*
|
||||||
|
* Description: [Detailed explanation of what this file does, its main purpose,
|
||||||
|
* and how it fits into the overall system. Explain it as if teaching someone
|
||||||
|
* who is new to programming.]
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
### For HTML/CSS files:
|
||||||
|
|
||||||
|
```css
|
||||||
|
/**
|
||||||
|
* [File Purpose/Component Name]
|
||||||
|
* Author: Dario Pascoal
|
||||||
|
*
|
||||||
|
* Description: [Detailed explanation of what this file does, its main purpose,
|
||||||
|
* and how it fits into the overall system. Explain it as if teaching someone
|
||||||
|
* who is new to programming.]
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
### For VBScript files (.vbs):
|
||||||
|
|
||||||
|
```vb
|
||||||
|
' [File Purpose/Component Name]
|
||||||
|
' Author: Dario Pascoal
|
||||||
|
'
|
||||||
|
' Description: [Detailed explanation of what this file does, its main purpose,
|
||||||
|
' and how it fits into the overall system. Explain it as if teaching someone
|
||||||
|
' who is new to programming.]
|
||||||
|
'
|
||||||
|
' [Additional sections as needed: Prerequisites, Parameters, Returns, etc.]
|
||||||
|
```
|
||||||
|
|
||||||
|
### For PowerShell files (.ps1):
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# [File Purpose/Component Name]
|
||||||
|
# Author: Dario Pascoal
|
||||||
|
#
|
||||||
|
# Description: [Detailed explanation of what this file does, its main purpose,
|
||||||
|
# and how it fits into the overall system. Explain it as if teaching someone
|
||||||
|
# who is new to programming.]
|
||||||
|
#
|
||||||
|
# [Additional sections as needed: Prerequisites, Parameters, Returns, etc.]
|
||||||
|
```
|
||||||
|
|
||||||
|
### CRITICAL: Language-Specific Comment Formatting
|
||||||
|
|
||||||
|
**ALWAYS use the correct comment syntax for each programming language:**
|
||||||
|
|
||||||
|
- **JavaScript/TypeScript**: Use `/** */` for file headers and `/* */` or `//` for inline comments
|
||||||
|
- **VBScript (.vbs)**: Use single quotes `'` for ALL comments - NEVER use `/** */` or `/* */`
|
||||||
|
- **PowerShell (.ps1)**: Use hash symbol `#` for ALL comments
|
||||||
|
- **HTML/CSS**: Use `/* */` for comments
|
||||||
|
- **Python**: Use `#` for comments and `"""` for docstrings
|
||||||
|
- **Batch files (.bat/.cmd)**: Use `REM` or `::` for comments
|
||||||
|
|
||||||
|
**This is mandatory** - using incorrect comment syntax will cause syntax errors and prevent scripts from executing properly.
|
||||||
|
|
||||||
|
## Function Documentation
|
||||||
|
|
||||||
|
Document functions with comprehensive JSDoc comments that explain both what and how:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
/**
|
||||||
|
* [Clear description of what the function does and why it exists]
|
||||||
|
*
|
||||||
|
* [Detailed explanation of how the function works, step by step,
|
||||||
|
* written for someone learning to code]
|
||||||
|
*
|
||||||
|
* @param {Type} paramName - Detailed explanation of what this parameter is,
|
||||||
|
* what format it should be in, and how it's used
|
||||||
|
* @returns {Type} Detailed explanation of what gets returned and when
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Essential Comments - Write for Beginners
|
||||||
|
|
||||||
|
Focus comments on explaining code as if teaching someone new to programming:
|
||||||
|
|
||||||
|
- **Business logic**: Explain WHY certain decisions were made and WHAT the business requirement is
|
||||||
|
- **Complex algorithms**: Step-by-step explanation of HOW the code works
|
||||||
|
- **Integration points**: Explain HOW code connects to external systems and WHAT data flows between them
|
||||||
|
- **Non-obvious code**: Explain WHAT isn't immediately clear and WHY it works that way
|
||||||
|
- **Workarounds**: Explain WHAT the problem was and HOW this solution addresses it
|
||||||
|
- **Data structures**: Explain WHAT kind of data is stored and HOW it's organized
|
||||||
|
- **Control flow**: Explain WHAT conditions trigger different code paths and WHY
|
||||||
|
|
||||||
|
## Detailed Comment Guidelines
|
||||||
|
|
||||||
|
### Inline Comments - Explain the "What" and "Why"
|
||||||
|
|
||||||
|
Write comments that help a beginner understand:
|
||||||
|
|
||||||
|
- What each significant line or block of code is doing
|
||||||
|
- Why certain approaches were chosen
|
||||||
|
- What the expected input/output is at each step
|
||||||
|
- How different parts of the code work together
|
||||||
|
- What would happen if certain conditions are met
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Check if the user has permission to access this feature
|
||||||
|
// This prevents unauthorized users from seeing sensitive data
|
||||||
|
if (user.hasPermission("admin")) {
|
||||||
|
// Load the admin dashboard with all management tools
|
||||||
|
// This includes user management, system settings, and reports
|
||||||
|
loadAdminDashboard();
|
||||||
|
} else {
|
||||||
|
// Show a basic user dashboard with limited functionality
|
||||||
|
// Regular users only see their own data and basic features
|
||||||
|
loadUserDashboard();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Complex Logic Comments
|
||||||
|
|
||||||
|
For any complex business logic, algorithms, or multi-step processes:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
/**
|
||||||
|
* PROCESS EXPLANATION:
|
||||||
|
*
|
||||||
|
* This function handles the complete user login workflow:
|
||||||
|
* 1. First, it validates the username and password format
|
||||||
|
* 2. Then it checks the credentials against the database
|
||||||
|
* 3. If successful, it creates a secure session token
|
||||||
|
* 4. Finally, it redirects the user to their appropriate dashboard
|
||||||
|
*
|
||||||
|
* The reason we do this in multiple steps is to provide better
|
||||||
|
* error messages to the user and to log security events properly.
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comment Quality Standards
|
||||||
|
|
||||||
|
- **Be educational**: Write as if teaching a programming student
|
||||||
|
- **Explain assumptions**: State what the code assumes about inputs/environment
|
||||||
|
- **Describe data flow**: Explain what data goes in and what comes out
|
||||||
|
- **Clarify complex conditions**: Break down complicated if/else logic
|
||||||
|
- **Document error cases**: Explain what can go wrong and how it's handled
|
||||||
|
- **Use plain language**: Avoid jargon, explain technical terms when used
|
||||||
|
- **Provide context**: Explain how this code fits into the bigger picture# README Maintenance Requirements
|
||||||
|
|
||||||
|
## MANDATORY: README Updates
|
||||||
|
|
||||||
|
The project README.md file MUST be updated whenever making significant changes to the codebase. This ensures the documentation stays synchronized with the actual implementation.
|
||||||
|
|
||||||
|
### When to Update README:
|
||||||
|
|
||||||
|
**ALWAYS update the README when:**
|
||||||
|
|
||||||
|
- Adding new features or functionality
|
||||||
|
- Changing installation or setup procedures
|
||||||
|
- Modifying configuration requirements
|
||||||
|
- Adding new dependencies or technologies
|
||||||
|
- Changing project structure or architecture
|
||||||
|
- Adding new scripts or build processes
|
||||||
|
- Modifying environment variables or configuration files
|
||||||
|
- Updating system requirements or compatibility
|
||||||
|
- Adding new command-line interfaces or APIs
|
||||||
|
- Changing deployment procedures
|
||||||
|
|
||||||
|
### README Sections to Maintain:
|
||||||
|
|
||||||
|
1. **Project Description**: Keep the main purpose and features up-to-date
|
||||||
|
2. **Technology Stack**: Update when adding new technologies or frameworks
|
||||||
|
3. **Installation Instructions**: Verify and update setup steps
|
||||||
|
4. **Configuration**: Document new settings, environment variables, or config files
|
||||||
|
5. **Usage Examples**: Add examples for new features
|
||||||
|
6. **API Documentation**: Update when adding new endpoints or methods
|
||||||
|
7. **Development Setup**: Keep development environment instructions current
|
||||||
|
8. **Build and Deployment**: Update build scripts and deployment procedures
|
||||||
|
9. **Troubleshooting**: Add common issues and solutions
|
||||||
|
10. **Contributing Guidelines**: Update development and contribution processes
|
||||||
|
|
||||||
|
### README Update Standards:
|
||||||
|
|
||||||
|
- **Be Comprehensive**: Include all necessary information for new team members
|
||||||
|
- **Keep Examples Current**: Ensure all code examples work with the current version
|
||||||
|
- **Update Screenshots**: Replace outdated UI screenshots when interface changes
|
||||||
|
- **Maintain Accuracy**: Verify all instructions work on a clean environment
|
||||||
|
- **Version Information**: Update version numbers and compatibility information
|
||||||
|
- **Link Validation**: Ensure all links are current and functional
|
||||||
|
|
||||||
|
### README Quality Checklist:
|
||||||
|
|
||||||
|
Before committing code changes, verify:
|
||||||
|
|
||||||
|
- [ ] README reflects all new features and changes
|
||||||
|
- [ ] Installation instructions are accurate and complete
|
||||||
|
- [ ] All code examples are tested and working
|
||||||
|
- [ ] Configuration documentation is up-to-date
|
||||||
|
- [ ] System requirements are current
|
||||||
|
- [ ] Links and references are valid
|
||||||
|
- [ ] Screenshots and diagrams reflect current state
|
||||||
|
- [ ] Troubleshooting section addresses known issues
|
||||||
|
|
||||||
|
### Automatic README Triggers:
|
||||||
|
|
||||||
|
**High Priority Updates** - Always update README for:
|
||||||
|
|
||||||
|
- New major features or modules
|
||||||
|
- Changes to package.json dependencies
|
||||||
|
- Environment variable additions/changes
|
||||||
|
- New configuration files or formats
|
||||||
|
- Changes to build/deployment processes
|
||||||
|
- New user-facing functionality
|
||||||
|
|
||||||
|
**Medium Priority Updates** - Consider updating README for:
|
||||||
|
|
||||||
|
- Internal architecture changes that affect setup
|
||||||
|
- New development tools or workflows
|
||||||
|
- Performance improvements with user impact
|
||||||
|
- Security enhancements with configuration changes
|
||||||
|
|
||||||
|
The README should serve as the single source of truth for project onboarding, setup, and usage. Keep it comprehensive, accurate, and user-friendly.
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
# 🎨 Modern UI Modernization Complete!
|
||||||
|
|
||||||
|
## ✅ Successfully Updated Files
|
||||||
|
|
||||||
|
### 1. **Main.py** - ✅ FULLY MODERNIZED
|
||||||
|
- **Dark Theme**: Professional dark color scheme (#1a1a1a, #2d2d2d, #3d3d3d)
|
||||||
|
- **Modern Typography**: Segoe UI font family with size hierarchy
|
||||||
|
- **Card-Based Layout**: Elegant card containers with shadows and spacing
|
||||||
|
- **Responsive Design**: Grid-based layout that scales with window size
|
||||||
|
- **Hover Effects**: Interactive button states and animations
|
||||||
|
- **Modern Buttons**: Flat design with accent colors and hover states
|
||||||
|
|
||||||
|
### 2. **shorts_generator2.py** - ✅ FULLY MODERNIZED
|
||||||
|
- **Modern Color Palette**: Consistent dark theme across all components
|
||||||
|
- **Card Interface**: Settings panels organized in modern card layouts
|
||||||
|
- **Progress Indicators**: Styled progress bars with modern aesthetics
|
||||||
|
- **Action Buttons**: Professional button styling with color-coded actions
|
||||||
|
- **Responsive Controls**: Grid layouts that adapt to window resizing
|
||||||
|
- **Modern Typography**: Clear font hierarchy for better readability
|
||||||
|
|
||||||
|
### 3. **thumbnail_editor.py** - ✅ COMPLETELY REDESIGNED
|
||||||
|
- **Professional Interface**: Canvas-based editing with modern controls
|
||||||
|
- **Dark Theme Editor**: Black canvas background with light UI elements
|
||||||
|
- **Card-Based Tools**: Text tools, stickers, and export options in cards
|
||||||
|
- **Timeline Slider**: Modern styled timeline for frame selection
|
||||||
|
- **Interactive Elements**: Drag-and-drop functionality with visual feedback
|
||||||
|
- **Modern Buttons**: Color-coded actions (blue, green, orange, purple, red)
|
||||||
|
|
||||||
|
## 🎯 Key Improvements Implemented
|
||||||
|
|
||||||
|
### Design System
|
||||||
|
```python
|
||||||
|
colors = {
|
||||||
|
'bg_primary': '#1a1a1a', # Dark background
|
||||||
|
'bg_secondary': '#2d2d2d', # Card backgrounds
|
||||||
|
'bg_tertiary': '#3d3d3d', # Elevated elements
|
||||||
|
'accent_blue': '#007acc', # Primary actions
|
||||||
|
'accent_green': '#28a745', # Success states
|
||||||
|
'accent_orange': '#fd7e14', # Warning actions
|
||||||
|
'accent_purple': '#6f42c1', # Secondary actions
|
||||||
|
'accent_red': '#dc3545', # Danger actions
|
||||||
|
'text_primary': '#ffffff', # Primary text
|
||||||
|
'text_secondary': '#b8b8b8', # Secondary text
|
||||||
|
'text_muted': '#6c757d' # Muted text
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Typography System
|
||||||
|
```python
|
||||||
|
fonts = {
|
||||||
|
'title': ('Segoe UI', 18, 'bold'), # Main titles
|
||||||
|
'heading': ('Segoe UI', 14, 'bold'), # Section headers
|
||||||
|
'subheading': ('Segoe UI', 12, 'bold'), # Card titles
|
||||||
|
'body': ('Segoe UI', 10), # Body text
|
||||||
|
'caption': ('Segoe UI', 9), # Small text
|
||||||
|
'button': ('Segoe UI', 10, 'bold') # Button text
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Responsive Features
|
||||||
|
- **Window Resize Handling**: All layouts adapt to different window sizes
|
||||||
|
- **Minimum Size Constraints**: Prevents UI from becoming too small
|
||||||
|
- **Grid Weight Configuration**: Proper expansion and contraction
|
||||||
|
- **Proportional Scaling**: Elements maintain proper relationships
|
||||||
|
|
||||||
|
### Modern UI Components
|
||||||
|
- **Card Containers**: Elevated surfaces with consistent padding
|
||||||
|
- **Hover Effects**: Interactive feedback on all clickable elements
|
||||||
|
- **Modern Buttons**: Flat design with semantic color coding
|
||||||
|
- **Progress Indicators**: Styled progress bars and status displays
|
||||||
|
- **Dark Theme**: Professional dark interface throughout
|
||||||
|
|
||||||
|
## 🚀 Features Enhanced
|
||||||
|
|
||||||
|
### Main Application (Main.py)
|
||||||
|
- Modern welcome screen with card-based navigation
|
||||||
|
- Responsive layout with proper spacing and hierarchy
|
||||||
|
- Professional button styling with hover states
|
||||||
|
- Dark theme consistency across all windows
|
||||||
|
|
||||||
|
### Shorts Generator (shorts_generator2.py)
|
||||||
|
- Settings organized in modern card layout
|
||||||
|
- Color-coded action buttons for different operations
|
||||||
|
- Modern progress tracking with styled progress bars
|
||||||
|
- Responsive controls that adapt to window size
|
||||||
|
|
||||||
|
### Thumbnail Editor (thumbnail_editor.py)
|
||||||
|
- Complete redesign with professional canvas interface
|
||||||
|
- Timeline slider for frame-by-frame navigation
|
||||||
|
- Card-based tool organization (Text, Stickers, Export)
|
||||||
|
- Modern drag-and-drop interaction design
|
||||||
|
- Professional save/export functionality
|
||||||
|
|
||||||
|
## 🎨 Visual Design Principles Applied
|
||||||
|
|
||||||
|
1. **Consistency**: Unified color scheme and typography across all windows
|
||||||
|
2. **Hierarchy**: Clear visual hierarchy using font sizes and colors
|
||||||
|
3. **Spacing**: Proper padding and margins for clean layouts
|
||||||
|
4. **Feedback**: Hover states and visual feedback for user interactions
|
||||||
|
5. **Accessibility**: High contrast and readable font sizes
|
||||||
|
6. **Professionalism**: Modern flat design with subtle shadows and effects
|
||||||
|
|
||||||
|
## 📱 Responsive Design Features
|
||||||
|
|
||||||
|
- **Grid Layouts**: Replaced pack() with grid() for better control
|
||||||
|
- **Weight Configuration**: Proper expansion behavior
|
||||||
|
- **Minimum Sizes**: Prevents UI from becoming unusable
|
||||||
|
- **Aspect Ratios**: Maintained proper proportions
|
||||||
|
- **Flexible Containers**: Adapts to different screen sizes
|
||||||
|
|
||||||
|
## 🔧 Technical Improvements
|
||||||
|
|
||||||
|
- **Modern Tkinter**: Used ttk widgets where appropriate
|
||||||
|
- **Style Configuration**: Custom styles for modern appearance
|
||||||
|
- **Event Handling**: Improved interaction patterns
|
||||||
|
- **Memory Management**: Proper image reference handling
|
||||||
|
- **Error Handling**: Graceful degradation and user feedback
|
||||||
|
|
||||||
|
## 🎉 Result
|
||||||
|
|
||||||
|
The AI Shorts Generator now features a completely modern, professional interface that:
|
||||||
|
- Looks contemporary and professional
|
||||||
|
- Provides excellent user experience
|
||||||
|
- Scales properly across different window sizes
|
||||||
|
- Uses consistent design patterns throughout
|
||||||
|
- Offers intuitive navigation and controls
|
||||||
|
|
||||||
|
All three requested files have been successfully modernized with a cohesive, professional dark theme that transforms the application from a basic GUI to a modern, professional tool! 🎨✨
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
# Professional Video Editor
|
||||||
|
|
||||||
|
A standalone video editor with timeline controls and real-time preview, designed specifically for editing generated shorts.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
### ✅ Working Features (OpenCV Backend)
|
||||||
|
- **🎬 Video Playback**: Load and play video files with timeline controls
|
||||||
|
- **📺 Real-time Preview**: Professional video player with frame-by-frame seeking
|
||||||
|
- **⏯️ Timeline Controls**: Play, Pause, Stop buttons with synchronized video playback
|
||||||
|
- **🕒 Time Display**: Current time and total duration with precise seeking
|
||||||
|
- **📊 Interactive Timeline**: Click and drag to seek to specific time positions
|
||||||
|
- **🎯 Frame-accurate Seeking**: Navigate to exact frames using the timeline
|
||||||
|
|
||||||
|
### 🔧 Advanced Features (Requires MoviePy)
|
||||||
|
- **✂️ Video Trimming**: Cut videos to specific time ranges
|
||||||
|
- **⚡ Speed Control**: Adjust playback speed (0.25x to 3.0x)
|
||||||
|
- **🔊 Volume Adjustment**: Control audio levels (0x to 2.0x)
|
||||||
|
- **🌅 Fade Effects**: Add professional fade in/out transitions
|
||||||
|
- **📝 Text Overlays**: Add custom text with positioning
|
||||||
|
- **💾 Video Export**: Save edited videos in MP4 format
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### From Main Application
|
||||||
|
1. Run `python Main.py`
|
||||||
|
2. Click "✏️ Edit Generated Shorts" button
|
||||||
|
3. Select a video from your shorts folder or browse for any video file
|
||||||
|
|
||||||
|
### Standalone Mode
|
||||||
|
1. Run `python video_editor.py`
|
||||||
|
2. The editor will open directly
|
||||||
|
|
||||||
|
## Installation Requirements
|
||||||
|
|
||||||
|
### Basic Functionality (OpenCV)
|
||||||
|
```bash
|
||||||
|
pip install opencv-python pillow
|
||||||
|
```
|
||||||
|
|
||||||
|
### Full Functionality (MoviePy)
|
||||||
|
```bash
|
||||||
|
pip install moviepy opencv-python pillow
|
||||||
|
```
|
||||||
|
|
||||||
|
## How to Use
|
||||||
|
|
||||||
|
1. **Load Video**: Click "📁 Select Video" to choose a video file
|
||||||
|
2. **Navigate**: Use timeline controls (Play/Pause/Stop) or click on timeline to seek
|
||||||
|
3. **Edit** (if MoviePy available):
|
||||||
|
- Adjust trim start/end times and click "✂️ Apply Trim"
|
||||||
|
- Change speed with slider and click "⚡ Apply Speed"
|
||||||
|
- Adjust volume and click "🔊 Apply Volume"
|
||||||
|
- Add text overlay and click "📝 Add Text"
|
||||||
|
- Apply fade effects with "🌅 Add Fade In/Out"
|
||||||
|
4. **Export**: Click "💾 Export Video" to save your changes
|
||||||
|
|
||||||
|
## Timeline Controls
|
||||||
|
|
||||||
|
- **▶️ Play**: Start video playback and timeline animation
|
||||||
|
- **⏸️ Pause**: Pause both video and timeline
|
||||||
|
- **⏹️ Stop**: Stop and return to beginning
|
||||||
|
- **Timeline Click**: Seek to specific time position
|
||||||
|
- **Time Display**: Shows current time / total duration
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- The editor automatically detects available libraries and adjusts functionality
|
||||||
|
- Without MoviePy, you get a professional video player with timeline controls
|
||||||
|
- With MoviePy, you get full editing capabilities
|
||||||
|
- All timeline controls are synchronized with actual video playback
|
||||||
|
- The interface is responsive and works with different window sizes
|
||||||
|
|
||||||
|
## File Support
|
||||||
|
|
||||||
|
Supports common video formats: MP4, AVI, MOV, MKV, WMV, FLV, WEBM
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
The editor is built with:
|
||||||
|
- **Tkinter**: Modern GUI with professional styling
|
||||||
|
- **OpenCV**: Video loading and frame display (always available)
|
||||||
|
- **MoviePy**: Advanced video editing features (optional)
|
||||||
|
- **PIL**: Image processing and display
|
||||||
|
- **Threading**: Non-blocking video playback and timeline updates
|
||||||
@@ -0,0 +1,489 @@
|
|||||||
|
"""
|
||||||
|
PyQt6 Professional Video Player - Prototype
|
||||||
|
Author: Dario Pascoal
|
||||||
|
|
||||||
|
Description: This is a PyQt6 implementation of a professional video player to demonstrate
|
||||||
|
the advantages PyQt6 could bring to the video editor application. This prototype shows:
|
||||||
|
|
||||||
|
- Hardware-accelerated video playback with QMediaPlayer
|
||||||
|
- Professional video controls and scrubbing
|
||||||
|
- Modern UI styling with dark theme
|
||||||
|
- Smooth timeline with precise seeking
|
||||||
|
- Professional video display with proper aspect ratio
|
||||||
|
- Keyboard shortcuts (Space, arrows, etc.)
|
||||||
|
- Full-screen capabilities
|
||||||
|
- Real-time effects pipeline ready
|
||||||
|
|
||||||
|
This serves as a proof-of-concept for upgrading the current Tkinter video editor
|
||||||
|
to PyQt6 for better performance and professional features.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
|
||||||
|
QHBoxLayout, QSlider, QPushButton, QLabel,
|
||||||
|
QFileDialog, QFrame, QSizePolicy, QSpacerItem,
|
||||||
|
QStyle, QStyleFactory, QMessageBox)
|
||||||
|
from PyQt6.QtCore import (Qt, QUrl, QTimer, pyqtSignal, QPropertyAnimation,
|
||||||
|
QEasingCurve, QRect, QThread, pyqtSlot)
|
||||||
|
from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput
|
||||||
|
from PyQt6.QtMultimediaWidgets import QVideoWidget
|
||||||
|
from PyQt6.QtGui import (QPalette, QColor, QFont, QIcon, QKeySequence,
|
||||||
|
QShortcut, QPixmap, QPainter, QBrush)
|
||||||
|
|
||||||
|
class ModernSlider(QSlider):
|
||||||
|
"""Custom slider with modern styling and smooth scrubbing"""
|
||||||
|
|
||||||
|
def __init__(self, orientation=Qt.Orientation.Horizontal):
|
||||||
|
super().__init__(orientation)
|
||||||
|
self.setStyleSheet("""
|
||||||
|
QSlider::groove:horizontal {
|
||||||
|
background: #404040;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
QSlider::handle:horizontal {
|
||||||
|
background: #00aaff;
|
||||||
|
border: 2px solid #ffffff;
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
margin: -7px 0;
|
||||||
|
border-radius: 9px;
|
||||||
|
}
|
||||||
|
QSlider::handle:horizontal:hover {
|
||||||
|
background: #0088cc;
|
||||||
|
border: 2px solid #ffffff;
|
||||||
|
}
|
||||||
|
QSlider::sub-page:horizontal {
|
||||||
|
background: #00aaff;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
|
||||||
|
class ProfessionalVideoPlayer(QMainWindow):
|
||||||
|
"""Professional video player with PyQt6 multimedia capabilities"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.current_video_path = None
|
||||||
|
self.is_fullscreen = False
|
||||||
|
self.setup_ui()
|
||||||
|
self.setup_media_player()
|
||||||
|
self.setup_shortcuts()
|
||||||
|
self.setup_styling()
|
||||||
|
|
||||||
|
# Load a sample video if available
|
||||||
|
self.auto_load_sample_video()
|
||||||
|
|
||||||
|
def setup_ui(self):
|
||||||
|
"""Setup the professional video player interface"""
|
||||||
|
self.setWindowTitle("PyQt6 Professional Video Player - Prototype")
|
||||||
|
self.setGeometry(100, 100, 1200, 800)
|
||||||
|
self.setMinimumSize(800, 600)
|
||||||
|
|
||||||
|
# Central widget
|
||||||
|
central_widget = QWidget()
|
||||||
|
self.setCentralWidget(central_widget)
|
||||||
|
|
||||||
|
# Main layout
|
||||||
|
main_layout = QVBoxLayout(central_widget)
|
||||||
|
main_layout.setContentsMargins(10, 10, 10, 10)
|
||||||
|
main_layout.setSpacing(10)
|
||||||
|
|
||||||
|
# Video display area
|
||||||
|
self.video_widget = QVideoWidget()
|
||||||
|
self.video_widget.setMinimumHeight(400)
|
||||||
|
self.video_widget.setStyleSheet("""
|
||||||
|
QVideoWidget {
|
||||||
|
background-color: #000000;
|
||||||
|
border: 2px solid #333333;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
main_layout.addWidget(self.video_widget, 1) # Takes most space
|
||||||
|
|
||||||
|
# Controls panel
|
||||||
|
controls_frame = QFrame()
|
||||||
|
controls_frame.setFixedHeight(120)
|
||||||
|
controls_frame.setStyleSheet("""
|
||||||
|
QFrame {
|
||||||
|
background-color: #2d2d2d;
|
||||||
|
border: 1px solid #404040;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
main_layout.addWidget(controls_frame)
|
||||||
|
|
||||||
|
controls_layout = QVBoxLayout(controls_frame)
|
||||||
|
|
||||||
|
# Timeline slider
|
||||||
|
timeline_layout = QHBoxLayout()
|
||||||
|
|
||||||
|
self.current_time_label = QLabel("00:00")
|
||||||
|
self.current_time_label.setStyleSheet("color: #ffffff; font-weight: bold;")
|
||||||
|
self.current_time_label.setMinimumWidth(50)
|
||||||
|
timeline_layout.addWidget(self.current_time_label)
|
||||||
|
|
||||||
|
self.timeline_slider = ModernSlider()
|
||||||
|
self.timeline_slider.setRange(0, 1000)
|
||||||
|
self.timeline_slider.setValue(0)
|
||||||
|
self.timeline_slider.sliderPressed.connect(self.on_timeline_pressed)
|
||||||
|
self.timeline_slider.sliderReleased.connect(self.on_timeline_released)
|
||||||
|
self.timeline_slider.valueChanged.connect(self.on_timeline_changed)
|
||||||
|
timeline_layout.addWidget(self.timeline_slider, 1)
|
||||||
|
|
||||||
|
self.duration_label = QLabel("00:00")
|
||||||
|
self.duration_label.setStyleSheet("color: #ffffff; font-weight: bold;")
|
||||||
|
self.duration_label.setMinimumWidth(50)
|
||||||
|
timeline_layout.addWidget(self.duration_label)
|
||||||
|
|
||||||
|
controls_layout.addLayout(timeline_layout)
|
||||||
|
|
||||||
|
# Playback controls
|
||||||
|
playback_layout = QHBoxLayout()
|
||||||
|
|
||||||
|
# Load video button
|
||||||
|
self.load_btn = self.create_control_button("📁", "Load Video", self.load_video)
|
||||||
|
playback_layout.addWidget(self.load_btn)
|
||||||
|
|
||||||
|
playback_layout.addSpacerItem(QSpacerItem(20, 20, QSizePolicy.Policy.Expanding))
|
||||||
|
|
||||||
|
# Previous frame
|
||||||
|
self.prev_frame_btn = self.create_control_button("⏮", "Previous Frame", self.previous_frame)
|
||||||
|
playback_layout.addWidget(self.prev_frame_btn)
|
||||||
|
|
||||||
|
# Play/Pause
|
||||||
|
self.play_pause_btn = self.create_control_button("▶", "Play/Pause", self.toggle_playback)
|
||||||
|
self.play_pause_btn.setStyleSheet(self.play_pause_btn.styleSheet() + "min-width: 60px;")
|
||||||
|
playback_layout.addWidget(self.play_pause_btn)
|
||||||
|
|
||||||
|
# Next frame
|
||||||
|
self.next_frame_btn = self.create_control_button("⏭", "Next Frame", self.next_frame)
|
||||||
|
playback_layout.addWidget(self.next_frame_btn)
|
||||||
|
|
||||||
|
playback_layout.addSpacerItem(QSpacerItem(20, 20, QSizePolicy.Policy.Expanding))
|
||||||
|
|
||||||
|
# Volume control
|
||||||
|
volume_layout = QHBoxLayout()
|
||||||
|
volume_icon = QLabel("🔊")
|
||||||
|
volume_icon.setStyleSheet("color: #ffffff; font-size: 16px;")
|
||||||
|
volume_layout.addWidget(volume_icon)
|
||||||
|
|
||||||
|
self.volume_slider = ModernSlider()
|
||||||
|
self.volume_slider.setRange(0, 100)
|
||||||
|
self.volume_slider.setValue(70)
|
||||||
|
self.volume_slider.setMaximumWidth(100)
|
||||||
|
self.volume_slider.valueChanged.connect(self.on_volume_changed)
|
||||||
|
volume_layout.addWidget(self.volume_slider)
|
||||||
|
|
||||||
|
playback_layout.addLayout(volume_layout)
|
||||||
|
|
||||||
|
# Fullscreen button
|
||||||
|
self.fullscreen_btn = self.create_control_button("⛶", "Fullscreen (F11)", self.toggle_fullscreen)
|
||||||
|
playback_layout.addWidget(self.fullscreen_btn)
|
||||||
|
|
||||||
|
controls_layout.addLayout(playback_layout)
|
||||||
|
|
||||||
|
# Status bar
|
||||||
|
self.status_label = QLabel("Ready - Load a video to start")
|
||||||
|
self.status_label.setStyleSheet("""
|
||||||
|
color: #aaaaaa;
|
||||||
|
background-color: #1e1e1e;
|
||||||
|
padding: 5px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
""")
|
||||||
|
main_layout.addWidget(self.status_label)
|
||||||
|
|
||||||
|
def create_control_button(self, text, tooltip, callback):
|
||||||
|
"""Create a styled control button"""
|
||||||
|
btn = QPushButton(text)
|
||||||
|
btn.setToolTip(tooltip)
|
||||||
|
btn.clicked.connect(callback)
|
||||||
|
btn.setStyleSheet("""
|
||||||
|
QPushButton {
|
||||||
|
background-color: #404040;
|
||||||
|
color: #ffffff;
|
||||||
|
border: 2px solid #555555;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
min-width: 40px;
|
||||||
|
min-height: 30px;
|
||||||
|
}
|
||||||
|
QPushButton:hover {
|
||||||
|
background-color: #505050;
|
||||||
|
border: 2px solid #00aaff;
|
||||||
|
}
|
||||||
|
QPushButton:pressed {
|
||||||
|
background-color: #00aaff;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
return btn
|
||||||
|
|
||||||
|
def setup_media_player(self):
|
||||||
|
"""Setup PyQt6 media player with hardware acceleration"""
|
||||||
|
self.media_player = QMediaPlayer()
|
||||||
|
self.audio_output = QAudioOutput()
|
||||||
|
|
||||||
|
# Connect media player to video widget
|
||||||
|
self.media_player.setVideoOutput(self.video_widget)
|
||||||
|
self.media_player.setAudioOutput(self.audio_output)
|
||||||
|
|
||||||
|
# Connect signals
|
||||||
|
self.media_player.positionChanged.connect(self.update_position)
|
||||||
|
self.media_player.durationChanged.connect(self.update_duration)
|
||||||
|
self.media_player.playbackStateChanged.connect(self.update_playback_state)
|
||||||
|
self.media_player.errorOccurred.connect(self.handle_error)
|
||||||
|
|
||||||
|
# Timeline update timer
|
||||||
|
self.position_timer = QTimer()
|
||||||
|
self.position_timer.timeout.connect(self.update_timeline_position)
|
||||||
|
self.position_timer.start(50) # 20 FPS updates
|
||||||
|
|
||||||
|
# Timeline dragging state
|
||||||
|
self.timeline_dragging = False
|
||||||
|
|
||||||
|
def setup_shortcuts(self):
|
||||||
|
"""Setup keyboard shortcuts for professional video editing"""
|
||||||
|
# Spacebar - Play/Pause
|
||||||
|
space_shortcut = QShortcut(QKeySequence(Qt.Key.Key_Space), self)
|
||||||
|
space_shortcut.activated.connect(self.toggle_playback)
|
||||||
|
|
||||||
|
# Left/Right arrows - Frame navigation
|
||||||
|
left_shortcut = QShortcut(QKeySequence(Qt.Key.Key_Left), self)
|
||||||
|
left_shortcut.activated.connect(self.previous_frame)
|
||||||
|
|
||||||
|
right_shortcut = QShortcut(QKeySequence(Qt.Key.Key_Right), self)
|
||||||
|
right_shortcut.activated.connect(self.next_frame)
|
||||||
|
|
||||||
|
# Shift + Left/Right - Skip by seconds
|
||||||
|
shift_left = QShortcut(QKeySequence(Qt.KeyboardModifier.ShiftModifier | Qt.Key.Key_Left), self)
|
||||||
|
shift_left.activated.connect(lambda: self.seek_relative(-5000))
|
||||||
|
|
||||||
|
shift_right = QShortcut(QKeySequence(Qt.KeyboardModifier.ShiftModifier | Qt.Key.Key_Right), self)
|
||||||
|
shift_right.activated.connect(lambda: self.seek_relative(5000))
|
||||||
|
|
||||||
|
# Home/End - Start/End
|
||||||
|
home_shortcut = QShortcut(QKeySequence(Qt.Key.Key_Home), self)
|
||||||
|
home_shortcut.activated.connect(lambda: self.media_player.setPosition(0))
|
||||||
|
|
||||||
|
end_shortcut = QShortcut(QKeySequence(Qt.Key.Key_End), self)
|
||||||
|
end_shortcut.activated.connect(lambda: self.media_player.setPosition(self.media_player.duration()))
|
||||||
|
|
||||||
|
# F11 - Fullscreen
|
||||||
|
f11_shortcut = QShortcut(QKeySequence(Qt.Key.Key_F11), self)
|
||||||
|
f11_shortcut.activated.connect(self.toggle_fullscreen)
|
||||||
|
|
||||||
|
# ESC - Exit fullscreen
|
||||||
|
esc_shortcut = QShortcut(QKeySequence(Qt.Key.Key_Escape), self)
|
||||||
|
esc_shortcut.activated.connect(self.exit_fullscreen)
|
||||||
|
|
||||||
|
def setup_styling(self):
|
||||||
|
"""Apply professional dark theme styling"""
|
||||||
|
self.setStyleSheet("""
|
||||||
|
QMainWindow {
|
||||||
|
background-color: #1e1e1e;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
QLabel {
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
|
||||||
|
def auto_load_sample_video(self):
|
||||||
|
"""Auto-load a sample video if available"""
|
||||||
|
sample_videos = ["short_1.mp4", "myvideo.mp4", "myvideo2.mp4"]
|
||||||
|
for video in sample_videos:
|
||||||
|
if os.path.exists(video):
|
||||||
|
self.load_video_file(video)
|
||||||
|
self.status_label.setText(f"✅ Auto-loaded: {video}")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.status_label.setText("📁 Click 'Load Video' to select a video file")
|
||||||
|
|
||||||
|
def load_video(self):
|
||||||
|
"""Load video file dialog"""
|
||||||
|
file_path, _ = QFileDialog.getOpenFileName(
|
||||||
|
self,
|
||||||
|
"Select Video File",
|
||||||
|
"",
|
||||||
|
"Video Files (*.mp4 *.avi *.mov *.mkv *.wmv *.flv *.webm)"
|
||||||
|
)
|
||||||
|
if file_path:
|
||||||
|
self.load_video_file(file_path)
|
||||||
|
|
||||||
|
def load_video_file(self, file_path):
|
||||||
|
"""Load video file into media player"""
|
||||||
|
try:
|
||||||
|
self.current_video_path = file_path
|
||||||
|
url = QUrl.fromLocalFile(file_path)
|
||||||
|
self.media_player.setSource(url)
|
||||||
|
self.status_label.setText(f"✅ Loaded: {os.path.basename(file_path)}")
|
||||||
|
|
||||||
|
# Enable controls
|
||||||
|
self.timeline_slider.setEnabled(True)
|
||||||
|
self.play_pause_btn.setEnabled(True)
|
||||||
|
self.prev_frame_btn.setEnabled(True)
|
||||||
|
self.next_frame_btn.setEnabled(True)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.status_label.setText(f"❌ Error loading video: {e}")
|
||||||
|
QMessageBox.critical(self, "Error", f"Failed to load video:\n{e}")
|
||||||
|
|
||||||
|
def toggle_playback(self):
|
||||||
|
"""Toggle between play and pause"""
|
||||||
|
if self.media_player.playbackState() == QMediaPlayer.PlaybackState.PlayingState:
|
||||||
|
self.media_player.pause()
|
||||||
|
else:
|
||||||
|
self.media_player.play()
|
||||||
|
|
||||||
|
def previous_frame(self):
|
||||||
|
"""Go to previous frame (1/30th second)"""
|
||||||
|
current_pos = self.media_player.position()
|
||||||
|
frame_duration = 1000 // 30 # ~33ms for 30fps
|
||||||
|
new_pos = max(0, current_pos - frame_duration)
|
||||||
|
self.media_player.setPosition(new_pos)
|
||||||
|
|
||||||
|
def next_frame(self):
|
||||||
|
"""Go to next frame (1/30th second)"""
|
||||||
|
current_pos = self.media_player.position()
|
||||||
|
frame_duration = 1000 // 30 # ~33ms for 30fps
|
||||||
|
new_pos = min(self.media_player.duration(), current_pos + frame_duration)
|
||||||
|
self.media_player.setPosition(new_pos)
|
||||||
|
|
||||||
|
def seek_relative(self, ms):
|
||||||
|
"""Seek relative to current position"""
|
||||||
|
current_pos = self.media_player.position()
|
||||||
|
new_pos = max(0, min(self.media_player.duration(), current_pos + ms))
|
||||||
|
self.media_player.setPosition(new_pos)
|
||||||
|
|
||||||
|
def toggle_fullscreen(self):
|
||||||
|
"""Toggle fullscreen mode"""
|
||||||
|
if self.is_fullscreen:
|
||||||
|
self.exit_fullscreen()
|
||||||
|
else:
|
||||||
|
self.enter_fullscreen()
|
||||||
|
|
||||||
|
def enter_fullscreen(self):
|
||||||
|
"""Enter fullscreen mode"""
|
||||||
|
self.is_fullscreen = True
|
||||||
|
self.video_widget.setParent(None)
|
||||||
|
self.video_widget.showFullScreen()
|
||||||
|
self.video_widget.setFocus()
|
||||||
|
|
||||||
|
# Add fullscreen controls overlay (simplified)
|
||||||
|
self.fullscreen_btn.setText("🗗")
|
||||||
|
self.status_label.setText("🖥️ Fullscreen mode - Press ESC or F11 to exit")
|
||||||
|
|
||||||
|
def exit_fullscreen(self):
|
||||||
|
"""Exit fullscreen mode"""
|
||||||
|
if self.is_fullscreen:
|
||||||
|
self.is_fullscreen = False
|
||||||
|
self.video_widget.setParent(self.centralWidget())
|
||||||
|
|
||||||
|
# Re-add to layout
|
||||||
|
layout = self.centralWidget().layout()
|
||||||
|
layout.insertWidget(0, self.video_widget, 1)
|
||||||
|
|
||||||
|
self.video_widget.showNormal()
|
||||||
|
self.fullscreen_btn.setText("⛶")
|
||||||
|
self.status_label.setText("🖥️ Exited fullscreen mode")
|
||||||
|
|
||||||
|
def on_volume_changed(self, value):
|
||||||
|
"""Handle volume changes"""
|
||||||
|
volume = value / 100.0
|
||||||
|
self.audio_output.setVolume(volume)
|
||||||
|
self.status_label.setText(f"🔊 Volume: {value}%")
|
||||||
|
|
||||||
|
def on_timeline_pressed(self):
|
||||||
|
"""Timeline slider pressed - start dragging"""
|
||||||
|
self.timeline_dragging = True
|
||||||
|
|
||||||
|
def on_timeline_released(self):
|
||||||
|
"""Timeline slider released - seek to position"""
|
||||||
|
self.timeline_dragging = False
|
||||||
|
if self.media_player.duration() > 0:
|
||||||
|
position = (self.timeline_slider.value() / 1000.0) * self.media_player.duration()
|
||||||
|
self.media_player.setPosition(int(position))
|
||||||
|
|
||||||
|
def on_timeline_changed(self, value):
|
||||||
|
"""Timeline slider value changed"""
|
||||||
|
if self.timeline_dragging and self.media_player.duration() > 0:
|
||||||
|
# Update time display while dragging
|
||||||
|
position = (value / 1000.0) * self.media_player.duration()
|
||||||
|
self.current_time_label.setText(self.format_time(int(position)))
|
||||||
|
|
||||||
|
def update_position(self, position):
|
||||||
|
"""Update timeline position from media player"""
|
||||||
|
if not self.timeline_dragging and self.media_player.duration() > 0:
|
||||||
|
value = (position / self.media_player.duration()) * 1000
|
||||||
|
self.timeline_slider.setValue(int(value))
|
||||||
|
self.current_time_label.setText(self.format_time(position))
|
||||||
|
|
||||||
|
def update_duration(self, duration):
|
||||||
|
"""Update duration display"""
|
||||||
|
self.duration_label.setText(self.format_time(duration))
|
||||||
|
self.timeline_slider.setEnabled(duration > 0)
|
||||||
|
|
||||||
|
def update_timeline_position(self):
|
||||||
|
"""High-frequency timeline updates"""
|
||||||
|
if not self.timeline_dragging:
|
||||||
|
position = self.media_player.position()
|
||||||
|
self.update_position(position)
|
||||||
|
|
||||||
|
def update_playback_state(self, state):
|
||||||
|
"""Update play/pause button based on playback state"""
|
||||||
|
if state == QMediaPlayer.PlaybackState.PlayingState:
|
||||||
|
self.play_pause_btn.setText("⏸")
|
||||||
|
self.status_label.setText("▶️ Playing...")
|
||||||
|
else:
|
||||||
|
self.play_pause_btn.setText("▶")
|
||||||
|
if state == QMediaPlayer.PlaybackState.PausedState:
|
||||||
|
self.status_label.setText("⏸️ Paused")
|
||||||
|
else:
|
||||||
|
self.status_label.setText("⏹️ Stopped")
|
||||||
|
|
||||||
|
def handle_error(self, error):
|
||||||
|
"""Handle media player errors"""
|
||||||
|
error_msg = f"Media player error: {error}"
|
||||||
|
self.status_label.setText(f"❌ {error_msg}")
|
||||||
|
QMessageBox.critical(self, "Playback Error", error_msg)
|
||||||
|
|
||||||
|
def format_time(self, ms):
|
||||||
|
"""Format time in mm:ss format"""
|
||||||
|
seconds = ms // 1000
|
||||||
|
minutes = seconds // 60
|
||||||
|
seconds = seconds % 60
|
||||||
|
return f"{minutes:02d}:{seconds:02d}"
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Run the PyQt6 video player prototype"""
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
# Set application properties
|
||||||
|
app.setApplicationName("PyQt6 Video Player Prototype")
|
||||||
|
app.setApplicationVersion("1.0")
|
||||||
|
|
||||||
|
# Apply dark style
|
||||||
|
app.setStyle(QStyleFactory.create('Fusion'))
|
||||||
|
|
||||||
|
# Create and show main window
|
||||||
|
player = ProfessionalVideoPlayer()
|
||||||
|
player.show()
|
||||||
|
|
||||||
|
print("🎬 PyQt6 Professional Video Player Started!")
|
||||||
|
print("📋 Features:")
|
||||||
|
print(" • Hardware-accelerated playback")
|
||||||
|
print(" • Professional timeline scrubbing")
|
||||||
|
print(" • Keyboard shortcuts (Space, arrows, F11)")
|
||||||
|
print(" • Fullscreen mode")
|
||||||
|
print(" • Modern dark theme")
|
||||||
|
print(" • Smooth 20 FPS UI updates")
|
||||||
|
|
||||||
|
sys.exit(app.exec())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
+3537
-288
File diff suppressed because it is too large
Load Diff
+755
-341
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,626 @@
|
|||||||
|
import os
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import filedialog, simpledialog, colorchooser, messagebox, ttk
|
||||||
|
from moviepy import VideoFileClip
|
||||||
|
from PIL import Image, ImageTk, ImageDraw, ImageFont
|
||||||
|
|
||||||
|
# Modern Thumbnail Editor with Professional UI Design
|
||||||
|
|
||||||
|
class ModernThumbnailEditor:
|
||||||
|
def __init__(self, video_path):
|
||||||
|
self.video_path = video_path
|
||||||
|
self.clip = None
|
||||||
|
self.current_frame_img = None
|
||||||
|
self.canvas_items = []
|
||||||
|
self.drag_data = {"item": None, "x": 0, "y": 0}
|
||||||
|
|
||||||
|
# Modern color scheme
|
||||||
|
self.colors = {
|
||||||
|
'bg_primary': '#1a1a1a', # Dark background
|
||||||
|
'bg_secondary': '#2d2d2d', # Card backgrounds
|
||||||
|
'bg_tertiary': '#3d3d3d', # Elevated elements
|
||||||
|
'accent_blue': '#007acc', # Primary blue
|
||||||
|
'accent_green': '#28a745', # Success green
|
||||||
|
'accent_orange': '#fd7e14', # Warning orange
|
||||||
|
'accent_purple': '#6f42c1', # Secondary purple
|
||||||
|
'accent_red': '#dc3545', # Error red
|
||||||
|
'text_primary': '#ffffff', # Primary text
|
||||||
|
'text_secondary': '#b8b8b8', # Secondary text
|
||||||
|
'text_muted': '#6c757d', # Muted text
|
||||||
|
'border': '#404040', # Border color
|
||||||
|
'hover': '#4a4a4a' # Hover state
|
||||||
|
}
|
||||||
|
|
||||||
|
# Modern fonts
|
||||||
|
self.fonts = {
|
||||||
|
'title': ('Segoe UI', 18, 'bold'),
|
||||||
|
'heading': ('Segoe UI', 14, 'bold'),
|
||||||
|
'subheading': ('Segoe UI', 12, 'bold'),
|
||||||
|
'body': ('Segoe UI', 10),
|
||||||
|
'caption': ('Segoe UI', 9),
|
||||||
|
'button': ('Segoe UI', 10, 'bold')
|
||||||
|
}
|
||||||
|
|
||||||
|
self.setup_ui()
|
||||||
|
|
||||||
|
def setup_ui(self):
|
||||||
|
self.editor = tk.Toplevel()
|
||||||
|
self.editor.title("📸 Professional Thumbnail Editor")
|
||||||
|
self.editor.geometry("1400x900")
|
||||||
|
self.editor.minsize(1200, 800)
|
||||||
|
self.editor.configure(bg=self.colors['bg_primary'])
|
||||||
|
|
||||||
|
# Load video
|
||||||
|
try:
|
||||||
|
print(f"📹 Loading video: {os.path.basename(self.video_path)}")
|
||||||
|
self.clip = VideoFileClip(self.video_path)
|
||||||
|
self.duration = int(self.clip.duration)
|
||||||
|
except Exception as e:
|
||||||
|
messagebox.showerror("Video Error", f"Failed to load video: {e}")
|
||||||
|
self.editor.destroy()
|
||||||
|
return
|
||||||
|
|
||||||
|
# Setup stickers folder
|
||||||
|
self.stickers_folder = os.path.join(os.path.dirname(__file__), "stickers")
|
||||||
|
os.makedirs(self.stickers_folder, exist_ok=True)
|
||||||
|
self.create_default_stickers()
|
||||||
|
|
||||||
|
self.create_modern_interface()
|
||||||
|
|
||||||
|
def create_modern_interface(self):
|
||||||
|
"""Create the modern thumbnail editor interface"""
|
||||||
|
# Header
|
||||||
|
header_frame = tk.Frame(self.editor, bg=self.colors['bg_secondary'], height=70)
|
||||||
|
header_frame.pack(fill="x", padx=0, pady=0)
|
||||||
|
header_frame.pack_propagate(False)
|
||||||
|
|
||||||
|
title_frame = tk.Frame(header_frame, bg=self.colors['bg_secondary'])
|
||||||
|
title_frame.pack(expand=True, fill="both", padx=30, pady=15)
|
||||||
|
|
||||||
|
title_label = tk.Label(title_frame, text="📸 Professional Thumbnail Editor",
|
||||||
|
font=self.fonts['title'], bg=self.colors['bg_secondary'],
|
||||||
|
fg=self.colors['text_primary'])
|
||||||
|
title_label.pack(side="left")
|
||||||
|
|
||||||
|
# Video info
|
||||||
|
video_name = os.path.basename(self.video_path)
|
||||||
|
info_label = tk.Label(title_frame, text=f"Editing: {video_name}",
|
||||||
|
font=self.fonts['caption'], bg=self.colors['bg_secondary'],
|
||||||
|
fg=self.colors['text_secondary'])
|
||||||
|
info_label.pack(side="right")
|
||||||
|
|
||||||
|
# Main content area
|
||||||
|
main_container = tk.Frame(self.editor, bg=self.colors['bg_primary'])
|
||||||
|
main_container.pack(fill="both", expand=True, padx=20, pady=20)
|
||||||
|
|
||||||
|
# Left panel - Canvas area
|
||||||
|
left_panel = tk.Frame(main_container, bg=self.colors['bg_secondary'])
|
||||||
|
left_panel.pack(side="left", fill="both", expand=True, padx=(0, 10))
|
||||||
|
|
||||||
|
self.setup_canvas_area(left_panel)
|
||||||
|
|
||||||
|
# Right panel - Controls
|
||||||
|
right_panel = tk.Frame(main_container, bg=self.colors['bg_secondary'], width=350)
|
||||||
|
right_panel.pack(side="right", fill="y")
|
||||||
|
right_panel.pack_propagate(False)
|
||||||
|
|
||||||
|
self.setup_controls_panel(right_panel)
|
||||||
|
|
||||||
|
def setup_canvas_area(self, parent):
|
||||||
|
"""Setup the main canvas area with modern styling"""
|
||||||
|
# Canvas header
|
||||||
|
canvas_header = tk.Frame(parent, bg=self.colors['bg_secondary'])
|
||||||
|
canvas_header.pack(fill="x", padx=20, pady=(20, 10))
|
||||||
|
|
||||||
|
canvas_title = tk.Label(canvas_header, text="🎬 Thumbnail Preview",
|
||||||
|
font=self.fonts['heading'], bg=self.colors['bg_secondary'],
|
||||||
|
fg=self.colors['text_primary'])
|
||||||
|
canvas_title.pack(side="left")
|
||||||
|
|
||||||
|
# Canvas container
|
||||||
|
canvas_container = tk.Frame(parent, bg=self.colors['bg_tertiary'], relief="flat", bd=2)
|
||||||
|
canvas_container.pack(fill="both", expand=True, padx=20, pady=(0, 20))
|
||||||
|
|
||||||
|
# Modern canvas with dark theme
|
||||||
|
self.canvas = tk.Canvas(canvas_container, bg='#000000', highlightthickness=0,
|
||||||
|
relief="flat", bd=0)
|
||||||
|
self.canvas.pack(fill="both", expand=True, padx=10, pady=10)
|
||||||
|
|
||||||
|
# Bind canvas events for dragging
|
||||||
|
self.canvas.bind("<Button-1>", self.on_canvas_click)
|
||||||
|
self.canvas.bind("<B1-Motion>", self.on_canvas_drag)
|
||||||
|
self.canvas.bind("<ButtonRelease-1>", self.on_canvas_release)
|
||||||
|
|
||||||
|
# Frame timeline slider
|
||||||
|
timeline_frame = tk.Frame(parent, bg=self.colors['bg_secondary'])
|
||||||
|
timeline_frame.pack(fill="x", padx=20, pady=(0, 20))
|
||||||
|
|
||||||
|
tk.Label(timeline_frame, text="⏱️ Timeline", font=self.fonts['subheading'],
|
||||||
|
bg=self.colors['bg_secondary'], fg=self.colors['text_primary']).pack(anchor="w", pady=(0, 10))
|
||||||
|
|
||||||
|
# Modern slider styling
|
||||||
|
style = ttk.Style()
|
||||||
|
style.configure("Modern.Horizontal.TScale",
|
||||||
|
background=self.colors['bg_secondary'],
|
||||||
|
troughcolor=self.colors['bg_tertiary'],
|
||||||
|
sliderlength=20,
|
||||||
|
sliderrelief="flat")
|
||||||
|
|
||||||
|
self.time_var = tk.DoubleVar(value=0)
|
||||||
|
self.time_slider = ttk.Scale(timeline_frame, from_=0, to=self.duration,
|
||||||
|
orient="horizontal", variable=self.time_var,
|
||||||
|
command=self.on_time_change, style="Modern.Horizontal.TScale")
|
||||||
|
self.time_slider.pack(fill="x", pady=(0, 5))
|
||||||
|
|
||||||
|
# Time display
|
||||||
|
time_display_frame = tk.Frame(timeline_frame, bg=self.colors['bg_secondary'])
|
||||||
|
time_display_frame.pack(fill="x")
|
||||||
|
|
||||||
|
self.time_label = tk.Label(time_display_frame, text="00:00",
|
||||||
|
font=self.fonts['body'], bg=self.colors['bg_secondary'],
|
||||||
|
fg=self.colors['text_secondary'])
|
||||||
|
self.time_label.pack(side="left")
|
||||||
|
|
||||||
|
duration_label = tk.Label(time_display_frame, text=f"/ {self.duration//60:02d}:{self.duration%60:02d}",
|
||||||
|
font=self.fonts['body'], bg=self.colors['bg_secondary'],
|
||||||
|
fg=self.colors['text_muted'])
|
||||||
|
duration_label.pack(side="right")
|
||||||
|
|
||||||
|
# Load initial frame
|
||||||
|
self.update_canvas_frame(0)
|
||||||
|
|
||||||
|
def setup_controls_panel(self, parent):
|
||||||
|
"""Setup the right panel controls with modern design"""
|
||||||
|
# Scroll container for controls
|
||||||
|
scroll_frame = tk.Frame(parent, bg=self.colors['bg_secondary'])
|
||||||
|
scroll_frame.pack(fill="both", expand=True, padx=20, pady=20)
|
||||||
|
|
||||||
|
# Title
|
||||||
|
controls_title = tk.Label(scroll_frame, text="🎨 Editing Tools",
|
||||||
|
font=self.fonts['heading'], bg=self.colors['bg_secondary'],
|
||||||
|
fg=self.colors['text_primary'])
|
||||||
|
controls_title.pack(anchor="w", pady=(0, 20))
|
||||||
|
|
||||||
|
# Text Tools Card
|
||||||
|
self.create_text_tools_card(scroll_frame)
|
||||||
|
|
||||||
|
# Stickers Card
|
||||||
|
self.create_stickers_card(scroll_frame)
|
||||||
|
|
||||||
|
# Export Card
|
||||||
|
self.create_export_card(scroll_frame)
|
||||||
|
|
||||||
|
def create_text_tools_card(self, parent):
|
||||||
|
"""Create modern text tools card"""
|
||||||
|
text_card = self.create_modern_card(parent, "✍️ Text Tools")
|
||||||
|
|
||||||
|
# Add text button
|
||||||
|
add_text_btn = self.create_modern_button(text_card, "➕ Add Text",
|
||||||
|
self.colors['accent_blue'], self.add_text)
|
||||||
|
add_text_btn.pack(fill="x", pady=(0, 10))
|
||||||
|
|
||||||
|
# Text style options
|
||||||
|
style_frame = tk.Frame(text_card, bg=self.colors['bg_secondary'])
|
||||||
|
style_frame.pack(fill="x", pady=(0, 10))
|
||||||
|
|
||||||
|
tk.Label(style_frame, text="Text Size:", font=self.fonts['body'],
|
||||||
|
bg=self.colors['bg_secondary'], fg=self.colors['text_secondary']).pack(anchor="w")
|
||||||
|
|
||||||
|
self.text_size_var = tk.IntVar(value=36)
|
||||||
|
size_frame = tk.Frame(style_frame, bg=self.colors['bg_secondary'])
|
||||||
|
size_frame.pack(fill="x", pady=(5, 0))
|
||||||
|
|
||||||
|
for size in [24, 36, 48, 64]:
|
||||||
|
btn = tk.Button(size_frame, text=str(size), font=self.fonts['caption'],
|
||||||
|
bg=self.colors['bg_tertiary'], fg=self.colors['text_primary'],
|
||||||
|
relief="flat", bd=0, padx=10, pady=5,
|
||||||
|
activebackground=self.colors['hover'],
|
||||||
|
command=lambda s=size: self.text_size_var.set(s))
|
||||||
|
btn.pack(side="left", padx=(0, 5))
|
||||||
|
self.add_hover_effect(btn)
|
||||||
|
|
||||||
|
# Text color
|
||||||
|
color_frame = tk.Frame(text_card, bg=self.colors['bg_secondary'])
|
||||||
|
color_frame.pack(fill="x", pady=(10, 0))
|
||||||
|
|
||||||
|
tk.Label(color_frame, text="Text Color:", font=self.fonts['body'],
|
||||||
|
bg=self.colors['bg_secondary'], fg=self.colors['text_secondary']).pack(anchor="w")
|
||||||
|
|
||||||
|
self.text_color_btn = self.create_modern_button(color_frame, "🎨 Choose Color",
|
||||||
|
self.colors['accent_purple'], self.choose_text_color)
|
||||||
|
self.text_color_btn.pack(fill="x", pady=(5, 0))
|
||||||
|
|
||||||
|
self.current_text_color = "#FFFFFF"
|
||||||
|
|
||||||
|
def create_stickers_card(self, parent):
|
||||||
|
"""Create modern stickers card"""
|
||||||
|
stickers_card = self.create_modern_card(parent, "😊 Stickers & Emojis")
|
||||||
|
|
||||||
|
# Load stickers button
|
||||||
|
load_btn = self.create_modern_button(stickers_card, "📁 Load Custom Sticker",
|
||||||
|
self.colors['accent_green'], self.load_custom_sticker)
|
||||||
|
load_btn.pack(fill="x", pady=(0, 15))
|
||||||
|
|
||||||
|
# Default stickers grid
|
||||||
|
stickers_frame = tk.Frame(stickers_card, bg=self.colors['bg_secondary'])
|
||||||
|
stickers_frame.pack(fill="x")
|
||||||
|
|
||||||
|
tk.Label(stickers_frame, text="Default Stickers:", font=self.fonts['body'],
|
||||||
|
bg=self.colors['bg_secondary'], fg=self.colors['text_secondary']).pack(anchor="w", pady=(0, 10))
|
||||||
|
|
||||||
|
# Create grid for stickers
|
||||||
|
self.create_stickers_grid(stickers_frame)
|
||||||
|
|
||||||
|
def create_stickers_grid(self, parent):
|
||||||
|
"""Create a grid of default stickers"""
|
||||||
|
sticker_files = [f for f in os.listdir(self.stickers_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
|
||||||
|
|
||||||
|
grid_frame = tk.Frame(parent, bg=self.colors['bg_secondary'])
|
||||||
|
grid_frame.pack(fill="x")
|
||||||
|
|
||||||
|
cols = 3
|
||||||
|
for i, sticker_file in enumerate(sticker_files[:12]): # Limit to 12 stickers
|
||||||
|
row = i // cols
|
||||||
|
col = i % cols
|
||||||
|
|
||||||
|
try:
|
||||||
|
sticker_path = os.path.join(self.stickers_folder, sticker_file)
|
||||||
|
img = Image.open(sticker_path)
|
||||||
|
img.thumbnail((40, 40), Image.Resampling.LANCZOS)
|
||||||
|
photo = ImageTk.PhotoImage(img)
|
||||||
|
|
||||||
|
btn = tk.Button(grid_frame, image=photo,
|
||||||
|
bg=self.colors['bg_tertiary'], relief="flat", bd=0,
|
||||||
|
activebackground=self.colors['hover'],
|
||||||
|
command=lambda path=sticker_path: self.add_sticker(path))
|
||||||
|
btn.image = photo # Keep reference
|
||||||
|
btn.grid(row=row, column=col, padx=5, pady=5, sticky="nsew")
|
||||||
|
self.add_hover_effect(btn)
|
||||||
|
|
||||||
|
# Configure grid weights
|
||||||
|
grid_frame.grid_columnconfigure(col, weight=1)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Error loading sticker {sticker_file}: {e}")
|
||||||
|
|
||||||
|
def create_export_card(self, parent):
|
||||||
|
"""Create modern export options card"""
|
||||||
|
export_card = self.create_modern_card(parent, "💾 Export Options")
|
||||||
|
|
||||||
|
# Clear all button
|
||||||
|
clear_btn = self.create_modern_button(export_card, "🗑️ Clear All Elements",
|
||||||
|
self.colors['accent_orange'], self.clear_all_elements)
|
||||||
|
clear_btn.pack(fill="x", pady=(0, 10))
|
||||||
|
|
||||||
|
# Save thumbnail button
|
||||||
|
save_btn = self.create_modern_button(export_card, "💾 Save Thumbnail",
|
||||||
|
self.colors['accent_green'], self.save_thumbnail)
|
||||||
|
save_btn.pack(fill="x", pady=(0, 10))
|
||||||
|
|
||||||
|
# Close editor button
|
||||||
|
close_btn = self.create_modern_button(export_card, "❌ Close Editor",
|
||||||
|
self.colors['accent_red'], self.close_editor)
|
||||||
|
close_btn.pack(fill="x")
|
||||||
|
|
||||||
|
def create_modern_card(self, parent, title):
|
||||||
|
"""Create a modern card container"""
|
||||||
|
card_frame = tk.Frame(parent, bg=self.colors['bg_tertiary'], relief="flat", bd=0)
|
||||||
|
card_frame.pack(fill="x", pady=(0, 20))
|
||||||
|
|
||||||
|
# Card header
|
||||||
|
header_frame = tk.Frame(card_frame, bg=self.colors['bg_tertiary'])
|
||||||
|
header_frame.pack(fill="x", padx=15, pady=(15, 10))
|
||||||
|
|
||||||
|
title_label = tk.Label(header_frame, text=title, font=self.fonts['subheading'],
|
||||||
|
bg=self.colors['bg_tertiary'], fg=self.colors['text_primary'])
|
||||||
|
title_label.pack(anchor="w")
|
||||||
|
|
||||||
|
# Card content
|
||||||
|
content_frame = tk.Frame(card_frame, bg=self.colors['bg_secondary'])
|
||||||
|
content_frame.pack(fill="both", expand=True, padx=15, pady=(0, 15))
|
||||||
|
|
||||||
|
return content_frame
|
||||||
|
|
||||||
|
def create_modern_button(self, parent, text, color, command):
|
||||||
|
"""Create a modern styled button"""
|
||||||
|
btn = tk.Button(parent, text=text, font=self.fonts['button'],
|
||||||
|
bg=color, fg=self.colors['text_primary'],
|
||||||
|
relief="flat", bd=0, padx=20, pady=12,
|
||||||
|
activebackground=self.colors['hover'],
|
||||||
|
command=command, cursor="hand2")
|
||||||
|
self.add_hover_effect(btn, color)
|
||||||
|
return btn
|
||||||
|
|
||||||
|
def add_hover_effect(self, widget, base_color=None):
|
||||||
|
"""Add hover effect to widget"""
|
||||||
|
if base_color is None:
|
||||||
|
base_color = self.colors['bg_tertiary']
|
||||||
|
|
||||||
|
def on_enter(e):
|
||||||
|
widget.configure(bg=self.colors['hover'])
|
||||||
|
|
||||||
|
def on_leave(e):
|
||||||
|
widget.configure(bg=base_color)
|
||||||
|
|
||||||
|
widget.bind("<Enter>", on_enter)
|
||||||
|
widget.bind("<Leave>", on_leave)
|
||||||
|
|
||||||
|
def capture_frame_at(self, time_sec):
|
||||||
|
"""Capture frame from video at specific time"""
|
||||||
|
try:
|
||||||
|
frame = self.clip.get_frame(max(0, min(time_sec, self.clip.duration - 0.1)))
|
||||||
|
img = Image.fromarray(frame)
|
||||||
|
# Maintain aspect ratio while fitting in canvas
|
||||||
|
img.thumbnail((720, 405), Image.Resampling.LANCZOS)
|
||||||
|
return img
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Error capturing frame: {e}")
|
||||||
|
# Create a placeholder image
|
||||||
|
img = Image.new('RGB', (720, 405), color='black')
|
||||||
|
return img
|
||||||
|
|
||||||
|
def update_canvas_frame(self, time_sec):
|
||||||
|
"""Update canvas with frame at specific time"""
|
||||||
|
try:
|
||||||
|
self.current_frame_img = self.capture_frame_at(time_sec)
|
||||||
|
self.tk_frame_img = ImageTk.PhotoImage(self.current_frame_img)
|
||||||
|
|
||||||
|
# Clear canvas and add new frame
|
||||||
|
self.canvas.delete("frame")
|
||||||
|
self.canvas.create_image(360, 202, image=self.tk_frame_img, tags="frame")
|
||||||
|
self.canvas.image = self.tk_frame_img
|
||||||
|
|
||||||
|
# Update time display
|
||||||
|
minutes = int(time_sec) // 60
|
||||||
|
seconds = int(time_sec) % 60
|
||||||
|
self.time_label.config(text=f"{minutes:02d}:{seconds:02d}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Error updating frame: {e}")
|
||||||
|
|
||||||
|
def on_time_change(self, val):
|
||||||
|
"""Handle timeline slider change"""
|
||||||
|
self.update_canvas_frame(float(val))
|
||||||
|
|
||||||
|
# Canvas interaction methods
|
||||||
|
def on_canvas_click(self, event):
|
||||||
|
"""Handle canvas click for dragging"""
|
||||||
|
item = self.canvas.find_closest(event.x, event.y)[0]
|
||||||
|
if item and item != self.canvas.find_withtag("frame"):
|
||||||
|
self.drag_data["item"] = item
|
||||||
|
self.drag_data["x"] = event.x
|
||||||
|
self.drag_data["y"] = event.y
|
||||||
|
|
||||||
|
def on_canvas_drag(self, event):
|
||||||
|
"""Handle canvas dragging"""
|
||||||
|
if self.drag_data["item"]:
|
||||||
|
dx = event.x - self.drag_data["x"]
|
||||||
|
dy = event.y - self.drag_data["y"]
|
||||||
|
self.canvas.move(self.drag_data["item"], dx, dy)
|
||||||
|
self.drag_data["x"] = event.x
|
||||||
|
self.drag_data["y"] = event.y
|
||||||
|
|
||||||
|
def on_canvas_release(self, event):
|
||||||
|
"""Handle canvas release"""
|
||||||
|
self.drag_data["item"] = None
|
||||||
|
|
||||||
|
# Editing functionality
|
||||||
|
def add_text(self):
|
||||||
|
"""Add text to the canvas"""
|
||||||
|
text = simpledialog.askstring("Add Text", "Enter text:")
|
||||||
|
if text:
|
||||||
|
try:
|
||||||
|
size = self.text_size_var.get()
|
||||||
|
item = self.canvas.create_text(360, 200, text=text, fill=self.current_text_color,
|
||||||
|
font=("Arial", size, "bold"), tags="draggable")
|
||||||
|
self.canvas_items.append(("text", item, text, self.current_text_color, size))
|
||||||
|
print(f"✅ Added text: {text}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Error adding text: {e}")
|
||||||
|
|
||||||
|
def choose_text_color(self):
|
||||||
|
"""Choose text color"""
|
||||||
|
color = colorchooser.askcolor(title="Choose text color")
|
||||||
|
if color[1]:
|
||||||
|
self.current_text_color = color[1]
|
||||||
|
# Update button color to show current selection
|
||||||
|
self.text_color_btn.config(bg=self.current_text_color)
|
||||||
|
|
||||||
|
def add_sticker(self, path):
|
||||||
|
"""Add sticker to canvas"""
|
||||||
|
try:
|
||||||
|
img = Image.open(path).convert("RGBA")
|
||||||
|
img.thumbnail((60, 60), Image.Resampling.LANCZOS)
|
||||||
|
tk_img = ImageTk.PhotoImage(img)
|
||||||
|
item = self.canvas.create_image(360, 200, image=tk_img, tags="draggable")
|
||||||
|
|
||||||
|
# Keep reference to prevent garbage collection
|
||||||
|
if not hasattr(self.canvas, 'images'):
|
||||||
|
self.canvas.images = []
|
||||||
|
self.canvas.images.append(tk_img)
|
||||||
|
self.canvas_items.append(("sticker", item, img, path))
|
||||||
|
print(f"✅ Added sticker: {os.path.basename(path)}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Failed to load sticker {path}: {e}")
|
||||||
|
|
||||||
|
def load_custom_sticker(self):
|
||||||
|
"""Load custom sticker file"""
|
||||||
|
file_path = filedialog.askopenfilename(
|
||||||
|
title="Select Sticker",
|
||||||
|
filetypes=[("Image files", "*.png *.jpg *.jpeg *.gif *.bmp")]
|
||||||
|
)
|
||||||
|
if file_path:
|
||||||
|
self.add_sticker(file_path)
|
||||||
|
|
||||||
|
def clear_all_elements(self):
|
||||||
|
"""Clear all added elements"""
|
||||||
|
# Clear all draggable items
|
||||||
|
self.canvas.delete("draggable")
|
||||||
|
self.canvas_items.clear()
|
||||||
|
if hasattr(self.canvas, 'images'):
|
||||||
|
self.canvas.images.clear()
|
||||||
|
print("🗑️ Cleared all elements")
|
||||||
|
|
||||||
|
def save_thumbnail(self):
|
||||||
|
"""Save the current thumbnail"""
|
||||||
|
if not self.current_frame_img:
|
||||||
|
messagebox.showerror("Error", "No frame loaded")
|
||||||
|
return
|
||||||
|
|
||||||
|
save_path = filedialog.asksaveasfilename(
|
||||||
|
title="Save Thumbnail",
|
||||||
|
defaultextension=".jpg",
|
||||||
|
filetypes=[("JPEG files", "*.jpg"), ("PNG files", "*.png")]
|
||||||
|
)
|
||||||
|
|
||||||
|
if not save_path:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Create a copy of the current frame
|
||||||
|
frame = self.current_frame_img.copy().convert("RGBA")
|
||||||
|
canvas_width = self.canvas.winfo_width()
|
||||||
|
canvas_height = self.canvas.winfo_height()
|
||||||
|
|
||||||
|
# Calculate scaling factors
|
||||||
|
scale_x = frame.width / canvas_width
|
||||||
|
scale_y = frame.height / canvas_height
|
||||||
|
|
||||||
|
draw = ImageDraw.Draw(frame)
|
||||||
|
|
||||||
|
# Process all canvas items
|
||||||
|
for item_type, item_id, *data in self.canvas_items:
|
||||||
|
coords = self.canvas.coords(item_id)
|
||||||
|
if not coords:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if item_type == "sticker":
|
||||||
|
# Handle sticker overlay
|
||||||
|
img_data, path = data
|
||||||
|
x, y = coords[0], coords[1]
|
||||||
|
px = int(x * scale_x)
|
||||||
|
py = int(y * scale_y)
|
||||||
|
|
||||||
|
# Scale sticker size
|
||||||
|
sticker_img = img_data.copy()
|
||||||
|
new_size = (int(60 * scale_x), int(60 * scale_y))
|
||||||
|
sticker_img = sticker_img.resize(new_size, Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
|
# Calculate position to center the sticker
|
||||||
|
paste_x = px - sticker_img.width // 2
|
||||||
|
paste_y = py - sticker_img.height // 2
|
||||||
|
|
||||||
|
frame.paste(sticker_img, (paste_x, paste_y), sticker_img)
|
||||||
|
|
||||||
|
elif item_type == "text":
|
||||||
|
# Handle text overlay
|
||||||
|
text_value, color, font_size = data
|
||||||
|
x, y = coords[0], coords[1]
|
||||||
|
px = int(x * scale_x)
|
||||||
|
py = int(y * scale_y)
|
||||||
|
|
||||||
|
# Scale font size
|
||||||
|
scaled_font_size = int(font_size * scale_x)
|
||||||
|
|
||||||
|
try:
|
||||||
|
font = ImageFont.truetype("arial.ttf", scaled_font_size)
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
font = ImageFont.truetype("calibri.ttf", scaled_font_size)
|
||||||
|
except:
|
||||||
|
font = ImageFont.load_default()
|
||||||
|
|
||||||
|
# Get text bounding box for centering
|
||||||
|
bbox = draw.textbbox((0, 0), text_value, font=font)
|
||||||
|
text_w = bbox[2] - bbox[0]
|
||||||
|
text_h = bbox[3] - bbox[1]
|
||||||
|
|
||||||
|
# Draw text with outline
|
||||||
|
outline_w = max(2, scaled_font_size // 15)
|
||||||
|
for dx in range(-outline_w, outline_w + 1):
|
||||||
|
for dy in range(-outline_w, outline_w + 1):
|
||||||
|
draw.text((px - text_w//2 + dx, py - text_h//2 + dy),
|
||||||
|
text_value, font=font, fill="black")
|
||||||
|
|
||||||
|
draw.text((px - text_w//2, py - text_h//2), text_value, font=font, fill=color)
|
||||||
|
|
||||||
|
# Convert to RGB and save
|
||||||
|
if save_path.lower().endswith('.png'):
|
||||||
|
frame.save(save_path, "PNG", quality=95)
|
||||||
|
else:
|
||||||
|
background = Image.new("RGB", frame.size, (255, 255, 255))
|
||||||
|
background.paste(frame, mask=frame.split()[3] if frame.mode == 'RGBA' else None)
|
||||||
|
background.save(save_path, "JPEG", quality=95)
|
||||||
|
|
||||||
|
print(f"✅ Thumbnail saved: {save_path}")
|
||||||
|
messagebox.showinfo("Success", f"Thumbnail saved successfully!\n{save_path}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error saving thumbnail: {e}")
|
||||||
|
messagebox.showerror("Error", f"Failed to save thumbnail:\n{str(e)}")
|
||||||
|
|
||||||
|
def close_editor(self):
|
||||||
|
"""Close the editor"""
|
||||||
|
try:
|
||||||
|
if self.clip:
|
||||||
|
self.clip.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.editor.destroy()
|
||||||
|
|
||||||
|
def create_default_stickers(self):
|
||||||
|
"""Create default emoji stickers"""
|
||||||
|
stickers_data = {
|
||||||
|
"smile.png": "😊",
|
||||||
|
"laugh.png": "😂",
|
||||||
|
"happy-face.png": "😀",
|
||||||
|
"sad-face.png": "😢",
|
||||||
|
"confused.png": "😕",
|
||||||
|
"party.png": "🎉",
|
||||||
|
"emoji.png": "👍",
|
||||||
|
"emoji (1).png": "❤️",
|
||||||
|
"smile (1).png": "😄"
|
||||||
|
}
|
||||||
|
|
||||||
|
for filename, emoji in stickers_data.items():
|
||||||
|
filepath = os.path.join(self.stickers_folder, filename)
|
||||||
|
if not os.path.exists(filepath):
|
||||||
|
try:
|
||||||
|
# Create simple emoji images
|
||||||
|
img = Image.new('RGBA', (64, 64), (255, 255, 255, 0))
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
|
||||||
|
# Try to use a font for emoji, fallback to colored rectangles
|
||||||
|
try:
|
||||||
|
font = ImageFont.truetype("seguiemj.ttf", 48)
|
||||||
|
draw.text((8, 8), emoji, font=font, fill="black")
|
||||||
|
except:
|
||||||
|
# Fallback: create colored circles/shapes
|
||||||
|
colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', '#DDA0DD', '#98D8C8', '#F7DC6F', '#BB8FCE']
|
||||||
|
color = colors[hash(filename) % len(colors)]
|
||||||
|
draw.ellipse([8, 8, 56, 56], fill=color)
|
||||||
|
draw.text((20, 20), emoji[:2], fill="white", font=ImageFont.load_default())
|
||||||
|
|
||||||
|
img.save(filepath, 'PNG')
|
||||||
|
print(f"✅ Created default sticker: {filename}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Error creating sticker {filename}: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
# Legacy function to maintain compatibility
|
||||||
|
def open_thumbnail_editor(video_path):
|
||||||
|
"""Legacy function for backward compatibility"""
|
||||||
|
editor = ModernThumbnailEditor(video_path)
|
||||||
|
return editor
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Test the editor
|
||||||
|
test_video = "myvideo.mp4" # Replace with actual video path
|
||||||
|
if os.path.exists(test_video):
|
||||||
|
root = tk.Tk()
|
||||||
|
root.withdraw() # Hide main window
|
||||||
|
editor = ModernThumbnailEditor(test_video)
|
||||||
|
root.mainloop()
|
||||||
|
else:
|
||||||
|
print("Please provide a valid video file path")
|
||||||
+3371
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user