def changeKbAndImWithLang(self): # setup keyboard self.curKb = IlUtil.getDefaultKbWithLang(self.curIl) self.kbCb.set_active(self.kbList.index(self.curKb)) # setup input method self.curImInfoDic = IlUtil.getImInfoDicWithLang(self.curIl).copy() self.setupImComboBox() # check if it need disable/enable im if self.curImInfoDic.keys() == [IlUtil.EnglishImUuid]: self.setEnableImAndChangeUi(False) else: self.setEnableImAndChangeUi(True)
def createImModel(self,langStr): #get data from simf and current scim config imInfoDic=IlUtil.getImInfoDicWithLang(langStr,"all") for uuid in imInfoDic: if uuid in self.curImInfoDic: imInfoDic[uuid]=self.curImInfoDic[uuid] else: imInfoDic[uuid][IlUtil.InfoPri]=0 #create language list langList=[] for uuid in imInfoDic: langList.append(imInfoDic[uuid][IlUtil.InfoLocale]) langList=list(set(langList)) langList.sort() #insert im in model model=gtk.TreeStore(gtk.gdk.Pixbuf,gobject.TYPE_STRING,gobject.TYPE_BOOLEAN,\ gobject.TYPE_BOOLEAN,gobject.TYPE_STRING) langImDic={} for lang in langList: iter=model.append(None) model.set(iter, IconCol,None, NameCol,_(IlUtil.convertLocaleToLang(lang)), EnableCol,True, IncCol,False, UuidCol,None) langInfoList=[] for uuid in imInfoDic: if imInfoDic[uuid][IlUtil.InfoLocale]==lang: langInfoList.append(imInfoDic[uuid]); langImDic[lang]=langInfoList for imInfo in langImDic[lang]: childIter=model.append(iter) model.set(childIter, IconCol,gtk.gdk.pixbuf_new_from_file_at_size(imInfo[IlUtil.InfoIcon],20,20), NameCol,_(imInfo[IlUtil.InfoName]), EnableCol,imInfo[IlUtil.InfoPri]>0, IncCol,False, UuidCol,imInfo[IlUtil.InfoUuid]) return model
def __init__(self, parent, parentWin=None, inputWidgetW=widgetW, inputSaveMode=IlUtil.NS): # class variable(just for comments) self.parent = parent # the parent(class) self.window = parentWin # the window which include MainWidget(gtk.Window) cbW = inputWidgetW - 2 * sideW # combobox width self.saveMode = inputSaveMode # the current save mode(IlUtil.NS/IlUtil.IS) self.widget = None # the main widget for return(gtk.Alignment) self.ilList = [] # input language list([il1,il2,...]) self.kbList = [] # keyboard list([kb1,kb2,...]) self.oriIl = None # original input language(string) self.oriKb = None # original keyboard(string) self.oriEnableIm = None # original im flag(true/false) self.oriImInfoDic = {} # original IM info dictionary({uuid:ImInfo}) self.curIl = None # current input language(string) self.curKb = None # current keyboard(string) self.curEnableIm = None # current im flag(true/false) self.curImInfoDic = {} # current IM info dictionary({uuid:ImInfo}) self.ilCb = None # input language combobox(gtk.ComboBox) self.kbCb = None # keyboard combobox(gtk.ComboBox) self.imCBtn = None # input method check btn(gtk.CheckButton) self.imLs = None # input method listStore(gtk.ListStore) self.imCb = None # input method combobox(gtk.ComboBox) self.imCbIndexDic = {} # input method combobox index directory # =index:im info(list)/"LangLabel"(string)/"AddRemoveBtn"(string) self.detailBtn = None # input method detail btn(gtk.Button) self.detailHandlerId = None # detail btn press handler self.advBtn = None # advance btn(gtk.Button) self.detailChange = dict([(value, False) for value in IlUtil.SetupModuleDic.keys()]) self.advanceChange = False # -----data initiailize----- # get env variables self.ilList = IlUtil.getInputLangList() self.kbList = IlUtil.getKeyboardList() self.curIl = Util.get_env_param("INPUTLANG") if self.curIl == None or self.curIl == "": self.curIl = Util.get_env_param("LANGNAME") Util.set_env_param("INPUTLANG", self.curIl) self.curKb = Util.get_env_param("KEYBOARD") if self.curKb not in self.kbList: if self.curKb == "U.S.English": self.curKb = "English U.S." Util.set_env_param("KEYBOARD", self.curKb) elif self.curKb == "United Kingdom": self.curKb = "English U.K." Util.set_env_param("KEYBOARD", self.curKb) elif self.curKb == "Arabic(001)": self.curKb = "Arabic (001)" Util.set_env_param("KEYBOARD", self.curKb) elif self.curKb == "Arabic(002)": self.curKb = "Arabic (002)" Util.set_env_param("KEYBOARD", self.curKb) elif self.curKb == "Czech(QWERTY)": self.curKb = "Czech (QWERTY)" Util.set_env_param("KEYBOARD", self.curKb) elif self.curKb == "Polish(programmers)": self.curKb = "Polish (programmers)" Util.set_env_param("KEYBOARD", self.curKb) elif self.curKb == "Portuguese(Brazilian ABNT)": self.curKb = "Portuguese (Brazilian ABNT)" Util.set_env_param("KEYBOARD", self.curKb) elif self.curKb == "Slovak(QWERTY)": self.curKb = "Slovak (QWERTY)" Util.set_env_param("KEYBOARD", self.curKb) else: pass curNoIm = Util.get_env_param("NO_IM") if curNoIm == "" or curNoIm == "no": self.curEnableIm = True else: self.curEnableIm = False self.curImInfoDic = IlUtil.getImInfoDicWithLang(self.curIl).copy() # store initial data self.storeCurToOri() # -----ui initiailize----- # initiailize locale gettext.bindtextdomain(IlUtil.RcDomain, IlUtil.LocaleDir) gettext.textdomain(IlUtil.RcDomain) gettext.install(IlUtil.RcDomain, IlUtil.LocaleDir, unicode=1) # ---mid area--- # create ilBox and the return widget ilBox = gtk.VBox(False, IlUtil.padW * 2) ilBox.set_size_request(inputWidgetW, -1) ilAlign = gtk.Alignment(0.5, 0.5, 0, 0) ilAlign.add(ilBox) self.widget = ilAlign # create langSelect set langSelectBox = gtk.VBox(False, IlUtil.padW * 2) langSelectBox.set_size_request(cbW, -1) langSelectBoxAlign = gtk.Alignment(0.5, 0.5, 0, 0) langSelectBoxAlign.add(langSelectBox) ilBox.pack_start(langSelectBoxAlign, False, True) langSelectLb = gtk.Label(_("Input Language:")) langSelectLbAlign = gtk.Alignment(0, 0.8, 0, 0) langSelectLbAlign.add(langSelectLb) langSelectBox.pack_start(langSelectLbAlign, False, True) ilCb = gtk.combo_box_new_text() for il in self.ilList: ilCb.append_text(_(il)) if self.curIl not in self.ilList: # if previous setting not in list, set English if "English" in self.ilList: i = self.ilList.index("English") ilCb.set_active(i) else: ilCb.set_active(0) else: i = self.ilList.index(self.curIl) ilCb.set_active(i) ilCb.connect("changed", self.onIlComboBoxChanged) langSelectBox.pack_start(ilCb, True, True) self.ilCb = ilCb # create kbAndIm set kbAndImFrame = gtk.Frame() kbAndImFrame.set_shadow_type(gtk.SHADOW_OUT) ilBox.pack_start(kbAndImFrame, True, True) kbAndImBox = gtk.VBox(True, IlUtil.padW) kbAndImBox.set_border_width(IlUtil.padW * 2) kbAndImBox.set_size_request(cbW + (IlUtil.padW * 2) * 2, -1) kbAndImBoxAlign = gtk.Alignment(0.5, 0.5, 0, 0) kbAndImBoxAlign.add(kbAndImBox) kbAndImFrame.add(kbAndImBoxAlign) # create keyboardSelect set kbLb = gtk.Label(_("Keyboard:")) kbLbAlign = gtk.Alignment(0, 0.8, 0, 0) kbLbAlign.add(kbLb) kbAndImBox.pack_start(kbLbAlign, False, True) kbCb = gtk.combo_box_new_text() kbCb.connect("changed", self.onKbComboBoxChanged) for kb in self.kbList: kbCb.append_text(_(kb)) kbAndImBox.pack_start(kbCb, False, True) self.kbCb = kbCb # setup keyboard self.kbCb.set_active(self.kbList.index(self.curKb)) # create imSelect set imCBtn = gtk.CheckButton(_("Input Method:")) imCBtn.connect("toggled", self.onImCheckBtnToggled) self.imCBtn = imCBtn imLbAlign = gtk.Alignment(0, 0.8, 0, 0) imLbAlign.add(imCBtn) kbAndImBox.pack_start(imLbAlign, False, True) imFunBox = gtk.HBox(False, IlUtil.padW) kbAndImBox.pack_start(imFunBox, False, True) imLs = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_STRING) self.imLs = imLs imCb = gtk.ComboBox(imLs) imCb.connect("changed", self.onImComboBoxChanged) titleCell = gtk.CellRendererText() # titleCell.set_properties(scale_set=True,scale=0.9) titleCell.set_property("scale_set", True) titleCell.set_property("scale", 0.9) iconCell = gtk.CellRendererPixbuf() imnameCell = gtk.CellRendererText() actionCell = gtk.CellRendererText() # actionCell.set_properties(scale_set=True,scale=0.9,\ # underline_set=True,underline=pango.UNDERLINE_LOW) actionCell.set_property("scale_set", True) actionCell.set_property("scale", 0.9) actionCell.set_property("underline_set", True) actionCell.set_property("underline", pango.UNDERLINE_LOW) imCb.pack_start(titleCell, False) imCb.pack_start(iconCell, False) imCb.pack_start(imnameCell, True) imCb.pack_start(actionCell, False) imCb.add_attribute(titleCell, "text", LangCol) imCb.add_attribute(iconCell, "pixbuf", IconCol) imCb.add_attribute(imnameCell, "text", NameCol) imCb.add_attribute(actionCell, "text", FunCol) imFunBox.pack_start(imCb, True, True) self.imCb = imCb detailBtn = gtk.Button(_("...")) detailBtn.set_sensitive(False) imFunBox.pack_start(detailBtn, False, False) self.detailBtn = detailBtn # create advance btn advBtn = gtk.Button(_("Advanced")) advBtn.set_size_request(IlUtil.btnW, IlUtil.btnH) advBtn.connect("button-press-event", self.onAdvBtnPressed) advBtnAlign = gtk.Alignment(1, 0.5, 0, 0) advBtnAlign.add(advBtn) kbAndImBox.pack_start(advBtnAlign, False, True) self.advBtn = advBtn # setup input method self.setupImComboBox() # setup disable/enable im self.setEnableImAndChangeUi(self.curEnableIm)
def __init__(self,parent,inputIl,inputKb,inputImInfoDic={},\ parentWin=None,inputPage=IlUtil.AddRmImPage,inputSaveMode=IlUtil.NS): #class variables self.curIl=inputIl self.curKb=inputKb #No use now, prepare for keyboard checking self.curImInfoDic={} self.parent=parent self.window=None self.saveMode=inputSaveMode self.imTv=None #---data initialize--- if inputImInfoDic=={} or inputImInfoDic==None: self.curImInfoDic=IlUtil.getImInfoDicWithLang(inputIl).copy() else: self.curImInfoDic=inputImInfoDic.copy() #initialize ssml ssml.init(PanelSetupModule); #---ui initialize--- #initiailize locale gettext.bindtextdomain(IlUtil.RcDomain,IlUtil.LocaleDir) gettext.textdomain(IlUtil.RcDomain) gettext.install(IlUtil.RcDomain,IlUtil.LocaleDir,unicode=1) #main window window=gtk.Window(gtk.WINDOW_TOPLEVEL) window.connect("delete_event",self.delete_event) window.connect("destroy",self.destroy) window.set_size_request(IlUtil.mainW,IlUtil.mainH) window.set_resizable(False) window.set_modal(True) window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) window.set_title(_("Advanced Input Language Settings")) window.set_keep_above(True) if parentWin!=None: window.set_transient_for(parentWin) if inputSaveMode==IlUtil.IS: window.set_decorated(False) self.window=window #main vbox mainBox=gtk.VBox(False,IlUtil.padW) mainBox.set_border_width(IlUtil.padW) self.window.add(mainBox) #--im notebook-- imNotebook=gtk.Notebook() self.imNotebook=imNotebook mainBox.pack_start(self.imNotebook,True,True) #-add/remove input method page- addRmImBox=gtk.VBox(False,IlUtil.padW) addRmImBox.set_border_width(IlUtil.padW) addRmPageLb=gtk.Label(_("Add/Remove Input Method")) self.imNotebook.append_page(addRmImBox,addRmPageLb) #add/remove im label addRmLb=gtk.Label(_("The installed input method services:")) addRmLbAlign=gtk.Alignment(0,0,0,0) addRmLbAlign.add(addRmLb) addRmImBox.pack_start(addRmLbAlign,False,False) #add/remove im treeview sw=gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) addRmImBox.pack_start(sw,True,True) model=self.createImModel(inputIl) self.imTv=gtk.TreeView(model) self.imTv.set_rules_hint(True) #create name col column=gtk.TreeViewColumn() column.set_title(_("Name")) renderer=gtk.CellRendererPixbuf() column.pack_start(renderer,expand=False) column.add_attribute(renderer,'pixbuf',IconCol) renderer=gtk.CellRendererText() column.pack_start(renderer,expand=True) column.add_attribute(renderer,'text',NameCol) self.imTv.append_column(column) #create enable col renderer=gtk.CellRendererToggle(); renderer.set_property("xalign",0.0) renderer.set_data("column",EnableCol) renderer.connect("toggled",self.onEnableToggled) column=gtk.TreeViewColumn(_("Enable"),renderer,active=EnableCol,inconsistent=IncCol) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) column.set_fixed_width(100) column.set_clickable(True) self.imTv.append_column(column) self.updateIncState() sw.add(self.imTv) #add/remove im btns addRmBtnsBox=gtk.HBox(False,IlUtil.padW) addRmBtnsBox.set_border_width(IlUtil.padW) addRmImBox.pack_start(addRmBtnsBox,False,False) expBtn=gtk.Button(_("Expand")) expBtn.set_size_request(IlUtil.btnW,IlUtil.btnH) expBtn.connect("button-press-event",self.onExpPressed) addRmBtnsBox.pack_start(expBtn,False,False) colBtn=gtk.Button(_("Collapse")) colBtn.set_size_request(IlUtil.btnW,IlUtil.btnH) colBtn.connect("button-press-event",self.onColPressed) addRmBtnsBox.pack_start(colBtn,False,False) enAllBtn=gtk.Button(_("Enable All")) enAllBtn.set_size_request(IlUtil.btnW,IlUtil.btnH) enAllBtn.connect("button-press-event",self.onEnAllPressed) addRmBtnsBox.pack_start(enAllBtn,False,False) disAllBtn=gtk.Button(_("Disable All")) disAllBtn.set_size_request(IlUtil.btnW,IlUtil.btnH) disAllBtn.connect("button-press-event",self.onDisAllPressed) addRmBtnsBox.pack_start(disAllBtn,False,False) #-toolbar page- self.setupWidget=ssml.getwidget() ssml.loadconfig() self.setupWidget.show() toolPageLb=gtk.Label(_("Toolbar")) self.imNotebook.append_page(self.setupWidget,toolPageLb) #--bottom btns hbox-- btnsBox=gtk.HBox(False,IlUtil.padW*3) btnsBox.set_border_width(IlUtil.padW*3) bbAlign=gtk.Alignment(1,0,0,0) bbAlign.add(btnsBox) mainBox.pack_start(bbAlign,False,False) #ok btn okBtn=gtk.Button(_("Apply")) okBtn.set_size_request(IlUtil.btnW,IlUtil.btnH) okBtn.connect("button-press-event",self.onOkPressed) btnsBox.pack_start(okBtn) #cancel btn cancelBtn=gtk.Button(_("Cancel")) cancelBtn.set_size_request(IlUtil.btnW,IlUtil.btnH) cancelBtn.connect("button-press-event",self.onCancelPressed) btnsBox.pack_start(cancelBtn) #show all ui self.window.show_all() #XXX:set current page must be called at the last, # because it only works when all widgets in notebook are shown. self.imNotebook.set_current_page(inputPage)