daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Jun 27th, 2012 4 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
  2. ### BEGIN LICENSE
  3. # This file is in the public domain
  4. ### END LICENSE
  5.  
  6. import gettext
  7. from gettext import gettext as _
  8. gettext.textdomain('rymate-notes')
  9. import os
  10. from gi.repository import GLib # pylint: disable=E0611
  11. from gi.repository import Gtk # pylint: disable=E0611
  12. from gi.repository import Gio # pylint: disable=E0611
  13. import logging
  14. logger = logging.getLogger('rymate_notes')
  15. import pango
  16.  
  17. from rymate_notes_lib import Window
  18. from rymate_notes.AboutRymateNotesDialog import AboutRymateNotesDialog
  19. from rymate_notes.PreferencesRymateNotesDialog import PreferencesRymateNotesDialog
  20.  
  21. # See rymate_notes_lib.Window.py for more details about how this class works
  22. class RymateNotesWindow(Window):
  23.     __gtype_name__ = "RymateNotesWindow"
  24.    
  25.     def finish_initializing(self, builder): # pylint: disable=E1002
  26.         """Set up the main window"""
  27.         super(RymateNotesWindow, self).finish_initializing(builder)
  28.         self.AboutDialog = AboutRymateNotesDialog
  29.         self.PreferencesDialog = PreferencesRymateNotesDialog
  30.         settings = Gio.Settings("net.launchpad.rymate-notes")
  31.         pangoFont = pango.FontDescription(settings.get_string("font"))
  32.         self.ui.textview1.modify_font(pangoFont)
  33.  
  34.         # Code for other initialization actions should be added here.
  35.  
  36.     def on_mnu_save_activate(self, widget, data=None):
  37.         #get the title for the note
  38.         title = self.ui.comboBoxEntry.get_text()
  39.  
  40.         #get the string
  41.         buff = self.ui.textview1.get_buffer()
  42.         start_iter = buff.get_start_iter()
  43.         end_iter = buff.get_end_iter()
  44.         text = buff.get_text(start_iter, end_iter, True)
  45.  
  46.         #create the filename
  47.         data_dir = GLib.get_user_data_dir()
  48.         jotty_dir = os.path.join(data_dir, "rymate_notes")
  49.         filename = os.path.join(jotty_dir, title)
  50.  
  51.         #write the data
  52.         GLib.mkdir_with_parents(jotty_dir, 0o700)
  53.         GLib.file_set_contents(filename, text)
  54.  
  55.         #Annnnnd we're done! :)
  56.         print "Saved!"
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top