Skip to content

Commit

Permalink
wrap up
Browse files Browse the repository at this point in the history
  • Loading branch information
elbenfreund committed Jul 8, 2017
1 parent a33d210 commit a804ebe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
19 changes: 19 additions & 0 deletions hamster_gtk/hamster_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def _reload_config(self):
"""Reload configuration from designated store."""
config = self._get_config_from_file()
self._config = config
self.config = config
return config

def _config_changed(self, sender):
Expand All @@ -284,6 +285,8 @@ def _get_default_config(self):
# Frontend
'autocomplete_activities_range': 30,
'autocomplete_split_activity': False,
'tracking_show_recent_activities': True,
'tracking_recent_activities_items': 6,
}

def _config_to_configparser(self, config):
Expand Down Expand Up @@ -320,6 +323,12 @@ def get_autocomplete_activities_range():
def get_autocomplete_split_activity():
return text_type(config['autocomplete_split_activity'])

def get_tracking_show_recent_activities():
return text_type(config['tracking_show_recent_activities'])

def get_tracking_recent_activities_items():
return text_type(config['tracking_recent_activities_items'])

cp_instance = SafeConfigParser()
cp_instance.add_section('Backend')
cp_instance.set('Backend', 'store', get_store())
Expand All @@ -336,6 +345,8 @@ def get_autocomplete_split_activity():
get_autocomplete_split_activity())
cp_instance.set('Frontend', 'tracking_show_recent_activities',
get_tracking_show_recent_activities())
cp_instance.set('Frontend', 'tracking_recent_activities_items',
get_tracking_recent_activities_items())

return cp_instance

Expand Down Expand Up @@ -392,13 +403,21 @@ def get_autocomplete_activities_range():
def get_autocomplete_split_activity():
return cp_instance.getboolean('Frontend', 'autocomplete_split_activity')

def get_tracking_show_recent_activities():
return cp_instance.getboolean('Frontend', 'tracking_show_recent_activities')

def get_tracking_recent_activities_items():
return int(cp_instance.get('Frontend', 'tracking_recent_activities_items'))

result = {
'store': get_store(),
'day_start': get_day_start(),
'fact_min_delta': get_fact_min_delta(),
'tmpfile_path': get_tmpfile_path(),
'autocomplete_activities_range': get_autocomplete_activities_range(),
'autocomplete_split_activity': get_autocomplete_split_activity(),
'tracking_show_recent_activities': get_tracking_recent_activities_items(),
'tracking_recent_activities_items': get_tracking_recent_activities_items(),
}
result.update(get_db_config())
return result
Expand Down
2 changes: 2 additions & 0 deletions hamster_gtk/preferences/preferences_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def __init__(self, parent, app, initial, *args, **kwargs):
('tracking_show_recent_activities',
(_("Allow tracking based on recent activities."),
HamsterSwitch())),
('tracking_recent_activities_items', (_('How many recent activities?'),
HamsterSpinButton(SimpleAdjustment(0, GObject.G_MAXDOUBLE, 1)))),
]))),
]

Expand Down
18 changes: 7 additions & 11 deletions hamster_gtk/tracking/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import datetime
from gettext import gettext as _

from gi.repository import GObject, Gtk, Gdk
from gi.repository import GObject, Gtk
from hamster_lib import Fact

import hamster_gtk.helpers as helpers
Expand Down Expand Up @@ -254,7 +254,7 @@ def _get_recent_activities_widget(self):
# We fetch an arbitrary Button as height-reference
child = grid.get_children()[1]
height = child.get_preferred_height()[1]
min_height = 6 * height
min_height = self._app.config['tracking_recent_activities_items'] * height

scrolled_window.set_min_content_height(min_height)
scrolled_window.add(grid)
Expand All @@ -271,20 +271,17 @@ def _on_raw_fact_entry_activate(self, evt):

def _on_config_changed(self, sender):
"""Callback triggered when 'config-changed' event fired."""
print('CALLBACK TRIGGERD')
print(self._app.config)
if self._app.config['tracking_show_recent_activities']:
# We re-create it even if one existed before necause its parameters
# (e.g. size) may have changed.
if self.recent_activities_widget:
pass
else:
self.recent_activities_widget = self._get_recent_activities_widget()
self.pack_start(self.recent_activities_widget, True, True, 0)
self.recent_activities_widget.destroy()
self.recent_activities_widget = self._get_recent_activities_widget()
self.pack_start(self.recent_activities_widget, True, True, 0)
else:
if self.recent_activities_widget:
self.recent_activities_widget.destroy()
self.recent_activities_widget = None
else:
pass
self.show_all()


Expand Down Expand Up @@ -360,7 +357,6 @@ def get_start_button(activity):
add_row_widgets(row_counter, activity)
row_counter += 1


def _on_copy_button(self, button, activity):
"""
Set the activity/category text in the 'start tracking entry'.
Expand Down

0 comments on commit a804ebe

Please sign in to comment.