Skip to content
Browse files

Respect PEP-8

git-svn-id: https://labyrinth.googlecode.com/svn/trunk@353 8f060a39-251c-0410-b1f3-431655927647
  • Loading branch information...
1 parent 6d5da1a commit e3422097e44df19c7aaf4fa4b688e4148d2fec45 matthias.vogelgesang@gmail.com committed Apr 23, 2011
Showing with 5,989 additions and 5,994 deletions.
  1. +6 −1 ChangeLog
  2. +1 −1 Windows/defs.py
  3. +20 −20 Windows/winsetup.py
  4. +300 −300 src/BaseThought.py
  5. +299 −300 src/Browser.py
  6. +573 −573 src/DrawingThought.py
  7. +278 −280 src/ImageThought.py
  8. +246 −247 src/Links.py
  9. +1,307 −1,308 src/MMapArea.py
  10. +766 −767 src/MainWindow.py
  11. +184 −184 src/MapList.py
  12. +9 −10 src/PeriodicSaveThread.py
  13. +109 −109 src/ResourceThought.py
  14. +271 −273 src/TextBufferMarkup.py
  15. +1,195 −1,195 src/TextThought.py
  16. +35 −35 src/TrayIcon.py
  17. +211 −211 src/UndoManager.py
  18. +3 −3 src/__init__.py
  19. +48 −48 src/labyrinth.py
  20. +8 −8 src/prefs.py
  21. +120 −121 src/utils.py
