Skip to content

Commit 3b81be5

Browse files
committed
Get only the first 10 results from PIO library API
Added option to get the Next and Previous Page Added string translation in language files
1 parent 58f0e53 commit 3b81be5

File tree

10 files changed

+87
-18
lines changed

10 files changed

+87
-18
lines changed

languages/de.lang

+6
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ msgstr "Hochladen per OTA ist nur Espressif (ESP8266) Plattform. Wählen Sie ein
309309
msgid "select_library"
310310
msgstr "Bibliothek auswählen"
311311

312+
msgid "library_page_previous_{0}"
313+
msgstr "<< {0} Previous Page"
314+
315+
msgid "library_page_next_{0}"
316+
msgstr "Next Page {0} >>"
317+
312318
msgid "select_example"
313319
msgstr "Beispiel auswählen"
314320

languages/en.lang

+6
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ msgstr "Select a Port From The List"
306306
msgid "ota_error_platform"
307307
msgstr "OTA Upload is only available for Espressif (ESP8266) platform. Select other serial port or change the current environment"
308308

309+
msgid "library_page_previous_{0}"
310+
msgstr "<< {0} Previous Page"
311+
312+
msgid "library_page_next_{0}"
313+
msgstr "Next Page {0} >>"
314+
309315
msgid "select_library"
310316
msgstr "Select a Library"
311317

languages/es.lang

+6
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ msgstr "Cargas vía OTA sólo están disponibles para plataformas Espressif (ESP
309309
msgid "select_library"
310310
msgstr "Selecciona una Librería"
311311

312+
msgid "library_page_previous_{0}"
313+
msgstr "<< {0} Página Anterior"
314+
315+
msgid "library_page_next_{0}"
316+
msgstr "Página Siguiente {0} >>"
317+
312318
msgid "select_example"
313319
msgstr "Selecciona un Ejemplo"
314320

languages/fr.lang

+6
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ msgstr "OTA Upload are only available for Espressif (ESP8266) platforms currentl
309309
msgid "select_library"
310310
msgstr "Select a Library"
311311

312+
msgid "library_page_previous_{0}"
313+
msgstr "<< {0} Previous Page"
314+
315+
msgid "library_page_next_{0}"
316+
msgstr "Next Page {0} >>"
317+
312318
msgid "select_example"
313319
msgstr "Select an Example"
314320

languages/it.lang

+6
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ msgstr "Gli aggiornamenti OTA sono al momento disponibili solo per piattaforme E
309309
msgid "select_library"
310310
msgstr "Scegli una Libreria"
311311

312+
msgid "library_page_previous_{0}"
313+
msgstr "<< {0} Previous Page"
314+
315+
msgid "library_page_next_{0}"
316+
msgstr "Next Page {0} >>"
317+
312318
msgid "select_example"
313319
msgstr "Scegli un Esempio"
314320

languages/ko.lang

+6
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ msgstr "OTA Upload are only available for Espressif (ESP8266) platforms currentl
309309
msgid "select_library"
310310
msgstr "Select a Library"
311311

312+
msgid "library_page_previous_{0}"
313+
msgstr "<< {0} Previous Page"
314+
315+
msgid "library_page_next_{0}"
316+
msgstr "Next Page {0} >>"
317+
312318
msgid "select_example"
313319
msgstr "Select an Example"
314320

languages/pl.lang

+6
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ msgstr "OTA Upload jest dostępny tylko dla platform Espressif (ESP8266)"
306306
msgid "select_library"
307307
msgstr "Wybierz Bibliotekę"
308308

309+
msgid "library_page_previous_{0}"
310+
msgstr "<< {0} Previous Page"
311+
312+
msgid "library_page_next_{0}"
313+
msgstr "Next Page {0} >>"
314+
309315
msgid "select_example"
310316
msgstr "Wybierz Przykład"
311317

languages/pt_br.lang

+6
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ msgstr "O upload da OTA só Está Dsponível Para a Plataforma Espressif (ESP826
310310
msgid "select_library"
311311
msgstr "Selecione a Biblioteca"
312312

313+
msgid "library_page_previous_{0}"
314+
msgstr "<< {0} Próxima página"
315+
316+
msgid "library_page_next_{0}"
317+
msgstr "Pagina anterior {0} >>"
318+
313319
msgid "select_example"
314320
msgstr "Selecione o Examplo"
315321

