2010-11-10 20 views
6

क्या आरबीएल भाषाओं जैसे अरबी या हिब्रू के लिए उपयोगकर्ता इंटरफेस प्रस्तुत करने के लिए टिंकर का उपयोग करना संभव है? मैंने "tkinter rtl" पर googling की कोशिश की और खोज परिणाम निराशाजनक थे। Tk wiki इंगित करता है कि इस समय कोई बोली समर्थन नहीं है।पायथन/टिंकर: अरबी/हिब्रू जैसी आरटीएल (दाएं से बाएं) भाषाओं के लिए टिंकर का उपयोग करना?

क्या कोई अरबी या हिब्रू लोकेशंस के लिए टिंकर अनुप्रयोगों का विकास कर रहा है?

+0

इस पर कुछ और: http://wiki.tcl.tk/699 –

+0

2011 के बाद से, टीके और इसलिए विंडोज़ से समर्थन का उपयोग करते हुए विंडोज़ पर टीकेटर और आईडीएलई समर्थन बिडी हिब्रू और अरबी। https://wiki.tcl.tk/3158। मैंने आईडीई पर फ़ॉन्ट चयन नमूने में से कुछ को जोड़ा है ताकि लोग देख सकें कि उनके विशेष सिस्टम पर क्या काम करता है या नहीं। –

उत्तर

3

मुझे एहसास है कि यह एक पुराना सवाल है, लेकिन मैंने कल टिंकर के साथ पाइथन में एक हिब्रू एप्लिकेशन विकसित करने के लिए काम करना शुरू कर दिया। दाएं से बाएं (बीडीआई) ढांचे के हिस्से के रूप में उपलब्ध नहीं है, लेकिन कुछ गुगलिंग और कुछ शोध के बाद, मैं कुंजीबंडिंग के माध्यम से दृढ़तापूर्वक नकली करने में कामयाब रहा और जबरन कर्सर को पुनर्स्थापित कर रहा था। मेरा एंट्री विजेट औचित्य को बरकरार रखता है, ताकि हिब्रू पाठ लगभग उसी स्थिति में कुछ अंग्रेजी के समान स्थिति में हो, लेकिन इस दृष्टिकोण को सही-सही बॉक्स के लिए आसानी से संशोधित किया जा सकता है। (या, सही-औचित्य यह आसान बना सकता है)। फिर भी, मैंने यह किया है।

अनिवार्य रूप से आप यहां क्या कर रहे हैं कॉलबैक, चरित्र कोड और अनुक्रमणिका स्थिरांक का उपयोग कर कर्सर स्थिति को मैन्युअल रूप से लागू कर रहा है। इसके अलावा, आपको तीर कुंजियों के लिए खाता होना चाहिए (मेरा ध्यान दिशा में आगे बढ़ने के रूप में व्यवहार करता है। मैंने हमेशा से नफरत की है कि कैसे आरटीएल आम तौर पर तीरों को उलट देता है। हालांकि, यदि आप अन्यथा पसंद करते हैं तो यह आसानी से बदला जाता है।) बैकस्पेस और डेल, भी, कुछ मैन्युअल repositioning का कारण बनना है। बेशक, अगर आप कर्सर को मैन्युअल रूप से ट्रैक रखते हैं, तो आपको उस स्थिति में अपना ट्रैकिंग वैरिएबल अपडेट करना होगा जब उपयोगकर्ता माउस का उपयोग करके इसे बदल देता है। नीचे मेरा कोड है, अपवाद के साथ कि यहां वैश्विक का उपयोग स्पष्टीकरण से जटिलता के पतंग को हटाने का इरादा है।

   # Here, the necessary bindings. We're going to 
      # have to make modifications on key press, release, 
      # and on a completed mouse click. 
      entryWidget.bind("<KeyPress>", rtlPress) 
      entryWidget.bind("<KeyRelease>", rtlRelease) 
      entryWidget.bind("<ButtonRelease>", rtlMouse) 

अगला, तीन कॉलबैक फ़ंक्शन, जो हमारे सभी कर्सर ट्रैकिंग और स्थानांतरित करते हैं।

#With the following functions, keep in mind that we only want the cursor to move RIGHT 
#(increase in index) in response to a right arrow press or a DEL. Essentially, we are 
#compensating for any movement but these explicit conditions. Since the indexing of the 
#cursor position is LTR, holding it in its current position 
#while we append more text is 
#tantamount to moving it right. 