View
7 ChangeLog
@@ -1,4 +1,9 @@
-2009-03-08 Matthias Vogelgesang <matthias.vogelgesang@gmail.com>
+2011-04-23 Matthias Vogelgesang <matthias.vogelgesang@gmail.com>
+
+ * src/*.py
+ Respect PEP-8.
+
+2011-04-23 Matthias Vogelgesang <matthias.vogelgesang@gmail.com>
* src/MainWindow.py
* src/utils.py
View
2 Windows/defs.py
@@ -1,4 +1,4 @@
prefix = ""
DATA_DIR = "glade\\"
VERSION="0.3"
-pkgdatadir="glade\\"
+pkgdatadir="glade\\"
View
40 Windows/winsetup.py
@@ -22,7 +22,7 @@
# GNU General Public License, version 2 or later
-# for build this on a win32 environment and becames with a standalone distribution
+# for build this on a win32 environment and becames with a standalone distribution
# a base python 2.4 for 2in32 instalation must be present
# along with gtk+ development libraries
# pywin32com extensions, reportlab module, pygtk for win32 and pysqlite-1.1.7.win32-py2.4 (current win32 distro install is using this pysqlite 3 version)
@@ -50,31 +50,31 @@
import glob
import py2exe
-opts = {
- "py2exe": {
+opts = {
+ "py2exe": {
"includes": "cairo,pangocairo,pango,atk,gobject,xml.dom,xml.dom.minidom,threading,shutil,pygtk,gtk,sys,gtk.glade",
"optimize": 2,
- "dist_dir": "dist\\data_files",
- }
-}
+ "dist_dir": "dist\\data_files",
+ }
+}
setup(
name = "Labyrinth",
description = "Labyrinth",
version = "0.3",
- windows = [
- {
- "script": "src\\labyrinth.py",
- "icon_resources": [(1, "Windows\labyrinth.ico")]
+ windows = [
+ {
+ "script": "src\\labyrinth.py",
+ "icon_resources": [(1, "Windows\labyrinth.ico")]
}],
- options = opts,
- data_files=[
- ("images",
- glob.glob("data\\*.png")),
- ("data",
- glob.glob("data\\*.glade")),
- ("data",
- glob.glob("data\\*.xml")),
- ("",
- glob.glob("src\\*.py"))],
+ options = opts,
+ data_files=[
+ ("images",
+ glob.glob("data\\*.png")),
+ ("data",
+ glob.glob("data\\*.glade")),
+ ("data",
+ glob.glob("data\\*.xml")),
+ ("",
+ glob.glob("src\\*.py"))],
)
View
600 src/BaseThought.py
@@ -31,308 +31,308 @@
MODE_DRAW = 2
class BaseThought (gobject.GObject):
- ''' The basic class to derive other thoughts from. \
- Instructions for creating derivative thought types are \
- given as comments'''
- # These are general signals. They are available to all thoughts to
- # emit. If you emit other signals, the chances are they'll be ignored
- # by the MMapArea. It's you're responsiblity to catch and handle them.
- # All these signals are handled correctly by the MMapArea.
- __gsignals__ = dict (select_thought = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- (gobject.TYPE_PYOBJECT,)),
- begin_editing = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ()),
- popup_requested = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- (gobject.TYPE_PYOBJECT, gobject.TYPE_INT)),
- claim_unending_link = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ()),
- update_view = (gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_NONE,
- ()),
- create_link = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- (gobject.TYPE_PYOBJECT,)),
- title_changed = (gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_NONE,
- (gobject.TYPE_STRING,)),
- finish_editing = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ()),
- delete_thought = (gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_NONE,
- ()),
- text_selection_changed = (gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_NONE,
- (gobject.TYPE_INT, gobject.TYPE_INT, gobject.TYPE_STRING)),
- change_mouse_cursor = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- (gobject.TYPE_INT,)),
- update_links = (gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_NONE,
- ()),
- grab_focus = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- (gobject.TYPE_BOOLEAN,)),
- update_attrs = (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- (gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN, pango.FontDescription)))
-
- # The first thing that should be called is this constructor
- # It sets some basic properties of all thoughts and should be called
- # before you start doing you're own thing with thoughts
- # save: the save document passed into the derived constructor
- # elem_type: a string representing the thought type (e.g. "image_thought")
- def __init__ (self, save, elem_type, undo, background_color, foreground_color):
- # Note: Once the thought has been successfully initialised (i.e. at the end
- # of the constructor) you MUST set all_okay to True
- # Otherwise, bad things will happen.
- self.all_okay = False
- super (BaseThought, self).__init__()
- self.ul = self.lr = None
- self.am_primary = False
- self.am_selected = False
- self.sensitive = 5
- self.editing = False
- self.identity = -1
- self.index = 0
- self.end_index = 0
- self.text = ""
- self.want_move = False
- self.undo = undo
- self.background_color = background_color
- self.foreground_color = foreground_color
- self.model_iter = None
- extended_elem = save.createElement ("Extended")
- self.extended_buffer = TextBufferMarkup.ExtendedBuffer (self.undo, extended_elem, save)
- self.extended_buffer.set_text("")
- self.extended_buffer.connect ("set_focus", self.focus_buffer)
- self.extended_buffer.connect ("set_attrs", self.set_extended_attrs)
- self.element = save.createElement (elem_type)
- self.element.appendChild (extended_elem)
-
- # These are self-explanitory. You probably don't want to
- # overwrite these methods, unless you have a very good reason
- def get_save_element (self):
- return self.element
-
- def make_primary (self):
- self.am_primary = True
-
- def select (self):
- self.am_selected = True
-
- def unselect (self):
- self.am_selected = False
-
- def get_max_area (self):
- if not self.ul or not self.lr:
- return 999,999,-999,-999
- return self.ul[0], self.ul[1], self.lr[0], self.lr[1]
-
- def okay (self):
- return self.all_okay
-
- def move_by (self, x, y):
- self.ul = (self.ul[0]+x, self.ul[1]+y)
- self.recalc_edges ()
- self.emit ("update_links")
- self.emit ("update_view")
-
- def focus_buffer (self, buf):
- self.emit ("select_thought", None)
- self.emit ("grab_focus", True)
-
- def set_extended_attrs(self, buf, bold, underline, italics, pango_font):
- self.emit("update_attrs", bold, underline, italics, pango_font)
-
- def can_be_parent (self):
- return True
-
- # This, you may want to change. Though, doing so will only affect
- # thoughts that are "parents"
- def find_connection (self, other):
- if self.editing or other.editing:
- return None, None
- if not self.ul or not self.lr or not other.ul \
- or not other.lr:
- return None, None
-
- if utils.use_bezier_curves:
- if other.ul[0] > self.lr[0]:
- xfrom = self.lr[0]
- xto = other.ul[0]
- else:
- xfrom = self.ul[0]
- xto = other.lr[0]
- else:
- xfrom = self.ul[0]-((self.ul[0]-self.lr[0]) / 2.)
- xto = other.ul[0]-((other.ul[0]-other.lr[0]) / 2.)
-
- yfrom = self.ul[1]-((self.ul[1]-self.lr[1]) / 2.)
- yto = other.ul[1]-((other.ul[1]-other.lr[1]) / 2.)
- return (xfrom, yfrom), (xto, yto)
-
- # All the rest of these should be handled within you're thought
- # type, supposing you actually want to handle them.
- # You almost certianly do want to ;)
- def process_button_down (self, event, mode, transformed):
- return False
-
- def process_button_release (self, event, unending_link, mode, transformed):
- return False
-
- def process_key_press (self, event, mode):
- return False
-
- def handle_motion (self, event, mode, transformed):
- pass
-
- def includes (self, coords, mode):
- pass
-
- def begin_editing (self):
- return False
-
- def finish_editing (self):
- pass
-
- def draw (self, context):
- pass
-
- def load (self, node):
- pass
-
- def update_save (self):
- pass
-
- def copy_text (self, clip):
- pass
-
- def cut_text (self, clip):
- pass
-
- def paste_text (self, clip):
- pass
+ ''' The basic class to derive other thoughts from. \
+ Instructions for creating derivative thought types are \
+ given as comments'''
+ # These are general signals. They are available to all thoughts to
+ # emit. If you emit other signals, the chances are they'll be ignored
+ # by the MMapArea. It's you're responsiblity to catch and handle them.
+ # All these signals are handled correctly by the MMapArea.
+ __gsignals__ = dict (select_thought = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_PYOBJECT,)),
+ begin_editing = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ popup_requested = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_PYOBJECT, gobject.TYPE_INT)),
+ claim_unending_link = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ update_view = (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ ()),
+ create_link = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_PYOBJECT,)),
+ title_changed = (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_STRING,)),
+ finish_editing = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ delete_thought = (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ ()),
+ text_selection_changed = (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_INT, gobject.TYPE_INT, gobject.TYPE_STRING)),
+ change_mouse_cursor = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_INT,)),
+ update_links = (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ ()),
+ grab_focus = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_BOOLEAN,)),
+ update_attrs = (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN, pango.FontDescription)))
+
+ # The first thing that should be called is this constructor
+ # It sets some basic properties of all thoughts and should be called
+ # before you start doing you're own thing with thoughts
+ # save: the save document passed into the derived constructor
+ # elem_type: a string representing the thought type (e.g. "image_thought")
+ def __init__ (self, save, elem_type, undo, background_color, foreground_color):
+ # Note: Once the thought has been successfully initialised (i.e. at the end
+ # of the constructor) you MUST set all_okay to True
+ # Otherwise, bad things will happen.
+ self.all_okay = False
+ super (BaseThought, self).__init__()
+ self.ul = self.lr = None
+ self.am_primary = False
+ self.am_selected = False
+ self.sensitive = 5
+ self.editing = False
+ self.identity = -1
+ self.index = 0
+ self.end_index = 0
+ self.text = ""
+ self.want_move = False
+ self.undo = undo
+ self.background_color = background_color
+ self.foreground_color = foreground_color
+ self.model_iter = None
+ extended_elem = save.createElement ("Extended")
+ self.extended_buffer = TextBufferMarkup.ExtendedBuffer (self.undo, extended_elem, save)
+ self.extended_buffer.set_text("")
+ self.extended_buffer.connect ("set_focus", self.focus_buffer)
+ self.extended_buffer.connect ("set_attrs", self.set_extended_attrs)
+ self.element = save.createElement (elem_type)
+ self.element.appendChild (extended_elem)
+
+ # These are self-explanitory. You probably don't want to
+ # overwrite these methods, unless you have a very good reason
+ def get_save_element (self):
+ return self.element
+
+ def make_primary (self):
+ self.am_primary = True
+
+ def select (self):
+ self.am_selected = True
+
+ def unselect (self):
+ self.am_selected = False
+
+ def get_max_area (self):
+ if not self.ul or not self.lr:
+ return 999,999,-999,-999
+ return self.ul[0], self.ul[1], self.lr[0], self.lr[1]
+
+ def okay (self):
+ return self.all_okay
+
+ def move_by (self, x, y):
+ self.ul = (self.ul[0]+x, self.ul[1]+y)
+ self.recalc_edges ()
+ self.emit ("update_links")
+ self.emit ("update_view")
+
+ def focus_buffer (self, buf):
+ self.emit ("select_thought", None)
+ self.emit ("grab_focus", True)
+
+ def set_extended_attrs(self, buf, bold, underline, italics, pango_font):
+ self.emit("update_attrs", bold, underline, italics, pango_font)
+
+ def can_be_parent (self):
+ return True
+
+ # This, you may want to change. Though, doing so will only affect
+ # thoughts that are "parents"
+ def find_connection (self, other):
+ if self.editing or other.editing:
+ return None, None
+ if not self.ul or not self.lr or not other.ul \
+ or not other.lr:
+ return None, None
+
+ if utils.use_bezier_curves:
+ if other.ul[0] > self.lr[0]:
+ xfrom = self.lr[0]
+ xto = other.ul[0]
+ else:
+ xfrom = self.ul[0]
+ xto = other.lr[0]
+ else:
+ xfrom = self.ul[0]-((self.ul[0]-self.lr[0]) / 2.)
+ xto = other.ul[0]-((other.ul[0]-other.lr[0]) / 2.)
+
+ yfrom = self.ul[1]-((self.ul[1]-self.lr[1]) / 2.)
+ yto = other.ul[1]-((other.ul[1]-other.lr[1]) / 2.)
+ return (xfrom, yfrom), (xto, yto)
+
+ # All the rest of these should be handled within you're thought
+ # type, supposing you actually want to handle them.
+ # You almost certianly do want to ;)
+ def process_button_down (self, event, mode, transformed):
+ return False
+
+ def process_button_release (self, event, unending_link, mode, transformed):
+ return False
+
+ def process_key_press (self, event, mode):
+ return False
+
+ def handle_motion (self, event, mode, transformed):
+ pass
+
+ def includes (self, coords, mode):
+ pass
- def export (self, context, move_x, move_y):
- pass
-
- def commit_text (self, im_context, string, mode):
- pass
-
- def want_motion (self):
- return False
-
- def recalc_edges (self):
- pass
-
- def delete_surroundings(self, imcontext, offset, n_chars, mode):
- pass
-
- def preedit_changed (self, imcontext, mode):
- pass
-
- def preedit_end (self, imcontext, mode):
- pass
-
- def preedit_start (self, imcontext, mode):
- pass
+ def begin_editing (self):
+ return False
- def retrieve_surroundings (self, imcontext, mode):
- pass
-
- def set_bold (self, active):
- pass
-
- def get_popup_menu_items(self):
- pass
+ def finish_editing (self):
+ pass
+
+ def draw (self, context):
+ pass
+
+ def load (self, node):
+ pass
+
+ def update_save (self):
+ pass
+
+ def copy_text (self, clip):
+ pass
+
+ def cut_text (self, clip):
+ pass
+
+ def paste_text (self, clip):
+ pass
+
+ def export (self, context, move_x, move_y):
+ pass
+
+ def commit_text (self, im_context, string, mode):
+ pass
+
+ def want_motion (self):
+ return False
+
+ def recalc_edges (self):
+ pass
+
+ def delete_surroundings(self, imcontext, offset, n_chars, mode):
+ pass
+
+ def preedit_changed (self, imcontext, mode):
+ pass
+
+ def preedit_end (self, imcontext, mode):
+ pass
+
+ def preedit_start (self, imcontext, mode):
+ pass
+
+ def retrieve_surroundings (self, imcontext, mode):
+ pass
+
+ def set_bold (self, active):
+ pass
+
+ def get_popup_menu_items(self):
+ pass
class ResizableThought (BaseThought):
- ''' A resizable thought base class. This allows the sides and corners \
- of the thought to be dragged around. It only provides the very basic \
- functionality. Other stuff must be done within the derived classes'''
-
- # Possible types of resizing - where the user selected to resize
- RESIZE_NONE = 0
- RESIZE_LEFT = 1
- RESIZE_RIGHT = 2
- RESIZE_TOP = 3
- RESIZE_BOTTOM = 4
- RESIZE_UL = 5
- RESIZE_UR = 6
- RESIZE_LL = 7
- RESIZE_LR = 8
-
- def __init__ (self, save, elem_type, undo, background_color, foreground_color):
- super (ResizableThought, self).__init__(save, elem_type, undo, background_color, foreground_color)
- self.resizing = False
- self.button_down = False
-
- def includes (self, coords, mode):
- if not self.ul or not self.lr or not coords:
- return False
-
- inside = (coords[0] < self.lr[0] + self.sensitive) and \
- (coords[0] > self.ul[0] - self.sensitive) and \
- (coords[1] < self.lr[1] + self.sensitive) and \
- (coords[1] > self.ul[1] - self.sensitive)
-
- self.resizing = self.RESIZE_NONE
- self.motion_coords = coords
-
- if inside and (mode != MODE_EDITING or self.button_down):
- self.emit ("change_mouse_cursor", gtk.gdk.LEFT_PTR)
- return inside
-
- if inside:
- # 2 cases: 1. The click was within the main area
- # 2. The click was near the border
- # In the first case, we handle as normal
- # In the second case, we want to intercept all the fun thats
- # going to happen so we can resize the thought
- if abs (coords[0] - self.ul[0]) < self.sensitive:
- # its near the top edge somewhere
- if abs (coords[1] - self.ul[1]) < self.sensitive:
- # Its in the ul corner
- self.resizing = self.RESIZE_UL
- self.emit ("change_mouse_cursor", gtk.gdk.TOP_LEFT_CORNER)
- elif abs (coords[1] - self.lr[1]) < self.sensitive:
- # Its in the ll corner
- self.resizing = self.RESIZE_LL
- self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_LEFT_CORNER)
- elif coords[1] < self.lr[1] and coords[1] > self.ul[1]:
- #anywhere else along the left edge
- self.resizing = self.RESIZE_LEFT
- self.emit ("change_mouse_cursor", gtk.gdk.LEFT_SIDE)
- elif abs (coords[0] - self.lr[0]) < self.sensitive:
- if abs (coords[1] - self.ul[1]) < self.sensitive:
- # Its in the UR corner
- self.resizing = self.RESIZE_UR
- self.emit ("change_mouse_cursor", gtk.gdk.TOP_RIGHT_CORNER)
- elif abs (coords[1] - self.lr[1]) < self.sensitive:
- # Its in the lr corner
- self.resizing = self.RESIZE_LR
- self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_RIGHT_CORNER)
- elif coords[1] < self.lr[1] and coords[1] > self.ul[1]:
- #anywhere else along the right edge
- self.resizing = self.RESIZE_RIGHT
- self.emit ("change_mouse_cursor", gtk.gdk.RIGHT_SIDE)
- elif abs (coords[1] - self.ul[1]) < self.sensitive and \
- (coords[0] < self.lr[0] and coords[0] > self.ul[0]):
- # Along the top edge somewhere
- self.resizing = self.RESIZE_TOP
- self.emit ("change_mouse_cursor", gtk.gdk.TOP_SIDE)
- elif abs (coords[1] - self.lr[1]) < self.sensitive and \
- (coords[0] < self.lr[0] and coords[0] > self.ul[0]):
- # Along the bottom edge somewhere
- self.resizing = self.RESIZE_BOTTOM
- self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_SIDE)
- else:
- self.emit ("change_mouse_cursor", gtk.gdk.LEFT_PTR)
- self.want_move = (self.resizing != self.RESIZE_NONE)
- return inside
+ ''' A resizable thought base class. This allows the sides and corners \
+ of the thought to be dragged around. It only provides the very basic \
+ functionality. Other stuff must be done within the derived classes'''
+
+ # Possible types of resizing - where the user selected to resize
+ RESIZE_NONE = 0
+ RESIZE_LEFT = 1
+ RESIZE_RIGHT = 2
+ RESIZE_TOP = 3
+ RESIZE_BOTTOM = 4
+ RESIZE_UL = 5
+ RESIZE_UR = 6
+ RESIZE_LL = 7
+ RESIZE_LR = 8
+
+ def __init__ (self, save, elem_type, undo, background_color, foreground_color):
+ super (ResizableThought, self).__init__(save, elem_type, undo, background_color, foreground_color)
+ self.resizing = False
+ self.button_down = False
+
+ def includes (self, coords, mode):
+ if not self.ul or not self.lr or not coords:
+ return False
+
+ inside = (coords[0] < self.lr[0] + self.sensitive) and \
+ (coords[0] > self.ul[0] - self.sensitive) and \
+ (coords[1] < self.lr[1] + self.sensitive) and \
+ (coords[1] > self.ul[1] - self.sensitive)
+
+ self.resizing = self.RESIZE_NONE
+ self.motion_coords = coords
+
+ if inside and (mode != MODE_EDITING or self.button_down):
+ self.emit ("change_mouse_cursor", gtk.gdk.LEFT_PTR)
+ return inside
+
+ if inside:
+ # 2 cases: 1. The click was within the main area
+ # 2. The click was near the border
+ # In the first case, we handle as normal
+ # In the second case, we want to intercept all the fun thats
+ # going to happen so we can resize the thought
+ if abs (coords[0] - self.ul[0]) < self.sensitive:
+ # its near the top edge somewhere
+ if abs (coords[1] - self.ul[1]) < self.sensitive:
+ # Its in the ul corner
+ self.resizing = self.RESIZE_UL
+ self.emit ("change_mouse_cursor", gtk.gdk.TOP_LEFT_CORNER)
+ elif abs (coords[1] - self.lr[1]) < self.sensitive:
+ # Its in the ll corner
+ self.resizing = self.RESIZE_LL
+ self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_LEFT_CORNER)
+ elif coords[1] < self.lr[1] and coords[1] > self.ul[1]:
+ #anywhere else along the left edge
+ self.resizing = self.RESIZE_LEFT
+ self.emit ("change_mouse_cursor", gtk.gdk.LEFT_SIDE)
+ elif abs (coords[0] - self.lr[0]) < self.sensitive:
+ if abs (coords[1] - self.ul[1]) < self.sensitive:
+ # Its in the UR corner
+ self.resizing = self.RESIZE_UR
+ self.emit ("change_mouse_cursor", gtk.gdk.TOP_RIGHT_CORNER)
+ elif abs (coords[1] - self.lr[1]) < self.sensitive:
+ # Its in the lr corner
+ self.resizing = self.RESIZE_LR
+ self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_RIGHT_CORNER)
+ elif coords[1] < self.lr[1] and coords[1] > self.ul[1]:
+ #anywhere else along the right edge
+ self.resizing = self.RESIZE_RIGHT
+ self.emit ("change_mouse_cursor", gtk.gdk.RIGHT_SIDE)
+ elif abs (coords[1] - self.ul[1]) < self.sensitive and \
+ (coords[0] < self.lr[0] and coords[0] > self.ul[0]):
+ # Along the top edge somewhere
+ self.resizing = self.RESIZE_TOP
+ self.emit ("change_mouse_cursor", gtk.gdk.TOP_SIDE)
+ elif abs (coords[1] - self.lr[1]) < self.sensitive and \
+ (coords[0] < self.lr[0] and coords[0] > self.ul[0]):
+ # Along the bottom edge somewhere
+ self.resizing = self.RESIZE_BOTTOM
+ self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_SIDE)
+ else:
+ self.emit ("change_mouse_cursor", gtk.gdk.LEFT_PTR)
+ self.want_move = (self.resizing != self.RESIZE_NONE)
+ return inside
View
599 src/Browser.py
@@ -2,7 +2,7 @@
# This file is part of Labyrinth
#
# Copyright (C) 2006 - Don Scorgie <Don@Scorgie.org>
-# - Andreas Sliwka <andreas.sliwka@gmail.com>
+# - Andreas Sliwka <andreas.sliwka@gmail.com>
#
# Labyrinth is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
from os.path import *
import os
if os.name != 'nt':
- import gconf
+ import gconf
import gtk.glade
import MainWindow
from MapList import MapList
@@ -39,303 +39,302 @@
import gettext
_ = gettext.gettext
-AUTHORS = ['Don Scorgie <Don@Scorgie.org>',
- 'Martin Schaaf <mascha@ma-scha.de>',
- 'Matthias Vogelgesang <matthias.vogelgesang@gmail.com>',
- 'Andreas Sliwka <andreas.sliwka@gmail.com>']
+AUTHORS = ['Don Scorgie <Don@Scorgie.org>',
+ 'Martin Schaaf <mascha@ma-scha.de>',
+ 'Matthias Vogelgesang <matthias.vogelgesang@gmail.com>',
+ 'Andreas Sliwka <andreas.sliwka@gmail.com>']
class Browser (gtk.Window):
- COL_ID = 0
- COL_TITLE = 1
- COL_MODTIME = 2
-
- def __init__(self, start_hidden, tray_icon):
- super(Browser, self).__init__()
- self.glade=gtk.glade.XML(utils.get_data_file_name('labyrinth.glade'))
- self.view = self.glade.get_widget ('MainView')
- self.populate_view ()
- self.view.connect ('row-activated', self.open_row_cb)
- self.view.connect ('cursor-changed', self.cursor_change_cb)
-
- self.view_dependants = []
-
- self.open_button = self.glade.get_widget('OpenButton')
- self.delete_button = self.glade.get_widget('DeleteButton')
- self.open_menu = self.glade.get_widget('open1')
- self.delete_menu = self.glade.get_widget('delete1')
-
- self.view_dependants.append (self.open_button)
- self.view_dependants.append (self.delete_button)
- self.view_dependants.append (self.open_menu)
- self.view_dependants.append (self.delete_menu)
-
- self.open_button.connect ('clicked', self.open_clicked)
- self.glade.get_widget('NewButton').connect ('clicked', self.new_clicked)
- self.delete_button.connect ('clicked', self.delete_clicked)
-
- self.open_menu.connect ('activate', self.open_clicked)
- self.glade.get_widget('new1').connect ('activate', self.new_clicked)
- self.delete_menu.connect ('activate', self.delete_clicked)
- self.glade.get_widget('import1').connect ('activate', self.import_clicked)
- self.glade.get_widget('quit1').connect ('activate', self.quit_clicked)
- self.glade.get_widget('about1').connect ('activate', self.about_clicked)
- self.glade.get_widget('showhelp').connect ('activate', self.show_help_clicked)
-
- map(lambda x : x.set_sensitive(False), self.view_dependants)
-
- props = { gnome.PARAM_APP_DATADIR : '/usr/share' }
- prog = gnome.program_init('labyrinth', '0.5', properties=props)
-
- self.main_window = self.glade.get_widget ('MapBrowser')
-
- # set remembered size
- if os.name != 'nt':
- self.config_client = gconf.client_get_default()
- self.config_client.add_dir ("/apps/labyrinth", gconf.CLIENT_PRELOAD_NONE)
-
- width = self.config_client.get_int ('/apps/labyrinth/width')
- height = self.config_client.get_int ('/apps/labyrinth/height')
- utils.use_bezier_curves = self.config_client.get_bool ('/apps/labyrinth/curves')
- if width == 0 or height == 0:
- width = 400
- height = 300
- else:
- width = 400
- height = 300
-
- view_sortable = self.view.get_model ()
- view_sortable.connect ('sort-column-changed', self.sort_column_changed_cb)
- if os.name != 'nt':
- sort_order = self.config_client.get_int('/apps/labyrinth/map_sort_order')
- column_id = self.config_client.get_int('/apps/labyrinth/map_sort_order_column')
- view_sortable.set_sort_column_id (column_id, sort_order)
-
- self.main_window.resize (width, height)
-
- if os.name != 'nt':
- try:
- self.main_window.set_icon_name ('labyrinth')
- except:
- self.main_window.set_icon_from_file(utils.get_data_file_name('labyrinth.svg'))
- else:
- self.main_window.set_icon_from_file('images\\labyrinth-24.png')
- if tray_icon:
- self.main_window.connect ('delete_event', self.toggle_main_window, None)
- traymenu = gtk.Menu()
- quit_item = gtk.MenuItem("Quit")
- quit_item.connect("activate",self.quit_clicked)
- traymenu.add(quit_item)
- traymenu.show_all()
- self.traymenu = traymenu
- self.trayicon = TrayIcon.TrayIcon(
- icon_name="labyrinth",
- menu=traymenu,
- activate=self.toggle_main_window)
- else:
- self.main_window.connect('delete_event', self.quit_clicked, None)
- if start_hidden:
- self.main_window.hide ()
- else:
- self.main_window.show_all ()
-
- def toggle_main_window(self,*args):
- if self.main_window.get_property("visible"):
- self.main_window.hide()
- else:
- self.main_window.show()
- return True
-
- def map_title_cb (self, mobj, new_title, mobj1):
- map = MapList.get_by_window(mobj)
- if not map:
- raise AttributeError ("What a mess, can't find the map")
- map.title = new_title
-
- def get_selected_map(self):
- sel = self.view.get_selection ()
- (model, it) = sel.get_selected ()
- if it:
- (num,) = MapList.tree_view_model.get (it, self.COL_ID)
- return MapList.get_by_index(num)
- return None
-
- def cursor_change_cb (self, treeview):
- selected_map = self.get_selected_map ()
- sensitive = not not self.get_selected_map ()
- map(lambda x : x.set_sensitive(sensitive), self.view_dependants)
-
- def open_map_filename (self, fname):
- win = MainWindow.LabyrinthWindow (fname)
- win.show ()
-
- def open_map (self, map, imported=False):
- win = MainWindow.LabyrinthWindow (map.filename, imported)
- win.connect ("title-changed", self.map_title_cb)
- win.connect ("window_closed", self.remove_map_cb)
- win.connect ("file_saved", self.file_save_cb)
- win.show ()
- map.window = win
- return (MapList.index(map), win)
-
- def open_selected_map(self):
- map = self.get_selected_map()
- if map is None:
- raise "you clicked the 'open' button bud had no map selected"
- if map.window:
- print "Window for map '%s' is already open" % map.title
- # may be the window should be raised?
- else:
- self.open_map (map)
-
- def show_help_clicked(self, arg):
- try:
- gnome.help_display('labyrinth')
- except gobject.GError, e:
- print _('Unable to display help: %s') % str(e)
-
- def about_clicked (self, arg):
- about_dialog = gtk.AboutDialog ()
- about_dialog.set_name ("Labyrinth")
- about_dialog.set_version (utils.get_version())
- if os.name != 'nt':
- try:
- about_dialog.set_logo_icon_name("labyrinth")
- except:
- pass
- else:
- about_dialog.set_logo (gtk.gdk.pixbuf_new_from_file("images\\labyrinth-24.png"))
- about_dialog.set_license (
- "Labyrinth is free software; you can redistribute it and/or modify "
- "it under the terms of the GNU General Public Licence as published by "
- "the Free Software Foundation; either version 2 of the Licence, or "
- "(at your option) any later version."
- "\n\n"
- "Labyrinth is distributed in the hope that it will be useful, "
- "but WITHOUT ANY WARRANTY; without even the implied warranty of "
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
- "GNU General Public Licence for more details."
- "\n\n"
- "You should have received a copy of the GNU General Public Licence "
- "along with Labyrinth; if not, write to the Free Software Foundation, Inc., "
- "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA")
- about_dialog.set_wrap_license (True)
- about_dialog.set_copyright ("2006-2008 Don Scorgie et. al")
- about_dialog.set_authors (AUTHORS)
- about_dialog.set_website ("http://code.google.com/p/labyrinth")
- about_dialog.set_translator_credits (_("Translation by Don Scorgie"))
- about_dialog.run ()
- about_dialog.hide ()
- del (about_dialog)
- return
-
- def open_clicked (self, button):
- self.open_selected_map()
-
- def open_row_cb (self, view, path, col):
- self.open_selected_map ()
-
- def new_clicked (self, button):
- map = MapList.create_empty_map()
- self.open_map(map)
-
- def delete_clicked (self, button):
- map = self.get_selected_map ()
- if not map:
- raise "You clicked on delete but had no map selected"
- error_message = ""
- if map.window:
- error_message = _("The map cannot be deleted right now. Is it open?")
- elif not map.filename:
- error_message = _("The map has no associated filename.")
- if error_message:
- dialog = gtk.MessageDialog (self, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK,
- _("Cannot delete this map"))
- dialog.format_secondary_text (error_message)
- dialog.run ()
- dialog.hide ()
- del (dialog)
- return
- dialog = gtk.MessageDialog (self, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO,
- _("Do you really want to delete this Map?"))
- resp = dialog.run ()
- dialog.hide ()
- del (dialog)
- if resp != gtk.RESPONSE_YES:
- return
- MapList.delete (map)
- self.view.emit ('cursor-changed')
-
- def remove_map_cb (self, mobj, a):
- map = MapList.get_by_window(mobj)
- if map:
- MapList.delete(map)
- self.view.emit ('cursor-changed')
- return
- raise "Cant remove map of window %s" % mobj
-
- def file_save_cb (self, mobj, new_fname, mobj1):
- map = MapList.get_by_window(mobj)
- if map:
- map.window = None
- map.filename = new_fname
- return
-
- def import_clicked(self, button, other=None, *data):
- chooser = gtk.FileChooserDialog(title=_("Open File"), action=gtk.FILE_CHOOSER_ACTION_OPEN, \
- buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
-
- filtr = gtk.FileFilter ()
- filtr.set_name(_('MAPZ Compressed Map (*.mapz)'))
- filtr.add_pattern('*.mapz')
- chooser.add_filter(filtr)
-
- response = chooser.run()
- if response == gtk.RESPONSE_OK:
- filename = chooser.get_filename()
- tf = tarfile.open(filename)
- mapname = utils.get_save_dir() + tf.getnames()[0]
- tf.extractall(utils.get_save_dir())
- tf.close()
- map = MapList.new_from_file(mapname)
- map.filename = mapname
-
- chooser.destroy()
-
- def quit_clicked (self, button, other=None, *data):
- for map in MapList.get_open_windows():
- map.window.close_window_cb (None)
-
- width, height = self.main_window.get_size()
-
- if os.name != 'nt':
- self.config_client.set_int('/apps/labyrinth/width', width)
- self.config_client.set_int('/apps/labyrinth/height', height)
-
- gtk.main_quit ()
-
- def populate_view (self):
- cellrenderer = gtk.CellRendererText()
- cellrenderer.set_property("ellipsize", pango.ELLIPSIZE_END)
- column = gtk.TreeViewColumn(_("Map Name"), cellrenderer,
- text=self.COL_TITLE)
- column.set_resizable(True)
- column.set_expand (True)
- column.set_sort_column_id (1)
- self.view.append_column(column)
-
- col1 = gtk.TreeViewColumn (_("Last Modified"), gtk.CellRendererText(),
- text=self.COL_MODTIME)
- col1.set_resizable(True)
- col1.set_sort_column_id (2)
- self.view.append_column(col1)
-
- self.view.set_model (MapList.get_TreeViewModel())
- self.view.set_search_column(self.COL_TITLE)
- self.view.set_enable_search (True)
-
- def sort_column_changed_cb (self, data):
- column_id, sort_order = data.get_sort_column_id ()
- if os.name != 'nt':
- self.config_client.set_int('/apps/labyrinth/map_sort_order', sort_order)
- self.config_client.set_int('/apps/labyrinth/map_sort_order_column', column_id)
-
+ COL_ID = 0
+ COL_TITLE = 1
+ COL_MODTIME = 2
+
+ def __init__(self, start_hidden, tray_icon):
+ super(Browser, self).__init__()
+ self.glade=gtk.glade.XML(utils.get_data_file_name('labyrinth.glade'))
+ self.view = self.glade.get_widget ('MainView')
+ self.populate_view ()
+ self.view.connect ('row-activated', self.open_row_cb)
+ self.view.connect ('cursor-changed', self.cursor_change_cb)
+
+ self.view_dependants = []
+
+ self.open_button = self.glade.get_widget('OpenButton')
+ self.delete_button = self.glade.get_widget('DeleteButton')
+ self.open_menu = self.glade.get_widget('open1')
+ self.delete_menu = self.glade.get_widget('delete1')
+
+ self.view_dependants.append (self.open_button)
+ self.view_dependants.append (self.delete_button)
+ self.view_dependants.append (self.open_menu)
+ self.view_dependants.append (self.delete_menu)
+
+ self.open_button.connect ('clicked', self.open_clicked)
+ self.glade.get_widget('NewButton').connect ('clicked', self.new_clicked)
+ self.delete_button.connect ('clicked', self.delete_clicked)
+
+ self.open_menu.connect ('activate', self.open_clicked)
+ self.glade.get_widget('new1').connect ('activate', self.new_clicked)
+ self.delete_menu.connect ('activate', self.delete_clicked)
+ self.glade.get_widget('import1').connect ('activate', self.import_clicked)
+ self.glade.get_widget('quit1').connect ('activate', self.quit_clicked)
+ self.glade.get_widget('about1').connect ('activate', self.about_clicked)
+ self.glade.get_widget('showhelp').connect ('activate', self.show_help_clicked)
+
+ map(lambda x : x.set_sensitive(False), self.view_dependants)
+
+ props = { gnome.PARAM_APP_DATADIR : '/usr/share' }
+ prog = gnome.program_init('labyrinth', '0.5', properties=props)
+
+ self.main_window = self.glade.get_widget ('MapBrowser')
+
+ # set remembered size
+ if os.name != 'nt':
+ self.config_client = gconf.client_get_default()
+ self.config_client.add_dir ("/apps/labyrinth", gconf.CLIENT_PRELOAD_NONE)
+
+ width = self.config_client.get_int ('/apps/labyrinth/width')
+ height = self.config_client.get_int ('/apps/labyrinth/height')
+ utils.use_bezier_curves = self.config_client.get_bool ('/apps/labyrinth/curves')
+ if width == 0 or height == 0:
+ width = 400
+ height = 300
+ else:
+ width = 400
+ height = 300
+
+ view_sortable = self.view.get_model ()
+ view_sortable.connect ('sort-column-changed', self.sort_column_changed_cb)
+ if os.name != 'nt':
+ sort_order = self.config_client.get_int('/apps/labyrinth/map_sort_order')
+ column_id = self.config_client.get_int('/apps/labyrinth/map_sort_order_column')
+ view_sortable.set_sort_column_id (column_id, sort_order)
+
+ self.main_window.resize (width, height)
+
+ if os.name != 'nt':
+ try:
+ self.main_window.set_icon_name ('labyrinth')
+ except:
+ self.main_window.set_icon_from_file(utils.get_data_file_name('labyrinth.svg'))
+ else:
+ self.main_window.set_icon_from_file('images\\labyrinth-24.png')
+ if tray_icon:
+ self.main_window.connect ('delete_event', self.toggle_main_window, None)
+ traymenu = gtk.Menu()
+ quit_item = gtk.MenuItem("Quit")
+ quit_item.connect("activate",self.quit_clicked)
+ traymenu.add(quit_item)
+ traymenu.show_all()
+ self.traymenu = traymenu
+ self.trayicon = TrayIcon.TrayIcon(
+ icon_name="labyrinth",
+ menu=traymenu,
+ activate=self.toggle_main_window)
+ else:
+ self.main_window.connect('delete_event', self.quit_clicked, None)
+ if start_hidden:
+ self.main_window.hide ()
+ else:
+ self.main_window.show_all ()
+
+ def toggle_main_window(self,*args):
+ if self.main_window.get_property("visible"):
+ self.main_window.hide()
+ else:
+ self.main_window.show()
+ return True
+
+ def map_title_cb (self, mobj, new_title, mobj1):
+ map = MapList.get_by_window(mobj)
+ if not map:
+ raise AttributeError ("What a mess, can't find the map")
+ map.title = new_title
+
+ def get_selected_map(self):
+ sel = self.view.get_selection ()
+ (model, it) = sel.get_selected ()
+ if it:
+ (num,) = MapList.tree_view_model.get (it, self.COL_ID)
+ return MapList.get_by_index(num)
+ return None
+
+ def cursor_change_cb (self, treeview):
+ selected_map = self.get_selected_map ()
+ sensitive = not not self.get_selected_map ()
+ map(lambda x : x.set_sensitive(sensitive), self.view_dependants)
+
+ def open_map_filename (self, fname):
+ win = MainWindow.LabyrinthWindow (fname)
+ win.show ()
+
+ def open_map (self, map, imported=False):
+ win = MainWindow.LabyrinthWindow (map.filename, imported)
+ win.connect ("title-changed", self.map_title_cb)
+ win.connect ("window_closed", self.remove_map_cb)
+ win.connect ("file_saved", self.file_save_cb)
+ win.show ()
+ map.window = win
+ return (MapList.index(map), win)
+
+ def open_selected_map(self):
+ map = self.get_selected_map()
+ if map is None:
+ raise "you clicked the 'open' button bud had no map selected"
+ if map.window:
+ print "Window for map '%s' is already open" % map.title
+ # may be the window should be raised?
+ else:
+ self.open_map (map)
+
+ def show_help_clicked(self, arg):
+ try:
+ gnome.help_display('labyrinth')
+ except gobject.GError, e:
+ print _('Unable to display help: %s') % str(e)
+
+ def about_clicked (self, arg):
+ about_dialog = gtk.AboutDialog ()
+ about_dialog.set_name ("Labyrinth")
+ about_dialog.set_version (utils.get_version())
+ if os.name != 'nt':
+ try:
+ about_dialog.set_logo_icon_name("labyrinth")
+ except:
+ pass
+ else:
+ about_dialog.set_logo (gtk.gdk.pixbuf_new_from_file("images\\labyrinth-24.png"))
+ about_dialog.set_license (
+"Labyrinth is free software; you can redistribute it and/or modify "
+"it under the terms of the GNU General Public Licence as published by "
+"the Free Software Foundation; either version 2 of the Licence, or "
+"(at your option) any later version."
+"\n\n"
+"Labyrinth is distributed in the hope that it will be useful, "
+"but WITHOUT ANY WARRANTY; without even the implied warranty of "
+"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
+"GNU General Public Licence for more details."
+"\n\n"
+"You should have received a copy of the GNU General Public Licence "
+"along with Labyrinth; if not, write to the Free Software Foundation, Inc., "
+"59 Temple Place, Suite 330, Boston, MA 02111-1307 USA")
+ about_dialog.set_wrap_license (True)
+ about_dialog.set_copyright ("2006-2008 Don Scorgie et. al")
+ about_dialog.set_authors (AUTHORS)
+ about_dialog.set_website ("http://code.google.com/p/labyrinth")
+ about_dialog.set_translator_credits (_("Translation by Don Scorgie"))
+ about_dialog.run ()
+ about_dialog.hide ()
+ del (about_dialog)
+ return
+
+ def open_clicked (self, button):
+ self.open_selected_map()
+
+ def open_row_cb (self, view, path, col):
+ self.open_selected_map ()
+
+ def new_clicked (self, button):
+ map = MapList.create_empty_map()
+ self.open_map(map)
+
+ def delete_clicked (self, button):
+ map = self.get_selected_map ()
+ if not map:
+ raise "You clicked on delete but had no map selected"
+ error_message = ""
+ if map.window:
+ error_message = _("The map cannot be deleted right now. Is it open?")
+ elif not map.filename:
+ error_message = _("The map has no associated filename.")
+ if error_message:
+ dialog = gtk.MessageDialog (self, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK,
+ _("Cannot delete this map"))
+ dialog.format_secondary_text (error_message)
+ dialog.run ()
+ dialog.hide ()
+ del (dialog)
+ return
+ dialog = gtk.MessageDialog (self, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO,
+ _("Do you really want to delete this Map?"))
+ resp = dialog.run ()
+ dialog.hide ()
+ del (dialog)
+ if resp != gtk.RESPONSE_YES:
+ return
+ MapList.delete (map)
+ self.view.emit ('cursor-changed')
+
+ def remove_map_cb (self, mobj, a):
+ map = MapList.get_by_window(mobj)
+ if map:
+ MapList.delete(map)
+ self.view.emit ('cursor-changed')
+ return
+ raise "Cant remove map of window %s" % mobj
+
+ def file_save_cb (self, mobj, new_fname, mobj1):
+ map = MapList.get_by_window(mobj)
+ if map:
+ map.window = None
+ map.filename = new_fname
+ return
+
+ def import_clicked(self, button, other=None, *data):
+ chooser = gtk.FileChooserDialog(title=_("Open File"), action=gtk.FILE_CHOOSER_ACTION_OPEN, \
+ buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
+
+ filtr = gtk.FileFilter ()
+ filtr.set_name(_('MAPZ Compressed Map (*.mapz)'))
+ filtr.add_pattern('*.mapz')
+ chooser.add_filter(filtr)
+
+ response = chooser.run()
+ if response == gtk.RESPONSE_OK:
+ filename = chooser.get_filename()
+ tf = tarfile.open(filename)
+ mapname = utils.get_save_dir() + tf.getnames()[0]
+ tf.extractall(utils.get_save_dir())
+ tf.close()
+ map = MapList.new_from_file(mapname)
+ map.filename = mapname
+
+ chooser.destroy()
+
+ def quit_clicked (self, button, other=None, *data):
+ for map in MapList.get_open_windows():
+ map.window.close_window_cb (None)
+
+ width, height = self.main_window.get_size()
+
+ if os.name != 'nt':
+ self.config_client.set_int('/apps/labyrinth/width', width)
+ self.config_client.set_int('/apps/labyrinth/height', height)
+
+ gtk.main_quit ()
+
+ def populate_view (self):
+ cellrenderer = gtk.CellRendererText()
+ cellrenderer.set_property("ellipsize", pango.ELLIPSIZE_END)
+ column = gtk.TreeViewColumn(_("Map Name"), cellrenderer,
+ text=self.COL_TITLE)
+ column.set_resizable(True)
+ column.set_expand (True)
+ column.set_sort_column_id (1)
+ self.view.append_column(column)
+
+ col1 = gtk.TreeViewColumn (_("Last Modified"), gtk.CellRendererText(),
+ text=self.COL_MODTIME)
+ col1.set_resizable(True)
+ col1.set_sort_column_id (2)
+ self.view.append_column(col1)
+
+ self.view.set_model (MapList.get_TreeViewModel())
+ self.view.set_search_column(self.COL_TITLE)
+ self.view.set_enable_search (True)
+
+ def sort_column_changed_cb (self, data):
+ column_id, sort_order = data.get_sort_column_id ()
+ if os.name != 'nt':
+ self.config_client.set_int('/apps/labyrinth/map_sort_order', sort_order)
+ self.config_client.set_int('/apps/labyrinth/map_sort_order_column', column_id)
View
1,146 src/DrawingThought.py
@@ -44,576 +44,576 @@
UNDO_ERASE = 2
class DrawingThought (BaseThought.ResizableThought):
- class DrawingPoint (object):
- def __init__ (self, coords, style=STYLE_CONTINUE, color = gtk.gdk.Color(0,0,0), width = 2):
- self.x, self.y = coords
- self.style = style
- if color == None:
- color = gtk.gdk.Color(0,0,0)
- self.color = color
- self.width = 1
- def move_by (self, x, y):
- self.x += x
- self.y += y
-
- def __init__ (self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color):
- global ndraw
- super (DrawingThought, self).__init__(save, "drawing_thought", undo, background_color, foreground_color)
- ndraw+=1
- self.identity = thought_number
- self.want_move = False
- self.points = []
- self.text = _("Drawing #%d" % ndraw)
- self.drawing = 0
- if not loading:
- margin = utils.margin_required (utils.STYLE_NORMAL)
- self.ul = (coords[0]-margin[0], coords[1]-margin[1])
- self.lr = (coords[0]+100+margin[2], coords[1]+100+margin[3])
- self.min_x = coords[0]+90
- self.max_x = coords[0]+15
- self.min_y = coords[1]+90
- self.max_y = coords[1]+15
- self.width = 100
- self.height = 100
-
- self.all_okay = True
-
- def draw (self, context):
- if len (self.extended_buffer.get_text()) == 0:
- utils.draw_thought_outline (context, self.ul, self.lr, self.background_color, self.am_selected, self.am_primary, utils.STYLE_NORMAL)
- else:
- utils.draw_thought_outline (context, self.ul, self.lr, self.background_color, self.am_selected, self.am_primary, utils.STYLE_EXTENDED_CONTENT)
- cwidth = context.get_line_width ()
- context.set_line_width (2)
- if len (self.points) > 0:
- for p in self.points:
- if p.style == STYLE_BEGIN:
- context.move_to (p.x, p.y)
- r,g,b = utils.gtk_to_cairo_color(self.foreground_color)
- context.set_source_rgb (r, g, b)
- elif p.style == STYLE_END:
- context.line_to (p.x, p.y)
- context.stroke()
- else:
- context.line_to (p.x, p.y)
-
- context.set_line_width (cwidth)
- context.stroke ()
- return
-
- def want_motion (self):
- return self.want_move
-
- def recalc_edges (self):
- self.lr = (self.ul[0]+self.width, self.ul[1]+self.height)
-
- def undo_resize (self, action, mode):
- self.undo.block ()
- choose = 1
- if mode == UndoManager.UNDO:
- choose = 0
- self.ul = action.args[choose][0]
- self.width = action.args[choose][1]
- self.height = action.args[choose][2]
- self.recalc_edges ()
- self.emit ("update_links")
- self.emit ("update_view")
- self.undo.unblock ()
-
- def undo_drawing (self, action, mode):
- self.undo.block ()
- if mode == UndoManager.UNDO:
- choose = 1
- for p in action.args[0]:
- self.points.remove (p)
- else:
- choose = 2
- for p in action.args[0]:
- self.points.append (p)
-
- self.ul = action.args[choose][0]
- self.width = action.args[choose][1]
- self.height = action.args[choose][2]
- self.recalc_edges ()
- self.emit ("update_links")
- self.emit ("update_view")
- self.undo.unblock ()
-
- def process_button_down (self, event, mode, transformed):
- modifiers = gtk.accelerator_get_default_mod_mask ()
- self.button_down = True
- if event.button == 1:
- if event.type == gtk.gdk.BUTTON_PRESS:
- self.emit ("select_thought", event.state & modifiers)
- self.emit ("update_view")
- if mode == MODE_EDITING and self.resizing != self.RESIZE_NONE:
- self.want_move = True
- self.drawing = 0
- self.orig_size = (self.ul, self.width, self.height)
- return True
- elif mode == MODE_DRAW:
- self.want_move = True
- self.drawing = 2
- if not event.state & gtk.gdk.SHIFT_MASK:
- self.drawing = 1
- self.orig_size = (self.ul, self.width, self.height)
- self.ins_points = []
- self.del_points = []
- return True
- elif event.button == 3:
- self.emit ("popup_requested", event, 1)
- self.emit ("update_view")
-
- def process_button_release (self, event, unending_link, mode, transformed):
- self.button_down = False
- if unending_link:
- unending_link.set_child (self)
- self.emit ("claim_unending_link")
- if len(self.points) > 0:
- self.points[-1].style=STYLE_END
- self.emit ("update_view")
- if self.want_move and self.drawing == 0:
- self.undo.add_undo (UndoManager.UndoAction (self, UNDO_RESIZE, self.undo_resize, \
- self.orig_size, (self.ul, self.width, self.height)))
- elif self.want_move and self.drawing == 1:
- self.undo.add_undo (UndoManager.UndoAction (self, UNDO_DRAW, self.undo_drawing, \
- self.ins_points, self.orig_size, \
- (self.ul, self.width, self.height)))
- elif self.want_move and self.drawing == 2:
- self.undo.add_undo (UndoManager.UndoAction (self, UNDO_ERASE, self.undo_erase, \
- self.ins_points))
- self.drawing = 0
- self.want_move = False
-
- def undo_erase (self, action, mode):
- self.undo.block ()
- action.args[0].reverse ()
- if mode == UndoManager.UNDO:
- for x in action.args[0]:
- if x[0] == 0:
- self.points.remove (x[2])
- else:
- self.points.insert (x[1],x[2])
- else:
- for x in action.args[0]:
- if x[0] == 0:
- self.points.insert (x[1], x[2])
- else:
- self.points.remove (x[2])
- self.undo.unblock ()
- self.emit ("update_view")
-
- def handle_motion (self, event, mode, transformed):
- if (self.resizing == self.RESIZE_NONE or not self.want_move or not event.state & gtk.gdk.BUTTON1_MASK) \
- and mode != MODE_DRAW:
- if not event.state & gtk.gdk.BUTTON1_MASK or mode != MODE_EDITING:
- return False
- else:
- self.emit ("create_link", \
- (self.ul[0]-((self.ul[0]-self.lr[0]) / 2.), self.ul[1]-((self.ul[1]-self.lr[1]) / 2.)))
- diffx = transformed[0] - self.motion_coords[0]
- diffy = transformed[1] - self.motion_coords[1]
- change = (len(self.points) == 0)
- tmp = self.motion_coords
- self.motion_coords = transformed
- if self.resizing != self.RESIZE_NONE:
- if self.resizing == self.RESIZE_LEFT:
- if self.ul[0] + diffx > self.min_x:
- self.motion_coords = tmp
- return True
- self.ul = (self.ul[0]+diffx, self.ul[1])
- if change:
- self.max_x += diffx
- elif self.resizing == self.RESIZE_RIGHT:
- if self.lr[0] + diffx < self.max_x:
- self.motion_coords = tmp
- return True
- self.lr = (self.lr[0]+diffx, self.lr[1])
- if change:
- self.min_x += diffx
- elif self.resizing == self.RESIZE_TOP:
- if self.ul[1] + diffy > self.min_y:
- self.motion_coords = tmp
- return True
- self.ul = (self.ul[0], self.ul[1]+diffy)
- if change:
- self.max_y += diffy
- elif self.resizing == self.RESIZE_BOTTOM:
- if self.lr[1] + diffy < self.max_y:
- self.motion_coords = tmp
- return True
- self.lr = (self.lr[0], self.lr[1]+diffy)
- if change:
- self.min_y += diffy
- elif self.resizing == self.RESIZE_UL:
- if self.ul[1] + diffy > self.min_y or self.ul[0] + diffx > self.min_x:
- self.motion_coords = tmp
- return True
- self.ul = (self.ul[0]+diffx, self.ul[1]+diffy)
- if change:
- self.max_x += diffx
- self.max_y += diffy
- elif self.resizing == self.RESIZE_UR:
- if self.ul[1] + diffy > self.min_y or self.lr[0] + diffx < self.max_x:
- self.motion_coords = tmp
- return True
- self.ul = (self.ul[0], self.ul[1]+diffy)
- self.lr = (self.lr[0]+diffx, self.lr[1])
- if change:
- self.min_x += diffx
- self.max_y += diffy
- elif self.resizing == self.RESIZE_LL:
- if self.lr[1] + diffy < self.max_y or self.ul[0] + diffx > self.min_x:
- self.motion_coords = tmp
- return True
- self.ul = (self.ul[0]+diffx, self.ul[1])
- self.lr = (self.lr[0], self.lr[1]+diffy)
- if change:
- self.max_x += diffx
- self.min_y += diffy
- elif self.resizing == self.RESIZE_LR:
- if self.lr[1] + diffy < self.max_y:
- self.motion_coords = tmp
- return True
- if self.lr[0] + diffx < self.max_x:
- self.motion_coords = tmp
- return True
- self.lr = (self.lr[0]+diffx, self.lr[1]+diffy)
- if change:
- self.min_x += diffx
- self.min_y += diffy
- self.width = self.lr[0] - self.ul[0]
- self.height = self.lr[1] - self.ul[1]
- self.emit ("update_links")
- self.emit ("update_view")
- return True
-
- elif self.drawing == 1:
- if transformed[0] < self.ul[0]+5:
- self.ul = (transformed[0]-5, self.ul[1])
- elif transformed[0] > self.lr[0]-5:
- self.lr = (transformed[0]+5, self.lr[1])
- if transformed[1] < self.ul[1]+5:
- self.ul = (self.ul[0], transformed[1]-5)
- elif transformed[1] > self.lr[1]-5:
- self.lr = (self.lr[0], transformed[1]+5)
-
- if transformed[0] < self.min_x:
- self.min_x = transformed[0]-10
- elif transformed[0] > self.max_x:
- self.max_x = transformed[0]+5
- if transformed[1] < self.min_y:
- self.min_y = transformed[1]-10
- elif transformed[1] > self.max_y:
- self.max_y = transformed[1]+5
- self.width = self.lr[0] - self.ul[0]
- self.height = self.lr[1] - self.ul[1]
- if len(self.points) == 0 or self.points[-1].style == STYLE_END:
- p = self.DrawingPoint (transformed, STYLE_BEGIN, self.foreground_color)
- else:
- p = self.DrawingPoint (transformed, STYLE_CONTINUE)
- self.points.append (p)
- self.ins_points.append (p)
- elif self.drawing == 2 and len (self.points) > 0:
- out = self.points[0]
- loc = []
- handle = []
- ins_point = -1
-
- for x in self.points:
- ins_point += 1
- dist = (x.x - transformed[0])**2 + (x.y - transformed[1])**2
-
- if dist < 16:
- if x == self.points[0]:
- out = None
- loc.append ((ins_point, x, dist))
- else:
- if len(loc) != 0:
- handle.append ((loc, out, x))
- loc = []
- elif x.style != STYLE_BEGIN:
- x1 = x.x - out.x
- y1 = x.y - out.y
- d_rsqr = x1**2 + y1 **2
- d = ((out.x-transformed[0])*(x.y-transformed[1]) - (x.x-transformed[0])*(out.y-transformed[1]))
- det = (d_rsqr*16) - d**2
- if det > 0:
- xt = -99999
- yt = -99999
- xalt = -99999
- yalt = -99999
- if y1 < 0:
- sgn = -1
- else:
- sgn = 1
- xt = (((d*y1) + sgn*x1 * math.sqrt (det)) / d_rsqr) +transformed[0]
- xalt = (((d*y1) - sgn*x1 * math.sqrt (det)) / d_rsqr) +transformed[0]
- yt = (((-d*x1) + abs(y1)*math.sqrt(det)) / d_rsqr) + transformed[1]
- yalt = (((-d*x1) - abs(y1)*math.sqrt(det)) / d_rsqr) +transformed[1]
- x1_inside = (xt > x.x and xt < out.x) or (xt > out.x and xt < x.x)
- x2_inside = (xalt > x.x and xalt < out.x) or (xalt > out.x and xalt < x.x)
- y1_inside = (yt > x.y and yt < out.y) or (yt > out.y and yt < x.y)
- y2_inside = (yalt > x.y and yalt < out.y) or (yalt > out.y and yalt < x.y)
-
-
- if (x1_inside and x2_inside and y1_inside and y2_inside):
- if abs (xalt - x.x) < abs (xt - x.x):
- handle.append ((None, out, x, ins_point, xt, xalt, yt, yalt))
- else:
- handle.append ((None, out, x, ins_point, xalt, xt, yalt, yt))
- elif x.x == out.x and y1_inside and y2_inside:
- if abs (yalt - x.y) < abs (yt - x.y):
- handle.append ((None, out, x, ins_point, xt, xalt, yt, yalt))
- else:
- handle.append ((None, out, x, ins_point, xalt, xt, yalt, yt))
- elif x.y == out.y and x1_inside and x2_inside:
- if abs (xalt - x.x) < abs (xt - x.x):
- handle.append ((None, out, x, ins_point, xt, xalt, yt, yalt))
- else:
- handle.append ((None, out, x, ins_point, xalt, xt, yalt, yt))
-
- out = x
- if loc:
- handle.append ((loc, out, None))
- appends = []
- dels = []
- for l in handle:
- inside = l[0]
- prev = l[1]
- next = l[2]
- if not inside:
- ins = l[3]
- x1 = l[4]
- x2 = l[5]
- y1 = l[6]
- y2 = l[7]
- p1 = self.DrawingPoint ((x1,y1), STYLE_END)
- p2 = self.DrawingPoint ((x2,y2), STYLE_BEGIN)
- appends.append ((p1, ins))
- appends.append ((p2, ins))
- else:
- first = inside[0][1]
- last = inside[-1][1]
- done_ins = 0
- if last.style != STYLE_END:
- end_dist = math.sqrt (inside[-1][2]) - 4
- alpha = math.atan2 ((last.y-next.y), (last.x-next.x))
- new_x = end_dist * math.cos(alpha) + last.x
- new_y = end_dist * math.sin(alpha) + last.y
- p = self.DrawingPoint ((new_x, new_y), STYLE_BEGIN)
- appends.append ((p, inside[-1][0]))
- done_ins = 1
- if first.style != STYLE_BEGIN:
- start_dist = math.sqrt (inside[0][2]) - 4
- alpha = math.atan2 ((first.y-prev.y),(first.x-prev.x))
- new_x = start_dist * math.cos (alpha) + first.x
- new_y = start_dist * math.sin (alpha) + first.y
- p = self.DrawingPoint ((new_x, new_y), STYLE_END)
- appends.append ((p, inside[0][0]-done_ins))
- for i in inside:
- dels.append (i[1])
- inserts = 0
- for x in appends:
- self.points.insert (x[1]+inserts, x[0])
- self.ins_points.append ((0, x[1]+inserts, x[0]))
- inserts+=1
- for x in dels:
- self.ins_points.append ((1, self.points.index (x), x))
- self.points.remove (x)
-
- self.emit ("update_links")
- self.emit ("update_view")
- return True
-
- def move_by (self, x, y):
- self.ul = (self.ul[0]+x, self.ul[1]+y)
- self.min_x += x
- self.min_y += y
- self.max_x += x
- self.max_y += y
- map(lambda p : p.move_by(x,y), self.points)
- self.recalc_edges ()
- self.emit ("update_links")
-
- def update_save (self):
- next = self.element.firstChild
- while next:
- m = next.nextSibling
- if next.nodeName == "point":
- self.element.removeChild (next)
- next.unlink ()
- next = m
- text = self.extended_buffer.get_text ()
- if text:
- self.extended_buffer.update_save()
- else:
- try:
- self.element.removeChild(self.extended_buffer.element)
- except xml.dom.NotFoundErr:
- pass
- self.element.setAttribute ("ul-coords", str(self.ul))
- self.element.setAttribute ("lr-coords", str(self.lr))
- self.element.setAttribute ("identity", str(self.identity))
- self.element.setAttribute ("background-color", self.background_color.to_string())
- self.element.setAttribute ("foreground-color", self.foreground_color.to_string())
- self.element.setAttribute ("min_x", str(self.min_x))
- self.element.setAttribute ("min_y", str(self.min_y))
- self.element.setAttribute ("max_x", str(self.max_x))
- self.element.setAttribute ("max_y", str(self.max_y))
-
- if self.am_selected:
- self.element.setAttribute ("current_root", "true")
- else:
- try:
- self.element.removeAttribute ("current_root")
- except xml.dom.NotFoundErr:
- pass
- if self.am_primary:
- self.element.setAttribute ("primary_root", "true");
- else:
- try:
- self.element.removeAttribute ("primary_root")
- except xml.dom.NotFoundErr:
- pass
- doc = self.element.ownerDocument
- for p in self.points:
- elem = doc.createElement ("point")
- self.element.appendChild (elem)
- elem.setAttribute ("coords", str((p.x,p.y)))
- elem.setAttribute ("type", str(p.style))
- elem.setAttribute ("color", p.color.to_string())
- return
-
- def load (self, node):
- tmp = node.getAttribute ("ul-coords")
- self.ul = utils.parse_coords (tmp)
- tmp = node.getAttribute ("lr-coords")
- self.lr = utils.parse_coords (tmp)
- self.identity = int (node.getAttribute ("identity"))
- try:
- tmp = node.getAttribute ("background-color")
- self.background_color = gtk.gdk.color_parse(tmp)
- tmp = node.getAttribute ("foreground-color")
- self.foreground_color = gtk.gdk.color_parse(tmp)
- except ValueError:
- pass
- self.min_x = float(node.getAttribute ("min_x"))
- self.min_y = float(node.getAttribute ("min_y"))
- self.max_x = float(node.getAttribute ("max_x"))
- self.max_y = float(node.getAttribute ("max_y"))
-
- self.width = self.lr[0] - self.ul[0]
- self.height = self.lr[1] - self.ul[1]
-
- self.am_selected = node.hasAttribute ("current_root")
- self.am_primary = node.hasAttribute ("primary_root")
-
- for n in node.childNodes:
- if n.nodeName == "Extended":
- self.extended_buffer.load(n)
- elif n.nodeName == "point":
- style = int (n.getAttribute ("type"))
- tmp = n.getAttribute ("coords")
- c = utils.parse_coords (tmp)
- col = None
- try:
- tmp = n.getAttribute ("color")
- col = gtk.gdk.color_parse (tmp)
- except ValueError:
- pass
- self.points.append (self.DrawingPoint (c, style, col))
- else:
- print "Unknown node type: "+str(n.nodeName)
-
- def export (self, context, move_x, move_y):
- utils.export_thought_outline (context, self.ul, self.lr, self.background_color, self.am_selected, self.am_primary, utils.STYLE_NORMAL,
- (move_x, move_y))
- cwidth = context.get_line_width ()
- context.set_line_width (1)
- if len (self.points) > 0:
- for p in self.points:
- if p.style == STYLE_BEGIN:
- context.move_to (p.x+move_x, p.y+move_y)
- else:
- context.line_to (p.x+move_x,p.y+move_y)
-
- context.set_line_width (cwidth)
- r,g,b = utils.gtk_to_cairo_color(self.foreground_color)
- context.set_source_rgb (r, g, b)
- context.stroke ()
- return
-
- def includes (self, coords, mode):
- if not self.ul or not self.lr or not coords:
- return False
-
- if self.want_move and mode == MODE_DRAW:
- self.emit ("change_mouse_cursor", gtk.gdk.PENCIL)
- return True
-
- inside = (coords[0] < self.lr[0] + self.sensitive) and \
- (coords[0] > self.ul[0] - self.sensitive) and \
- (coords[1] < self.lr[1] + self.sensitive) and \
- (coords[1] > self.ul[1] - self.sensitive)
-
- self.resizing = self.RESIZE_NONE
- self.motion_coords = coords
-
- if inside and (mode != MODE_EDITING or self.button_down):
- if mode == MODE_DRAW:
- self.emit ("change_mouse_cursor", gtk.gdk.PENCIL)
- else:
- self.emit ("change_mouse_cursor", gtk.gdk.LEFT_PTR)
- return inside
-
- if inside:
- # 2 cases: 1. The click was within the main area
- # 2. The click was near the border
- # In the first case, we handle as normal
- # In the second case, we want to intercept all the fun thats
- # going to happen so we can resize the thought
- if abs (coords[0] - self.ul[0]) < self.sensitive:
- # its near the top edge somewhere
- if abs (coords[1] - self.ul[1]) < self.sensitive:
- # Its in the ul corner
- self.resizing = self.RESIZE_UL
- self.emit ("change_mouse_cursor", gtk.gdk.TOP_LEFT_CORNER)
- elif abs (coords[1] - self.lr[1]) < self.sensitive:
- # Its in the ll corner
- self.resizing = self.RESIZE_LL
- self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_LEFT_CORNER)
- elif coords[1] < self.lr[1] and coords[1] > self.ul[1]:
- #anywhere else along the left edge
- self.resizing = self.RESIZE_LEFT
- self.emit ("change_mouse_cursor", gtk.gdk.LEFT_SIDE)
- elif abs (coords[0] - self.lr[0]) < self.sensitive:
- if abs (coords[1] - self.ul[1]) < self.sensitive:
- # Its in the UR corner
- self.resizing = self.RESIZE_UR
- self.emit ("change_mouse_cursor", gtk.gdk.TOP_RIGHT_CORNER)
- elif abs (coords[1] - self.lr[1]) < self.sensitive:
- # Its in the lr corner
- self.resizing = self.RESIZE_LR
- self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_RIGHT_CORNER)
- elif coords[1] < self.lr[1] and coords[1] > self.ul[1]:
- #anywhere else along the right edge
- self.resizing = self.RESIZE_RIGHT
- self.emit ("change_mouse_cursor", gtk.gdk.RIGHT_SIDE)
- elif abs (coords[1] - self.ul[1]) < self.sensitive and \
- (coords[0] < self.lr[0] and coords[0] > self.ul[0]):
- # Along the top edge somewhere
- self.resizing = self.RESIZE_TOP
- self.emit ("change_mouse_cursor", gtk.gdk.TOP_SIDE)
- elif abs (coords[1] - self.lr[1]) < self.sensitive and \
- (coords[0] < self.lr[0] and coords[0] > self.ul[0]):
- # Along the bottom edge somewhere
- self.resizing = self.RESIZE_BOTTOM
- self.emit ("change_mouse_cursor", gtk.gdk.BOTTOM_SIDE)
- else:
- self.emit ("change_mouse_cursor", gtk.gdk.LEFT_PTR)
- self.want_move = (self.resizing != self.RESIZE_NONE)
- return inside
-
- def get_popup_menu_items(self):
- return []
+ class DrawingPoint (object):
+ def __init__ (self, coords, style=STYLE_CONTINUE, color = gtk.gdk.Color(0,0,0), width = 2):
+ self.x, self.y = coords
+ self.style = style
+ if color == None:
+ color = gtk.gdk.Color(0,0,0)
+ self.color = color
+ self.width = 1
+ def move_by (self, x, y):
+ self.x += x
+ self.y += y
+
+ def __init__ (self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color):
+ global ndraw
+ super (DrawingThought, self).__init__(save, "drawing_thought", undo, background_color, foreground_color)
+ ndraw+=1
+ self.identity = thought_number
+ self.want_move = False
+ self.points = []
+ self.text = _("Drawing #%d" % ndraw)
+ self.drawing = 0
+ if not loading:
+ margin = utils.margin_required (utils.STYLE_NORMAL)
+ self.ul = (coords[0]-margin[0], coords[1]-margin[1])
+ self.lr = (coords[0]+100+margin[2], coords[1]+100+margin[3])
+ self.min_x = coords[0]+90
+ self.max_x = coords[0]+15
+ self.min_y = coords[1]+90
+ self.max_y = coords[1]+15
+ self.width = 100
+ self.height = 100
+
+ self.all_okay = True
+
+ def draw (self, context):
+ if len (self.extended_buffer.get_text()) == 0:
+ utils.draw_thought_outline (context, self.ul, self.lr, self.background_color, self.am_selected, self.am_primary, utils.STYLE_NORMAL)
+ else:
+ utils.draw_thought_outline (context, self.ul, self.lr, self.background_color, self.am_selected, self.am_primary, utils.STYLE_EXTENDED_CONTENT)
+ cwidth = context.get_line_width ()
+ context.set_line_width (2)
+ if len (self.points) > 0:
+ for p in self.points:
+ if p.style == STYLE_BEGIN:
+ context.move_to (p.x, p.y)
+ r,g,b = utils.gtk_to_cairo_color(self.foreground_color)
+ context.set_source_rgb (r, g, b)
+ elif p.style == STYLE_END:
+ context.line_to (p.x, p.y)
+ context.stroke()
+ else:
+ context.line_to (p.x, p.y)
+
+ context.set_line_width (cwidth)
+ context.stroke ()
+ return
+
+ def want_motion (self):
+ return self.want_move
+
+ def recalc_edges (self):
+ self.lr = (self.ul[0]+self.width, self.ul[1]+self.height)
+
+ def undo_resize (self, action, mode):
+ self.undo.block ()
+ choose = 1
+ if mode == UndoManager.UNDO:
+ choose = 0
+ self.ul = action.args[choose][0]
+ self.width = action.args[choose][1]
+ self.height = action.args[choose][2]
+ self.recalc_edges ()
+ self.emit ("update_links")
+ self.emit ("update_view")
+ self.undo.unblock ()
+
+ def undo_drawing (self, action, mode):
+ self.undo.block ()
+ if mode == UndoManager.UNDO:
+ choose = 1
+ for p in action.args[0]:
+ self.points.remove (p)
+ else:
+ choose = 2
+ for p in action.args[0]:
+ self.points.append (p)
+
+ self.ul = action.args[choose][0]
+ self.width = action.args[choose][1]
+ self.height = action.args[choose][2]
+ self.recalc_edges ()
+ self.emit ("update_links")
+ self.emit ("update_view")
+ self.undo.unblock ()
+
+ def process_button_down (self, event, mode, transformed):
+ modifiers = gtk.accelerator_get_default_mod_mask ()
+ self.button_down = True
+ if event.button == 1:
+ if event.type == gtk.gdk.BUTTON_PRESS:
+ self.emit ("select_thought", event.state & modifiers)
+ self.emit ("update_view")
+ if mode == MODE_EDITING and self.resizing != self.RESIZE_NONE:
+ self.want_move = True
+ self.drawing = 0
+ self.orig_size = (self.ul, self.width, self.height)
+ return True
+ elif mode == MODE_DRAW:
+ self.want_move = True
+ self.drawing = 2
+ if not event.state & gtk.gdk.SHIFT_MASK:
+ self.drawing = 1
+ self.orig_size = (self.ul, self.width, self.height)
+ self.ins_points = []
+ self.del_points = []
+ return True
+ elif event.button == 3:
+ self.emit ("popup_requested", event, 1)
+ self.emit ("update_view")
+
+ def process_button_release (self, event, unending_link, mode, transformed):
+ self.button_down = False
+ if unending_link:
+ unending_link.set_child (self)
+ self.emit ("claim_unending_link")
+ if len(self.points) > 0:
+ self.points[-1].style=STYLE_END
+ self.emit ("update_view")
+ if self.want_move and self.drawing == 0:
+ self.undo.add_undo (UndoManager.UndoAction (self, UNDO_RESIZE, self.undo_resize, \
+ self.orig_size, (self.ul, self.width, self.height)))
+ elif self.want_move and self.drawing == 1:
+ self.undo.add_undo (UndoManager.UndoAction (self, UNDO_DRAW, self.undo_drawing, \
+ self.ins_points, self.orig_size, \
+ (self.ul, self.width, self.height)))
+ elif self.want_move and self.drawing == 2:
+ self.undo.add_undo (UndoManager.UndoAction (self, UNDO_ERASE, self.undo_erase, \
+ self.ins_points))
+ self.drawing = 0
+ self.want_move = False
+
+ def undo_erase (self, action, mode):
+ self.undo.block ()
+ action.args[0].reverse ()
+ if mode == UndoManager.UNDO:
+ for x in action.args[0]:
+ if x[0] == 0:
+ self.points.remove (x[2])
+ else:
+ self.points.insert (x[1],x[2])
+ else:
+ for x in action.args[0]:
+ if x[0] == 0:
+ self.points.insert (x[1], x[2])
+ else:
+ self.points.remove (x[2])
+ self.undo.unblock ()
+ self.emit ("update_view")
+
+ def handle_motion (self, event, mode, transformed):
+ if (self.resizing == self.RESIZE_NONE or not self.want_move or not event.state & gtk.gdk.BUTTON1_MASK) \
+ and mode != MODE_DRAW:
+ if not event.state & gtk.gdk.BUTTON1_MASK or mode != MODE_EDITING:
+ return False
+ else:
+ self.emit ("create_link", \
+ (self.ul[0]-((self.ul[0]-self.lr[0]) / 2.), self.ul[1]-((self.ul[1]-self.lr[1]) / 2.)))
+ diffx = transformed[0] - self.motion_coords[0]
+ diffy = transformed[1] - self.motion_coords[1]
+ change = (len(self.points) == 0)
+ tmp = self.motion_coords
+ self.motion_coords = transformed
+ if self.resizing != self.RESIZE_NONE:
+ if self.resizing == self.RESIZE_LEFT:
+ if self.ul[0] + diffx > self.min_x:
+ self.motion_coords = tmp
+ return True
+ self.ul = (self.ul[0]+diffx, self.ul[1])
+ if change:
+ self.max_x += diffx
+ elif self.resizing == self.RESIZE_RIGHT:
+ if self.lr[0] + diffx < self.max_x:
+ self.motion_coords = tmp
+ return True
+ self.lr = (self.lr[0]+diffx, self.lr[1])
+ if change:
+ self.min_x += diffx
+ elif self.resizing == self.RESIZE_TOP:
+ if self.ul[1] + diffy > self.min_y:
+ self.motion_coords = tmp
+ return True
+ self.ul = (self.ul[0], self.ul[1]+diffy)
+ if change:
+ self.max_y += diffy
+ elif self.resizing == self.RESIZE_BOTTOM:
+ if self.lr[1] + diffy < self.max_y:
+ self.motion_coords = tmp
+ return True
+ self.lr = (self.lr[0], self.lr[1]+diffy)
+ if change:
+ self.min_y += diffy
+ elif self.resizing == self.RESIZE_UL:
+ if self.ul[1] + diffy > self.min_y or self.ul[0] + diffx > self.min_x:
+ self.motion_coords = tmp
+ return True
+ self.ul = (self.ul[0]+diffx, self.ul[1]+diffy)
+ if change:
+ self.max_x += diffx
+ self.max_y += diffy
+ elif self.resizing == self.RESIZE_UR:
+ if self.ul[1] + diffy > self.min_y or self.lr[0] + diffx < self.max_x:
+ self.motion_coords = tmp
+ return True
+ self.ul = (self.ul[0], self.ul[1]+diffy)
+ self.lr = (self.lr[0]+diffx, self.lr[1])
+ if change:
+ self.min_x += diffx
+ self.max_y += diffy
+ elif self.resizing == self.RESIZE_LL:
+ if self.lr[1] + diffy < self.max_y or self.ul[0] + diffx > self.min_x:
+ self.motion_coords = tmp
+ return True
+ self.ul = (self.ul[0]+diffx, self.ul[1])
+ self.lr = (self.lr[0], self.lr[1]+diffy)
+ if change:
+ self.max_x += diffx
+ self.min_y += diffy
+ elif self.resizing == self.RESIZE_LR:
+ if self.lr[1] + diffy < self.max_y:
+ self.motion_coords = tmp
+ return True
+ if self.lr[0] + diffx < self.max_x:
+ self.motion_coords = tmp
+ return True
+ self.lr = (self.lr[0]+diffx, self.lr[1]+diffy)
+ if change:
+ self.min_x += diffx
+ self.min_y += diffy
+ self.width = self.lr[0] - self.ul[0]
+ self.height = self.lr[1] - self.ul[1]
+ self.emit ("update_links")
+ self.emit ("update_view")
+ return True
+
+ elif self.drawing == 1:
+ if transformed[0] < self.ul[0]+5:
+ self.ul = (transformed[0]-5, self.ul[1])
+ elif transformed[0] > self.lr[0]-5:
+ self.lr = (transformed[0]+5, self.lr[1])
+ if transformed[1] < self.ul[1]+5:
+ self.ul = (self.ul[0], transformed[1]-5)
+ elif transformed[1] > self.lr[1]-5:
+ self.lr = (self.lr[0], transformed[1]