Skip to content

Commit

Permalink
Added experimental implimentation of #11
Browse files Browse the repository at this point in the history
  • Loading branch information
mikan committed Jan 27, 2016
1 parent 222048b commit 0481a12
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 33 deletions.
328 changes: 298 additions & 30 deletions resources/forms/racm_ui.fbp

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ def __init__(self, path):
self._path = path

@staticmethod
def _run(args):
def _startup_info():
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
return startupinfo

@staticmethod
def _run(args):
p = subprocess.Popen(flatten(args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=False, startupinfo=startupinfo)
shell=False, startupinfo=Adb._startup_info())
ret = p.wait()
output = Adb._out2str(p.stdout.readlines())
error = Adb._out2str(p.stderr.readlines())
Expand All @@ -42,6 +46,11 @@ def shell(self, host, command):
print (args)
return self._run(args)

def logcat(self, host):
args = [self._path, "-s", host, "logcat"]
return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
shell=False, startupinfo=Adb._startup_info())

def install_apk(self, host, file_path):
_state = self.get_state(host)
if _state is "offline":
Expand Down
57 changes: 57 additions & 0 deletions src/logcat.py
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()
58 changes: 58 additions & 0 deletions src/racm_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def __init__( self, parent ):

self.menu_bar.Append( self.edit_menu, _(u"Edit") )

self.log_menu = wx.Menu()
self.logcat_menu_item = wx.MenuItem( self.log_menu, wx.ID_ANY, _(u"LogCat (EXPERIMENTAL)"), wx.EmptyString, wx.ITEM_NORMAL )
self.log_menu.AppendItem( self.logcat_menu_item )

self.menu_bar.Append( self.log_menu, _(u"Log") )

self.help_menu = wx.Menu()
self.releases_menu_item = wx.MenuItem( self.help_menu, wx.ID_ANY, _(u"Check releases..."), wx.EmptyString, wx.ITEM_NORMAL )
self.help_menu.AppendItem( self.releases_menu_item )
Expand Down Expand Up @@ -137,6 +143,12 @@ def __init__( self, parent ):

manage_box.Add( self.remove_button, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, 5 )

self.logcat_button = wx.Button( manage_box.GetStaticBox(), wx.ID_ANY, _(u"LogCat..."), wx.DefaultPosition, wx.DefaultSize, 0 )
self.logcat_button.Enable( False )
self.logcat_button.Hide()

manage_box.Add( self.logcat_button, 0, wx.ALL, 5 )


list_area_box.Add( manage_box, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 5 )

Expand All @@ -158,6 +170,7 @@ def __init__( self, parent ):
self.Bind( wx.EVT_MENU, self.on_settings_selected, id = self.settings_menu_item.GetId() )
self.Bind( wx.EVT_MENU, self.on_edit_selected, id = self.edit_menu_item.GetId() )
self.Bind( wx.EVT_MENU, self.on_remove_selected, id = self.remove_menu_item.GetId() )
self.Bind( wx.EVT_MENU, self.on_logcat_selected, id = self.logcat_menu_item.GetId() )
self.Bind( wx.EVT_MENU, self.on_releases_selected, id = self.releases_menu_item.GetId() )
self.Bind( wx.EVT_MENU, self.on_issues_selected, id = self.issues_menu_item.GetId() )
self.Bind( wx.EVT_MENU, self.on_about_selected, id = self.about_menu_item.GetId() )
Expand All @@ -172,6 +185,7 @@ def __init__( self, parent ):
self.apk_install_button.Bind( wx.EVT_BUTTON, self.on_apk_install_clicked )
self.add_button.Bind( wx.EVT_BUTTON, self.on_add_clicked )
self.remove_button.Bind( wx.EVT_BUTTON, self.on_remove_clicked )
self.logcat_button.Bind( wx.EVT_BUTTON, self.on_logcat_clicked )

def __del__( self ):
pass
Expand Down Expand Up @@ -199,6 +213,9 @@ def on_edit_selected( self, event ):
def on_remove_selected( self, event ):
pass

def on_logcat_selected( self, event ):
pass

def on_releases_selected( self, event ):
pass

Expand Down Expand Up @@ -241,6 +258,9 @@ def on_add_clicked( self, event ):
def on_remove_clicked( self, event ):
pass

def on_logcat_clicked( self, event ):
pass


###########################################################################
## Class SettingsFrame
Expand Down Expand Up @@ -591,3 +611,41 @@ def on_cancel_clicked( self, event ):
pass


###########################################################################
## Class LogFrame
###########################################################################

class LogFrame ( wx.Frame ):

def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = _(u"LogCat"), pos = wx.DefaultPosition, size = wx.Size( 500,400 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
self.SetForegroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOW ) )
self.SetBackgroundColour( wx.Colour( 255, 255, 255 ) )

wrapper = wx.BoxSizer( wx.VERTICAL )

self.log_text = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_DONTWRAP|wx.TE_MULTILINE|wx.TE_READONLY|wx.VSCROLL )
self.log_text.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 76, 90, 90, False, wx.EmptyString ) )

wrapper.Add( self.log_text, 1, wx.ALL|wx.EXPAND, 5 )


self.SetSizer( wrapper )
self.Layout()

self.Centre( wx.BOTH )

# Connect Events
self.Bind( wx.EVT_CLOSE, self.on_log_closed )

def __del__( self ):
pass


# Virtual event handlers, overide them in your derived class
def on_log_closed( self, event ):
pass


22 changes: 22 additions & 0 deletions src/racm_ui_log_frame.py
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()
15 changes: 14 additions & 1 deletion src/racm_ui_main_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from racm_ui_add_dialog import AddDialog as InheritedAddDialog
from racm_ui_edit_dialog import EditDialog as InheritedEditDialog
from racm_ui_settings_frame import SettingsFrame as InheritedSettingsFrame
from racm_ui_log_frame import LogFrame as InheritedLogFrame

_COLUMN_HOST = 0
_COLUMN_NAME = 1
Expand Down Expand Up @@ -84,11 +85,14 @@ def on_releases_selected(self, event):
def on_issues_selected(self, event):
self._open_browser("https://github.com/mikan/racm/issues")

def on_logcat_selected(self, event):
self.on_logcat_clicked(event)

def on_about_selected(self, event):
about = wx.AboutDialogInfo()
about.Name = "Remote ADB Connection Manager"
about.Version = self._version
about.Copyright = "(C) 2015 Yutaka Kato"
about.Copyright = "(C) 2015-2016 Yutaka Kato"
about.WebSite = "https://github.com/mikan/racm"
about.SetIcon(icon.get_icon())
wx.AboutBox(about)
Expand All @@ -106,6 +110,7 @@ def on_host_selection_changed(self, event):
self.apk_install_button.Enable(selected)
self.shell_button.Enable(selected)
self.remove_button.Enable(selected)
self.logcat_button.Enable(selected)

def on_host_selection_item_activated(self, event):
row = self.host_list.GetSelectedRow()
Expand Down Expand Up @@ -172,6 +177,14 @@ def on_remove_clicked(self, event):
else:
self._show_error("No items selected.")

def on_logcat_clicked(self, event):
row = self.host_list.GetSelectedRow()
if row >= 0:
frame = InheritedLogFrame(self, self.host_list.GetValue(row, _COLUMN_HOST), self._adb)
frame.Show()
else:
self._show_error("No items selected.")

def apply_config(self):
# ADB
adb_path = self._config.get("adb.path")
Expand Down

0 comments on commit 0481a12

Please sign in to comment.