Skip to content

Commit

Permalink
Merge pull request thinkle#1013 from kirienko/upstream_pr
Browse files Browse the repository at this point in the history
Add further Gtk3 port fixes
  • Loading branch information
thinkle authored Oct 28, 2020
2 parents 10ba31a + c33089b commit 8af29c8
Show file tree
Hide file tree
Showing 41 changed files with 433 additions and 560 deletions.
25 changes: 18 additions & 7 deletions .flatpak/io.github.thinkle.Gourmet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,43 @@ finish-args:
- --socket=pulseaudio
- --share=network
modules:
- name: poppler
buildsystem: cmake-ninja
config-opts:
- -DENABLE_UTILS=OFF
- -DENABLE_CPP=OFF
- -DENABLE_QT5=OFF
sources:
- url: https://poppler.freedesktop.org/poppler-20.10.0.tar.xz
sha256: 434ecbbb539c1a75955030a1c9b24c7b58200b7f68d2e4269e29acf2f8f13336
type: archive

- name: cpython
sources:
- type: archive
url: https://www.python.org/ftp/python/3.8.4/Python-3.8.4.tar.xz
sha256: 5f41968a95afe9bc12192d7e6861aab31e80a46c46fa59d3d837def6a4cd4d37
url: https://www.python.org/ftp/python/3.8.4/Python-3.8.4.tar.xz
sha256: 5f41968a95afe9bc12192d7e6861aab31e80a46c46fa59d3d837def6a4cd4d37

- name: intltool
buildsystem: autotools
sources:
- type: archive
url: https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz
sha256: 67c74d94196b153b774ab9f89b2fa6c6ba79352407037c8c14d5aeb334e959cd
url: https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz
sha256: 67c74d94196b153b774ab9f89b2fa6c6ba79352407037c8c14d5aeb334e959cd

- name: gourmet
buildsystem: simple
build-options:
build-args:
- --share=network
build-commands:
- pip3 install pyenchant pygobject
- python3 -m pip install --upgrade pip
- pip3 install pyenchant pygobject Sphinx
- pip3 install -r requirements.txt
- python3 setup.py build_i18n
- python3 setup.py install --prefix=/app
- install -Dm644 .flatpak/io.github.thinkle.Gourmet.desktop -t /app/share/applications/
- install -Dm644 .flatpak/io.github.thinkle.Gourmet.svg -t /app/share/icons/hicolor/scalable/apps/

sources:
- type: git
url: https://github.com/thinkle/gourmet
url: https://github.com/thinkle/gourmet
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
sudo apt-get update -q && sudo apt-get install
--no-install-recommends -y xvfb python3-dev python3-gi
python3-gi-cairo gir1.2-gtk-3.0 libgirepository1.0-dev libcairo2-dev
intltool enchant python3-enchant
intltool enchant python3-enchant python3-gst-1.0
- name: Install dependencies
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
--no-install-recommends -y xvfb python3-dev python3-gi
python3-gi-cairo gir1.2-gtk-3.0 libgirepository1.0-dev
gir1.2-poppler-0.18 libcairo2-dev enchant python3-enchant intltool
python3-gst-1.0
- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Before you start development, you should first build localized *.mo and
*.gourmet-plugin files within a build/ subdirectory of the source tree by
running

python3 setup.py build_i18n -m
python3 setup.py build_i18n

You can then install Gourmet in edit mode so:

Expand Down
10 changes: 5 additions & 5 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Installation
Gourmet is currently available in the form of Flatpak and Python wheel.
We recommend that you install it from the Flatpak.
Gourmet is currently available in the form of Flatpak and Python wheel.
We recommend that you install it from the Flatpak.
In both cases, you will need an internet connection.