#On key release, if an arrow key has been invoked, we update our tracking variable to 
#reflect the new cursor position. If any other key was pressed, we snap the cursor back 
#to where it was prior to the keypress to prevent it from moving right and cause the 
#next letter to be appended on the left side of the previous letter. 

def rtlRelease(event): 
     global hebCursorPos 
     if event.keycode==114 or event.keycode==113: 
       hebCursorPos=event.widget.index(INSERT) 
     else: 
       event.widget.icursor(hebCursorPos) 
     print(str(event.keycode)+" "+str(hebCursorPos)) 

#On keypress, we must compensate for the natural LTR behavior of backspace(22) and 
#del(119) 

def rtlPress(event): 
     global hebCursorPos 
     #In LTR text entry, a backspace naturally removes the character to the left of 
     #the cursor. 
     if event.keycode==22: 
       length = len(event.widget.get()) 
       #In RTL, the right edge is the beginning of the string, so backspace 
       #should do nothing. 
       #If we're at the right edge of the string, we insert a meaningless 
       #character to be deleted so that it appears to the user as if we have 
       #done nothing. 
    if hebCursorPos==length: 
         event.widget.insert(hebCursorPos, " ") 
       #In order to cause the backspace to delete the character to the right 
       #rather than the left of the cursor from the user's perspective, we step 
       #the cursor forward one. This will cause the backspace to delete the 
       #character to the left of the new cursor position, which will be the 
       #character that was to the right of the cursor from the user's 
       #perspective. If we were at the right end of the line, we insert a space 
       #and delete it milliseconds later. We do not need to update the cursor's 
       #position, in the tracking variable, because after the character is 
       #deleted, it is back at the index from which it started, counting index 
       #from an LTR perspective. 
       event.widget.icursor(hebCursorPos+1) 
     else: 
       #Del is more of the same. It deletes the character to the right of the 
       #cursor, but we want it to delete the character to the right. 
       if event.keycode==119: 
       #If we're at the left edge of the string, insert a meaningless character 
       #for the del to delete, so that from the user's perspective it does 
       #nothing. 
         if hebCursorPos==0: 
           event.widget.insert(hebCursorPos, " ") 
         #Otherwise, we will be stepping the cursor one to the left, so 
         #that when it deletes the character to its new right, it will be 
         #deleting the character from what the user thinks is its left. 
         #Because we are deleting a character from the left of the cursor 
         #from the user's perspective, there will be fewer characters to 
         #the left of the cursor once the operation is complete. As 
         #cursor positioning is tracked as an LTR index, we must update 
         #our tracking variable. 
         else: 
           hebCursorPos-=1 
       #Now, we snap our cursor to the position of our tracking variable. 
       #Either we are preventing it from drifting right due to overlapping 
       #keypresses, or we are repositioning it to maintain the correct index 
       #after a del. 
       event.widget.icursor(hebCursorPos) 

#Simply put, if the user repositions the cursor with the mouse, track it. 
def rtlMouse(event): 
     global hebCursorPos 
     hebCursorPos=event.widget.index(INSERT) 

आशा है कि इससे मदद मिलती है! चूंकि यह मजबूर कर्सर गति द्वारा पूरा किया जाता है, टाइपिंग के दौरान मामूली दृश्य कर्सर जिटर होता है, लेकिन टेक्स्ट ऑर्डरिंग सही प्रतीत होती है, और कर्सर हमेशा सही स्थिति को इंगित करता है जब उपयोगकर्ता मिड-कीप्रेस नहीं होता है। मैं कोड पूर्णता का कोई दावा नहीं कर रहा हूं, यद्यपि!

+0

यह एक भयानक हैक है, और केवल अरबी/हिब्रू पाठ प्रतिपादन द्वारा प्रस्तुत समस्याओं का एक अंश tackles। – dietr

0

यह शायद पूरी समस्या को हल नहीं करता है, लेकिन यह प्रदर्शन की समस्या को हल कर सकता है जिसे मैं मुख्य समस्या देखता हूं।

मूल रूप से आप चरित्र क्रम को उल्टा करने के लिए और उन्हें एक साथ शामिल होने के मैं इस reshaper इस्तेमाल किया जाने के लिए दो चीजों की आवश्यकता होगी, यह विशेषक الحركات बिना सरल शब्दों के साथ ठीक काम किया लेकिन यह अभी भी कुछ मामलों में छोटी गाड़ी।

संबंधित मुद्दे