#!/usr/bin/env python
from gi.repository import Gtk,GObject
import os
import sys
import gettext
import locale
import xmlrpclib
locale.textdomain("lliurex-moving-editor")
gettext.textdomain("lliurex-moving-editor")
_=gettext.gettext
from net.Lliurex.Classroom.MovingProfiles import MovingProfiles
login_data=(None,None)
class Login:
glade_file="/usr/share/lliurex-moving-editor/rsrc/ui.glade"
def __init__(self):
uitree = Gtk.Builder()
uitree.add_from_file(ProfileEditor.glade_file)
self.winlogin=uitree.get_object("winlogin")
self.winlogin.connect("destroy",Gtk.main_quit)
self.lblMsg=uitree.get_object("lblMsg")
self.btnlogin=uitree.get_object("btnLogin")
self.btnlogin.connect("clicked",self.onBtnLoginClick)
self.btnCancel=uitree.get_object("btnCancel")
self.btnCancel.connect("clicked",self.onBtnCancelClick)
self.txtUser=uitree.get_object("txtUser")
self.txtPassword=uitree.get_object("txtPassword")
self.winlogin.show_all()
def onBtnLoginClick(self,data):
user=self.txtUser.get_text()
password=self.txtPassword.get_text()
proxy=xmlrpclib.ServerProxy("https://localhost:9779")
status=proxy.validate_user(user,password)
if(status[0]==False):
self.lblMsg.set_markup(""+_("Invalid user or password")+"")
else:
self.lblMsg.set_markup(""+_("Succesfully logged into the N4D")+"")
self.winlogin.hide()
global login_data
login_data=(user,password)
p = ProfileEditor()
def onBtnCancelClick(self,data):
Gtk.main_quit()
class ProfileEditor:
icon_table={"mozilla":"firefox-3.5","pidgin":"pidgin","adobe":"application-pdf","face":"system-users","thunderbird":"thunderbird","tux":"tuxpaint","exe":"exelearning","lliurex-art":"lliurex-tux-paint","jclic":"jclic","opera":"opera","openshot":"openshot"}
glade_file="/usr/share/lliurex-moving-editor/rsrc/ui.glade"
def __init__(self):
#uitree=gtk.glade.XML("/usr/share/lliurex-moving-editor/rsrc/ui.glade")
uitree = Gtk.Builder()
uitree.add_from_file(ProfileEditor.glade_file)
self.winmain=uitree.get_object("winmain")
self.winmain.connect("destroy",self.OnDestroy)
self.treefiles=uitree.get_object("treeFiles")
self.treeregex=uitree.get_object("treeRegex")
self.btnquit=uitree.get_object("btnQuit")
self.btnquit.connect("clicked",self.OnBtnQuitClick)
self.btnsave=uitree.get_object("btnSave")
self.btnsave.connect("clicked",self.OnBtnSaveClick)
self.btnadd=uitree.get_object("btnAdd")
self.btndel=uitree.get_object("btnDel")
self.btnaddrule=uitree.get_object("btnAddRule")
self.btnadd.connect("clicked",self.OnBtnAddClick)
self.btndel.connect("clicked",self.OnBtnDelClick)
self.btnaddrule.connect("clicked",self.OnBtnAddRuleClick)
model_files=Gtk.ListStore(str,str,str)
self.treefiles.set_model(model_files)
model_regex=Gtk.ListStore(str,str,str,str)
self.treeregex.set_model(model_regex)
col=Gtk.TreeViewColumn(_("Save"))
col.set_resizable(True)
self.treefiles.append_column(col)
cell=Gtk.CellRendererPixbuf()
col.pack_start(cell, True)
col.add_attribute(cell, 'icon-name', 0)
col.set_sort_column_id(0)
col.set_sort_order(Gtk.SortType.ASCENDING)
col.set_sort_indicator(True)
col=Gtk.TreeViewColumn()
col.set_resizable(True)
cell=Gtk.CellRendererPixbuf()
col.pack_start(cell, True)
col.add_attribute(cell, 'icon-name', 1)
cell.set_property("stock-size",Gtk.IconSize.DND)
self.treefiles.append_column(col)
col=Gtk.TreeViewColumn(_("File"))
col.set_resizable(True)
cell = Gtk.CellRendererText()
col.pack_start(cell, True)
col.add_attribute(cell, 'text', 2)
self.treefiles.append_column(col)
#regex tree view
type_model=Gtk.ListStore(str)
type_model.append(["include"])
type_model.append(["exclude"])
col=Gtk.TreeViewColumn()
col.set_resizable(True)
cell=Gtk.CellRendererPixbuf()
col.pack_start(cell, True)
col.add_attribute(cell, 'icon-name', 3)
cell.set_property("stock-size",Gtk.IconSize.DND)
self.treeregex.append_column(col)
col=Gtk.TreeViewColumn(_("Type"))
col.set_resizable(True)
col.set_sort_column_id(0)
cell = Gtk.CellRendererCombo()
cell.set_property("model",type_model)
cell.set_property("editable",True)
cell.set_property("text-column",0)
cell.connect("edited",self.OnCellTypeEdit)
col.pack_start(cell, True)
col.add_attribute(cell, 'text', 0)
self.treeregex.append_column(col)
col=Gtk.TreeViewColumn(_("Name"))
col.set_resizable(True)
cell = Gtk.CellRendererText()
cell.set_property("editable",True)
cell.connect("edited",self.OnCellNameEdit)
col.pack_start(cell, True)
col.add_attribute(cell, 'text', 1)
self.treeregex.append_column(col)
col=Gtk.TreeViewColumn(_("Rule"))
col.set_resizable(True)
cell = Gtk.CellRendererText()
cell.set_property("editable",True)
cell.connect("edited",self.OnCellRegexEdit)
col.pack_start(cell, True)
col.add_attribute(cell, 'text', 2)
self.treeregex.append_column(col)
self.mp=MovingProfiles(login_data)
self.LoadRegex()
self.ComputeFiles()
self.winmain.show_all()
def OnDestroy(self,data):
Gtk.main_quit()
def OnCellTypeEdit(self,cell,path,new_text):
model=self.treeregex.get_model()
iter=model.get_iter(path)
model.set_value(iter,0,new_text)
self.RecomputeRegex()
def OnCellNameEdit(self,cell,path,new_text):
model=self.treeregex.get_model()
iter=model.get_iter(path)
model.set_value(iter,1,new_text)
model.set_value(iter,3,self.GetIcon(new_text))
self.RecomputeRegex()
def OnCellRegexEdit(self,cell,path,new_text):
model=self.treeregex.get_model()
iter=model.get_iter(path)
model.set_value(iter,2,new_text)
self.RecomputeRegex()
def OnBtnAddClick(self,data):
model=self.treeregex.get_model()
model.append(["include","noname","noname",self.GetIcon("")])
self.RecomputeRegex()
def OnBtnDelClick(self,data):
model,iter=self.treeregex.get_selection().get_selected()
if not iter==None:
model.remove(iter)
self.RecomputeRegex()
def OnBtnAddRuleClick(self,data):
model,iter=self.treefiles.get_selection().get_selected()
if not iter==None:
filename=model.get_value(iter,2)
model=self.treeregex.get_model()
name=filename.replace(".","_")
name=name.replace(" ","_")
model.append(["include",name,filename,self.GetIcon("")])
self.RecomputeRegex()
def OnBtnSaveClick(self,data):
self.mp.Save()
def RecomputeRegex(self):
model=self.treeregex.get_model()
iter=model.get_iter_first()
#clear current set up
self.mp.Clear()
"""
self.mp.cfg.remove_section("include")
self.mp.cfg.remove_section("exclude")
self.mp.cfg.add_section("include")
self.mp.cfg.add_section("exclude")
"""
while not iter==None:
type=model.get_value(iter,0)
name= model.get_value(iter,1)
regex=model.get_value(iter,2)
#self.mp.cfg.set(type,name,regex)
self.mp.cfg[type][name]=regex
iter=model.iter_next(iter)
self.ComputeFiles()
def GetIcon(self,name):
if name in ProfileEditor.icon_table:
return ProfileEditor.icon_table[name]
else:
return "application-x-executable"
def LoadRegex(self):
model_regex=self.treeregex.get_model()
for name in self.mp.cfg["include"]:
value=self.mp.cfg["include"][name]
icon=self.GetIcon(name)
model_regex.append(["include",name,value,icon])
for name in self.mp.cfg["exclude"]:
value=self.mp.cfg["exclude"][name]
icon=self.GetIcon(name)
model_regex.append(["exclude",name,value,icon])
def ComputeFiles(self):
model_files=self.treefiles.get_model()
model_files.clear()
for file in os.listdir(os.path.expanduser("~")):
if os.path.isdir(os.path.expanduser("~")+os.path.sep+file):
mime_icon="folder"
else:
mime_icon="text-x-generic"
if not self.mp.isInclude(file)==None:
if not self.mp.isExclude(file)==None:
model_files.append(["gtk-no",mime_icon,file])
else:
model_files.append(["gtk-apply",mime_icon,file])
else:
if not self.mp.isExclude(file)==None:
model_files.append(["gtk-no",mime_icon,file])
else:
model_files.append(["",mime_icon,file])
def OnBtnQuitClick(self,data):
Gtk.main_quit()
if __name__=="__main__":
#p = ProfileEditor()
p = Login()
Gtk.main()