示例#1
0
def processDroppedDate(text, dtype):
    ## data_type: "UTF8_STRING", "application/x-color", "text/uri-list",
    if dtype=='UTF8_STRING':
        if text.startswith('file://'):
            path = core.urlToPath(text)
            try:
                t = os.stat(path).st_mtime ## modification time
            except OSError:
                print 'Dropped invalid file "%s"'%path
            else:
                y, m, d = localtime(t)[:3]
                #print 'Dropped file "%s", modification time: %s/%s/%s'%(path, y, m, d)
                return (y, m, d, core.DATE_GREG)
        else:
            date = ui.parseDroppedDate(text)
            if date:
                return date + (ui.dragRecMode,)
            else:
                ## Hot to deny dragged object (to return to it's first location)
                ## FIXME
                print 'Dropped unknown text "%s"'%text
                #print etime
                #context.drag_status(gdk.ACTION_DEFAULT, etime)
                #context.drop_reply(False, etime)
                #context.drag_abort(etime)##Segmentation fault
                #context.drop_finish(False, etime)
                #context.finish(False, True, etime)
                #return True
    elif dtype=='text/uri-list':
        path = core.urlToPath(selection.data)
        try:
            t = os.stat(path).st_mtime ## modification time
        except OSError:
            print 'Dropped invalid uri "%s"'%path
            return True
        else:
            return localtime(t)[:3] + (core.DATE_GREG,)
示例#2
0
 def dragDataRec(self, obj, context, x, y, selection, target_id, etime):
     try:
         dtype = selection.get_data_type()
     except AttributeError:## Old PyGTK
         dtype = selection.type
     text = selection.get_text()
     ## data_type: "UTF8_STRING", "application/x-color", "text/uri-list",
     if dtype=='UTF8_STRING':
         #text = selection.get_text()
         #print 'Dropped text "%s"'%text
         if text.startswith('file://'):
             path = core.urlToPath(text)
             try:
                 t = os.stat(path).st_mtime ## modification time
             except OSError:
                 print 'Dropped invalid file "%s"'%path
             else:
                 (y, m, d) = localtime(t)[:3]
                 #print 'Dropped file "%s", modification time: %s/%s/%s'%(path, y, m, d)
                 self.changeDate(y, m, d, core.DATE_GREG)
             """
         elif text.startswith('#') and len(text)>=7:## not occures! disable it????
             ui.bgColor = ui.htmlColorToGdk(text)
             self.emit('pref-update-bg-color')
             self.queue_draw()"""
         else:
             date = ui.parseDroppedDate(text)
             if date:
                 (y, m, d) = date
                 self.changeDate(y, m, d, ui.dragRecMode)
             else:
                 ## Hot to deny(throw down) dragged object (to return to it's first location)
                 ##??????????????????????????????????????????????????????
                 print 'Dropped unknown text "%s"'%text
                 #print etime
                 #context.drag_status(gdk.ACTION_DEFAULT, etime)
                 #context.drop_reply(False, etime)
                 #context.drag_abort(etime)##Segmentation fault
                 #context.drop_finish(False, etime)
                 #context.finish(False, True, etime)
                 #return True
     elif dtype=='application/x-color':
         ## selection.get_text() == None
         text = selection.data
         ui.bgColor = (
             ord(text[1]),
             ord(text[3]),
             ord(text[5]),
             ord(text[7]),
         )
         self.emit('pref-update-bg-color')
         self.queue_draw()
     elif dtype=='text/uri-list':
             path = core.urlToPath(selection.data)
             try:
                 t = os.stat(path).st_mtime ## modification time
             except OSError:
                 print 'Dropped invalid uri "%s"'%path
                 return True
             else:
                 (y, m, d) = localtime(t)[:3]
                 self.changeDate(y, m, d, core.DATE_GREG)
     else:
         print 'Unknown dropped data type "%s", text="%s", data="%s"'%(dtype, text, selection.data)
         return True
     return False