Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

a snapshot of Note taking app with glade and python

By: a guest on Nov 2nd, 2012  |  syntax: Python  |  size: 7.63 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. from locale import gettext as _
  7.  
  8. from gi.repository import Gtk, Gdk, Gio, GObject, Pango # pylint: disable=E0611
  9. import logging
  10. import sys
  11. import os
  12. logger = logging.getLogger('college')
  13.  
  14. from college_lib import Window
  15. from college.AboutCollegeDialog import AboutCollegeDialog
  16. from college.PreferencesCollegeDialog import PreferencesCollegeDialog
  17.  
  18. # See college_lib.Window.py for more details about how this class works
  19. class CollegeWindow(Window):
  20.     __gtype_name__ = "CollegeWindow"
  21.    
  22.     def finish_initializing(self, builder): # pylint: disable=E1002
  23.         """Set up the main window"""
  24.         super(CollegeWindow, self).finish_initializing(builder)
  25.  
  26. ############################################################removedev
  27.         self.AboutDialog = AboutCollegeDialog
  28.         self.PreferencesDialog = PreferencesCollegeDialog
  29.         self.editdesign = self.builder.get_object("editdesign")
  30.         self.editedit = self.builder.get_object("editedit")
  31. ############################################################removedev
  32.         self.toolbar = self.builder.get_object("toolbar")
  33.  
  34.         self.notelist = self.builder.get_object("notelist")
  35.  
  36.         self.textview = self.builder.get_object("textview")
  37.         self.textbuffer = self.textview.get_buffer()
  38.  
  39.         self.saver = self.builder.get_object("saver")
  40.         self.opener = self.builder.get_object("opener")
  41.  
  42.         self.switch = self.builder.get_object("switch")
  43.         self.switch2 = self.builder.get_object("switch2")
  44.         self.switch.set_active(False)
  45.         self.switch2.set_active(False)
  46.         self.switch.connect('notify::active', self.switcher)
  47.         self.switch2.connect('notify::active', self.switcher2)
  48.  
  49.         self.mainpanel = self.builder.get_object("mainpanel")
  50.         self.scrolledwindow = self.builder.get_object("scrolledwindow")
  51.         self.sidebar = self.builder.get_object("sidebarholder")
  52.         self.sidebar.hide()
  53.  
  54.         self.bolder = self.builder.get_object("bolder")
  55.         self.italicer = self.builder.get_object("italicer")
  56.         self.underliner = self.builder.get_object("underliner")
  57.        
  58.         #Auto Open
  59.         file = open("note.txt", "r")
  60.         text = file.read()
  61.         file.close()    
  62.         self.textbuffer.set_text(text)
  63.         #Style tags for text
  64.         self.bold = self.textbuffer.create_tag("bold", weight=Pango.Weight.BOLD)
  65.         self.italic = self.textbuffer.create_tag("italic", style=Pango.Style.ITALIC)
  66.         self.underline = self.textbuffer.create_tag("underline", underline=Pango.Underline.SINGLE)
  67.         # Code for other initialization actions should be added here.
  68.  
  69.         #Ubuntu style toolbar
  70.         context = self.toolbar.get_style_context()
  71.         context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
  72.  
  73. ############################################################rmdev
  74.     def on_editdesign_activate(self, widget):
  75.         os.system("~/.college/./collegedesign")
  76.     def on_editedit_activate(self, widget):
  77.         os.system("~/.college/./collegeedit")
  78. ############################################################rmdev
  79.  
  80.     def switcher(self, button, active):
  81.         if button.get_active():        
  82.             self.mainpanel.set_position(-1)
  83.         else:
  84.             self.mainpanel.set_position(9999)
  85.  
  86.     def switcher2(self, button, active):
  87.         if button.get_active():        
  88.             self.sidebar.show()
  89.         else:
  90.             self.sidebar.hide()
  91.     #Styling Functions, Formatting.
  92.     def on_bolder_toggled(self, widget):
  93.         if self.bolder.get_active():
  94.             print "Bold activated"
  95.             if len(self.textbuffer.get_selection_bounds()) !=0:
  96.                 start, end = self.textbuffer.get_selection_bounds()
  97.                 self.textbuffer.apply_tag(self.bold, start, end)
  98.             elif len(self.textbuffer.get_bounds()) !=0:
  99.                 start, end = self.textbuffer.get_bounds()
  100.                 self.textbuffer.apply_tag(self.bold, start, end)
  101.         else:
  102.             print "Bold deactivated"
  103.             if len(self.textbuffer.get_selection_bounds()) !=0:
  104.                 start, end = self.textbuffer.get_selection_bounds()
  105.                 self.textbuffer.remove_tag(self.bold, start, end)
  106.             elif len(self.textbuffer.get_bounds()) !=0:
  107.                 start, end = self.textbuffer.get_bounds()
  108.                 self.textbuffer.remove_tag(self.bold, start, end)
  109.  
  110.     def on_italicer_toggled(self, widget):
  111.         if self.italicer.get_active():
  112.             print "Italic activated"
  113.             if len(self.textbuffer.get_selection_bounds()) !=0:
  114.                 start, end = self.textbuffer.get_selection_bounds()
  115.                 self.textbuffer.apply_tag(self.italic, start, end)
  116.             elif len(self.textbuffer.get_bounds()) !=0:
  117.                 start, end = self.textbuffer.get_bounds()
  118.                 self.textbuffer.apply_tag(self.italic, start, end)
  119.         else:
  120.             print "Italic deactivated"
  121.             if len(self.textbuffer.get_selection_bounds()) !=0:
  122.                 start, end = self.textbuffer.get_selection_bounds()
  123.                 self.textbuffer.remove_tag(self.italic, start, end)
  124.             elif len(self.textbuffer.get_bounds()) !=0:
  125.                 start, end = self.textbuffer.get_bounds()
  126.                 self.textbuffer.remove_tag(self.italic, start, end)
  127.  
  128.     def on_underliner_toggled(self, widget):
  129.         if self.underliner.get_active():
  130.             print "Underline activated"
  131.             if len(self.textbuffer.get_selection_bounds()) !=0:
  132.                 start, end = self.textbuffer.get_selection_bounds()
  133.                 self.textbuffer.apply_tag(self.underline, start, end)
  134.             elif len(self.textbuffer.get_bounds()) !=0:
  135.                 start, end = self.textbuffer.get_bounds()
  136.                 self.textbuffer.apply_tag(self.underline, start, end)
  137.         else:
  138.             print "Underline deactivated"
  139.             if len(self.textbuffer.get_selection_bounds()) !=0:
  140.                 start, end = self.textbuffer.get_selection_bounds()
  141.                 self.textbuffer.remove_tag(self.underline, start, end)
  142.             elif len(self.textbuffer.get_bounds()) !=0:
  143.                 start, end = self.textbuffer.get_bounds()
  144.                 self.textbuffer.remove_tag(self.underline, start, end)
  145.  
  146.     def on_saver_clicked(self, widget):
  147.         print "Saved"
  148.         start, end = self.textbuffer.get_bounds()  
  149.         text = self.textbuffer.get_text(start, end, False)
  150.         file = open("note.txt", "w")
  151.         file.write(text)
  152.         file.close()
  153.     def on_mnu_save_activate(self, widget):
  154.         print "Saved"
  155.         start, end = self.textbuffer.get_bounds()  
  156.         text = self.textbuffer.get_text(start, end, False)
  157.         file = open("note.txt", "w")
  158.         file.write(text)
  159.         file.close()
  160.  
  161.     def on_opener_clicked(self, widget):
  162.         print "Loaded"
  163.         file = open("note.txt", "r")
  164.         text = file.read()
  165.         file.close()    
  166.         self.textbuffer.set_text(text)
  167.     def on_mnu_open_activate(self, widget):
  168.         print "Loaded"
  169.         file = open("note.txt", "r")
  170.         text = file.read()
  171.         file.close()    
  172.         self.textbuffer.set_text(text)
  173.  
  174.     def on_college_window_destroy(self, widget):
  175.         start, end = self.textbuffer.get_bounds()  
  176.         text = self.textbuffer.get_text(start, end, False)
  177.         file = open("note.txt", "w")
  178.         file.write(text)
  179.         file.close()
  180.         print "Saved your data before exiting"
  181.         print "BYE!"