यह एक known bug/issue कि जीटीके में एक लेबल गतिशील आकार नहीं बदलेंगे जब मूल परिवर्तनों है। यह उन वास्तव में कष्टप्रद छोटे विवरणों में से एक है, और यदि संभव हो तो मैं इसके आसपास हैक करना चाहता हूं।PyGTK: गतिशील लेबल लपेटकर
मैं 16 software पर दृष्टिकोण पीछा किया, लेकिन त्याग के अनुसार आपको तो यह छोटे आकार नहीं कर सकते हैं। तो मैंने टिप्पणियों में से एक में उल्लिखित एक चाल का प्रयास किया (set_size_request
सिग्नल कॉलबैक में कॉल), लेकिन इसके परिणामस्वरूप कुछ प्रकार के अनंत लूप (इसे आज़माएं और देखें)।
किसी को भी किसी भी अन्य विचारों है?
(तुम सिर्फ कॉल की अवधि के लिए संकेत नहीं रोक सकते हैं, के बाद से के रूप में print
बयानों से संकेत मिलता है लगता है, समस्या समारोह छोड़ दिया है के बाद शुरू होता है।)
कोड के नीचे है। यदि आप इसे चलाते हैं तो आप देख सकते हैं कि मेरा क्या मतलब है और विंडो को बड़ा आकार देने का प्रयास करें और फिर छोटा। (यदि आप मूल समस्या देखना चाहते हैं, तो "आकार-आवंटित सिग्नल से कनेक्ट करें" के बाद लाइन को टिप्पणी करें, इसे चलाएं, और विंडो को बड़ा आकार दें।)
ग्लेड फ़ाइल ("example.glade"):
<?xml version="1.0"?>
<glade-interface>
<!-- interface-requires gtk+ 2.16 -->
<!-- interface-naming-policy project-wide -->
<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<signal name="destroy" handler="on_destroy"/>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">In publishing and graphic design, lorem ipsum[p][1][2] is the name given to commonly used placeholder text (filler text) to demonstrate the graphic elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text, which is typically a nonsensical list of semi-Latin words, is a hacked version of a Latin text by Cicero, with words/letters omitted and others inserted, but not proper Latin[1][2] (see below: History and discovery). The closest English translation would be "pain itself" (dolorem = pain, grief, misery, suffering; ipsum = itself).</property>
<property name="wrap">True</property>
</widget>
</child>
</widget>
</glade-interface>
अजगर कोड:
#!/usr/bin/python
import pygtk
import gobject
import gtk.glade
def wrapped_label_hack(gtklabel, allocation):
print "In wrapped_label_hack"
gtklabel.set_size_request(allocation.width, -1)
# If you uncomment this, we get INFINITE LOOPING!
# gtklabel.set_size_request(-1, -1)
print "Leaving wrapped_label_hack"
class ExampleGTK:
def __init__(self, filename):
self.tree = gtk.glade.XML(filename, "window1", "Example")
self.id = "window1"
self.tree.signal_autoconnect(self)
# Connect to the size-allocate signal
self.get_widget("label1").connect("size-allocate", wrapped_label_hack)
def on_destroy(self, widget):
self.close()
def get_widget(self, id):
return self.tree.get_widget(id)
def close(self):
window = self.get_widget(self.id)
if window is not None:
window.destroy()
gtk.main_quit()
if __name__ == "__main__":
window = ExampleGTK("example.glade")
gtk.main()
और भी आसान हो सकता है: अंत में मेरी पोस्ट देखें। http://stackoverflow.com/questions/2014804/word-wrap-in-pygtk-treeview –