-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathTextViewer.py
More file actions
109 lines (93 loc) · 3.11 KB
/
TextViewer.py
File metadata and controls
109 lines (93 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import string
import xbmc
import xbmcaddon
import xbmcgui
Addon = xbmcaddon.Addon()
addon = Addon.getAddonInfo('id')
addonName = Addon.getAddonInfo('name')
moduleName = 'Log Viewer'
dialog = xbmcgui.Dialog()
contents = ''
path = ''
# get actioncodes from keymap.xml
ACTION_MOVE_LEFT = 1
ACTION_MOVE_RIGHT = 2
ACTION_MOVE_UP = 3
ACTION_MOVE_DOWN = 4
ACTION_PAGE_UP = 5
ACTION_PAGE_DOWN = 6
ACTION_SELECT_ITEM = 7
class Viewer(xbmcgui.WindowXML):
def __init__(self, strXMLname, strFallbackPath):
self.previous_menu = 10
self.back = 92
self.page_up = 5
self.page_down = 6
# XML id's
self.main_window = 1100
self.title_box_control = 20301
self.content_box_control = 20302
self.list_box_control = 20303
self.line_number_box_control = 20201
self.scroll_bar = 20212
def onInit(self):
# title box
title_box = self.getControl(self.title_box_control)
title_box.setText(str.format('%s %s') % (addonName, moduleName))
# content box
content_box = self.getControl(self.content_box_control)
content_box.setText(contents)
# Set initial focus
self.setFocusId(self.scroll_bar)
def onAction(self, action):
# non Display Button control
if action == self.previous_menu:
self.close()
elif action == self.back:
self.close()
def onClick(self, control_id):
if control_id == 20293:
self.close()
text_view(path)
def onFocus(self, control_id):
pass
def text_view(pathi='', data=''):
global contents
global path
contents = ''
path = pathi
# todo, path can be a url to an internet file
if not path and not data:
return
if path and not data:
if path == 'log':
logfile_path = xbmc.translatePath('special://logpath')
logfile_names = ('kodi.log', 'spmc.log', 'tvmc.log', 'freetelly.log', 'ftmc.log', 'firemc.log', 'nodi.log')
for logfile_name in logfile_names:
log_file_path = os.path.join(logfile_path, logfile_name)
if os.path.isfile(log_file_path):
path = log_file_path
break
elif 'http' in string.lower(path):
# todo, open internet files from a url path
dialog.ok('Notice', 'This feature is not yet available')
return
# Open and read the file from path location
temp_file = open(path, 'rb')
contents = temp_file.read()
temp_file.close()
# Send contents to text display function
elif data:
contents = data
if not contents:
dialog.ok('Notice', 'The file was empty')
return
contents = contents.replace(' ERROR: ', ' [COLOR red]ERROR[/COLOR]: ') \
.replace(' WARNING: ', ' [COLOR gold]WARNING[/COLOR]: ')
win = Viewer('textview-skin.xml', Addon.getAddonInfo('path'))
win.doModal()
del win
# To call module put the following in the addon list or context menu
# import TextViewer
# TextViewer.text_view('log')