Permalink
Browse files

Changes

- Black sides on Ubuntu
- Begining of Attachments! :D
  • Loading branch information...
1 parent dd1be36 commit 08f74b3c7e6feffe12502406a8694a21ae85c7c3 @kennydude committed Jan 2, 2012
Showing with 114 additions and 31 deletions.
  1. +3 −0 lifedrawer/backend.py
  2. +56 −21 lifedrawer/{main-window.ui → main-window.xml}
  3. +55 −10 lifedrawer/ui.py
View
@@ -5,6 +5,9 @@
from lifedrawer import utils, config
import xml.parsers.expat
+def get_attachment_path(date):
+ return os.path.join(config.drawer, str(date.year), str(date.month))
+
def get_filename(date):
return os.path.join(config.drawer, str(date.year), str(date.month), str(date.day) + ".html")
@@ -13,36 +13,68 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
- <object class="GtkBox" id="leftBox">
+ <object class="GtkBox" id="leftMostBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkLabel" id="dateLabel">
+ <object class="GtkToolbar" id="leftToolBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="ypad">1</property>
- <property name="label">DATE</property>
- <property name="justify">center</property>
+ <property name="toolbar_style">both-horiz</property>
+ <style>
+ <class name="primary-toolbar" />
+ </style>
+ <child>
+ <object class="GtkToolItem" id="bgo">
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <child>
+ <object class="GtkBox" id="leftBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="dateLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="ypad">1</property>
+ <property name="label">DATE</property>
+ <property name="justify">center</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="padding">20</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparator" id="separator">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="padding">20</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">False</property>
- <property name="padding">20</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkSeparator" id="separator">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- </object>
- <packing>
- <property name="expand">True</property>
<property name="fill">True</property>
- <property name="padding">20</property>
- <property name="position">1</property>
+ <property name="position">0</property>
</packing>
</child>
<child>
@@ -56,7 +88,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -75,6 +107,9 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">both-horiz</property>
+ <style>
+ <class name="primary-toolbar" />
+ </style>
</object>
<packing>
<property name="expand">False</property>
View
@@ -3,7 +3,7 @@
'''
from gi.repository import Gtk, Pango, GObject
-import datetime, threading
+import datetime, threading, shutil, os
from lifedrawer import utils, backend
class MainWindow(object):
@@ -19,7 +19,7 @@ def __init__(self):
self.date = datetime.date.today()
self.builder = Gtk.Builder()
- self.uifile = "lifedrawer/main-window.ui"
+ self.uifile = "lifedrawer/main-window.xml"
self.builder.add_from_file(self.uifile)
self.window = self.builder.get_object ("MainWindow")
self.window.connect ("destroy", Gtk.main_quit)
@@ -71,6 +71,12 @@ def __init__(self):
self.quoteButton.set_label("Quote")
self.quoteButton.connect("toggled", self.setTag, "blockquote")
self.toolbar.insert(self.quoteButton, 3)
+
+ self.insertImage = Gtk.ToolButton()
+ self.insertImage.set_icon_name("add")
+ self.insertImage.set_label("Add Image")
+ self.insertImage.connect("clicked", self.clickInsertImage)
+ self.toolbar.insert(self.insertImage, 4)
self.updateDate()
@@ -103,14 +109,15 @@ def real_saveContent(self):
end = self.textBuffer.get_end_iter().get_offset()
for i in range(0, end):
it = self.textBuffer.get_iter_at_offset(i)
-
- for (tag, html) in tags:
- if it.begins_tag(tag):
- content += '<%s>' % html
- elif it.ends_tag(tag):
- content += '</%s>' % html
-
- content += it.get_char()
+ if it.get_pixbuf() != None:
+ content += "<img src='%s' />" % it.get_pixbuf().get_data("url")
+ else:
+ for (tag, html) in tags:
+ if it.begins_tag(tag):
+ content += '<%s>' % html
+ elif it.ends_tag(tag):
+ content += '</%s>' % html
+ content += it.get_char()
backend.save_content(self.date, content)
@@ -142,6 +149,44 @@ def updateToggles(self, widget=None, event=None, tmpVar=None, tmpVar2=None, begi
self.quoteButton.set_active("quote" in bag)
self.saveContent()
+ def clickInsertImage(self, widget, data=None):
+ dialog = Gtk.FileChooserDialog("Please choose a file", self.window,
+ Gtk.FileChooserAction.OPEN,
+ (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+ Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
+
+ filter_text = Gtk.FileFilter()
+ filter_text.set_name("Images")
+ filter_text.add_mime_type("image/*")
+ dialog.add_filter(filter_text)
+
+ response = dialog.run()
+ if response == Gtk.ResponseType.OK:
+ print "Adding File... ", dialog.get_filename()
+ fname = dialog.get_filename().split('/')[-1]
+ fname = os.path.join(backend.get_attachment_path(self.date), "%s_%s" %(self.date.day, fname) )
+
+ while os.path.exists(fname):
+ fname = fname.rsplit('.', 2)[-2] + "_" + fname.rsplit('.', 2)[-1]
+
+ if not os.path.exists(os.path.join(*fname.split('/')[:-1])):
+ os.makedirs(os.path.join(*fname.split('/')[:-1]))
+ shutil.copy(dialog.get_filename(), fname)
+ try:
+ from gi.repository import GdkPixbuf
+ p = GdkPixbuf.Pixbuf.new_from_file(fname)
+ iters = self.textBuffer.get_selection_bounds()
+ print iters
+ if iters != None and len(iters) == 2:
+ iters = iters[0]
+ else:
+ iters = self.textBuffer.get_iter_at_offset(0)
+ p.set_data("url", fname)
+ self.textBuffer.insert_pixbuf(iters, p)
+ except Exception as ex:
+ print "TODO: Exception box", repr(ex)
+ dialog.destroy()
+
def setTag(self, widget, data=None):
'''
Set a tag. For buttons

0 comments on commit 08f74b3

Please sign in to comment.