#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import with_statement
+
"""
This file is part of Multilist.
import os
import logging
+import ConfigParser
import gtk
raise
self.db = libspeichern.Speichern()
- self.window_in_fullscreen = False #The window isn't in full screen mode initially.
+ self.__window_in_fullscreen = False #The window isn't in full screen mode initially.
+ self.__isPortrait = False
#Haupt vbox für alle Elemente
self.window = gtk.Window()
+ self.__settingsWindow = None
+ self.__settingsManager = None
self.vbox = gtk.VBox(homogeneous = False, spacing = 0)
self.selection = libselection.Selection(self.db, isHildon)
helpMenuItem.show()
helpMenuItem.set_submenu(helpMenu)
- menu_bar = gtk.MenuBar()
- menu_bar.show()
- menu_bar.append (fileMenuItem)
- menu_bar.append (listMenuItem)
- menu_bar.append (viewMenuItem)
- # unten -> damit als letztes menu_bar.append (helpMenuItem)
+ menuBar = gtk.MenuBar()
+ menuBar.show()
+ menuBar.append (fileMenuItem)
+ menuBar.append (listMenuItem)
+ menuBar.append (viewMenuItem)
+ # unten -> damit als letztes menuBar.append (helpMenuItem)
#Als letztes menü
- menu_bar.append (helpMenuItem)
+ menuBar.append (helpMenuItem)
- self.vbox.pack_start(menu_bar, False, False, 0)
+ self.vbox.pack_start(menuBar, False, False, 0)
else:
menuBar = gtk.MenuBar()
menuBar.show()
self.window = hildonize.hildonize_window(self, self.window)
hildonize.set_application_title(self.window, "%s" % constants.__pretty_app_name__)
- menu_bar = hildonize.hildonize_menu(
+ menuBar = hildonize.hildonize_menu(
self.window,
- menu_bar,
+ menuBar,
)
if hildonize.IS_FREMANTLE_SUPPORTED:
button = hildonize.hildon.GtkRadioButton(gtk.HILDON_SIZE_AUTO, None)
filterGroup = button
button = hildonize.hildon.GtkRadioButton(gtk.HILDON_SIZE_AUTO, filterGroup)
+ button.set_label("New")
+ menuBar.add_filter(button)
+ button.connect("clicked", self._on_click_menu_filter, self.liststorehandler.SHOW_NEW)
+ button.set_mode(False)
+
+ button = hildonize.hildon.GtkRadioButton(gtk.HILDON_SIZE_AUTO, filterGroup)
button.set_label("Active")
menuBar.add_filter(button)
button.connect("clicked", self._on_click_menu_filter, self.liststorehandler.SHOW_ACTIVE)
button.set_mode(False)
+ button = hildonize.hildon.GtkRadioButton(gtk.HILDON_SIZE_AUTO, filterGroup)
+ button.set_label("Done")
+ menuBar.add_filter(button)
+ button.connect("clicked", self._on_click_menu_filter, self.liststorehandler.SHOW_COMPLETE)
+ button.set_mode(False)
+
renameListButton= gtk.Button(_("Rename List"))
renameListButton.connect("clicked", self.bottombar.rename_list)
menuBar.append(renameListButton)
self.window.show_all()
self._search.hide()
+ self._load_settings()
self._prepare_sync_dialog()
+ def _save_settings(self):
+ config = ConfigParser.SafeConfigParser()
+ self.save_settings(config)
+ with open(self._user_settings, "wb") as configFile:
+ config.write(configFile)
+
+ def save_settings(self, config):
+ config.add_section(constants.__pretty_app_name__)
+ config.set(constants.__pretty_app_name__, "portrait", str(self.__isPortrait))
+ config.set(constants.__pretty_app_name__, "fullscreen", str(self.__window_in_fullscreen))
+
+ def _load_settings(self):
+ config = ConfigParser.SafeConfigParser()
+ config.read(self._user_settings)
+ self.load_settings(config)
+
+ def load_settings(self, config):
+ isPortrait = False
+ window_in_fullscreen = False
+ try:
+ isPortrait = config.getboolean(constants.__pretty_app_name__, "portrait")
+ window_in_fullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
+ except ConfigParser.NoSectionError, e:
+ _moduleLogger.info(
+ "Settings file %s is missing section %s" % (
+ self._user_settings,
+ e.section,
+ )
+ )
+
+ if isPortrait ^ self.__isPortrait:
+ if isPortrait:
+ orientation = gtk.ORIENTATION_VERTICAL
+ else:
+ orientation = gtk.ORIENTATION_HORIZONTAL
+ self.set_orientation(orientation)
+
+ self.__window_in_fullscreen = window_in_fullscreen
+ if self.__window_in_fullscreen:
+ self.window.fullscreen()
+ else:
+ self.window.unfullscreen()
+
def _toggle_search(self):
if self._search.get_property("visible"):
self._search.hide()
else:
self._search.show()
+ def set_orientation(self, orientation):
+ if orientation == gtk.ORIENTATION_VERTICAL:
+ hildonize.window_to_portrait(self.window)
+ self.bottombar.set_orientation(gtk.ORIENTATION_VERTICAL)
+ self.selection.set_orientation(gtk.ORIENTATION_VERTICAL)
+ self.__isPortrait = True
+ elif orientation == gtk.ORIENTATION_HORIZONTAL:
+ hildonize.window_to_landscape(self.window)
+ self.bottombar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+ self.selection.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+ self.__isPortrait = False
+ else:
+ raise NotImplementedError(orientation)
+
+ def get_orientation(self):
+ return gtk.ORIENTATION_VERTICAL if self.__isPortrait else gtk.ORIENTATION_HORIZONTAL
+
+ def _toggle_rotate(self):
+ if self.__isPortrait:
+ self.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+ else:
+ self.set_orientation(gtk.ORIENTATION_VERTICAL)
+
@gtk_toolbox.log_exception(_moduleLogger)
def _on_checkout_all(self, widget):
self.liststorehandler.checkout_rows()
event.keyval in RETURN_TYPES and isCtrl
):
# The "Full screen" hardware key has been pressed
- if self.window_in_fullscreen:
+ if self.__window_in_fullscreen:
self.window.unfullscreen ()
else:
self.window.fullscreen ()
return True
+ elif event.keyval == gtk.keysyms.r and isCtrl:
+ self._toggle_rotate()
+ return True
elif event.keyval == gtk.keysyms.f and isCtrl:
self._toggle_search()
return True
@gtk_toolbox.log_exception(_moduleLogger)
def _on_window_state_change(self, widget, event, *args):
if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
- self.window_in_fullscreen = True
+ self.__window_in_fullscreen = True
else:
- self.window_in_fullscreen = False
+ self.__window_in_fullscreen = False
@gtk_toolbox.log_exception(_moduleLogger)
def _on_sync_finished(self, data = None, data2 = None):
@gtk_toolbox.log_exception(_moduleLogger)
def _on_settings(self, *args):
- col_dialog = gtk.Dialog(
- _("Settings"),
- self.window,
- gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
- (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
- )
+ if self.__settingsWindow is None:
+ vbox = gtk.VBox()
+ self.__settingsManager = settings.SettingsDialog(vbox, self.db, self.liststorehandler)
+
+ self.__settingsWindow = gtk.Window()
+ self.__settingsWindow.add(vbox)
+ self.__settingsWindow = hildonize.hildonize_window(self, self.__settingsWindow)
+
+ self.__settingsWindow.set_title(_("Settings"))
+ self.__settingsWindow.set_transient_for(self.window)
+ self.__settingsWindow.set_default_size(*self.window.get_size())
+ self.__settingsWindow.connect("delete-event", self._on_settings_delete)
+ self.__settingsManager.set_portrait_state(self.__isPortrait)
+ self.__settingsWindow.set_modal(True)
+ self.__settingsWindow.show_all()
- cols = settings.SettingsDialog(col_dialog.vbox, self.db, self.liststorehandler)
- col_dialog.show_all()
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def _on_settings_delete(self, *args):
+ self.__settingsWindow.emit_stop_by_name("delete-event")
+ self.__settingsWindow.hide()
+ self.__settingsWindow.set_modal(False)
+
+ logging.info("changing columns")
+ self.__settingsManager.save(self.db)
+ self.view.reload_view()
+
+ isPortrait = self.__settingsManager.is_portrait()
+ if isPortrait ^ self.__isPortrait:
+ if isPortrait:
+ orientation = gtk.ORIENTATION_VERTICAL
+ else:
+ orientation = gtk.ORIENTATION_HORIZONTAL
+ self.set_orientation(orientation)
- resp = col_dialog.run()
- try:
- col_dialog.hide()
- if resp == gtk.RESPONSE_ACCEPT:
- logging.info("changing columns")
- cols.save(self.db)
- self.view.reload_view()
- finally:
- col_dialog.destroy()
+ return True
@gtk_toolbox.log_exception(_moduleLogger)
def _on_destroy(self, widget = None, data = None):
try:
self.db.close()
+ self._save_settings()
+
try:
self._osso_c.close()
except AttributeError: