lyrpy 0.0.2__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.
lyr/LUQThread.py ADDED
@@ -0,0 +1,139 @@
1
+ """LUQThread.py"""
2
+ # -*- coding: UTF-8 -*-
3
+ __annotations__ = """
4
+ =======================================================
5
+ Copyright (c) 2023
6
+ Author:
7
+ Lisitsin Y.R.
8
+ Project:
9
+ LU_PY
10
+ Python (LU)
11
+ Module:
12
+ LUQThread.py
13
+
14
+ =======================================================
15
+ """
16
+
17
+ #------------------------------------------
18
+ # БИБЛИОТЕКИ python
19
+ #------------------------------------------
20
+ import psutil
21
+
22
+ #------------------------------------------
23
+ # БИБЛИОТЕКИ сторонние
24
+ #------------------------------------------
25
+ import PySide6.QtCore as QtCore
26
+ from PySide6.QtCore import QObject, QThread, Signal, Slot
27
+
28
+ #------------------------------------------
29
+ # БИБЛИОТЕКА LU
30
+ #------------------------------------------
31
+ import lyr.LULog as LULog
32
+
33
+ # Signals must inherit QObject
34
+ class MySignals(QObject):
35
+ signal_str = Signal(str)
36
+ signal_int = Signal(int)
37
+ #endclass
38
+
39
+ # Create the Worker Thread
40
+ class TQThread (QThread):
41
+ """TQThread"""
42
+ luClassName = 'TQThread'
43
+
44
+ #--------------------------------------------------
45
+ # constructor
46
+ #--------------------------------------------------
47
+ def __init__ (self, parent = None):
48
+ #beginfunction
49
+ QThread.__init__ (self, parent = parent)
50
+ # super ().__init__ (*args, **kwargs)
51
+ # self.args = args
52
+ # self.kwargs = kwargs
53
+
54
+ self.__FStopThread = False
55
+
56
+ # Instantiate signals and connect signals to the slots
57
+ self.signals = MySignals ()
58
+ self.signals.signal_str.connect (parent.update_str_field)
59
+ self.signals.signal_int.connect (parent.update_int_field)
60
+
61
+ #endfunction
62
+
63
+ #--------------------------------------------------
64
+ # destructor
65
+ #--------------------------------------------------
66
+ def __del__ (self):
67
+ """destructor"""
68
+ #beginfunction
69
+ LClassName = self.__class__.__name__
70
+ s = '{} уничтожен'.format (LClassName)
71
+ # LULog.LoggerTOOLS_AddLevel (LULog.DEBUGTEXT, s)
72
+ #print (s)
73
+ #endfunction
74
+
75
+ #--------------------------------------------------
76
+ # @property QThread
77
+ #--------------------------------------------------
78
+ # getter
79
+ @property
80
+ def QThread(self) -> QThread:
81
+ #beginfunction
82
+ return self
83
+ #endfunction
84
+
85
+ #--------------------------------------------------
86
+ # run
87
+ #--------------------------------------------------
88
+ def run(self):
89
+ """Запуск потока"""
90
+ #beginfunction
91
+ super ().run()
92
+ s = 'run - Запуск потока...'
93
+ LULog.LoggerTOOLS_AddDebug (s)
94
+
95
+ # Do something on the worker thread
96
+ a = 1 + 1
97
+ # Emit signals whenever you want
98
+ self.signals.signal_int.emit (a)
99
+ self.signals.signal_str.emit ("This text comes to Main thread from our Worker thread.")
100
+
101
+ while not self.__FStopThread:
102
+ s = 'Выполнение потока...'
103
+ # LULog.LoggerTOOLS_AddDebug (s)
104
+ Lval = psutil.cpu_percent ()
105
+ self.emit(QtCore.SIGNAL('CPU_VALUE'), Lval)
106
+ continue
107
+ #endwhile
108
+
109
+ # # Do something on the worker thread
110
+ # a = 1 + 1
111
+ # # Emit signals whenever you want
112
+ # self.signals.signal_int.emit (a)
113
+ # self.signals.signal_str.emit ("This text comes to Main thread from our Worker thread.")
114
+ # while 1:
115
+ # Lval = psutil.cpu_percent ()
116
+ # # self.emit(QtCore.SIGNAL('CPU_VALUE'), Lval)
117
+ # ...
118
+ # #endwhile
119
+
120
+ #endfunction
121
+ #endclass
122
+
123
+ #---------------------------------------------------------
124
+ # main
125
+ #---------------------------------------------------------
126
+ def main ():
127
+ #beginfunction
128
+ ...
129
+ #endfunction
130
+
131
+ #---------------------------------------------------------
132
+ #
133
+ #---------------------------------------------------------
134
+ #beginmodule
135
+ if __name__ == "__main__":
136
+ main()
137
+ #endif
138
+
139
+ #endmodule
lyr/LUQTimer.py ADDED
@@ -0,0 +1,197 @@
1
+ """LUQTimer.py"""
2
+ # -*- coding: UTF-8 -*-
3
+ __annotations__ = """
4
+ =======================================================
5
+ Copyright (c) 2023-2024
6
+ Author:
7
+ Lisitsin Y.R.
8
+ Project:
9
+ LU_PY
10
+ Python (LU)
11
+ Module:
12
+ LUQTimer.py
13
+
14
+ =======================================================
15
+ """
16
+
17
+ #------------------------------------------
18
+ # БИБЛИОТЕКИ python
19
+ #------------------------------------------
20
+
21
+ #------------------------------------------
22
+ # БИБЛИОТЕКИ сторонние
23
+ #------------------------------------------
24
+ from PySide6 import QtCore
25
+
26
+ from PySide6.QtCore import (
27
+ QObject, QThread, Signal, Slot, QTimer, QCoreApplication,
28
+ QEventLoop, QTime, QTimer, Slot
29
+ )
30
+ from PySide6.QtWidgets import (
31
+ QApplication, QPushButton, QVBoxLayout, QWidget,
32
+ QLCDNumber
33
+ )
34
+
35
+ #------------------------------------------
36
+ # БИБЛИОТЕКА LU
37
+ #------------------------------------------
38
+ import lyr.LULog as LULog
39
+
40
+ # blocking.py
41
+ def wait(milliseconds, /):
42
+ timer = QTimer()
43
+ timer.start(milliseconds)
44
+ wait_for_event(timer.timeout)
45
+ def wait_for_event(event, /):
46
+ loop = QEventLoop()
47
+ event.connect(loop.quit)
48
+ loop.exec()
49
+
50
+
51
+ # Signals must inherit QObject
52
+ class MySignals(QObject):
53
+ signal_str = Signal(str)
54
+ signal_int = Signal(int)
55
+ #endclass
56
+
57
+ class TQTimer (QTimer):
58
+ """TQTimer"""
59
+ luClassName = 'TQTimer'
60
+
61
+ signals = MySignals ()
62
+
63
+ #--------------------------------------------------
64
+ # constructor
65
+ #--------------------------------------------------
66
+ def __init__ (self, parent=None):
67
+ #beginfunction
68
+ QTimer.__init__ (self, parent=parent)
69
+ self.__FStopTimer = False
70
+ self.__Fidle = False
71
+ self.__Fparent = parent
72
+
73
+ self.FQTimerName: str = ''
74
+
75
+ self.interval = 1
76
+ # self.setInterval (1)
77
+
78
+ self.signals.signal_str.connect (parent.update_str_field)
79
+ self.signals.signal_int.connect (parent.update_int_field)
80
+
81
+ # self.timeout.connect (self.run_CPU)
82
+ #endfunction
83
+
84
+ #--------------------------------------------------
85
+ # destructor
86
+ #--------------------------------------------------
87
+ def __del__ (self):
88
+ """destructor"""
89
+ #beginfunction
90
+ LClassName = self.__class__.__name__
91
+ s = '{} уничтожен'.format (LClassName)
92
+ # LULog.LoggerTOOLS_AddLevel (LULog.DEBUGTEXT, s)
93
+ #print (s)
94
+ #endfunction
95
+
96
+ #--------------------------------------------------
97
+ # @property QTimer
98
+ #--------------------------------------------------
99
+ # getter
100
+ @property
101
+ def QTimer(self) -> QTimer:
102
+ #beginfunction
103
+ return self
104
+ #endfunction
105
+
106
+ #--------------------------------------------------
107
+ # start
108
+ #--------------------------------------------------
109
+ def start(self):
110
+ """start - Запуск таймера..."""
111
+ #beginfunction
112
+ s = 'Запуск таймера '+self.FQTimerName+'...'
113
+ LULog.LoggerTOOLS_AddLevel (LULog.DEBUGTEXT, s)
114
+ super ().start ()
115
+ self.__Fidle = True
116
+ #endfunction
117
+
118
+ #--------------------------------------------------
119
+ # stop
120
+ #--------------------------------------------------
121
+ def stop(self):
122
+ """stop - Остановить таймер..."""
123
+ #beginfunction
124
+ s = 'Остановка таймера '+self.FQTimerName+'...'
125
+ LULog.LoggerTOOLS_AddLevel (LULog.DEBUGTEXT, s)
126
+ super ().stop ()
127
+ #endfunction
128
+
129
+ #--------------------------------------------------
130
+ # __run_TEST
131
+ #--------------------------------------------------
132
+ @QtCore.Slot (str, name = '__run_TEST')
133
+ def __run_TEST(self):
134
+ """__run_TEST..."""
135
+ #beginfunction
136
+ s = '__run_TEST...'
137
+ # LULog.LoggerTOOLS_AddDebug (s)
138
+
139
+ # Do something on the worker thread
140
+
141
+ # Emit signals whenever you want
142
+ a = 1 + 1
143
+ self.signals.signal_int.emit (a)
144
+ self.signals.signal_str.emit ("This text comes to Main thread from our Worker thread.")
145
+
146
+ # while self.__Fidle:
147
+ # QCoreApplication.processEvents ()
148
+ # #endwhile
149
+
150
+ QCoreApplication.processEvents ()
151
+ #endfunction
152
+ #endclass
153
+
154
+ class DigitalClock(QLCDNumber):
155
+ def __init__(self, parent=None):
156
+ super().__init__(parent)
157
+ self.setSegmentStyle(QLCDNumber.Filled)
158
+ self.setDigitCount(8)
159
+
160
+ self.timer = QTimer(self)
161
+ self.timer.timeout.connect(self.show_time)
162
+ self.timer.start(1000)
163
+
164
+ self.show_time()
165
+
166
+ self.setWindowTitle("Digital Clock")
167
+ self.resize(250, 60)
168
+
169
+ @Slot (str, name = 'show_time')
170
+ def show_time(self):
171
+ time = QTime.currentTime()
172
+ text = time.toString("hh:mm:ss")
173
+
174
+ # Blinking effect
175
+ if (time.second() % 2) == 0:
176
+ text = text.replace(":", " ")
177
+
178
+ self.display(text)
179
+ #endclass
180
+
181
+ #---------------------------------------------------------
182
+ # main
183
+ #---------------------------------------------------------
184
+ def main ():
185
+ #beginfunction
186
+ ...
187
+ #endfunction
188
+
189
+ #---------------------------------------------------------
190
+ #
191
+ #---------------------------------------------------------
192
+ #beginmodule
193
+ if __name__ == "__main__":
194
+ main()
195
+ #endif
196
+
197
+ #endmodule