languages/zh.lang

+6
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ msgstr "在线上传只支持 Espressif (ESP8266) 平台, 选择其他串口或
309309
msgid "select_library"
310310
msgstr "选择库"
311311

312+
msgid "library_page_previous_{0}"
313+
msgstr "<< {0} Previous Page"
314+
315+
msgid "library_page_next_{0}"
316+
msgstr "Next Page {0} >>"
317+
312318
msgid "select_example"
313319
msgstr "选择示例"
314320

libraries/libraries.py

+33-18
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def __init__(self, window=None, view=None, feedback=True):
4040
self.view = self.window.active_view()
4141
self.lib_file_path = getLibrariesFileDataPath()
4242
self.quick_list = []
43+
self.page = 1
44+
self.keyword = ""
4345
self.cwd = None
4446

4547
self.dprint = None
@@ -74,11 +76,13 @@ def download_list_async(self, keyword):
7476
Arguments:
7577
keyword {str} -- keyword to be search
7678
"""
77-
thread = Thread(target=self.download_list, args=(keyword,))
79+
self.keyword = keyword
80+
81+
thread = Thread(target=self.download_list)
7882
thread.start()
7983
ThreadProgress(thread, self.translate('searching'), '')
8084

81-
def download_list(self, keyword):
85+
def download_list(self):
8286
"""PlatformIO API
8387
8488
Search a library in the platformio API api.platformio.org.
@@ -90,7 +94,8 @@ def download_list(self, keyword):
9094
Keyword to search the library in the platformio API
9195
"""
9296
request = {}
93-
request['query'] = keyword
97+
request['query'] = self.keyword
98+
request['page'] = self.page
9499
query = urlencode(request)
95100

96101
url = 'http://api.platformio.org/lib/search?{0}'.format(query)
@@ -99,26 +104,23 @@ def download_list(self, keyword):
99104
response = urlopen(req)
100105
response_list = loads(response.read().decode())
101106

102-
nloop = response_list['total'] / response_list['perpage']
103-
if(nloop > 1):
104-
105-
nloop = int(nloop) + 1 if nloop > int(nloop) else int(nloop)
106-
for page in range(2, nloop + 1):
107-
108-
request['page'] = page
109-
query = urlencode(request)
110-
req = Request(url, headers=get_headers())
111-
112-
response = urlopen(req)
113-
page_next = loads(response.read().decode())
114-
for item_next in page_next['items']:
115-
response_list['items'].append(item_next)
107+
pages = response_list['total'] / response_list['perpage']
108+
page_previous = self.page - 1
109+
page_next = self.page + 1
116110

117111
if(len(response_list['items']) == 0):
118112
self.quick_list.append([self.translate('none_lib_found')])
119113
else:
120114
self.quicked(response_list['items'])
121115
self.quick_list.insert(0, [self.translate('select_library').upper()])
116+
117+
if(self.page > 1):
118+
caption = self.translate("library_page_previous_{0}", page_previous)
119+
self.quick_list.insert(1, [caption, page_previous])
120+
121+
if(self.page < pages):
122+
caption = self.translate("library_page_next_{0}", page_next)
123+
self.quick_list.insert(len(self.quick_list), [caption, page_next])
122124

123125
quick_panel(self.quick_list, self.library_install_async)
124126

@@ -140,7 +142,10 @@ def quicked(self, source_list):
140142
frameworks = ''
141143

142144
for framework in item['frameworks']:
143-
frameworks += framework + ' '
145+
try:
146+
frameworks += framework + ' '
147+
except:
148+
frameworks += framework["name"] + ' '
144149

145150
info = "{0} | {1}".format(id, frameworks)
146151
quick_list.append([name, description, info])
@@ -157,9 +162,19 @@ def library_install_async(self, selected):
157162
Arguments:
158163
selected {int} -- user selection index
159164
"""
165+
list_selection = self.quick_list[selected];
166+
160167
if(selected <= 0):
161168
return
162169

170+
try:
171+
page = int(list_selection[1])
172+
self.page = page
173+
self.download_list_async(self.keyword)
174+
return
175+
except:
176+
pass
177+
163178
thread = Thread(target=self.library_install, args=(selected,))
164179
thread.start()
165180
ThreadProgress(thread, self.translate('installing'), '')

0 commit comments

Comments
 (0)