auto away status update

This commit is contained in:
ingvar1995 2016-08-29 20:59:22 +03:00
parent 5002dbe33f
commit 7708ce1d24
4 changed files with 31 additions and 17 deletions

View File

@ -37,6 +37,7 @@ class AutoAwayStatusLinux(plugin_super_class.PluginSuperClass):
self._exec = None self._exec = None
self._active = False self._active = False
self._time = json.loads(self.load_settings())['time'] self._time = json.loads(self.load_settings())['time']
self._prev_status = 0
def close(self): def close(self):
self.stop() self.stop()
@ -54,8 +55,10 @@ class AutoAwayStatusLinux(plugin_super_class.PluginSuperClass):
def save(self): def save(self):
self.save_settings('{"time": ' + str(self._time) + '}') self.save_settings('{"time": ' + str(self._time) + '}')
def change_status(self): def change_status(self, status=1):
invoke_in_main_thread(self._profile.set_status, 1) if self._profile.status != 1:
self._prev_status = self._profile.status
invoke_in_main_thread(self._profile.set_status, status)
def get_window(self): def get_window(self):
inst = self inst = self
@ -66,15 +69,15 @@ class AutoAwayStatusLinux(plugin_super_class.PluginSuperClass):
self.setGeometry(QtCore.QRect(450, 300, 350, 100)) self.setGeometry(QtCore.QRect(450, 300, 350, 100))
self.label = QtGui.QLabel(self) self.label = QtGui.QLabel(self)
self.label.setGeometry(QtCore.QRect(20, 0, 310, 35)) self.label.setGeometry(QtCore.QRect(20, 0, 310, 35))
self.label.setText(QtGui.QApplication.translate("AutoAwayStatusWindows", "Auto away time in minutes\n(0 - to disable)", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("AutoAwayStatusLinux", "Auto away time in minutes\n(0 - to disable)", None, QtGui.QApplication.UnicodeUTF8))
self.time = QtGui.QLineEdit(self) self.time = QtGui.QLineEdit(self)
self.time.setGeometry(QtCore.QRect(20, 40, 310, 25)) self.time.setGeometry(QtCore.QRect(20, 40, 310, 25))
self.time.setText(str(inst._time)) self.time.setText(str(inst._time))
self.setWindowTitle("AutoAwayStatusWindows") self.setWindowTitle("AutoAwayStatusLinux")
self.ok = QtGui.QPushButton(self) self.ok = QtGui.QPushButton(self)
self.ok.setGeometry(QtCore.QRect(20, 70, 310, 25)) self.ok.setGeometry(QtCore.QRect(20, 70, 310, 25))
self.ok.setText( self.ok.setText(
QtGui.QApplication.translate("AutoAwayStatusWindows", "Save", None, QtGui.QApplication.UnicodeUTF8)) QtGui.QApplication.translate("AutoAwayStatusLinux", "Save", None, QtGui.QApplication.UnicodeUTF8))
self.ok.clicked.connect(self.update) self.ok.clicked.connect(self.update)
def update(self): def update(self):
@ -91,8 +94,11 @@ class AutoAwayStatusLinux(plugin_super_class.PluginSuperClass):
def loop(self): def loop(self):
self._active = True self._active = True
while self._exec: while self._exec:
time.sleep(30) time.sleep(5)
d = check_output(['xprintidle']) d = check_output(['xprintidle'])
d = int(d) // 1000 d = int(d) // 1000
if self._time and d > 60 * self._time: if self._time:
if d > 60 * self._time:
self.change_status() self.change_status()
elif self._profile.status == 1:
self.change_status(self._prev_status)

View File

@ -1 +1 @@
Required: xprintidle (sudo apt-get install ) Required package: xprintidle (sudo apt-get install xprintidle)

View File

@ -49,6 +49,7 @@ class AutoAwayStatusWindows(plugin_super_class.PluginSuperClass):
self._exec = None self._exec = None
self._active = False self._active = False
self._time = json.loads(self.load_settings())['time'] self._time = json.loads(self.load_settings())['time']
self._prev_status = 0
def close(self): def close(self):
self.stop() self.stop()
@ -66,8 +67,10 @@ class AutoAwayStatusWindows(plugin_super_class.PluginSuperClass):
def save(self): def save(self):
self.save_settings('{"time": ' + str(self._time) + '}') self.save_settings('{"time": ' + str(self._time) + '}')
def change_status(self): def change_status(self, status=1):
invoke_in_main_thread(self._profile.set_status, 1) if self._profile.status != 1:
self._prev_status = self._profile.status
invoke_in_main_thread(self._profile.set_status, status)
def get_window(self): def get_window(self):
inst = self inst = self
@ -103,7 +106,10 @@ class AutoAwayStatusWindows(plugin_super_class.PluginSuperClass):
def loop(self): def loop(self):
self._active = True self._active = True
while self._exec: while self._exec:
time.sleep(30) time.sleep(5)
d = get_idle_duration() d = get_idle_duration()
if self._time and d > 60 * self._time: if self._time:
if d > 60 * self._time:
self.change_status() self.change_status()
elif self._profile.status == 1:
self.change_status(self._prev_status)

View File

@ -8,8 +8,10 @@ For more info visit [plugins.md](https://github.com/xveduk/toxygen/blob/master/d
- ToxId - share your Tox ID and copy friend's Tox ID easily. - ToxId - share your Tox ID and copy friend's Tox ID easily.
- MarqueeStatus - create ticker from your status message. - MarqueeStatus - create ticker from your status message.
- BirthDay - get notifications on your friends' birthdays - BirthDay - get notifications on your friends' birthdays.
- Bot - bot which can communicate with your friends when you are away - Bot - bot which can communicate with your friends when you are away.
- SearchPlugin - select text in message and find it in search engine - SearchPlugin - select text in message and find it in search engine.
- AutoAwayStatusLinux - sets "Away" status when user is inactive (Linux only).
- AutoAwayStatusWindows - sets "Away" status when user is inactive (Windows only).