Permalink
Browse files

cleanup of preferences

  • Loading branch information...
1 parent 66adab9 commit 78a569ed54d4e69375812ceccf2e79b8bc0a2c93 Pontus Ekberg committed Dec 30, 2007
Showing with 111 additions and 110 deletions.
  1. +4 −0 src/comix.py
  2. +3 −0 src/constants.py
  3. +8 −9 src/event.py
  4. +2 −2 src/filehandler.py
  5. +40 −42 src/main.py
  6. +54 −57 src/preferences.py
View
@@ -33,6 +33,8 @@
import gettext
import main
+import icons
+import preferences
# ------------------------------------------------------------------------
# Check for PyGTK and PIL dependencies.
@@ -86,6 +88,8 @@
gettext.install('comix', os.path.join(base_dir, '/share/locale'),
unicode=True)
+ preferences.read_config_file()
+ icons.load()
window = main.MainWindow()
if len(sys.argv) >= 2:
window.file_handler.open_file(os.path.normpath(sys.argv[1]))
View
@@ -2,5 +2,8 @@
# constants.py - Miscellaneous constants for Comix.
# ============================================================================
+import os
+
VERSION = '4.0dev'
+COMIX_DIR = os.path.join(os.environ['HOME'], '.comix')
View
@@ -114,12 +114,9 @@ def key_press_event(self, widget, event, *args):
# If Shift is pressed we should backtrack instead.
# ----------------------------------------------------------------
elif event.keyval == gtk.keysyms.space:
- if prefs['space scroll type'] == 'window':
- x_step, y_step = self._window.get_layout_size()
- elif prefs['space scroll type'] == 'image':
- x_step, y_step = self._window.main_layout.get_size()
- x_step = x_step * prefs['space scroll length'] // 100
- y_step = y_step * prefs['space scroll length'] // 100
+ x_step, y_step = self._window.get_visible_area_size()
+ x_step = x_step * prefs['space scroll percent'] // 100
+ y_step = y_step * prefs['space scroll percent'] // 100
if 'GDK_SHIFT_MASK' in event.state.value_names:
next_page_function = self._window.previous_page
startfirst = 'endfirst'
@@ -133,7 +130,9 @@ def key_press_event(self, widget, event, *args):
x_step *= -1
# FIXME: Smart space in DP mode is not implemented
if prefs['smart space scroll']:
- if not self._window.is_double():
+ if self._window.displayed_double():
+ pass
+ else:
if not self._window.scroll(x_step, 0):
if not self._window.scroll(0, y_step):
next_page_function()
@@ -146,8 +145,8 @@ def key_press_event(self, widget, event, *args):
next_page_function()
# ----------------------------------------------------------------
- # We kill the signals here for the Up, Down, Space and Enter keys.
- # Otherwise they will start fiddling with the thumbnail selector.
+ # We kill the signals here for the Up, Down, Space and Enter keys,
+ # or they will start fiddling with the thumbnail selector (bad).
# ----------------------------------------------------------------
if (event.keyval in [gtk.keysyms.Up, gtk.keysyms.Down,
gtk.keysyms.space, gtk.keysyms.KP_Enter] or
View
@@ -138,7 +138,7 @@ def next_page(self):
old_image = self.current_page()
step = self._window.is_double_page and 2 or 1
if self.current_page() + step > self.number_of_pages():
- if prefs['go to next archive']:
+ if prefs['auto open next archive']:
#open_file(NEXT_ARCHIVE)
print 'open next archive'
return False
@@ -157,7 +157,7 @@ def previous_page(self):
if not self.file_loaded:
return False
if self.current_page() == 1:
- if prefs['go to next archive']:
+ if prefs['auto open next archive']:
#open_file(PREVIOUS_ARCHIVE)
print 'open previous archive'
return False
View
@@ -11,16 +11,14 @@
import encoding
import event
import filehandler
-import icons
import image
import pilpixbuf
+import preferences
from preferences import prefs
import ui
import status
import thumbbar
-icons.load()
-
class MainWindow(gtk.Window):
def __init__(self):
@@ -66,8 +64,6 @@ def __init__(self):
# Setup
# ----------------------------------------------------------------
self.set_title('Comix')
- if prefs['save window pos']:
- self.move(prefs['window x'], prefs['window y'])
self.set_size_request(300, 300) # Avoid making the window *too* small
self.resize(prefs['window width'], prefs['window height'])
@@ -84,7 +80,7 @@ def __init__(self):
self._main_layout.put(self._image_box, 0, 0)
self._main_layout.modify_bg(gtk.STATE_NORMAL,
gtk.gdk.colormap_get_system().alloc_color(gtk.gdk.Color(
- prefs['red bg'], prefs['green bg'], prefs['blue bg']), False, True))
+ *prefs['bg colour']), False, True))
self._vadjust.step_increment = 15
self._vadjust.page_increment = 1
@@ -180,7 +176,7 @@ def draw_image(self, at_bottom=False):
self.set_title('Comix')
return
- width, height = self._get_layout_size()
+ width, height = self.get_visible_area_size()
scale_width = self.zoom_mode == 'height' and -1 or width
scale_height = self.zoom_mode == 'width' and -1 or height
scale_up = prefs['stretch']
@@ -422,14 +418,15 @@ def scroll(self, x, y):
"""
Scrolls <x> px horizontally and <y> px vertically.
- Returns True if call resulted in new adjustment values, False otherwise.
+ Returns True if call resulted in new adjustment values, False
+ otherwise.
"""
old_hadjust = self._hadjust.get_value()
old_vadjust = self._vadjust.get_value()
- layout_width, layout_height = self._get_layout_size()
- hadjust_upper = self._hadjust.upper - layout_width
- vadjust_upper = self._vadjust.upper - layout_height
+ visible_width, visible_height = self.get_visible_area_size()
+ hadjust_upper = self._hadjust.upper - visible_width
+ vadjust_upper = self._vadjust.upper - visible_height
new_hadjust = old_hadjust + x
new_vadjust = old_vadjust + y
new_hadjust = max(0, new_hadjust)
@@ -462,9 +459,9 @@ def scroll_to_fixed(self, horiz=None, vert=None):
using manga mode or not.
"""
- layout_width, layout_height = self._get_layout_size()
- vadjust_upper = self._vadjust.upper - layout_height
- hadjust_upper = self._hadjust.upper - layout_width
+ visible_width, visible_height = self.get_visible_area_size()
+ vadjust_upper = self._vadjust.upper - visible_height
+ hadjust_upper = self._hadjust.upper - visible_width
if vert == 'top':
self._vadjust.set_value(0)
@@ -504,7 +501,7 @@ def scroll_to_fixed(self, horiz=None, vert=None):
elif horiz == 'endfirst':
if self.displayed_double():
self._hadjust.set_value(
- self._left_image.size_request()[0] - layout_width)
+ self._left_image.size_request()[0] - visible_width)
else:
self._hadjust.set_value(hadjust_upper)
elif horiz == 'startsecond':
@@ -518,6 +515,33 @@ def displayed_double(self):
return self.is_double_page and not self.file_handler.is_last_page()
+ def get_visible_area_size(self):
+
+ """
+ Returns a 2-tuple with the width and height of the visible part
+ of the main layout area.
+ """
+
+ width, height = self.get_size()
+ if not prefs['hide all'] and not (self.is_fullscreen and
+ prefs['hide all in fullscreen']):
+ if prefs['show toolbar']:
+ height -= self.toolbar.size_request()[1]
+ if prefs['show statusbar']:
+ height -= self.statusbar.size_request()[1]
+ if prefs['show thumbnails']:
+ width -= self.thumbnailsidebar.get_width()
+ if prefs['show menubar']:
+ height -= self.menubar.size_request()[1]
+ if prefs['show scrollbar'] and self.zoom_mode == 'width':
+ width -= self._vscroll.size_request()[0]
+ elif prefs['show scrollbar'] and self.zoom_mode == 'height':
+ height -= self._hscroll.size_request()[1]
+ elif prefs['show scrollbar'] and self.zoom_mode == 'manual':
+ width -= self._vscroll.size_request()[0]
+ height -= self._hscroll.size_request()[1]
+ return width, height
+
def _display_active_widgets(self):
"""
@@ -566,33 +590,6 @@ def _display_active_widgets(self):
self._vscroll.hide_all()
self._hscroll.hide_all()
- def _get_layout_size(self):
-
- """
- Returns a 2-tuple with the width and height of the visible part
- of the main layout area.
- """
-
- width, height = self.get_size()
- if not prefs['hide all'] and not (self.is_fullscreen and
- prefs['hide all in fullscreen']):
- if prefs['show toolbar']:
- height -= self.toolbar.size_request()[1]
- if prefs['show statusbar']:
- height -= self.statusbar.size_request()[1]
- if prefs['show thumbnails']:
- width -= self.thumbnailsidebar.get_width()
- if prefs['show menubar']:
- height -= self.menubar.size_request()[1]
- if prefs['show scrollbar'] and self.zoom_mode == 'width':
- width -= self._vscroll.size_request()[0]
- elif prefs['show scrollbar'] and self.zoom_mode == 'height':
- height -= self._hscroll.size_request()[1]
- elif prefs['show scrollbar'] and self.zoom_mode == 'manual':
- width -= self._vscroll.size_request()[0]
- height -= self._hscroll.size_request()[1]
- return width, height
-
def _set_title(self):
""" Sets the title acording to current state. """
@@ -618,5 +615,6 @@ def terminate_program(self, *args):
print 'Bye!'
gtk.main_quit()
self.file_handler.cleanup()
+ preferences.write_config_file()
sys.exit(0)
View
@@ -7,84 +7,81 @@
import gtk
+import constants
+
# ------------------------------------------------------------------------
# All the preferences are stored here.
# ------------------------------------------------------------------------
prefs = {
- 'auto comments': False,
- 'autocontrast': False,
- 'auto load last file': False,
- 'blue bg': 2100,
- 'brightness': 1.0,
+ #'auto comments': False,
+ #'comment extensions': 'txt nfo',
+ #'auto load last file': False,
+ #'page of last file': 0,
+ #'path to last file': '',
+ 'auto open next archive': True,
+ 'bg colour': (2100, 2100, 2100),
'cache': True,
- 'comment extensions': 'txt nfo',
- 'contrast': 1.0,
+ 'stretch': False,
'default double page': False,
'default fullscreen': False,
- 'default open path': os.getenv('HOME'), #XXX: remove?
- 'default zoom mode': 'fit', # fit, width, height or manual
+ 'default zoom mode': 'fit', # 'fit', 'width', 'height' or 'manual'
'default manga mode': False,
- 'emulate double page': False,
- 'go to next archive': True,
- 'green bg': 2100,
+ #'emulate double page': False,
'hide all': False,
'hide all in fullscreen': True,
+ 'stored hide all values': (True, True, True, True, True),
'interp mode': gtk.gdk.INTERP_TILES,
- 'last convert type': 'zip',
- 'lens magnification': 2,
- 'lens size from center': 90,
- 'library cover size': 128, #XXX: remove?
- 'lib window height': gtk.gdk.screen_get_default().get_height() * 3 / 4,
- 'lib window width': gtk.gdk.screen_get_default().get_width() * 3 / 4,
- 'max lens update interval': 15,
- 'no double page for wide images': True, #XXX: not implemented
+ #'last convert type': 'zip',
+ #'lens magnification': 2,
+ #'lens size from center': 90,
+ #'lens max update interval': 15,
+ #'library cover size': 128,
+ #'lib window height': gtk.gdk.screen_get_default().get_height() * 3 / 4,
+ #'lib window width': gtk.gdk.screen_get_default().get_width() * 3 / 4,
+ #'no double page for wide images': True,
'open defaults to last browsed': True,
- 'page of last file': 0,
'path of last browsed': os.getenv('HOME'),
- 'path to last file': '',
- 'red bg': 2100,
- 'saturation': 1.0,
- 'save image adjustments': False, #XXX: remove?
- 'save window pos': True,
- 'sharpness': 1.0,
+ #'default open path': os.getenv('HOME'),
'show menubar': True,
- 'show page numbers on thumbnails': True,
'show scrollbar': True,
'show statusbar': True,
- 'show thumbnails': True,
'show toolbar': True,
- 'slideshow delay': 6.0,
- 'smart space scroll': False,
- 'space scroll length': 85,
- 'space scroll type': 'window', # window or image
- 'stored hide all values': (True, True, True, True, True),
- 'store recent file info': True,
- 'stretch': False,
+ 'show thumbnails': True,
+ 'show page numbers on thumbnails': True,
'thumbnail size': 80,
- 'toolbar style': gtk.TOOLBAR_ICONS,
'create thumbnails': True,
+ #'slideshow delay': 6.0,
+ 'smart space scroll': True,
+ 'space scroll percent': 85,
+ #'store recent file info': True,
'window height': gtk.gdk.screen_get_default().get_height() * 3 / 4,
- 'window width': gtk.gdk.screen_get_default().get_width() / 2,
- 'window x': 50,
- 'window y': 50
+ 'window width': gtk.gdk.screen_get_default().get_width() / 2
}
-config_path = os.path.join(os.environ['HOME'], '.comix/preferences_data')
+_config_path = os.path.join(constants.COMIX_DIR, 'preferences_data')
-# ------------------------------------------------------------------------
-# Parse preferences_data file.
-# ------------------------------------------------------------------------
-if os.path.isfile(config_path):
- try:
- config = open(config_path)
- version = cPickle.load(config)
- if version < '4.0':
- config.close()
- os.remove(config_path)
- print 'Removed outdated config data (version %s).' % version
- else:
- prefs.update(cPickle.load(config))
- config.close()
- except:
- print '! preferences.py: Error reading or writing', config_path, '\n'
+def read_config_file():
+ if os.path.isfile(_config_path):
+ try:
+ config = open(_config_path)
+ version = cPickle.load(config)
+ if version < '4.0':
+ config.close()
+ os.remove(_config_path)
+ print 'Removed old incompatible config (version %s).' % version
+ else:
+ old_prefs = cPickle.load(config)
+ config.close()
+ for key in old_prefs.iterkeys():
+ if prefs.has_key(key):
+ prefs[key] = old_prefs[key]
+ except:
+ print '! preferences.py: Error reading or writing', _config_path
+ os.remove(_config_path)
+
+def write_config_file():
+ config = open(_config_path, 'w')
+ cPickle.dump(constants.VERSION, config, cPickle.HIGHEST_PROTOCOL)
+ cPickle.dump(prefs, config, cPickle.HIGHEST_PROTOCOL)
+ config.close()

0 comments on commit 78a569e

Please sign in to comment.