def saveNRXconfig(self): # Only the modification of ImList needn't restartx, other configures need to restartx. # compare the imInfoDic data(no need to restartx) oriSortedUuid = [] oriPriList = [self.oriImInfoDic[uuid][4] for uuid in self.oriImInfoDic.keys()] oriPriList.sort() for pri in oriPriList: for uuid in self.oriImInfoDic.keys(): if self.oriImInfoDic[uuid][4] == pri: oriSortedUuid.append(uuid) break curSortedUuid = [] curPriList = [self.curImInfoDic[uuid][4] for uuid in self.curImInfoDic.keys()] curPriList.sort() for pri in curPriList: for uuid in self.curImInfoDic.keys(): if self.curImInfoDic[uuid][4] == pri: curSortedUuid.append(uuid) break if oriSortedUuid != curSortedUuid: IlUtil.writeImInfo(oriSortedUuid, curSortedUuid, self.curIl) # if use XKB, also save the current input language and keyboard xkbenable = os.environ.get("DI_DEF_KB_XKB", "no") if xkbenable == "yes": if self.curIl != self.oriIl: Util.set_env_param("INPUTLANG", self.curIl) if self.curKb != self.oriKb: Util.set_env_param("KEYBOARD", self.curKb) cmd = "/bin/setuserkeyboard" os.system(cmd) if self.saveMode == IlUtil.IS: # restore configure data self.oriImInfoDic = self.curImInfoDic.copy()
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 onImComboBoxChanged(self, widget, data=None): selectedIndex = self.imCb.get_active() if selectedIndex == -1 or self.imCbIndexDic == None: return imCbData = self.imCbIndexDic[selectedIndex] if imCbData == "LangLabel": nextIndex = self.imCb.get_active() + 1 self.imCb.set_active(nextIndex) self.onImComboBoxChanged(self.imCb) if imCbData == "AddRemoveBtn": # trigger the Add/Remove Widget IlAdvance.DialogWidget( self, self.curIl, self.curKb, self.curImInfoDic, self.window, IlUtil.AddRmImPage, self.saveMode ) if type(imCbData) is ListType: # check if detail btn is available if imCbData[IlUtil.InfoUuid] in IlUtil.SetupModuleDic: self.detailBtn.set_sensitive(True) if self.detailHandlerId != None: self.detailBtn.disconnect(self.detailHandlerId) self.detailHandlerId = self.detailBtn.connect( "button-release-event", self.onDetailBtnPressed, imCbData[IlUtil.InfoUuid] ) else: self.detailBtn.set_sensitive(False) # change it to max pri im self.curImInfoDic = IlUtil.setUuidWithMaxPri( imCbData[IlUtil.InfoUuid], self.curImInfoDic.copy(), self.curIl ).copy() if self.saveMode == IlUtil.IS: # save im data immediately self.saveNRXconfig()
def setImInfoDic(self, inputImInfoDic=None): if inputImInfoDic == {} or inputImInfoDic == None: # 1.change the default IM to English self.curImInfoDic = IlUtil.setUuidWithMaxPri(IlUtil.EnglishImUuid, {}, self.curIl) # 2.disable IM self.setEnableImAndChangeUi(False) else: self.curImInfoDic = inputImInfoDic.copy() self.setupImComboBox()
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 setupImComboBox(self): # clear data self.imLs.clear() self.imCbIndexDic = {} # get max priority im maxPriUuid = IlUtil.getUuidWithMaxPri(self.curImInfoDic) # create locale list localeList = [] # localeList=[locale1,locale2,...] for uuid in self.curImInfoDic: localeList.append(self.curImInfoDic[uuid][IlUtil.InfoLocale]) localeList = list(set(localeList)) localeList.sort() # create im combo box localeInfoDic = {} # localeInfoDic={locale:im_info_list} counter = 0 for lang in localeList: localeInfoList = [] # localeInfoList=[im_info1,im_info2,...] for uuid in self.curImInfoDic: if self.curImInfoDic[uuid][IlUtil.InfoLocale] == lang: localeInfoList.append(self.curImInfoDic[uuid]) localeInfoDic[lang] = localeInfoList self.imLs.append((_(IlUtil.convertLocaleToLang(lang)), None, None, None)) self.imCbIndexDic[counter] = "LangLabel" counter += 1 for imInfo in localeInfoDic[lang]: self.imLs.append( ( " ", gtk.gdk.pixbuf_new_from_file_at_size(imInfo[IlUtil.InfoIcon], 20, 20), _(imInfo[IlUtil.InfoName]), "", ) ) self.imCbIndexDic[counter] = imInfo if imInfo[IlUtil.InfoUuid] == maxPriUuid: self.imCb.set_active(counter) counter += 1 self.imLs.append((None, None, None, _("Add/Remove..."))) self.imCbIndexDic[counter] = "AddRemoveBtn"
def onEnableToggled(self,cell,path_str): model=self.imTv.get_model() iter=model.get_iter_from_string(path_str) toggleItem=model.get_value(iter,EnableCol) if model.iter_parent(iter)==None: self.imTv.expand_row(path_str,True) for i in range(model.iter_n_children(iter)): childIter=model.iter_nth_child(iter,i) model.set(childIter,EnableCol,not toggleItem) uuid=model.get_value(childIter,UuidCol) #set all child im if toggleItem==True: self.curImInfoDic=IlUtil.disableImWithUuid(uuid,self.curImInfoDic).copy() else: self.curImInfoDic=IlUtil.setUuidWithMaxPri(uuid,self.curImInfoDic,self.curIl).copy() else: uuid=model.get_value(iter,UuidCol) if toggleItem==True: self.curImInfoDic=IlUtil.disableImWithUuid(uuid,self.curImInfoDic).copy() else: self.curImInfoDic=IlUtil.setUuidWithMaxPri(uuid,self.curImInfoDic,self.curIl).copy() model.set(iter,EnableCol,not toggleItem) self.updateIncState(iter)
def onDisAllPressed(self,widget,data=None): model=self.imTv.get_model() iter=model.get_iter_root() while iter!=None: model.set(iter,IncCol,False) model.set(iter,EnableCol,False) for i in range(model.iter_n_children(iter)): childIter=model.iter_nth_child(iter,i) enabledVal=model.get_value(childIter,EnableCol) if enabledVal==True: model.set(childIter,EnableCol,False) uuid=model.get_value(childIter,UuidCol) self.curImInfoDic=IlUtil.disableImWithUuid(uuid,self.curImInfoDic).copy() iter=model.iter_next(iter)
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)