예제 #1
0
    def event(self, event):
        _type = event.type()
        _event_str = "'%s' (%d)" % (i_to_e[_type]
                                    if _type in i_to_e else "unknown", _type)
        with track_base.frame_grabber(log(), _event_str):
            if _type == QtCore.QEvent.WindowActivate and not self._connected:
                # we abuse this event as some sort of WindowShow event
                if self._connect():
                    self._update_timer.start(1000)
                else:
                    QtWidgets.QMessageBox.information(
                        self,
                        "track service unreachable",
                        "Cannot reach the local track service even after starting "
                        "a new instance.\nPlease restart track on command "
                        "line to get some more info and file a bug!\n\nBye!",
                        buttons=QtWidgets.QMessageBox.Ok)
                    QtWidgets.QApplication.quit()
            elif _type == QtCore.QEvent.WindowStateChange and self.isMinimized(
            ):
                # The window is already minimized at this point.  AFAIK,
                # there is no hook stop a minimize event. Instead,
                # removing the Qt.Tool flag should remove the window
                # from the taskbar.
                self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.Tool)
                self.tray_icon.show()
                return True
            else:
                # log.debug("unhandled event '%s' (%d)",
                #         i_to_e[_type] if _type in i_to_e else "unknown",
                #         _type)
                pass

            return super(track_ui, self).event(event)
예제 #2
0
    def restore_window(self, reason):
        with track_base.frame_grabber(log()):

            if reason == QtGui.QSystemTrayIcon.DoubleClick:
                self.tray_icon.hide()
                # self.showNormal will restore the window even if it was
                # minimized.
                self.showNormal()
예제 #3
0
def sigint_handler(s, window):
    with track_base.frame_grabber(log()):
        sig_name = "unknown"
        if s == signal.SIGABRT:
            sig_name = "SIGABRT"
        if s == signal.SIGINT:
            sig_name = "SIGINT"
        if s == signal.SIGSEGV:
            sig_name = "SIGSEGV"
        if s == signal.SIGTERM:
            sig_name = "SIGTERM"
        log().info("got signal %s (%s)", sig_name, str(s))
        window.cleanup()
        QtGui.QApplication.quit()
예제 #4
0
    def update(self):
        with track_base.frame_grabber(log):

            received_data = self._request({'type': 'current'})
            if not 'current' in received_data:
                raise
            self._current_data = received_data['current']

            received_data = self._request({'type': 'apps'})
            if not 'apps' in received_data:
                raise
            self._applications.from_dict(received_data['apps'])

            self._initialized = True
예제 #5
0
    def update(self):
        with track_base.frame_grabber(log):

            received_data = self._request({'type': 'current'})
            if not 'current' in received_data:
                raise
            self._current_data = received_data['current']

            received_data = self._request({'type': 'apps'})
            if not 'apps' in received_data:
                raise
            self._applications.from_dict(received_data['apps'])

            self._initialized = True
예제 #6
0
    def update_idle(self):
        with track_base.frame_grabber(log()):
            self._tracker.update()
            _idle = self._tracker.get_idle()
            _app = self._tracker.get_current_app_title()

            try:
                self.lbl_idle.setText(str(_idle))
                #self.lbl_private.setText(str(self._tracker.get_private_time()))
                self.lbl_title.setText(self._tracker.get_current_app_title())
                self.lbl_process.setText(
                    self._tracker.get_current_process_name())

                # now-begin, active (.x) work (.x)
                _time_total = self._tracker.get_time_total()
                _time_active = self._tracker.get_time_active()
                _time_work = self._tracker.get_time_work()
                _time_private = self._tracker.get_time_private()
                _time_idle = self._tracker.get_time_idle()

                self.lbl_times.setText(
                    "T: %s  A: %s (%.1f)  W: %s (%.1f)  "
                    "P: %s (%.1f)  I: %s (%.1f)" %
                    (track_base.mins_to_dur(_time_total),
                     track_base.mins_to_dur(_time_active), _time_active /
                     float(_time_total), track_base.mins_to_dur(_time_work),
                     _time_work / float(_time_total),
                     track_base.mins_to_dur(_time_private), _time_private /
                     float(_time_total), track_base.mins_to_dur(_time_idle),
                     _time_idle / float(_time_total)))

                self.lbl_start_time.setText(
                    "%s - %s" %
                    (self._tracker.start_time(), self._tracker.now()))

            except Exception as e:
                log().error(e)

            p = self.lbl_idle.palette()
            if self._tracker.user_is_active():
                p.setColor(self.lbl_idle.backgroundRole(), QtCore.Qt.green)
            else:
                p.setColor(self.lbl_idle.backgroundRole(), QtCore.Qt.gray)
            self.lbl_idle.setPalette(p)

            self.update()
