pyloid 0.26.2__py3-none-any.whl → 0.26.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyloid/custom/titlebar.py CHANGED
@@ -1,61 +1,98 @@
1
1
  from PySide6.QtWidgets import (
2
- QWidget,
3
- QHBoxLayout,
4
- QLabel,
5
- QPushButton,
6
- QVBoxLayout,
7
- QApplication,
2
+ QWidget,
3
+ QHBoxLayout,
4
+ QLabel,
5
+ QPushButton,
6
+ QVBoxLayout,
7
+ QApplication,
8
+ )
9
+ from PySide6.QtGui import (
10
+ QColor,
11
+ QPalette,
12
+ QPixmap,
13
+ )
14
+ from PySide6.QtCore import (
15
+ Qt,
8
16
  )
9
- from PySide6.QtGui import QColor, QPalette, QPixmap
10
- from PySide6.QtCore import Qt
11
17
 
12
18
 
13
19
  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"""
20
+ def __init__(
21
+ self,
22
+ parent=None,
23
+ ):
24
+ super().__init__(parent)
25
+ self.layout = QHBoxLayout(self)
26
+ self.layout.setContentsMargins(
27
+ 5,
28
+ 0,
29
+ 5,
30
+ 0,
31
+ )
32
+ self.layout.setSpacing(0)
33
+
34
+ self.icon_label = QLabel()
35
+ self.icon_label.setFixedSize(
36
+ 20,
37
+ 20,
38
+ )
39
+ self.title = QLabel('Custom Title')
40
+
41
+ self.minimize_button = QPushButton('-')
42
+ self.maximize_button = QPushButton('❐')
43
+ self.close_button = QPushButton('×')
44
+
45
+ for button in (
46
+ self.minimize_button,
47
+ self.maximize_button,
48
+ self.close_button,
49
+ ):
50
+ button.setFixedSize(
51
+ 45,
52
+ 30,
53
+ )
54
+ button.setFlat(True)
55
+
56
+ self.layout.addWidget(self.icon_label)
57
+ self.layout.addSpacing(5)
58
+ self.layout.addWidget(self.title)
59
+ self.layout.addStretch(1)
60
+ self.layout.addWidget(self.minimize_button)
61
+ self.layout.addWidget(self.maximize_button)
62
+ self.layout.addWidget(self.close_button)
63
+
64
+ self.minimize_button.clicked.connect(self.window().showMinimized)
65
+ self.maximize_button.clicked.connect(self.toggle_maximize)
66
+ self.close_button.clicked.connect(self.window().close)
67
+
68
+ self.setFixedHeight(30)
69
+ self.set_style(
70
+ 'darkblue',
71
+ 'white',
72
+ )
73
+
74
+ def set_style(
75
+ self,
76
+ bg_color,
77
+ text_color,
78
+ ):
79
+ self.setAutoFillBackground(True)
80
+ palette = self.palette()
81
+ bg_qcolor = QColor(bg_color)
82
+ text_qcolor = QColor(text_color)
83
+ palette.setColor(
84
+ QPalette.Window,
85
+ bg_qcolor,
86
+ )
87
+ palette.setColor(
88
+ QPalette.WindowText,
89
+ text_qcolor,
90
+ )
91
+ self.setPalette(palette)
92
+
93
+ self.title.setStyleSheet(f'color: {text_color}; font-weight: bold;')
94
+
95
+ button_style = f"""
59
96
  QPushButton {{
60
97
  background-color: {bg_color};
61
98
  color: {text_color};
@@ -72,45 +109,71 @@ class CustomTitleBar(QWidget):
72
109
  background-color: {bg_qcolor.darker(110).name()};
73
110
  }}
74
111
  """
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"""
112
+ for button in (
113
+ self.minimize_button,
114
+ self.maximize_button,
115
+ self.close_button,
116
+ ):
117
+ button.setStyleSheet(button_style)
118
+
119
+ self.close_button.setStyleSheet(
120
+ button_style
121
+ + f"""
81
122
  QPushButton:hover {{
82
123
  background-color: #e81123;
83
124
  color: white;
84
125
  }}
85
126
  """
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)
127
+ )
128
+
129
+ def mousePressEvent(
130
+ self,
131
+ event,
132
+ ):
133
+ if event.button() == Qt.LeftButton:
134
+ self.window().moving = True
135
+ self.window().offset = event.pos()
136
+
137
+ def mouseMoveEvent(
138
+ self,
139
+ event,
140
+ ):
141
+ if self.window().moving:
142
+ self.window().move(event.globalPos() - self.window().offset)
143
+
144
+ def mouseReleaseEvent(
145
+ self,
146
+ event,
147
+ ):
148
+ if event.button() == Qt.LeftButton:
149
+ self.window().moving = False
150
+
151
+ def toggle_maximize(
152
+ self,
153
+ ):
154
+ if self.window().isMaximized():
155
+ self.window().showNormal()
156
+ self.maximize_button.setText('❐')
157
+ else:
158
+ self.window().showMaximized()
159
+ self.maximize_button.setText('❐')
160
+
161
+ def set_icon(
162
+ self,
163
+ icon_path,
164
+ ):
165
+ pixmap = QPixmap(icon_path)
166
+ self.icon_label.setPixmap(
167
+ pixmap.scaled(
168
+ 20,
169
+ 20,
170
+ Qt.KeepAspectRatio,
171
+ Qt.SmoothTransformation,
172
+ )
173
+ )
174
+
175
+ def set_title(
176
+ self,
177
+ title,
178
+ ):
179
+ self.title.setText(title)
pyloid/filewatcher.py CHANGED
@@ -1,163 +1,193 @@
1
- from PySide6.QtCore import QFileSystemWatcher, QObject, Signal
1
+ from PySide6.QtCore import (
2
+ QFileSystemWatcher,
3
+ QObject,
4
+ Signal,
5
+ )
6
+
2
7
 
3
8
  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())
9
+ """
10
+ FileWatcher class for monitoring file and directory changes.
11
+
12
+ This class automatically detects changes in specific files or directories and provides notifications.
13
+
14
+ Attributes
15
+ ----------
16
+ file_changed : Signal
17
+ Signal emitted when a file is changed.
18
+ directory_changed : Signal
19
+ Signal emitted when a directory is changed.
20
+
21
+ Methods
22
+ -------
23
+ add_path(path)
24
+ Adds a file or directory to the watch list.
25
+ remove_path(path)
26
+ Removes a file or directory from the watch list.
27
+ get_watched_paths()
28
+ Returns all currently watched paths (files and directories).
29
+ get_watched_files()
30
+ Returns all currently watched files.
31
+ get_watched_directories()
32
+ Returns all currently watched directories.
33
+ remove_all_paths()
34
+ Removes all paths from the watch list.
35
+ """
36
+
37
+ file_changed = Signal(str)
38
+ directory_changed = Signal(str)
39
+
40
+ def __init__(
41
+ self,
42
+ ):
43
+ """
44
+ Initializes the FileWatcher object.
45
+ """
46
+ super().__init__()
47
+ self.watcher = QFileSystemWatcher()
48
+ self.watcher.fileChanged.connect(self.file_changed)
49
+ self.watcher.directoryChanged.connect(self.directory_changed)
50
+
51
+ def add_path(
52
+ self,
53
+ path,
54
+ ):
55
+ """
56
+ Adds a file or directory to the watch list.
57
+
58
+ Parameters
59
+ ----------
60
+ path : str
61
+ The path of the file or directory to watch.
62
+
63
+ Returns
64
+ -------
65
+ bool
66
+ Whether the path was successfully added.
67
+
68
+ Examples
69
+ --------
70
+ >>> watcher = FileWatcher()
71
+ >>> result = watcher.add_path('/path/to/file_or_directory')
72
+ >>> if result:
73
+ >>> print("Watch started")
74
+ >>> else:
75
+ >>> print("Failed to start watching")
76
+ """
77
+ return self.watcher.addPath(path)
78
+
79
+ def remove_path(
80
+ self,
81
+ path,
82
+ ):
83
+ """
84
+ Removes a file or directory from the watch list.
85
+
86
+ Parameters
87
+ ----------
88
+ path : str
89
+ The path of the file or directory to remove.
90
+
91
+ Returns
92
+ -------
93
+ bool
94
+ Whether the path was successfully removed.
95
+
96
+ Examples
97
+ --------
98
+ >>> watcher = FileWatcher()
99
+ >>> result = watcher.remove_path('/path/to/file_or_directory')
100
+ >>> if result:
101
+ >>> print("Successfully stopped watching")
102
+ >>> else:
103
+ >>> print("Failed to stop watching")
104
+ """
105
+ return self.watcher.removePath(path)
106
+
107
+ def get_watched_paths(
108
+ self,
109
+ ):
110
+ """
111
+ Returns all currently watched paths (files and directories).
112
+
113
+ Returns
114
+ -------
115
+ list of str
116
+ All currently watched paths.
117
+
118
+ Examples
119
+ --------
120
+ >>> watcher = FileWatcher()
121
+ >>> paths = watcher.get_watched_paths()
122
+ >>> print(
123
+ ... 'Watched paths:',
124
+ ... paths,
125
+ ... )
126
+ """
127
+ return self.watcher.files() + self.watcher.directories()
128
+
129
+ def get_watched_files(
130
+ self,
131
+ ):
132
+ """
133
+ Returns all currently watched files.
134
+
135
+ Returns
136
+ -------
137
+ list of str
138
+ All currently watched files.
139
+
140
+ Examples
141
+ --------
142
+ >>> watcher = FileWatcher()
143
+ >>> files = watcher.get_watched_files()
144
+ >>> print(
145
+ ... 'Watched files:',
146
+ ... files,
147
+ ... )
148
+ """
149
+ return self.watcher.files()
150
+
151
+ def get_watched_directories(
152
+ self,
153
+ ):
154
+ """
155
+ Returns all currently watched directories.
156
+
157
+ Returns
158
+ -------
159
+ list of str
160
+ All currently watched directories.
161
+
162
+ Examples
163
+ --------
164
+ >>> watcher = FileWatcher()
165
+ >>> directories = watcher.get_watched_directories()
166
+ >>> print(
167
+ ... 'Watched directories:',
168
+ ... directories,
169
+ ... )
170
+ """
171
+ return self.watcher.directories()
172
+
173
+ def remove_all_paths(
174
+ self,
175
+ ):
176
+ """
177
+ Removes all paths from the watch list.
178
+
179
+ Returns
180
+ -------
181
+ bool
182
+ Whether all paths were successfully removed.
183
+
184
+ Examples
185
+ --------
186
+ >>> watcher = FileWatcher()
187
+ >>> result = watcher.remove_all_paths()
188
+ >>> if result:
189
+ >>> print("Successfully removed all paths")
190
+ >>> else:
191
+ >>> print("Failed to remove all paths")
192
+ """
193
+ return self.watcher.removePaths(self.get_watched_paths())