-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from mikan/logcat
Added experimental implimentation of #11
- Loading branch information
Showing
6 changed files
with
460 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import wx | ||
import threading | ||
|
||
|
||
class LogCatThread(threading.Thread): | ||
""""LogCat Thread""" | ||
|
||
_process = None | ||
|
||
def __init__(self, adb, host, display): | ||
super(LogCatThread, self).__init__() | ||
self._adb = adb | ||
self._host = host | ||
self._display = display | ||
self._stop_event = threading.Event() | ||
|
||
def run(self): | ||
print ("LogCat started.") | ||
self._process = self._adb.logcat(self._host) | ||
chars = [] | ||
count = 0 | ||
buffer_break = 4000 | ||
buff = [] | ||
while True: | ||
ch = self._process.stdout.read(1) | ||
if ch: | ||
if ch in ['\r', '\n']: | ||
line = "".join(chars).decode('utf-8').rstrip() | ||
if not chars: | ||
continue | ||
chars = [] | ||
count += 1 | ||
print (line) | ||
line += "\n" | ||
if count > buffer_break: | ||
wx.CallAfter(self.update, line) # direct output | ||
self._process.stdout.flush() | ||
elif count == buffer_break: | ||
buff.append(line) | ||
wx.CallAfter(self.update, "".join(buff)) # store buffered logs | ||
else: | ||
buff.append(line) # buffering | ||
else: | ||
chars.append(str(ch)) | ||
else: | ||
break | ||
|
||
print ("LogCat stopped.") | ||
|
||
def update(self, text): | ||
self._display.AppendText(text) | ||
|
||
def stop(self): | ||
self._stop_event.set() | ||
self._process.kill() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Subclass of LogFrame, which is generated by wxFormBuilder.""" | ||
|
||
import wx | ||
import racm_ui | ||
from logcat import LogCatThread | ||
|
||
|
||
# Implementing LogFrame | ||
class LogFrame(racm_ui.LogFrame): | ||
_thread = None | ||
|
||
def __init__(self, parent, host, adb): | ||
racm_ui.LogFrame.__init__(self, parent) | ||
self._adb = adb | ||
self.SetTitle("LogCat: " + host) | ||
self._thread = LogCatThread(adb, host, self.log_text) | ||
self._thread.start() | ||
|
||
# Handlers for LogFrame events. | ||
def on_log_closed(self, event): | ||
self._thread.stop() | ||
self.Destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters