~ubuntu-branches/ubuntu/saucy/wxwidgets2.8/saucy-proposed

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/util.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
"""
13
13
 
14
14
__author__ = "Cody Precord <cprecord@editra.org>"
15
 
__svnid__ = "$Id: util.py 64250 2010-05-08 16:00:52Z CJP $"
16
 
__revision__ = "$Revision: 64250 $"
 
15
__svnid__ = "$Id: util.py 67367 2011-03-31 19:27:05Z CJP $"
 
16
__revision__ = "$Revision: 67367 $"
17
17
 
18
18
#--------------------------------------------------------------------------#
19
19
# Imports
48
48
        @param window: window to recieve drop objects
49
49
 
50
50
        """
51
 
        wx.PyDropTarget.__init__(self)
 
51
        super(DropTargetFT, self).__init__()
52
52
 
53
53
        # Attributes
54
54
        self.window = window
78
78
                longest = ext
79
79
 
80
80
        cords = [ (0, x * longest[1]) for x in xrange(len(txt)) ]
81
 
        mdc = wx.MemoryDC(wx.EmptyBitmap(longest[0] + 5,
82
 
                                         longest[1] * len(txt), 32))
83
 
        mdc.SetBackgroundMode(wx.TRANSPARENT)
84
 
        mdc.SetTextForeground(stc.GetDefaultForeColour())
85
 
        mdc.SetFont(stc.GetDefaultFont())
86
 
        mdc.DrawTextList(txt, cords)
87
 
        self._tmp = wx.DragImage(mdc.GetAsBitmap())
 
81
        try:
 
82
            mdc = wx.MemoryDC(wx.EmptyBitmap(longest[0] + 5,
 
83
                                             longest[1] * len(txt), 32))
 
84
            mdc.SetBackgroundMode(wx.TRANSPARENT)
 
85
            mdc.SetTextForeground(stc.GetDefaultForeColour())
 
86
            mdc.SetFont(stc.GetDefaultFont())
 
87
            mdc.DrawTextList(txt, cords)
 
88
            self._tmp = wx.DragImage(mdc.GetAsBitmap())
 
89
        except wx.PyAssertionError, msg:
 
90
            Log("[droptargetft][err] %s" % str(msg))
88
91
 
89
92
    def InitObjects(self):
90
93
        """Initializes the text and file data objects
100
103
 
101
104
    def OnEnter(self, x_cord, y_cord, drag_result):
102
105
        """Called when a drag starts
 
106
        @keyword x_cord: x cord of enter point
 
107
        @keyword y_cord: y cord of enter point
103
108
        @return: result of drop object entering window
104
109
 
105
110
        """
125
130
 
126
131
    def OnDrop(self, x_cord=0, y_cord=0):
127
132
        """Gets the drop cords
128
 
        @keyword x: x cord of drop object
129
 
        @keyword y: y cord of drop object
 
133
        @keyword x_cord: x cord of drop object
 
134
        @keyword y_cord: y cord of drop object
130
135
        @todo: implement snapback when drop is out of range
131
136
 
132
137
        """
136
141
 
137
142
    def OnDragOver(self, x_cord, y_cord, drag_result):
138
143
        """Called when the cursor is moved during a drag action
 
144
        @keyword x_cord: x cord of mouse
 
145
        @keyword y_cord: y cord of mouse
139
146
        @return: result of drag over
140
147
        @todo: For some reason the caret position changes which can be seen
141
148
               by the brackets getting highlighted. However the actual caret
149
156
                self.ScrollBuffer(stc, x_cord, y_cord)
150
157
            drag_result = wx.DragCopy
151
158
        else:
 
159
            # A drag image was created
152
160
            if hasattr(stc, 'DoDragOver'):
153
161
                point = wx.Point(x_cord, y_cord)
154
162
                self._tmp.BeginDrag(point - self._lastp, stc)
190
198
            elif len(text) > 0:
191
199
                if self._data['tcallb'] is not None:
192
200
                    self._data['tcallb'](text)
193
 
                else:
 
201
                elif hasattr(self.window, 'DoDropText'):
194
202
                    self.window.DoDropText(x_cord, y_cord, text)
195
203
        self.InitObjects()
196
204
        return drag_result
433
441
        else:
434
442
            return 'nautilus'
435
443
 
 
444
def GetUserConfigBase():
 
445
    """Get the base user configuration directory path"""
 
446
    cbase = ed_glob.CONFIG['CONFIG_BASE']
 
447
    if cbase is None:
 
448
        cbase = wx.StandardPaths_Get().GetUserDataDir()
 
449
        if wx.Platform == '__WXGTK__':
 
450
            if u'.config' not in cbase and not os.path.exists(cbase):
 
451
                # If no existing configuration return xdg config path
 
452
                base, cfgdir = os.path.split(cbase)
 
453
                tmp_path = os.path.join(base, '.config')
 
454
                if os.path.exists(tmp_path):
 
455
                    cbase = os.path.join(tmp_path, cfgdir.lstrip(u'.'))
 
456
    return cbase + os.sep
 
457
 
436
458
def HasConfigDir(loc=u""):
437
459
    """ Checks if the user has a config directory and returns True
438
460
    if the config directory exists or False if it does not.
439
461
    @return: whether config dir in question exists on an expected path
440
462
 
441
463
    """
442
 
    cbase = ed_glob.CONFIG['CONFIG_BASE']
443
 
    if cbase is None:
444
 
        cbase = wx.StandardPaths_Get().GetUserDataDir() + os.sep
445
 
 
 
464
    cbase = GetUserConfigBase()
446
465
    to_check = os.path.join(cbase, loc)
447
466
    return os.path.exists(to_check)
448
467
 
451
470
    @param name: name of config directory to make in user config dir
452
471
 
453
472
    """
454
 
    cbase = ed_glob.CONFIG['CONFIG_BASE']
455
 
    if cbase is None:
456
 
        cbase = wx.StandardPaths_Get().GetUserDataDir()
457
 
 
 
473
    cbase = GetUserConfigBase()
458
474
    try:
459
 
        os.mkdir(cbase + os.sep + name)
 
475
        os.mkdir(cbase + name)
460
476
    except (OSError, IOError):
461
477
        pass
462
478
 
481
497
 
482
498
    """
483
499
    #---- Resolve Paths ----#
484
 
    config_dir = ed_glob.CONFIG['CONFIG_BASE']
485
 
    if config_dir is None:
486
 
        config_dir = wx.StandardPaths_Get().GetUserDataDir() + os.sep
487
 
 
 
500
    config_dir = GetUserConfigBase()
488
501
    profile_dir = os.path.join(config_dir, u"profiles")
489
502
    dest_file = os.path.join(profile_dir, u"default.ppb")
490
503
    ext_cfg = [u"cache", u"styles", u"plugins"]
519
532
           the code has proven itself.
520
533
 
521
534
    """
522
 
    stdpath = wx.StandardPaths_Get()
523
 
 
524
535
    # Try to get a User config directory
525
536
    if not sys_only:
526
 
        user_config = ed_glob.CONFIG['CONFIG_BASE']
527
 
        if user_config is None:
528
 
            user_config = stdpath.GetUserDataDir() + os.sep
529
 
 
 
537
        user_config = GetUserConfigBase()
530
538
        user_config = os.path.join(user_config, config_dir)
531
539
 
532
540
        if os.path.exists(user_config):
566
574
    # Tokenize path
567
575
    pieces = path.split(os.sep)
568
576
 
569
 
    if os.sys.platform == 'win32':
 
577
    if wx.Platform == u'__WXMSW__':
570
578
        # On Windows the exe is in same dir as config directories
571
579
        pro_path = os.sep.join(pieces[:-1])
572
580
 
573
581
        if os.path.isabs(pro_path):
574
582
            pass
575
 
        elif pro_path == "":
 
583
        elif pro_path == u"":
576
584
            pro_path = os.getcwd()
577
585
            pieces = pro_path.split(os.sep)
578
586
            pro_path = os.sep.join(pieces[:-1])
579
587
        else:
580
588
            pro_path = os.path.abspath(pro_path)
581
 
    elif os.sys.platform == "darwin":
 
589
    elif wx.Platform == u'__WXMAC__':
582
590
        # On OS X the config directories are in the applet under Resources
 
591
        stdpath = wx.StandardPaths_Get()
583
592
        pro_path = stdpath.GetResourcesDir()
584
593
        pro_path = os.path.join(pro_path, config_dir)
585
594
    else:
586
595
        pro_path = os.sep.join(pieces[:-2])
587
 
 
588
596
        if pro_path.startswith(os.sep):
589
597
            pass
590
598
        elif pro_path == u"":
595
603
        else:
596
604
            pro_path = os.path.abspath(pro_path)
597
605
 
598
 
    if os.sys.platform != "darwin":
 
606
    if wx.Platform != u'__WXMAC__':
599
607
        pro_path = pro_path + os.sep + config_dir + os.sep
600
608
 
601
609
    path = os.path.normpath(pro_path) + os.sep