**We strongly recommend that you make a backup of your recipe database.**
**We strongly recommend that you make a backup of your recipe database.**
As Gourmet is still in early stage of (re)development, make a backup of your
recipe database, typically found under `$HOME/.gourmet/recipe.db`:
```sh
Expand All @@ -22,7 +22,7 @@ sudo apt-get install flatpak
As Gourmet is still under active development, the flatpak is not available from
Flathub, and instead must be [downloaded and installed manually](https://github.com/kirienko/gourmet/releases/tag/v1-alpha2).

In a terminal, execute the following:
In a terminal, execute the following:
```sh
flatpak remote-add --if-not-exists --user flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak install gourmet-2db9db8f.flatpak
Expand Down Expand Up @@ -61,7 +61,7 @@ Install the following packages from `apt`:
```sh
sudo apt-get update

sudo apt-get install --no-install-recommends python3-argcomplete python3-gi python3-gi-cairo gir1.2-gtk-3.0 libgirepository1.0-dev libcairo2-dev enchant python3-bs4 python3-ebooklib python3-keyring python3-lxml python3-pil python3-cairo python3-enchant python3-gi python3-gtkspellcheck python3-requests python3-reportlab python3-selenium python3-setuptools python3-sqlalchemy python3-pip python3-toml gir1.2-poppler-0.18 ```
sudo apt-get install --no-install-recommends python3-argcomplete python3-gi python3-gi-cairo gir1.2-gtk-3.0 libgirepository1.0-dev libcairo2-dev enchant python3-bs4 python3-ebooklib python3-keyring python3-lxml python3-pil python3-cairo python3-enchant python3-gi python3-gst-1.0 python3-gtkspellcheck python3-requests python3-reportlab python3-selenium python3-setuptools python3-sqlalchemy python3-pip python3-toml gir1.2-poppler-0.18 ```
Then, install dependencies from the Python repository:
```sh
Expand Down
6 changes: 4 additions & 2 deletions gourmet/GourmetRecipeManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ def shop_recs (self, *args):
parent=self.app.get_toplevel(),
digits=2)
if not mult:
mult = float(1)
debug('getNumber cancelled', 2)
return
d=self.sl.getOptionalIngDic(self.rd.get_ings(r),mult,self.prefs)
self.sl.addRec(r,mult,d)
self.sl.show()
Expand Down Expand Up @@ -1029,7 +1030,8 @@ def setup_actions (self):
#None,None,self.email_recs),
('BatchEdit',None,_('Batch _edit recipes'),
'<Control><Shift>E',None,self.batch_edit_recs),
('ShopRec','add-to-shopping-list',None,None,None,self.shop_recs)
('ShopRec', 'add-to-shopping-list', _('Add to Shopping List'),
'<Control>B', None, self.shop_recs)
])

self.mainActionGroup = Gtk.ActionGroup(name='MainActions')
Expand Down
1 change: 1 addition & 0 deletions gourmet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from gi import require_version
require_version("Gdk", "3.0")
require_version("Gst", "1.0")
require_version("Gtk", "3.0")
require_version("Pango", "1.0")
6 changes: 3 additions & 3 deletions gourmet/backends/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

from gourmet.gdebug import debug, TimeAction
import gourmet.gglobals as gglobals
from gourmet import Undo, keymanager, convert
from gourmet import Undo, convert, image_utils
from gourmet.defaults import lang as defaults
from gourmet import image_utils
from gourmet.keymanager import KeyManager
import gourmet.version
import gourmet.recipeIdentifier as recipeIdentifier
from gourmet.plugin_loader import Pluggable, pluggable_method
Expand Down Expand Up @@ -1877,7 +1877,7 @@ def instance_for(
def __init__ (self, *args, **kwargs):
debug('recipeManager.__init__()',3)
self.rd = get_database(*args, **kwargs)
self.km = keymanager.get_keymanager(rm=self)
self.km = KeyManager.instance(recipe_manager=self)

def __getattr__(self, name):
# RecipeManager was previously a subclass of RecData.
Expand Down
Binary file added gourmet/data/images/blue_star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gourmet/data/images/half_blue_star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions gourmet/exporters/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,7 @@ def append_referenced_recipes (self):
)
for ref in reffed:
rec = self.rd.get_rec(ref.refid)
if not rec in self.recipes:
print('Appending recipe ',rec.title,'referenced in ',r.title)
if rec is not None and not rec in self.recipes:
self.recipes.append(rec)

@pluggable_method
Expand Down
119 changes: 72 additions & 47 deletions gourmet/gglobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import os.path
from pathlib import Path

from gi.repository import Gdk, GdkPixbuf, GObject, Gtk
from gettext import gettext as _
from gi.repository import Gdk, GdkPixbuf, Gtk

import tempfile
from .optionparser import args
from . import settings

tmpdir = tempfile.gettempdir()
uibase = os.path.join(settings.ui_base)
lib_dir = os.path.join(settings.lib_dir)

gourmetdir: Path = Path(os.environ['HOME']).absolute() / '.gourmet'
if os.name == 'nt':
Expand All @@ -21,62 +23,57 @@

