pyloid 0.20.2__py3-none-any.whl → 0.20.2.dev2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
pyloid/custom/titlebar.py CHANGED
@@ -1,116 +1,116 @@
1
- from PySide6.QtWidgets import (
2
- QWidget,
3
- QHBoxLayout,
4
- QLabel,
5
- QPushButton,
6
- QVBoxLayout,
7
- QApplication,
8
- )
9
- from PySide6.QtGui import QColor, QPalette, QPixmap
10
- from PySide6.QtCore import Qt
11
-
12
-
13
- class CustomTitleBar(QWidget):
14
- def __init__(self, parent=None):
15
- super().__init__(parent)
16
- self.layout = QHBoxLayout(self)
17
- self.layout.setContentsMargins(5, 0, 5, 0)
18
- self.layout.setSpacing(0)
19
-
20
- self.icon_label = QLabel()
21
- self.icon_label.setFixedSize(20, 20)
22
- self.title = QLabel("Custom Title")
23
-
24
- self.minimize_button = QPushButton("-")
25
- self.maximize_button = QPushButton("❐")
26
- self.close_button = QPushButton("×")
27
-
28
- for button in (self.minimize_button, self.maximize_button, self.close_button):
29
- button.setFixedSize(45, 30)
30
- button.setFlat(True)
31
-
32
- self.layout.addWidget(self.icon_label)
33
- self.layout.addSpacing(5)
34
- self.layout.addWidget(self.title)
35
- self.layout.addStretch(1)
36
- self.layout.addWidget(self.minimize_button)
37
- self.layout.addWidget(self.maximize_button)
38
- self.layout.addWidget(self.close_button)
39
-
40
- self.minimize_button.clicked.connect(self.window().showMinimized)
41
- self.maximize_button.clicked.connect(self.toggle_maximize)
42
- self.close_button.clicked.connect(self.window().close)
43
-
44
- self.setFixedHeight(30)
45
- self.set_style("darkblue", "white")
46
-
47
- def set_style(self, bg_color, text_color):
48
- self.setAutoFillBackground(True)
49
- palette = self.palette()
50
- bg_qcolor = QColor(bg_color)
51
- text_qcolor = QColor(text_color)
52
- palette.setColor(QPalette.Window, bg_qcolor)
53
- palette.setColor(QPalette.WindowText, text_qcolor)
54
- self.setPalette(palette)
55
-
56
- self.title.setStyleSheet(f"color: {text_color}; font-weight: bold;")
57
-
58
- button_style = f"""
59
- QPushButton {{
60
- background-color: {bg_color};
61
- color: {text_color};
62
- border: none;
63
- font-family: Arial;
64
- font-size: 14px;
65
- padding: 0px;
66
- text-align: center;
67
- }}
68
- QPushButton:hover {{
69
- background-color: {bg_qcolor.lighter(120).name()};
70
- }}
71
- QPushButton:pressed {{
72
- background-color: {bg_qcolor.darker(110).name()};
73
- }}
74
- """
75
- for button in (self.minimize_button, self.maximize_button, self.close_button):
76
- button.setStyleSheet(button_style)
77
-
78
- self.close_button.setStyleSheet(
79
- button_style
80
- + f"""
81
- QPushButton:hover {{
82
- background-color: #e81123;
83
- color: white;
84
- }}
85
- """
86
- )
87
-
88
- def mousePressEvent(self, event):
89
- if event.button() == Qt.LeftButton:
90
- self.window().moving = True
91
- self.window().offset = event.pos()
92
-
93
- def mouseMoveEvent(self, event):
94
- if self.window().moving:
95
- self.window().move(event.globalPos() - self.window().offset)
96
-
97
- def mouseReleaseEvent(self, event):
98
- if event.button() == Qt.LeftButton:
99
- self.window().moving = False
100
-
101
- def toggle_maximize(self):
102
- if self.window().isMaximized():
103
- self.window().showNormal()
104
- self.maximize_button.setText("❐")
105
- else:
106
- self.window().showMaximized()
107
- self.maximize_button.setText("❐")
108
-
109
- def set_icon(self, icon_path):
110
- pixmap = QPixmap(icon_path)
111
- self.icon_label.setPixmap(
112
- pixmap.scaled(20, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation)
113
- )
114
-
115
- def set_title(self, title):
116
- self.title.setText(title)
1
+ from PySide6.QtWidgets import (
2
+ QWidget,
3
+ QHBoxLayout,
4
+ QLabel,
5
+ QPushButton,
6
+ QVBoxLayout,
7
+ QApplication,
8
+ )
9
+ from PySide6.QtGui import QColor, QPalette, QPixmap
10
+ from PySide6.QtCore import Qt
11
+
12
+
13
+ class CustomTitleBar(QWidget):
14
+ def __init__(self, parent=None):
15
+ super().__init__(parent)
16
+ self.layout = QHBoxLayout(self)
17
+ self.layout.setContentsMargins(5, 0, 5, 0)
18
+ self.layout.setSpacing(0)
19
+
20
+ self.icon_label = QLabel()
21
+ self.icon_label.setFixedSize(20, 20)
22
+ self.title = QLabel("Custom Title")
23
+
24
+ self.minimize_button = QPushButton("-")
25
+ self.maximize_button = QPushButton("❐")
26
+ self.close_button = QPushButton("×")
27
+
28
+ for button in (self.minimize_button, self.maximize_button, self.close_button):
29
+ button.setFixedSize(45, 30)
30
+ button.setFlat(True)
31
+
32
+ self.layout.addWidget(self.icon_label)
33
+ self.layout.addSpacing(5)
34
+ self.layout.addWidget(self.title)
35
+ self.layout.addStretch(1)
36
+ self.layout.addWidget(self.minimize_button)
37
+ self.layout.addWidget(self.maximize_button)
38
+ self.layout.addWidget(self.close_button)
39
+
40
+ self.minimize_button.clicked.connect(self.window().showMinimized)
41
+ self.maximize_button.clicked.connect(self.toggle_maximize)
42
+ self.close_button.clicked.connect(self.window().close)
43
+
44
+ self.setFixedHeight(30)
45
+ self.set_style("darkblue", "white")
46
+
47
+ def set_style(self, bg_color, text_color):
48
+ self.setAutoFillBackground(True)
49
+ palette = self.palette()
50
+ bg_qcolor = QColor(bg_color)
51
+ text_qcolor = QColor(text_color)
52
+ palette.setColor(QPalette.Window, bg_qcolor)
53
+ palette.setColor(QPalette.WindowText, text_qcolor)
54
+ self.setPalette(palette)
55
+
56
+ self.title.setStyleSheet(f"color: {text_color}; font-weight: bold;")
57
+
58
+ button_style = f"""
59
+ QPushButton {{
60
+ background-color: {bg_color};
61
+ color: {text_color};
62
+ border: none;
63
+ font-family: Arial;
64
+ font-size: 14px;
65
+ padding: 0px;
66
+ text-align: center;
67
+ }}
68
+ QPushButton:hover {{
69
+ background-color: {bg_qcolor.lighter(120).name()};
70
+ }}
71
+ QPushButton:pressed {{
72
+ background-color: {bg_qcolor.darker(110).name()};
73
+ }}
74
+ """
75
+ for button in (self.minimize_button, self.maximize_button, self.close_button):
76
+ button.setStyleSheet(button_style)
77
+
78
+ self.close_button.setStyleSheet(
79
+ button_style
80
+ + f"""
81
+ QPushButton:hover {{
82
+ background-color: #e81123;
83
+ color: white;
84
+ }}
85
+ """
86
+ )
87
+
88
+ def mousePressEvent(self, event):
89
+ if event.button() == Qt.LeftButton:
90
+ self.window().moving = True
91
+ self.window().offset = event.pos()
92
+
93
+ def mouseMoveEvent(self, event):
94
+ if self.window().moving:
95
+ self.window().move(event.globalPos() - self.window().offset)
96
+
97
+ def mouseReleaseEvent(self, event):
98
+ if event.button() == Qt.LeftButton:
99
+ self.window().moving = False
100
+
101
+ def toggle_maximize(self):
102
+ if self.window().isMaximized():
103
+ self.window().showNormal()
104
+ self.maximize_button.setText("❐")
105
+ else:
106
+ self.window().showMaximized()
107
+ self.maximize_button.setText("❐")
108
+
109
+ def set_icon(self, icon_path):
110
+ pixmap = QPixmap(icon_path)
111
+ self.icon_label.setPixmap(
112
+ pixmap.scaled(20, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation)
113
+ )
114
+
115
+ def set_title(self, title):
116
+ self.title.setText(title)
pyloid/filewatcher.py CHANGED
@@ -1,163 +1,163 @@
1
- from PySide6.QtCore import QFileSystemWatcher, QObject, Signal
2
-
3
- class FileWatcher(QObject):
4
- """
5
- FileWatcher class for monitoring file and directory changes.
6
-
7
- This class automatically detects changes in specific files or directories and provides notifications.
8
-
9
- Attributes
10
- ----------
11
- file_changed : Signal
12
- Signal emitted when a file is changed.
13
- directory_changed : Signal
14
- Signal emitted when a directory is changed.
15
-
16
- Methods
17
- -------
18
- add_path(path)
19
- Adds a file or directory to the watch list.
20
- remove_path(path)
21
- Removes a file or directory from the watch list.
22
- get_watched_paths()
23
- Returns all currently watched paths (files and directories).
24
- get_watched_files()
25
- Returns all currently watched files.
26
- get_watched_directories()
27
- Returns all currently watched directories.
28
- remove_all_paths()
29
- Removes all paths from the watch list.
30
- """
31
-
32
- file_changed = Signal(str)
33
- directory_changed = Signal(str)
34
-
35
- def __init__(self):
36
- """
37
- Initializes the FileWatcher object.
38
- """
39
- super().__init__()
40
- self.watcher = QFileSystemWatcher()
41
- self.watcher.fileChanged.connect(self.file_changed)
42
- self.watcher.directoryChanged.connect(self.directory_changed)
43
-
44
- def add_path(self, path):
45
- """
46
- Adds a file or directory to the watch list.
47
-
48
- Parameters
49
- ----------
50
- path : str
51
- The path of the file or directory to watch.
52
-
53
- Returns
54
- -------
55
- bool
56
- Whether the path was successfully added.
57
-
58
- Examples
59
- --------
60
- >>> watcher = FileWatcher()
61
- >>> result = watcher.add_path("/path/to/file_or_directory")
62
- >>> if result:
63
- >>> print("Watch started")
64
- >>> else:
65
- >>> print("Failed to start watching")
66
- """
67
- return self.watcher.addPath(path)
68
-
69
- def remove_path(self, path):
70
- """
71
- Removes a file or directory from the watch list.
72
-
73
- Parameters
74
- ----------
75
- path : str
76
- The path of the file or directory to remove.
77
-
78
- Returns
79
- -------
80
- bool
81
- Whether the path was successfully removed.
82
-
83
- Examples
84
- --------
85
- >>> watcher = FileWatcher()
86
- >>> result = watcher.remove_path("/path/to/file_or_directory")
87
- >>> if result:
88
- >>> print("Successfully stopped watching")
89
- >>> else:
90
- >>> print("Failed to stop watching")
91
- """
92
- return self.watcher.removePath(path)
93
-
94
- def get_watched_paths(self):
95
- """
96
- Returns all currently watched paths (files and directories).
97
-
98
- Returns
99
- -------
100
- list of str
101
- All currently watched paths.
102
-
103
- Examples
104
- --------
105
- >>> watcher = FileWatcher()
106
- >>> paths = watcher.get_watched_paths()
107
- >>> print("Watched paths:", paths)
108
- """
109
- return self.watcher.files() + self.watcher.directories()
110
-
111
- def get_watched_files(self):
112
- """
113
- Returns all currently watched files.
114
-
115
- Returns
116
- -------
117
- list of str
118
- All currently watched files.
119
-
120
- Examples
121
- --------
122
- >>> watcher = FileWatcher()
123
- >>> files = watcher.get_watched_files()
124
- >>> print("Watched files:", files)
125
- """
126
- return self.watcher.files()
127
-
128
- def get_watched_directories(self):
129
- """
130
- Returns all currently watched directories.
131
-
132
- Returns
133
- -------
134
- list of str
135
- All currently watched directories.
136
-
137
- Examples
138
- --------
139
- >>> watcher = FileWatcher()
140
- >>> directories = watcher.get_watched_directories()
141
- >>> print("Watched directories:", directories)
142
- """
143
- return self.watcher.directories()
144
-
145
- def remove_all_paths(self):
146
- """
147
- Removes all paths from the watch list.
148
-
149
- Returns
150
- -------
151
- bool
152
- Whether all paths were successfully removed.
153
-
154
- Examples
155
- --------
156
- >>> watcher = FileWatcher()
157
- >>> result = watcher.remove_all_paths()
158
- >>> if result:
159
- >>> print("Successfully removed all paths")
160
- >>> else:
161
- >>> print("Failed to remove all paths")
162
- """
163
- return self.watcher.removePaths(self.get_watched_paths())
1
+ from PySide6.QtCore import QFileSystemWatcher, QObject, Signal
2
+
3
+ class FileWatcher(QObject):
4
+ """
5
+ FileWatcher class for monitoring file and directory changes.
6
+
7
+ This class automatically detects changes in specific files or directories and provides notifications.
8
+
9
+ Attributes
10
+ ----------
11
+ file_changed : Signal
12
+ Signal emitted when a file is changed.
13
+ directory_changed : Signal
14
+ Signal emitted when a directory is changed.
15
+
16
+ Methods
17
+ -------
18
+ add_path(path)
19
+ Adds a file or directory to the watch list.
20
+ remove_path(path)
21
+ Removes a file or directory from the watch list.
22
+ get_watched_paths()
23
+ Returns all currently watched paths (files and directories).
24
+ get_watched_files()
25
+ Returns all currently watched files.
26
+ get_watched_directories()
27
+ Returns all currently watched directories.
28
+ remove_all_paths()
29
+ Removes all paths from the watch list.
30
+ """
31
+
32
+ file_changed = Signal(str)
33
+ directory_changed = Signal(str)
34
+
35
+ def __init__(self):
36
+ """
37
+ Initializes the FileWatcher object.
38
+ """
39
+ super().__init__()
40
+ self.watcher = QFileSystemWatcher()
41
+ self.watcher.fileChanged.connect(self.file_changed)
42
+ self.watcher.directoryChanged.connect(self.directory_changed)
43
+
44
+ def add_path(self, path):
45
+ """
46
+ Adds a file or directory to the watch list.
47
+
48
+ Parameters
49
+ ----------
50
+ path : str
51
+ The path of the file or directory to watch.
52
+
53
+ Returns
54
+ -------
55
+ bool
56
+ Whether the path was successfully added.
57
+
58
+ Examples
59
+ --------
60
+ >>> watcher = FileWatcher()
61
+ >>> result = watcher.add_path("/path/to/file_or_directory")
62
+ >>> if result:
63
+ >>> print("Watch started")
64
+ >>> else:
65
+ >>> print("Failed to start watching")
66
+ """
67
+ return self.watcher.addPath(path)
68
+
69
+ def remove_path(self, path):
70
+ """
71
+ Removes a file or directory from the watch list.
72
+
73
+ Parameters
74
+ ----------
75
+ path : str
76
+ The path of the file or directory to remove.
77
+
78
+ Returns
79
+ -------
80
+ bool
81
+ Whether the path was successfully removed.
82
+
83
+ Examples
84
+ --------
85
+ >>> watcher = FileWatcher()
86
+ >>> result = watcher.remove_path("/path/to/file_or_directory")
87
+ >>> if result:
88
+ >>> print("Successfully stopped watching")
89
+ >>> else:
90
+ >>> print("Failed to stop watching")
91
+ """
92
+ return self.watcher.removePath(path)
93
+
94
+ def get_watched_paths(self):
95
+ """
96
+ Returns all currently watched paths (files and directories).
97
+
98
+ Returns
99
+ -------
100
+ list of str
101
+ All currently watched paths.
102
+
103
+ Examples
104
+ --------
105
+ >>> watcher = FileWatcher()
106
+ >>> paths = watcher.get_watched_paths()
107
+ >>> print("Watched paths:", paths)
108
+ """
109
+ return self.watcher.files() + self.watcher.directories()
110
+
111
+ def get_watched_files(self):
112
+ """
113
+ Returns all currently watched files.
114
+
115
+ Returns
116
+ -------
117
+ list of str
118
+ All currently watched files.
119
+
120
+ Examples
121
+ --------
122
+ >>> watcher = FileWatcher()
123
+ >>> files = watcher.get_watched_files()
124
+ >>> print("Watched files:", files)
125
+ """
126
+ return self.watcher.files()
127
+
128
+ def get_watched_directories(self):
129
+ """
130
+ Returns all currently watched directories.
131
+
132
+ Returns
133
+ -------
134
+ list of str
135
+ All currently watched directories.
136
+
137
+ Examples
138
+ --------
139
+ >>> watcher = FileWatcher()
140
+ >>> directories = watcher.get_watched_directories()
141
+ >>> print("Watched directories:", directories)
142
+ """
143
+ return self.watcher.directories()
144
+
145
+ def remove_all_paths(self):
146
+ """
147
+ Removes all paths from the watch list.
148
+
149
+ Returns
150
+ -------
151
+ bool
152
+ Whether all paths were successfully removed.
153
+
154
+ Examples
155
+ --------
156
+ >>> watcher = FileWatcher()
157
+ >>> result = watcher.remove_all_paths()
158
+ >>> if result:
159
+ >>> print("Successfully removed all paths")
160
+ >>> else:
161
+ >>> print("Failed to remove all paths")
162
+ """
163
+ return self.watcher.removePaths(self.get_watched_paths())
@@ -1,25 +1,25 @@
1
- from ..pyloid import Pyloid
2
- from ..api import PyloidAPI, Bridge
3
- from typing import Optional, Callable
4
-
5
-
6
- # class EventAPI(PyloidAPI):
7
- # def __init__(self, window_id: str, app):
8
- # super().__init__()
9
- # self.window_id: str = window_id
10
- # self.app: PylonApp = app
11
- # self.subscribers = {}
12
-
13
- # @Bridge(str, Callable)
14
- # def on(self, event_name: str, callback: Callable):
15
- # """특정 이벤트를 구독합니다."""
16
- # if event_name not in self.subscribers:
17
- # self.subscribers[event_name] = []
18
- # self.subscribers[event_name].append(callback)
19
-
20
- # @Bridge(str, result=Optional[str])
21
- # def emit(self, event_name: str, *args, **kwargs):
22
- # """다른 윈도우로 특정 이벤트를 보냅니다."""
23
- # if event_name in self.subscribers:
24
- # for callback in self.subscribers[event_name]:
1
+ from ..pyloid import Pyloid
2
+ from ..api import PyloidAPI, Bridge
3
+ from typing import Optional, Callable
4
+
5
+
6
+ # class EventAPI(PyloidAPI):
7
+ # def __init__(self, window_id: str, app):
8
+ # super().__init__()
9
+ # self.window_id: str = window_id
10
+ # self.app: PylonApp = app
11
+ # self.subscribers = {}
12
+
13
+ # @Bridge(str, Callable)
14
+ # def on(self, event_name: str, callback: Callable):
15
+ # """특정 이벤트를 구독합니다."""
16
+ # if event_name not in self.subscribers:
17
+ # self.subscribers[event_name] = []
18
+ # self.subscribers[event_name].append(callback)
19
+
20
+ # @Bridge(str, result=Optional[str])
21
+ # def emit(self, event_name: str, *args, **kwargs):
22
+ # """다른 윈도우로 특정 이벤트를 보냅니다."""
23
+ # if event_name in self.subscribers:
24
+ # for callback in self.subscribers[event_name]:
25
25
  # callback(*args, **kwargs)