emoticon binder : we can assotiate string to images

bindings are saved in config file
This commit is contained in:
Yann Leboulanger 2005-01-20 12:09:26 +00:00
parent 8290545487
commit 19a967fcd2
3 changed files with 339 additions and 91 deletions

View File

@ -264,6 +264,15 @@ class preference_Window:
del self.plugin.config['msg%i_name' % i]
del self.plugin.config['msg%i' % i]
i += 1
#Emoticons
model = self.emot_tree.get_model()
iter = model.get_iter_first()
emots = []
while iter:
emots.append(model.get_value(iter, 0))
emots.append(model.get_value(iter, 1))
iter = model.iter_next(iter)
self.plugin.config['emoticons'] = string.join(emots, '\t')
#trayicon
if self.chk_trayicon.get_active():
self.plugin.config['trayicon'] = 1
@ -319,11 +328,49 @@ class preference_Window:
model.set(iter, 0, self.plugin.config['msg%s_name' % i], 1, self.plugin.config['msg%s' % i])
i += 1
def image_is_ok(self, image):
if not os.path.exists(image):
return 0
img = gtk.Image()
try:
img.set_from_file(image)
except:
return 0
if img.get_storage_type() == gtk.IMAGE_PIXBUF:
pix = img.get_pixbuf()
else:
return 0
if pix.get_width() > 24 or pix.get_height() > 24:
return 0
return 1
def load_emots(self):
emots = {}
split_line = string.split(self.plugin.config['emoticons'], '\t')
for i in range(0, len(split_line)/2):
if not self.image_is_ok(split_line[2*i+1]):
continue
emots[split_line[2*i]] = split_line[2*i+1]
return emots
def fill_emot_treeview(self):
model = self.emot_tree.get_model()
model.clear()
emots = self.load_emots()
for i in emots:
iter = model.append()
model.set(iter, 0, i, 1,emots[i])
def on_msg_cell_edited(self, cell, row, new_text):
model = self.msg_tree.get_model()
iter = model.get_iter_from_string(row)
model.set_value(iter, 0, new_text)
def on_emot_cell_edited(self, cell, row, new_text):
model = self.emot_tree.get_model()
iter = model.get_iter_from_string(row)
model.set_value(iter, 0, new_text)
def on_msg_treeview_cursor_changed(self, widget, data=None):
self.xml.get_widget('delete_msg_button').set_sensitive(True)
buf = self.xml.get_widget('msg_textview').get_buffer()
@ -337,12 +384,70 @@ class preference_Window:
iter = model.append()
model.set(iter, 0, 'msg', 1, 'message')
def on_button_emoticons_clicked(self, widget, data=None):
(model, iter) = self.emot_tree.get_selection().get_selected()
if not iter:
return
file = model.get_value(iter, 1)
dialog = gtk.FileChooserDialog("Choose image",
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
filter = gtk.FileFilter()
filter.set_name("All files")
filter.add_pattern("*")
dialog.add_filter(filter)
filter = gtk.FileFilter()
filter.set_name("Images")
filter.add_mime_type("image/png")
filter.add_mime_type("image/jpeg")
filter.add_mime_type("image/gif")
filter.add_pattern("*.png")
filter.add_pattern("*.jpg")
filter.add_pattern("*.gif")
filter.add_pattern("*.tif")
filter.add_pattern("*.xpm")
dialog.add_filter(filter)
dialog.set_filter(filter)
file = os.path.join(os.getcwd(), file)
dialog.set_filename(file)
file = ''
ok = 0
while(ok == 0):
response = dialog.run()
if response == gtk.RESPONSE_OK:
file = dialog.get_filename()
if self.image_is_ok(file):
ok = 1
else:
ok = 1
dialog.destroy()
if file:
self.xml.get_widget('entry_emoticons').set_text(file)
self.xml.get_widget('image_emoticon').set_from_file(file)
model.set_value(iter, 1, file)
def on_delete_msg_button_clicked(self, widget, data=None):
(model, iter) = self.msg_tree.get_selection().get_selected()
buf = self.xml.get_widget('msg_textview').get_buffer()
model.remove(iter)
buf.set_text('')
self.xml.get_widget('delete_msg_button').set_sensitive(False)
def on_button_new_emoticon_clicked(self, widget, data=None):
model = self.emot_tree.get_model()
iter = model.append()
model.set(iter, 0, 'smeiley', 1, '')
def on_button_remove_emoticon_clicked(self, widget, data=None):
(model, iter) = self.emot_tree.get_selection().get_selected()
if not iter:
return
model.remove(iter)
def on_msg_textview_changed(self, widget, data=None):
(model, iter) = self.msg_tree.get_selection().get_selected()
@ -353,6 +458,14 @@ class preference_Window:
name = model.get_value(iter, 0)
model.set_value(iter, 1, buf.get_text(first_iter, end_iter))
def on_treeview_emoticons_cursor_changed(self, widget, data=None):
(model, iter) = self.emot_tree.get_selection().get_selected()
if not iter:
return
img_str = model.get_value(iter, 1)
self.xml.get_widget('entry_emoticons').set_text(img_str)
self.xml.get_widget('image_emoticon').set_from_file(img_str)
def on_chk_toggled(self, widget, widgets):
"""set or unset sensitivity of widgets when widget is toggled"""
for w in widgets:
@ -413,6 +526,25 @@ class preference_Window:
#Use emoticons
st = self.plugin.config['useemoticons']
self.xml.get_widget('use_emoticons_checkbutton').set_active(st)
self.xml.get_widget('button_new_emoticon').set_sensitive(st)
self.xml.get_widget('button_remove_emoticon').set_sensitive(st)
self.xml.get_widget('treeview_emoticons').set_sensitive(st)
self.xml.get_widget('entry_emoticons').set_sensitive(st)
self.xml.get_widget('button_emoticons').set_sensitive(st)
self.xml.get_widget('image_emoticon').set_sensitive(st)
#emoticons
self.emot_tree = self.xml.get_widget('treeview_emoticons')
model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.emot_tree.set_model(model)
col = gtk.TreeViewColumn('name')
self.emot_tree.append_column(col)
renderer = gtk.CellRendererText()
renderer.connect('edited', self.on_emot_cell_edited)
renderer.set_property('editable', True)
col.pack_start(renderer, True)
col.set_attributes(renderer, text=0)
self.fill_emot_treeview()
#Autopopup
st = self.plugin.config['autopopup']
@ -510,16 +642,31 @@ class preference_Window:
self.xml.signal_connect('on_cancel_clicked', self.on_cancel)
self.xml.signal_connect('on_msg_treeview_cursor_changed', \
self.on_msg_treeview_cursor_changed)
self.xml.signal_connect('on_treeview_emoticons_cursor_changed', \
self.on_treeview_emoticons_cursor_changed)
self.xml.signal_connect('on_button_emoticons_clicked', \
self.on_button_emoticons_clicked)
self.xml.signal_connect('on_new_msg_button_clicked', \
self.on_new_msg_button_clicked)
self.xml.signal_connect('on_delete_msg_button_clicked', \
self.on_delete_msg_button_clicked)
self.xml.signal_connect('on_button_new_emoticon_clicked', \
self.on_button_new_emoticon_clicked)
self.xml.signal_connect('on_button_remove_emoticon_clicked', \
self.on_button_remove_emoticon_clicked)
self.xml.signal_connect('on_chk_autopopup_toggled', \
self.on_chk_toggled, [self.chk_autoppaway])
self.xml.signal_connect('on_chk_autoaway_toggled', \
self.on_chk_toggled, [self.spin_autoawaytime])
self.xml.signal_connect('on_chk_autoxa_toggled', \
self.on_chk_toggled, [self.spin_autoxatime])
self.xml.signal_connect('on_use_emoticons_checkbutton_toggled', \
self.on_chk_toggled, [self.xml.get_widget('button_new_emoticon'),
self.xml.get_widget('button_remove_emoticon'),
self.xml.get_widget('treeview_emoticons'),
self.xml.get_widget('entry_emoticons'),
self.xml.get_widget('button_emoticons'),
self.xml.get_widget('image_emoticon')])
self.xml.signal_connect('on_lookfeel_button_clicked', \
self.on_lookfeel_button_clicked)
self.xml.signal_connect('on_events_button_clicked', \

View File

@ -4181,6 +4181,7 @@ on the server.</property>
<child>
<widget class="GtkVBox" id="vbox47">
<property name="border_width">5</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
@ -4196,6 +4197,7 @@ on the server.</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_use_emoticons_checkbutton_toggled" last_modification_time="Wed, 19 Jan 2005 23:02:04 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
@ -4210,7 +4212,7 @@ on the server.</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
@ -4227,7 +4229,171 @@ on the server.</property>
</child>
<child>
<placeholder/>
<widget class="GtkHBox" id="hbox2903">
<property name="border_width">5</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkVBox" id="vbox49">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">5</property>
<child>
<widget class="GtkButton" id="button_new_emoticon">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-add</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button_new_emoticon_clicked" last_modification_time="Wed, 19 Jan 2005 22:25:07 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button_remove_emoticon">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-remove</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button_remove_emoticon_clicked" last_modification_time="Wed, 19 Jan 2005 22:57:48 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow25">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="treeview_emoticons">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<signal name="cursor_changed" handler="on_treeview_emoticons_cursor_changed" last_modification_time="Tue, 18 Jan 2005 22:12:10 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox48">
<property name="border_width">5</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">5</property>
<child>
<widget class="GtkHBox" id="hbox2904">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">5</property>
<child>
<widget class="GtkEntry" id="entry_emoticons">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button_emoticons">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">...</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button_emoticons_clicked" last_modification_time="Wed, 19 Jan 2005 20:47:01 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkImage" id="image_emoticon">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>

View File

@ -1734,101 +1734,35 @@ class roster_Window:
self.plugin.windows[account]['browser'] = \
browseAgent_Window(self.plugin, account)
def image_is_ok(self, image):
if not os.path.exists(image):
return 0
img = gtk.Image()
try:
img.set_from_file(image)
except:
return 0
if img.get_storage_type() == gtk.IMAGE_PIXBUF:
pix = img.get_pixbuf()
else:
return 0
if pix.get_width() > 24 or pix.get_height() > 24:
return 0
return 1
def mkemoticons(self):
"""initialize emoticons array"""
emots = {':-)' : 'smile.png',
':)' : 'smile.png',
';-)' : 'wink.png',
';)' : 'wink.png',
':-p' : 'tongue.png',
':-P' : 'tongue.png',
':p' : 'tongue.png',
':P' : 'tongue.png',
':d' : 'biggrin.png',
':D' : 'biggrin.png',
':-d' : 'biggrin.png',
':-D' : 'biggrin.png',
':>' : 'biggrin.png',
':->' : 'biggrin.png',
':(' : 'unhappy.png',
':-(' : 'unhappy.png',
';(' : 'cry.png',
';-(' : 'cry.png',
':\'(' : 'cry.png',
';\'-(' : 'cry.png',
':-O' : 'oh.png',
':-o' : 'oh.png',
':O' : 'oh.png',
':o' : 'oh.png',
':-@' : 'angry.png',
':@' : 'angry.png',
':-$' : 'blush.png',
':$' : 'blush.png',
':-|' : 'stare.png',
':|' : 'stare.png',
':-S' : 'frowing.png',
':-s' : 'frowing.png',
':S' : 'frowing.png',
':s' : 'frowing.png',
'B-)' : 'coolglasses.png',
'B)' : 'coolglasses.png',
'8-)' : 'coolglasses.png',
'8)' : 'coolglasses.png',
'(H)' : 'coolglasses.png',
'(h)' : 'coolglasses.png',
':-[' : 'bat.png',
':[' : 'bat.png',
'(l)' : 'heart.png',
'(L)' : 'heart.png',
'(u)' : 'brheart.png',
'(U)' : 'brheart.png',
'(y)' : 'yes.png',
'(Y)' : 'yes.png',
'(n)' : 'no.png',
'(N)' : 'no.png',
'(z)' : 'boy.png',
'(Z)' : 'boy.png',
'(@)' : 'pussy.png',
'(})' : 'hugleft.png',
'({)' : 'hugright.png',
'(6)' : 'devil.png',
'(r)' : 'rainbow.png',
'(R)' : 'rainbow.png',
'(w)' : 'brflower.png',
'(W)' : 'brflower.png',
'(f)' : 'flower.png',
'(F)' : 'flower.png',
'(p)' : 'photo.png',
'(P)' : 'photo.png',
'(t)' : 'phone.png',
'(T)' : 'phone.png',
'(*)' : 'star.png',
'(8)' : 'music.png',
'(i)' : 'lamp.png',
'(I)' : 'lamp.png',
'(b)' : 'beer.png',
'(B)' : 'beer.png',
'(d)' : 'drink.png',
'(D)' : 'drink.png',
'(c)' : 'coffee.png',
'(C)' : 'coffee.png',
'(%)' : 'cuffs.png',
'(e)' : 'mail.png',
'(E)' : 'mail.png',
'(k)' : 'kiss.png',
'(K)' : 'kiss.png'
}
path = 'plugins/gtkgui/emoticons/'
self.emoticons = {}
self.begin_emot = ""
for e in emots:
file = path + emots[e]
if not os.path.exists(file):
split_line = string.split(self.plugin.config['emoticons'], '\t')
for i in range(0, len(split_line)/2):
file = split_line[2*i+1]
if not self.image_is_ok(file):
continue
pix = gtk.gdk.pixbuf_new_from_file(file)
self.emoticons[e] = pix
if not e[0] in self.begin_emot:
self.begin_emot += e[0]
self.emoticons[split_line[2*i]] = pix
if not split_line[2*i][0] in self.begin_emot:
self.begin_emot += split_line[2*i][0]
def mkpixbufs(self):
"""initialise pixbufs array"""
@ -2692,6 +2626,7 @@ class plugin:
'saveposition': 1,\
'mergeaccounts': 0,\
'useemoticons': 1,\
'emoticons':':-)\tplugins/gtkgui/emoticons/smile.png\t(@)\tplugins/gtkgui/emoticons/pussy.png\t8)\tplugins/gtkgui/emoticons/coolglasses.png\t:(\tplugins/gtkgui/emoticons/unhappy.png\t:)\tplugins/gtkgui/emoticons/smile.png\t(})\tplugins/gtkgui/emoticons/hugleft.png\t:$\tplugins/gtkgui/emoticons/blush.png\t(Y)\tplugins/gtkgui/emoticons/yes.png\t:-@\tplugins/gtkgui/emoticons/angry.png\t:-D\tplugins/gtkgui/emoticons/biggrin.png\t(U)\tplugins/gtkgui/emoticons/brheart.png\t(F)\tplugins/gtkgui/emoticons/flower.png\t:-[\tplugins/gtkgui/emoticons/bat.png\t:>\tplugins/gtkgui/emoticons/biggrin.png\t(T)\tplugins/gtkgui/emoticons/phone.png\t(l)\tplugins/gtkgui/emoticons/heart.png\t:-S\tplugins/gtkgui/emoticons/frowing.png\t:-P\tplugins/gtkgui/emoticons/tongue.png\t(h)\tplugins/gtkgui/emoticons/coolglasses.png\t(D)\tplugins/gtkgui/emoticons/drink.png\t:-O\tplugins/gtkgui/emoticons/oh.png\t(f)\tplugins/gtkgui/emoticons/flower.png\t(C)\tplugins/gtkgui/emoticons/coffee.png\t:-o\tplugins/gtkgui/emoticons/oh.png\t({)\tplugins/gtkgui/emoticons/hugright.png\t(*)\tplugins/gtkgui/emoticons/star.png\tB-)\tplugins/gtkgui/emoticons/coolglasses.png\t(z)\tplugins/gtkgui/emoticons/boy.png\t:-d\tplugins/gtkgui/emoticons/biggrin.png\t(E)\tplugins/gtkgui/emoticons/mail.png\t(N)\tplugins/gtkgui/emoticons/no.png\t(p)\tplugins/gtkgui/emoticons/photo.png\t(K)\tplugins/gtkgui/emoticons/kiss.png\t(r)\tplugins/gtkgui/emoticons/rainbow.png\t:-|\tplugins/gtkgui/emoticons/stare.png\t:-s\tplugins/gtkgui/emoticons/frowing.png\t:-p\tplugins/gtkgui/emoticons/tongue.png\t(c)\tplugins/gtkgui/emoticons/coffee.png\t(e)\tplugins/gtkgui/emoticons/mail.png\t;-)\tplugins/gtkgui/emoticons/wink.png\t;-(\tplugins/gtkgui/emoticons/cry.png\t(6)\tplugins/gtkgui/emoticons/devil.png\t:o\tplugins/gtkgui/emoticons/oh.png\t(L)\tplugins/gtkgui/emoticons/heart.png\t(w)\tplugins/gtkgui/emoticons/brflower.png\t:d\tplugins/gtkgui/emoticons/biggrin.png\t(Z)\tplugins/gtkgui/emoticons/boy.png\t(u)\tplugins/gtkgui/emoticons/brheart.png\t:|\tplugins/gtkgui/emoticons/stare.png\t(P)\tplugins/gtkgui/emoticons/photo.png\t:O\tplugins/gtkgui/emoticons/oh.png\t(R)\tplugins/gtkgui/emoticons/rainbow.png\t(t)\tplugins/gtkgui/emoticons/phone.png\t(i)\tplugins/gtkgui/emoticons/lamp.png\t;)\tplugins/gtkgui/emoticons/wink.png\t;(\tplugins/gtkgui/emoticons/cry.png\t:p\tplugins/gtkgui/emoticons/tongue.png\t(H)\tplugins/gtkgui/emoticons/coolglasses.png\t:s\tplugins/gtkgui/emoticons/frowing.png\t;\'-(\tplugins/gtkgui/emoticons/cry.png\t:-(\tplugins/gtkgui/emoticons/unhappy.png\t:-)\tplugins/gtkgui/emoticons/smile.png\t(b)\tplugins/gtkgui/emoticons/beer.png\t8-)\tplugins/gtkgui/emoticons/coolglasses.png\t(B)\tplugins/gtkgui/emoticons/beer.png\t(W)\tplugins/gtkgui/emoticons/brflower.png\t:D\tplugins/gtkgui/emoticons/biggrin.png\t(y)\tplugins/gtkgui/emoticons/yes.png\t(8)\tplugins/gtkgui/emoticons/music.png\t:@\tplugins/gtkgui/emoticons/angry.png\tB)\tplugins/gtkgui/emoticons/coolglasses.png\t:-$\tplugins/gtkgui/emoticons/blush.png\t:\'(\tplugins/gtkgui/emoticons/cry.png\t(n)\tplugins/gtkgui/emoticons/no.png\t(k)\tplugins/gtkgui/emoticons/kiss.png\t:->\tplugins/gtkgui/emoticons/biggrin.png\t:[\tplugins/gtkgui/emoticons/bat.png\t(I)\tplugins/gtkgui/emoticons/lamp.png\t:P\tplugins/gtkgui/emoticons/tongue.png\t(%)\tplugins/gtkgui/emoticons/cuffs.png\t(d)\tplugins/gtkgui/emoticons/drink.png\t:S\tplugins/gtkgui/emoticons/frowing.png',\
'x-position': 0,\
'y-position': 0,\
'width': 150,\