예제 #7
0
    def update(self):
        with track_base.frame_grabber(log):
            try:
                _today = track_common.today_int()
                self._current_minute = track_common.minutes_since_midnight()

                if self._active_day < _today:
                    print("current minute is %d - it's midnight" % self._current_minute)
                    #midnight!
                    self.save('track-log-%d.json' % self._active_day)
                    self.clear()

                self._active_day = _today

                self._current_minute = track_common.minutes_since_midnight()

                self._user_is_active = True

                self._idle_current = int(idle.getIdleSec())
                _app_info = applicationinfo.get_active_window_information()

                self._current_app_title = _app_info["TITLE"]
                if "COMMAND" in _app_info:
                    self._current_process_exe = _app_info["COMMAND"]
                else:
                    self._current_process_exe = "Process not found"

                self._rules.highlight_string(self._current_app_title)

                if self._idle_current > 10:
                    self._user_is_active = False
                    return

                _app = track_common.app_info(self._current_app_title,
                                self._current_process_exe)
                _app._category = self._rules.get_first_matching_key(_app)

                _app = self._applications.update(
                            self._current_minute,
                            _app)

            except applicationinfo.WindowInformationError:
                pass
            except applicationinfo.ToolError as ex:
                log.error(ex)
예제 #8
0
    def update(self):
        with track_base.frame_grabber(log):
            try:
                _today = track_common.today_int()
                self._current_minute = track_common.minutes_since_midnight()

                if self._active_day < _today:
                    print("current minute is %d - it's midnight" %
                          self._current_minute)
                    #midnight!
                    self.save('track-log-%d.json' % self._active_day)
                    self.clear()

                self._active_day = _today

                self._current_minute = track_common.minutes_since_midnight()

                self._user_is_active = True

                self._idle_current = int(desktop_usage_info.idle.getIdleSec())
                _app_info = desktop_usage_info.applicationinfo.get_active_window_information(
                )

                self._current_app_title = _app_info["TITLE"]
                if "COMMAND" in _app_info:
                    self._current_process_exe = _app_info["COMMAND"]
                else:
                    self._current_process_exe = "Process not found"

                self._rules.highlight_string(self._current_app_title)

                if self._idle_current > 10:
                    self._user_is_active = False
                    return

                _app = track_common.app_info(self._current_app_title,
                                             self._current_process_exe)
                _app._category = self._rules.get_first_matching_key(_app)

                _app = self._applications.update(self._current_minute, _app)

            except desktop_usage_info.WindowInformationError:
                pass
            except desktop_usage_info.ToolError as ex:
                log.error(ex)
예제 #9
0
 def save(self):
     with track_base.frame_grabber(log):
         _received_data = self._request({'type': 'save'})
예제 #10
0
 def _fetch_rules(self):
     with track_base.frame_grabber(log):
         _received_data = self._request({'type': 'rules'})
         self._rules.from_dict(_received_data)
         if not 'rules' in _received_data:
             raise
예제 #11
0
 def _check_version(self):
     with track_base.frame_grabber(log):
         self._req_send({'type': 'version'})
         _version = self._req_recv(timeout=1000, raise_on_timeout=True)
         log.info('server version: %s', _version)
예제 #12
0
 def save(self):
     with track_base.frame_grabber(log):
         _received_data = self._request({'type': 'save'})
예제 #13
0
 def _fetch_rules(self):
     with track_base.frame_grabber(log):
         _received_data = self._request({'type': 'rules'})
         self._rules.from_dict(_received_data)
         if not 'rules' in _received_data:
             raise
예제 #14
0
 def _check_version(self):
     with track_base.frame_grabber(log):
         self._req_send({'type': 'version'})
         _version = self._req_recv(timeout=1000, raise_on_timeout=True)
         log.info('server version: %s', _version)