How to implement an GInterface class from its python binding? ex of Gtk.CellEditable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some general question

it is for the python binding of Gtk3

I actually try to create a custom widget which implements try Gtk.CellEditable
but nothing good appears, any suggestions?

my code:

# -*- coding:utf-8 -*-

from gi.repository import Gtk, Gio, GLib, GObject
from gi.overrides import keysyms as kval
import datetime
from datetime import date


class EditableCalendar(Gtk.Calendar, Gtk.CellEditable):
      editing_canceled = GObject.property(type=bool, default=False)
      def __init__(self):
          #Gtk.CellEditable.__init__(self)
          Gtk.Calendar.__init__(self)
          self.canceled = False

      def editing_done(self):
          self.emit("editing_done")

      def remove_widget(self):
          self.emit("remove_widget")

      def start_editing(self, event):
          if(event.get_keyval() == kval.Escape):
             self.cancel = True
             self.editing_done()
             self.remove_widget()
          if(event.get_val() == kval.KP_Enter):
             self.editing_done()
             self.remove_widget()

      def get_date_str(): 
             day = self.get_property("day")
             month = self.get_property("month")
             year = self.get_property("year")
             return  date(year, month, day).strftime("%d-%m-%Y")
             

class RendererCalendar(Gtk.CellRendererText):
      def __init__(self):
          Gtk.CellRendererText.__init__(self)
          self.path = None
          self.widget = None

      def calendar_editing_done(self, editable):
          if(editable.canceled == True):
            editable.canceled = False
            return
          str_date = editable.get_date_str()
          self.emit("edited", path, str_date)
          

      def do_start_editing(self, event, widget, path, background_area, cell_area, flag):
          if( self.get_property("editable") != True):
            return
          editable = EditableCalendar()
          editable.show()
          editable.grab_focus()
          self.path = path
          self.widget = widget
          editable.connect("editing_done", self.calendar_editing_done, editable)
          self.connect("edited", self.edited)
          return editable

      def edited(self, path, next_text):
          store = self.widget.get_model()
          store[path][0] = next_text
          print(next_text)


class winpriv(Gtk.Window):
      def __init__(self, typ, tit):
          Gtk.Window.__init__(self, typ, title = tit)
          self.tree = Gtk.TreeView()
          self.store = Gtk.ListStore(str)
          self.treecol =  Gtk.TreeViewColumn()
          self.rend = RendererCalendar()
          self.rend.set_property("editable", True)
          self.treecol.pack_start(self.rend, True)
          self.treecol.add_attribute(self.rend, "text", 0)
          self.tree.set_model(self.store)
          self.store.append(["31-01-2014"])
          self.store.append(["20-01-2014"])
          self.add(self.tree)
          self.tree.append_column(self.treecol)
          self.connect("destroy", self.dest)

      def dest(self, widget):
          self.destroy()
          Gtk.main_quit()
          
          

win = winpriv(Gtk.WindowType.TOPLEVEL, "ESSAIE")
win.show_all()
Gtk.main()

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux