Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54352

Re: Qt connect and first connect or unicode

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <mohsen@pahlevanzadeh.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'source,': 0.04; 'output': 0.05; 'string.': 0.05; 'url:launchpad': 0.05; 'attribute': 0.07; 'encoded': 0.07; 'problem:': 0.07; 'utf-8': 0.07; 'string': 0.09; "'name':": 0.09; 'arguments': 0.09; 'bytes,': 0.09; 'callback': 0.09; 'lines:': 0.09; 'logic': 0.09; 'try:': 0.09; 'api': 0.11; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'gui': 0.12; 'called,': 0.16; 'dict': 0.16; 'function?': 0.16; 'help...': 0.16; 'lambda': 0.16; 'lambda:': 0.16; 'mutable': 0.16; 'oqapy': 0.16; 'paqager': 0.16; 'prefix:': 0.16; 'qt,': 0.16; 'set:': 0.16; 'skip:q 30': 0.16; 'subject:unicode': 0.16; 'trivially': 0.16; 'url:oqapy': 0.16; 'url:paqager': 0.16; 'url:qarte': 0.16; 'v.v.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; 'file,': 0.19; 'value.': 0.19; 'help.': 0.21; 'seems': 0.21; 'appears': 0.22; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'replace': 0.24; 'string,': 0.24; 'unicode': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'script': 0.25; 'changes,': 0.26; 'pass': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; 'correct': 0.29; 'external': 0.29; "doesn't": 0.30; "i'm": 0.30; 'code': 0.31; 'easier': 0.31; "skip:' 10": 0.31; "d'aprano": 0.31; 'ok.': 0.31; 'sep': 0.31; 'skip:q 20': 0.31; 'steven': 0.31; 'class': 0.32; 'this.': 0.32; 'probably': 0.32; 'text': 0.33; 'up.': 0.33; 'beginning': 0.33; 'problem': 0.35; 'except': 0.35; 'problem.': 0.35; 'skip:s 30': 0.35; 'convert': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; '+0200,': 0.36; "didn't": 0.36; 'method': 0.36; "i'll": 0.36; 'url:org': 0.36; 'turn': 0.37; 'two': 0.37; 'button': 0.38; 'connections': 0.38; 'e.g.': 0.38; 'filled': 0.38; 'question,': 0.38; 'needed': 0.38; 'that,': 0.38; 'does': 0.39; 'stock': 0.39; 'sure': 0.39; 'enough': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'read': 0.60; 'most': 0.60; 'first': 0.61; "you'll": 0.62; 'name': 0.63; 'field': 0.63; 'more': 0.64; 'different': 0.65; 'dear': 0.65; 'afraid': 0.65; 'website:': 0.67; 'design.': 0.68; 'day': 0.76; 'dict.': 0.84; 'god.': 0.84; 'happening?': 0.84; 'irrelevant': 0.84; 'skip:s 80': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pahlevanzadeh.org; s=default; h=Content-Transfer-Encoding:Mime-Version:Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID; bh=025Eg/gwaV09xUH3u4l7Q7tWDM9nLxWOAJHMi/wzRlA=; b=az51IjvqHjmf2AIqeMVEdexjV5nOQ5Gwha6mC4TSAdgTCJmyrlyxIvVM/tRXOYDfJ3e+gGFygybOwhi+Aax2JWFbQK35s7VAeZuimoe06MqtHHpd4loUAgbz2X/Mg3J9TxT+cPc4ubAr7hCCKel9CCVQpSp4FE5pWY55QXFAUHo=;
Subject Re: Qt connect and first connect or unicode
From Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org>
To Vincent Vande Vyvre <vincent.vandevyvre@swing.be>
Date Wed, 18 Sep 2013 08:04:14 +0430
In-Reply-To <52382FCC.50100@swing.be>
References <mailman.47.1379391172.18130.python-list@python.org> <52381b5b$0$29869$c3e8da3$5496439d@news.astraweb.com> <52382FCC.50100@swing.be>
Content-Type text/plain; charset="UTF-8"
X-Mailer Evolution 3.4.4-4+b1
Mime-Version 1.0
Content-Transfer-Encoding 8bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - part7.royal-servers.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - pahlevanzadeh.org
X-Get-Message-Sender-Via part7.royal-servers.com: authenticated_id: mohsen@pahlevanzadeh.org
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.100.1379475272.18130.python-list@python.org> (permalink)
Lines 148
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1379475272 news.xs4all.nl 15895 [2001:888:2000:d::a6]:59259
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:54352

Show key headers only | View raw


On Tue, 2013-09-17 at 12:32 +0200, Vincent Vande Vyvre wrote:
> Le 17/09/2013 11:05, Steven D'Aprano a écrit :
> > On Tue, 17 Sep 2013 08:42:35 +0430, Mohsen Pahlevanzadeh wrote:
> >
> >> Dear all,
> >>
> >> Unfortunately, i confused and need help... the following code is:
> >> ###################################################
> >> ##CheckBox:
> >>      QtCore.QObject.connect(self.checkBox,
> >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> >> self.materialsInstance.setFilterDict("C", self, "name",
> >> self.lineEdit.text()))
> >
> > I don't use Qt, but I'll try to help.
> >
> > First question, what does _fromUtf8 do? It appears to be a private
> > function. Is that your function? If you want to create a string from UTF-8
> > bytes, use:
> >
> > some_bytes.decode('utf-8')
> >
> > I don't think there is a need for a dedicated _fromUtf8 function.
> >
> > If you are using Python 3, then "toggled(bool)" is already a Unicode
> > string, and there is no need to convert from UTF-8.
> >
> > If you are using Python 2, then "toggled(bool)" is a byte string, and you
> > can turn it into a Unicode string by just using the u prefix:
> >
> > u"toggled(bool)"
> >
> > Again, no need to convert from UTF-8.
> >
> > The only time you need to convert from UTF-8 is when you are reading data
> > from a file, or other external source, that is encoded in UTF-8.
> >
> > Other than that, your first line of code seems like a straight-forward
> > call to set a callback function. When the button is pressed, the
> > instance's attribute materialsInstance calls the method setFilterDict.
> >
> >
> >>          QtCore.QObject.connect(self.checkBox_2,
> >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> >> self.materialsInstance.setFilterDict("C", self, "bought_price",
> >> persianToInteger(unicode(self.lineEdit_2.text()))))
> > Again, the same method is called, only this time with different
> > arguments. Hmmm, this strikes me as poor design. I think that a better
> > design would be for the object to have a few methods:
> >
> >      def toggle_checkbox(self, flag):
> >          # checkbox logic goes here, e.g.
> >          if flag:
> >              ...
> >          else:
> >              ...
> >
> > And then your callback is trivially
> >
> > lambda: self.toggle_checkbox(get_state)
> >
> >
> > I'm not sure how to get the checkbox state from Qt, you will need to
> > replace the "get_state" with the correct code.
> >
> > That, in my opinion, is easier to understand.
> >
> >
> >>          QtCore.QObject.connect(self.checkBox_4,
> >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> >> self.materialsInstance.setFilterDict("C",self,"stock",
> >> persianToInteger(unicode(self.lineEdit_3.text()))))
> > And more callbacks. Most of your code is probably irrelevant to the
> > problem you are having. You will help us to help you if you can read this
> > website:
> >
> > http://sscce.org/
> >
> >
> > and simplify your code.
> >
> >
> > [...many more callbacks...]
> >
> >
> >> ####################################################
> >> Description:
> >> I have 3 widget:
> >> 1. CheckBox:  a. name b. bought_price c. stock 2. LineEdit : a. name b.
> >> bought_price c. stock 3. One PushButton
> >>
> >> i have three slot: 1. responseToRequestForData()  2.setFilterDict()
> >> 3.unSetFilterDict()
> >> responseToRequestForData(): start to search in DB setFilterDict(): fill
> >> a dict from my LineEdit
> >>
> >> Problem:
> >> My name is filled in dict but its value doesn't fill up. b and c don't
> >> have any problem.
> > I'm afraid I don't understand this. Even your followup post doesn't
> > really help:
> >
> >> I see same output in console:
> >> {'stock': 2, 'name': PyQt4.QtCore.QString(u''), 'bought_price': 23}
> >
> > What result where you expecting?
> >
> > If I remember correctly, Qt strings are mutable unicode strings, so
> > 'name' is associated with an empty Qt string. If they are mutable, that
> > means that once the dict is set:
> >
> > {'name': QString(u'contents of text field'), ...}
> >
> >
> > if the text field changes, so will the string. Is that what is happening?
> >
> > (Or perhaps I have mis-remembered about Qt strings.)
> >
> > You have two callbacks that appear to set the "name" key in the dict.
> > Perhaps one of them is setting it to an empty value.
> >
> >
> >
> >
> 
> _fromUtf8 is needed for the API compatibility, at the beginning of the code of Moshen it is these lines:
> 
> try:
>      _fromUtf8 = QtCore.QString.fromUtf8
> except AttributeError:
>      _fromUtf8 = lambda s: s
> 
> 
> Moshen, I thing if you pass the instance of your GUI at the class materialsInstance you'll can simplify your connections
> 
> self.lineEdit.returnPressed.connect(self.materialsInstance.responseToRequestForData)
> self.lineEdit.editingFinnished.connect(self.materialsInstance.responseToRequestForData)
> 
> For the checkBoxes, I'm not sure you need all these arguments but I don't know enough your code.
> 
> 
> -- 
> Vincent V.V.
> Oqapy <https://launchpad.net/oqapy> . Qarte 
> <https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
i solved, I didn't think Qt hard up.i change priority of connect in my
script and every thing was OK. ohhhh day of hard code....Thanks GOD.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Qt connect and first connect or unicode Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-09-17 08:42 +0430
  Re: Qt connect and first connect or unicode Steven D'Aprano <steve@pearwood.info> - 2013-09-17 09:05 +0000
    Re: Qt connect and first connect or unicode Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-09-17 12:32 +0200
    Re: Qt connect and first connect or unicode Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-09-18 08:04 +0430

csiph-web