use_threads = args.threads
# Uncomment the below to test FauxThreads
#use_threads = False
# use_threads = False

# note: this stuff must be kept in sync with changes in setup.py
from . import settings
uibase = os.path.join(settings.ui_base)
lib_dir = os.path.join(settings.lib_dir)
from gettext import gettext as _

data_dir = settings.data_dir
imagedir = os.path.join(settings.data_dir,'images')
style_dir = os.path.join(settings.data_dir,'style')
imagedir = os.path.join(settings.data_dir, 'images')
style_dir = os.path.join(settings.data_dir, 'style')

icondir = os.path.join(settings.icon_base,"48x48","apps")
icondir = os.path.join(settings.icon_base, '48x48', 'apps')
doc_base = settings.doc_base
plugin_base = settings.plugin_base

# GRAB PLUGIN DIR FOR HTML IMPORT
if args.html_plugin_dir:
html_plugin_dir = args.html_plugin_dir
else:
html_plugin_dir = os.path.join(gourmetdir,'html_plugins')
html_plugin_dir = os.path.join(gourmetdir, 'html_plugins')
if not os.path.exists(html_plugin_dir):
os.makedirs(html_plugin_dir)
template_file = os.path.join(settings.data_dir,'RULES_TEMPLATE')
template_file = os.path.join(settings.data_dir, 'RULES_TEMPLATE')
if os.path.exists(template_file):
import shutil
shutil.copy(template_file,
os.path.join(html_plugin_dir,'RULES_TEMPLATE')
os.path.join(html_plugin_dir, 'RULES_TEMPLATE')
)

REC_ATTRS = [('title',_('Title'),'Entry'),
('category',_('Category'),'Combo'),
('cuisine',_('Cuisine'),'Combo'),
('rating',_('Rating'),'Entry'),
('source',_('Source'),'Combo'),
('link',_('Website'),'Entry'),
('yields',_('Yield'),'Entry'),
('yield_unit',_('Yield Unit'),'Combo'),
('preptime',_('Preparation Time'),'Entry'),
('cooktime',_('Cooking Time'),'Entry'),
REC_ATTRS = [('title', _('Title'), 'Entry'),
('category', _('Category'), 'Combo'),
('cuisine', _('Cuisine'), 'Combo'),
('rating', _('Rating'), 'Entry'),
('source', _('Source'), 'Combo'),
('link', _('Website'), 'Entry'),
('yields', _('Yield'), 'Entry'),
('yield_unit', _('Yield Unit'), 'Combo'),
('preptime', _('Preparation Time'), 'Entry'),
('cooktime', _('Cooking Time'), 'Entry'),
]

INT_REC_ATTRS = ['rating','preptime','cooktime']
INT_REC_ATTRS = ['rating', 'preptime', 'cooktime']
FLOAT_REC_ATTRS = ['yields']
TEXT_ATTR_DIC = {'instructions':_('Instructions'),
'modifications':_('Notes'),
TEXT_ATTR_DIC = {'instructions': _('Instructions'),
'modifications': _('Notes'),
}

REC_ATTR_DIC={}
NAME_TO_ATTR = {_('Instructions'):'instructions',
_('Notes'):'modifications',
_('Modifications'):'modifications',
REC_ATTR_DIC = {}
NAME_TO_ATTR = {_('Instructions'): 'instructions',
_('Notes'): 'modifications',
_('Modifications'): 'modifications',
}

DEFAULT_ATTR_ORDER = ['title',
#'servings',
# 'servings',
'yields',
'cooktime',
'preptime',
Expand All @@ -88,26 +85,29 @@
]

DEFAULT_TEXT_ATTR_ORDER = ['instructions',
'modifications',]
'modifications',
]


def build_rec_attr_dic ():
def build_rec_attr_dic():
for attr, name, widget in REC_ATTRS:
REC_ATTR_DIC[attr]=name
NAME_TO_ATTR[name]=attr
REC_ATTR_DIC[attr] = name
NAME_TO_ATTR[name] = attr


build_rec_attr_dic()

DEFAULT_HIDDEN_COLUMNS = [REC_ATTR_DIC[attr] for attr in
['link','yields','yield_unit','preptime','cooktime']
]
('link', 'yields', 'yield_unit', 'preptime', 'cooktime')] # noqa

# Set up custom STOCK items and ICONS!
icon_factory = Gtk.IconFactory()

def add_icon (file_name, stock_id, label=None, modifier=0, keyval=0):

def add_icon(file_name, stock_id, label=None, modifier=0, keyval=0):
pb = GdkPixbuf.Pixbuf.new_from_file(file_name)
iconset = Gtk.IconSet.new_from_pixbuf(pb)
icon_factory.add(stock_id,iconset)
icon_factory.add(stock_id, iconset)
icon_factory.add_default()
# TODO: fix adding icons
return
Expand All @@ -117,9 +117,34 @@ def add_icon (file_name, stock_id, label=None, modifier=0, keyval=0):
keyval,
"")])

