Skip to content

Instantly share code, notes, and snippets.

@Miuler
Created May 12, 2009 06:02
Show Gist options
  • Save Miuler/110343 to your computer and use it in GitHub Desktop.
Save Miuler/110343 to your computer and use it in GitHub Desktop.
Un widget que crea un a especie de combobox solo que en vers de desplegar una lista, desplega un calendario.
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# vim: ai ts=4 sts=4 et sw=4
# Autor: Hector Miuler Malpica Gallegos
# Email: miuler@gmail.com
# Rev: $Rev
# -------------------------------------------------------------------
import gtk
import datetime
class Window:
def __init__(self):
win = gtk.Window()
win.set_title('Prueba de Comobobox + Calendar')
win.connect('destroy', gtk.main_quit)
cmb = ComboBoxCalendar(win)
label = gtk.Label('Miuler')
vbox = gtk.VBox()
vbox.pack_start(label)
vbox.pack_start(cmb)
win.add(vbox)
win.show_all()
gtk.main()
class ComboBoxCalendar(gtk.HBox):
def __init__(self, window, *argv):
super(ComboBoxCalendar, self).__init__(*argv)
self._window = window
self.entry = gtk.Entry()
self.button = gtk.Button('V')
#self.entry.connect('key-press-event', self.on_key_or_button_press)
#self.entry.connect('button-press-event', self.on_key_or_button_press)
self.button.connect('clicked', self.on_button)
self.pack_start(self.entry, 0, 0)
self.pack_start(self.button, 0, 0)
def on_key_or_button_press(self, entry, event):
self.button.clicked()
def on_button(self, button):
#$win_pos=$this->parent_window->get_position();
win_position = self.window.get_position()
x_field_pos = self.entry.allocation.x
y_field_pos = self.entry.allocation.y
x_shift = 0
y_shift = 0 + self.entry.allocation.height
x_win = win_position[0] + x_field_pos + x_shift
y_win = win_position[1] + y_field_pos + y_shift
self.dialog = gtk.Dialog(None, None,
gtk.DIALOG_MODAL|gtk.DIALOG_NO_SEPARATOR)
self.dialog.set_decorated(False)
self.dialog.set_uposition(x_win, y_win)
calendar = gtk.Calendar()
calendar.show()
self.dialog.vbox.pack_start(calendar, 0, 0)
#calendar.connect('day-selected', self.on_select)
#calendar.connect('month-changed', self.on_select)
#self.dialog.connect('button-press-event', self.on_buttonpress)
self.dialog.add_button(gtk.STOCK_APPLY, gtk.RESPONSE_ACCEPT)
if self.dialog.run() == gtk.RESPONSE_ACCEPT:
self.date = datetime.date(*calendar.get_date())
self.entry.set_text(str(self.date))
self.dialog.destroy()
Window()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment