Browse Source

Merge origin/dev

remotes/github/refactor
octogene 6 years ago
parent
commit
a4e357d60f
  1. 31
      hadaly/app.py
  2. 4
      hadaly/editor.kv
  3. 4
      hadaly/editor.py
  4. 2
      hadaly/search.kv
  5. 11
      hadaly/search.py
  6. 10
      hadaly/viewer.py

31
hadaly/app.py

@ -4,19 +4,18 @@ import shutil
from kivy import require
require('1.9.0')
require('1.9.1')
import os, json
from sys import argv
from .meta import version as app_version
import urllib
from urllib.parse import urlencode
import re
try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse
from urllib.parse import urlparse
from urllib.parse import quote
from lxml import html
import tempfile
@ -29,7 +28,7 @@ Config.set('graphics', 'fullscreen', 'auto')
from kivy.app import App
from kivy.core.window import Window
from kivy.properties import StringProperty, ListProperty, DictProperty, NumericProperty
from kivy.properties import StringProperty, ListProperty, DictProperty
from kivy.uix.screenmanager import ScreenManager, FadeTransition
from kivy.uix.popup import Popup
from kivy.uix.label import Label
@ -79,7 +78,7 @@ class HadalyApp(App):
config.set('editor', 'autosave_time', '15')
config.set('editor', 'autosave', '0')
config.set('editor', 'font_size', '12')
config.set('editor', 'last_dir', None)
config.set('editor', 'last_dir', os.path.expanduser('~'))
config.set('editor', 'cols', '6')
config.set('viewer', 'thumb', '1')
config.set('viewer', 'thumb_pos', 'bottom left')
@ -233,7 +232,7 @@ class HadalyApp(App):
self.filename = filename
self.dirname = path
tar = tarfile.open(os.path.join(path, filename), 'w')
tar = tarfile.open(os.path.join(path, filename), 'a')
# Add image file to *.opah file
try:
@ -292,8 +291,6 @@ class HadalyApp(App):
pos = self.root.current_screen.carousel.current_slide.viewer.pos
self.root.current_screen.carousel.current_slide.viewer.pos = (pos[0] * 2, pos[1])
def compare_slide(self, index=None, action='add'):
"""Add new SlideBox to ViewerScreen based on SlideButton index.
@ -375,7 +372,7 @@ class HadalyApp(App):
api_key = '624d3a7086d14e85f1422430f0b889a1'
base_url = 'https://api.flickr.com/services/rest/?'
method = 'flickr.photos.search'
params = urllib.urlencode([('method', method),
params = urlencode([('method', method),
('text', term),
('api_key', api_key),
('format', 'json'),
@ -388,7 +385,7 @@ class HadalyApp(App):
return result
def request(self, url):
url = urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
url = quote(url, safe="%/:=&?~#+!$,;'@()*[]")
req = UrlRequest(url, debug=True)
req.wait()
return req.result
@ -397,7 +394,7 @@ class HadalyApp(App):
pb = ProgressBar(id='_pb')
self.progress_dialog = Popup(title=_('Downloading...'),
size_hint=(0.5, 0.2), content=pb, auto_dismiss=False)
url = urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
url = quote(url, safe="%/:=&?~#+!$,;'@()*[]")
path = os.path.join(self.tempdir,
os.path.basename(urlparse(url).path))
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"}
@ -465,7 +462,7 @@ class HadalyApp(App):
url = engines[engine].format(term=term,
rpp=self.config.get('search', 'search_rpp'),
page=page)
clean_url = urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
clean_url = quote(url, safe="%/:=&?~#+!$,;'@()*[]")
UrlRequest(clean_url, on_success=self.parse_results, debug=True)
@ -495,7 +492,7 @@ class HadalyApp(App):
object.xpath('./div[@class="list-view-object-info"]/div[@class="artist"]/text()')[::2][0]
except IndexError:
result['artist'] = 'Unknown'
result['thumb'] = urllib.quote(object.xpath('./div[@class="list-view-thumbnail"]//img/@src')[0],
result['thumb'] = quote(object.xpath('./div[@class="list-view-thumbnail"]//img/@src')[0],
safe="%/:=&?~#+!$,;'@()*[]")
object_info = object.xpath('./div[@class="list-view-object-info"]/div[@class="objectinfo"]/text()')
result['year'] = object_info[0].strip('Dates: ')
@ -521,7 +518,7 @@ class HadalyApp(App):
obj_link = tree.xpath(
'//div[@class="cs-result-data-brief"]//td[* = "Title:" or * = "Primary Title:"]/following-sibling::td[1]/p[@class="cs-record-link"]/a/@href')
results = [{'title': a, 'artist': b, 'year': c, 'thumb': urllib.quote(d, safe="%/:=&?~#+!$,;'@()*[]"),
results = [{'title': a, 'artist': b, 'year': c, 'thumb': quote(d, safe="%/:=&?~#+!$,;'@()*[]"),
'obj_link': e}
for a, b, c, d, e in zip(titles, artists, dates, thumb, obj_link)]

4
hadaly/editor.kv

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#:kivy 1.9.0
#:import win kivy.core.window
#:import expanduser os.path.expanduser
<EditorScreen@Screen>:
slides_view: _slides_view
@ -109,7 +110,7 @@
text: u'\uf05a'
text_size: self.size
font_name: 'data/fonts/fontawesome-webfont.ttf'
font_size: ''.join((unicode(int(root.width / 8)), 'sp'))
font_size: ''.join((str(int(root.width / 8)), 'sp'))
halign: 'center'
valign: 'middle'
background_color: [1, 1, 1, 0]
@ -264,6 +265,7 @@
id: filechooser
on_selection: text_input.text = self.selection and self.selection[0] or ''
filters: ['*.opah']
path: expanduser('~')
TextInput:
id: text_input
text: '*.opah'

4
hadaly/editor.py

@ -63,7 +63,7 @@ class Slide(BoxLayout):
self.info_panel = True
info_panel = Factory.SlideInfo(id='info_panel')
info_panel.font = ''.join((unicode(int(self.parent.height / 14)), 'sp'))
info_panel.font = ''.join((str(int(self.parent.height / 14)), 'sp'))
info_panel.artist.text = self.artist
info_panel.title.text = self.title
info_panel.year.text = self.year
@ -72,7 +72,7 @@ class Slide(BoxLayout):
def on_size(self, *args):
try:
info_panel = [child for child in self.children if child.id == 'info_panel'][0]
info_panel.font = ''.join((unicode(int(self.parent.height / 14)), 'sp'))
info_panel.font = ''.join((str(int(self.parent.height / 14)), 'sp'))
except IndexError:
Logger.debug('Editor: No child with "info_panel" id found.')

2
hadaly/search.kv

@ -53,7 +53,7 @@
TextInput:
id: _term
on_text_validate: root.search(self.text, root.action_bar.search_view.action_group.text)
font_size: ''.join((unicode(int(self.parent.height / 2)), 'sp'))
font_size: ''.join((str(int(self.parent.height / 2)), 'sp'))
multiline: False
GridLayout:
id: _grid

11
hadaly/search.py

@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import division, unicode_literals, absolute_import
try:
from urlparse import urlparse, parse_qs
except ImportError:
from urllib.parse import urlparse, parse_qs
import urllib
from urllib.parse import urlparse, parse_qs
from urllib.request import urlopen
from lxml import html
@ -112,7 +109,7 @@ class SearchItemInfo(Popup):
if self.provider == 'MET':
# Check if high-res is available.
url = self.photo['thumb'].replace('web-thumb', 'original')
req = urllib.urlopen(url)
req = urlopen(url)
if req.getcode() == 404:
Logger.debug('Search: High-res image not available.')
self.app.show_popup(_('Error'), _('High-res image not available, downloading inferior quality.'))
@ -124,7 +121,7 @@ class SearchItemInfo(Popup):
elif self.provider == 'Getty':
req = urllib.urlopen(self.photo['obj_link'])
req = urlopen(self.photo['obj_link'])
tree = html.parse(req)
img_link = tree.xpath('//div[@class="cs-result-image"]//span[@class="nav"]/a/@href')
if img_link:

10
hadaly/viewer.py

@ -25,7 +25,7 @@ class ViewerScreen(Screen):
app = ObjectProperty(None)
dialog = ObjectProperty(None)
def on_enter(self, *args):
def on_pre_enter(self, *args):
if not self.dialog:
self.dialog = Factory.SlidesDialog()
try:
@ -115,7 +115,7 @@ class SlideBox(BoxLayout, StencilView):
except IndexError:
Logger.debug('Viewer: No img_zoom to resize.')
self.gui_layout.slide_info.font = ''.join((unicode(int(self.height / 35)), 'sp'))
self.gui_layout.slide_info.font = ''.join((str(int(self.height / 35)), 'sp'))
def get_caption(self):
@ -197,7 +197,8 @@ class SlideViewer(ScatterLayout):
self.slidebox.toolbar.add_widget(PainterToolBar(painter=self.painter,
paint_color=self.painter.tools[self.painter.current_tool][
'color']))
self.app.root.get_screen('viewer').carousel.scroll_timeout = 50
self.app.root.get_screen('viewer').carousel.scroll_timeout = 20
self.app.root.get_screen('viewer').carousel.scroll_distance = '50dp'
elif self.locked:
Logger.info('Viewer: Unlocking Slide.')
self.locked = False
@ -206,6 +207,7 @@ class SlideViewer(ScatterLayout):
self.do_rotation = True
self.slidebox.toolbar.remove_widget(self.slidebox.toolbar.children[0])
self.app.root.get_screen('viewer').carousel.scroll_timeout = 200
self.app.root.get_screen('viewer').carousel.scroll_distance = '20dp'
def on_locked(self, *args):
self.slidebox.toolbar.lock_btn.text = {u'\uf13e': u'\uf023', u'\uf023': u'\uf13e'}[
@ -252,7 +254,7 @@ class SlideButton(ButtonBehavior, Image):
def on_release(self):
if self.parent.dialog.to_switch:
current_index = self.parent.children.index(self)
carousel_index = list(reversed(xrange(len(self.parent.children))))
carousel_index = list(reversed(range(len(self.parent.children))))
self.app.switch_slide(carousel_index[current_index])
else:
self.app.compare_slide(self.parent.children.index(self))

Loading…
Cancel
Save