for filename,stock_id,label,modifier,keyval in [
('AddToShoppingList.png','add-to-shopping-list',_('Add to _Shopping List'),Gdk.ModifierType.CONTROL_MASK,Gdk.keyval_from_name('l')),
('reccard.png','recipe-card',None,0,0),
('reccard_edit.png','edit-recipe-card',None,0,0),
]:
add_icon(os.path.join(imagedir,filename),stock_id,label,modifier,keyval)

for filename, stock_id, label, modifier, keyval in [
('AddToShoppingList.png',
'add-to-shopping-list',
_('Add to _Shopping List'),
Gdk.ModifierType.CONTROL_MASK,
Gdk.keyval_from_name('l')),

('reccard.png', 'recipe-card', None, 0, 0),

('reccard_edit.png', 'edit-recipe-card', None, 0, 0),
]:
add_icon(os.path.join(imagedir, filename), stock_id,
label, modifier, keyval)


# Color scheme preference
LINK_COLOR = 'blue'
star_color = 'blue'

style = Gtk.StyleContext.new()
_, bg_color = style.lookup_color('bg_color')
_, fg_color = style.lookup_color('fg_color')

if sum(fg_color) > sum(bg_color): # background is darker
LINK_COLOR = 'deeppink'
star_color = 'gold'

NO_STAR = Path(__file__).parent / 'data' / 'images' / 'no_star.png'
HALF_STAR = Path(__file__).parent / 'data' / 'images' / f'half_{star_color}_star.png' # noqa
FULL_STAR = Path(__file__).parent / 'data' / 'images' / f'{star_color}_star.png' # noqa
5 changes: 3 additions & 2 deletions gourmet/gtk_extras/LinkedTextView.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
import re
from typing import Optional
from gi.repository import Gdk, GObject, Gtk, Pango
from gourmet.gglobals import LINK_COLOR
from gourmet.gtk_extras.pango_buffer import PangoBuffer
from gourmet.gtk_extras.pango_html import PangoToHtml


class LinkedPangoBuffer(PangoBuffer):

href_regexp = re.compile(r"<a href=['\"]([^'\"]+)['\"][^>]*>(.*?)</a>")
url_markup = 'underline="single" color="blue"'
url_markup = f'underline="single" color="{LINK_COLOR}"'
url_props = [('underline', Pango.Underline.SINGLE),
('foreground-gdk', Gdk.color_parse('blue'))]
('foreground-gdk', LINK_COLOR)]
markup_dict = {}

def set_text(self, txt: str) -> None:
Expand Down
3 changes: 2 additions & 1 deletion gourmet/gtk_extras/cb_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def focus_out_cb (self, widget, event):
parent = widget.get_parent()
while parent and not isinstance(parent,Gtk.Window) :
parent = parent.get_parent()
for n in range(2): parent.emit('move-focus',Gtk.DIRECTION_LEFT)
for n in range(2):
parent.emit('move-focus',Gtk.DirectionType.RIGHT)
#parent.emit('move-focus',Gtk.DIRECTION_LEFT)

def keypress_event_cb (self, w, event):
Expand Down
4 changes: 2 additions & 2 deletions gourmet/gtk_extras/dialog_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from . import optionTable
from gourmet.gdebug import debug
from gourmet.image_utils import make_thumbnail
from gourmet.image_utils import image_to_pixbuf, make_thumbnail

H_PADDING=12
Y_PADDING=12
Expand Down Expand Up @@ -1126,7 +1126,7 @@ def update_preview (self, *args):
thumbnail = make_thumbnail(uri)

if thumbnail is not None:
self.preview.set_from_pixbuf(thumbnail)
self.preview.set_from_pixbuf(image_to_pixbuf(thumbnail))
self.preview.show()
else:
self.preview.hide()
Expand Down
Loading

0 comments on commit 8af29c8

Please sign in to comment.