Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
When Paperwork has been freshly launched, display "Paperwork"+version…
Browse files Browse the repository at this point in the history
… below the Paperwork's logo

Signed-off-by: Jerome Flesch <jflesch@gmail.com>
  • Loading branch information
jflesch committed Sep 22, 2016
1 parent 01ba3f9 commit e6b7137
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
# * update the ChangeLog file
# * change it also in
# src/paperwork/frontend/aboutdialog/aboutdialog.glade
# * change it also in
# src/paperwork/frontend/mainwindow/__init__.py:__version__
# * update the archive list in the README
# * update the dependency version on paperwork-backend
version="0.4",
version="1.0",
description=(
"Using scanner and OCR to grep dead trees the easy way (Linux only)"
),
Expand Down
2 changes: 1 addition & 1 deletion src/paperwork/frontend/aboutdialog/aboutdialog.glade
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="program_name">Paperwork</property>
<property name="version">0.4-git</property>
<property name="version">1.0-git</property>
<property name="copyright" translatable="yes">
</property>
<property name="comments" translatable="yes">Grep for Dead Trees</property>
Expand Down
19 changes: 18 additions & 1 deletion src/paperwork/frontend/mainwindow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from paperwork.frontend.util.canvas.animations import SpinnerAnimation
from paperwork.frontend.util.canvas.drawers import PillowImageDrawer
from paperwork.frontend.util.canvas.drawers import ProgressBarDrawer
from paperwork.frontend.util.canvas.drawers import TextDrawer
from paperwork.frontend.util.jobs import Job
from paperwork.frontend.util.jobs import JobFactory
from paperwork.frontend.util.jobs import JobScheduler
Expand All @@ -70,6 +71,9 @@
logger = logging.getLogger(__name__)


__version__ = '1.0-git'


def check_scanner(main_win, config):
if config['scanner_devid'].value is not None:
return True
Expand Down Expand Up @@ -2374,18 +2378,31 @@ def __init_window(self, widget_tree, config):
return window

def __init_canvas(self):
canvas_size = self.img['canvas'].visible_size
try:
canvas_size = self.img['canvas'].visible_size
logo = load_image("paperwork_100.png")
logo_size = logo.size
logo_drawer = PillowImageDrawer((
canvas_size[0] / 2 - (logo_size[0] / 2),
canvas_size[1] / 2 - (logo_size[1] / 2)
), logo)
logo_drawer.layer = logo_drawer.BACKGROUND_LAYER
self.img['canvas'].add_drawer(logo_drawer)
except Exception as exc:
logger.warning("Failed to display logo: {}".format(exc))

if __version__ != "1.0":
txt = "Paperwork {}".format(__version__)
else:
# "Paperwork 1.0" looks ugly... :p
txt = "Paperwork"
txt_drawer = TextDrawer((
int(canvas_size[0] / 2),
int((canvas_size[1] / 2) + (logo_size[1] / 2) + 12),
), txt, height=24)
self.img['canvas'].add_drawer(txt_drawer)


def set_search_availability(self, enabled):
set_widget_state(self.doc_browsing.values(), enabled)

Expand Down
8 changes: 5 additions & 3 deletions src/paperwork/frontend/mainwindow/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,13 @@ def draw_box_txt(self, cairo_context, box):
if 0 in txt_size:
return
txt_factor = min(
float(w) * Pango.SCALE / txt_size[0],
float(h) * Pango.SCALE / txt_size[1],
float(w) / txt_size[0],
float(h) / txt_size[1],
)

cairo_context.scale(txt_factor, txt_factor)
cairo_context.scale(
txt_factor * Pango.SCALE, txt_factor * Pango.SCALE
)

PangoCairo.update_layout(cairo_context, layout)
PangoCairo.show_layout(cairo_context, layout)
Expand Down
47 changes: 47 additions & 0 deletions src/paperwork/frontend/util/canvas/drawers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import math
import logging

from gi.repository import Pango
from gi.repository import PangoCairo

from paperwork_backend.util import image2surface


Expand Down Expand Up @@ -436,6 +439,50 @@ def do_draw(self, cairo_ctx):
self.size, self.angle)


class TextDrawer(Drawer):
"""
Centered text
"""
layer = Drawer.IMG_LAYER
visible = True

def __init__(self, position, text, height=12):
Drawer.__init__(self)
self.size = (10, 10) # will be updated later when text will be rendered
self.center_position = position
# In this case, it's actually the center of the text.
# Will be updated later to be the top-left
self.position = position
self.angle = 0
self.text = text
self.height = height

def do_draw(self, cairo_ctx):
cairo_ctx.save()
try:
layout = PangoCairo.create_layout(cairo_ctx)
layout.set_text(self.text, -1)
txt_size = layout.get_size()
if 0 in txt_size:
return
txt_factor = float(self.height) / txt_size[1]
self.size = (
int(txt_size[0] * txt_factor),
int(txt_size[1] * txt_factor)
)
self.position = (
int(self.center_position[0] - (self.size[0] / 2)),
int(self.center_position[1] - (self.size[1] / 2))
)
cairo_ctx.translate(self.position[0], self.position[1])
cairo_ctx.scale(txt_factor * Pango.SCALE, txt_factor * Pango.SCALE)
cairo_ctx.set_source_rgb(0.0, 0.0, 0.0)
PangoCairo.update_layout(cairo_ctx, layout)
PangoCairo.show_layout(cairo_ctx, layout)
finally:
cairo_ctx.restore()


class TargetAreaDrawer(Drawer):
layer = Drawer.BOX_LAYER
visible = True
Expand Down

0 comments on commit e6b7137

Please sign in to comment.