Change Progress Bar format to show x.x% in pyQt4 - format

I have been trying to find out which the right syntax for the .setFormat() method of the ProgressBar is, but i cannot find any information about that. %p% just shows the percentage as '34%' but I would like to display fractions as well like this: '33.7%'.

Yes you can simply add self.pbar.setFormat('%.02f%%' % (self.step)) with your code
and if you want to implemnt more precise formating you can re implement QProgressbar like this maybe
class qProress(QtGui.QProgressBar):
"""docstring for qProress"""
def __init__(self,args):
super(qProress, self).__init__(args)
self.valueChanged.connect(self.onValueChanged)
def onValueChanged(self, value):
self.setFormat('%.02f%%' % (self.prefixFloat))
def setValue(self, value):
self.prefixFloat = value
QtGui.QProgressBar.setValue(self, int(value))

Related

Kv related question - How to bound an on_press/release function to the viewclass of the recycleview?

I've been working on a project which required me to learn kv.
what I'm trying to do is use recycleview to display a list of people that are a part of a dataset I built and allow easy edit of the dataset.
what I've done is read the documentation and simply use the first example from there (with a slight change, the viewclass being a togglebutton:
[The Example][1]
so as for my question, what I want to do is simply bound an on_press/release function to the viewclass objects, for example what I want to do is to bound a function to all of the toggle buttons which appends the button's text to a list when It's being pressed and removes the name from the list when It's being released.
[1]: https://i.stack.imgur.com/55FlM.png
You can do that by adding the on_press to the data:
class RV(RecycleView):
def __init__(self, **kwargs):
self.list = []
super(RV, self).__init__(**kwargs)
self.data = [{'text': str(x), 'on_press':partial(self.toggle, str(x))} for x in range(100)]
def toggle(self, name):
print('toggle')
if name in self.list:
self.list.remove(name)
else:
self.list.append(name)
print('list is now:', self.list)

how to two-way link between a python object and an ipywidget

Dear ipywidgets gurus,
I want to set up a link between the attribute of some python object and the value of some ipywidget:
import ipywidgets as ipyw
w = ipyw.IntSlider(42)
class Foo(object):
def __init__(self, i=0):
self.i = i # not a traitlet, just an integer
foo = Foo(w.value)
two_way_link((w, 'value'), (foo, 'i')) # mimics ipyw.link()
foo.i = 5 # will move the slider of w
w.value = 8 # update foo.i
I thought of two_way_link instantiating a wrapper traitlet around foo.i and then use ipyw.link with this wrapper and w.value. Maybe someone can suggest and alternative method?
Normal python attributes (Foo.i, here) do not give any signals/events out of the box, so there is not any existing way to do this. A one way link from the traitlet to the attribute is possible by observing the traitlet, and having the handler set the attribute (ipywidget.dlink might already support this, not sure). Having something that goes the other way, you might have some luck with a __setattr__ method on Foo (https://docs.python.org/2/reference/datamodel.html#object.setattr).

get text with index number and then compare with the expected text

I need to write a method which will get text with the help of index number from popup and then i need to compare with the expected text
i.e i need to verify expected plan name is displayed at the bottom of the popup box
Setting the correct id for the query (which you can get by doing on calabash console the command query("*", :id)) on code below should do the trick. If you can't use id try to get another component property (like Android component by using query("*") ) and set the query inside theget_text calls.
def get_text(query)
query(plan_query, :text).first
end
def text_equals(text, expected_text)
unless text == expected_text
fail "#{text} not equal to #{expected_text}"
end
end
def verify_plan(index, expected_text)
plan_text = get_text("* id:'PLAN_TEXTS_ID' index:#{index}") # Can change 'id:...'' by Android class if plan does not have id
expected_text = get_text("* id:'BOTTOM_PLAN_ID'") # Same as above
text_equals(plan_text, expected_text)
end

want a calculation result instead of <bound method ...Python 2.8

I have tried finding this in the docs but don't quite get it. I am starting to work with Classes, When I try to get the result, I get instead of the actual 'width' I maybe I need to get but not sure.. It sounds too complicated just to get a result. Can someone advise?
I have:
class Rectangle(object):
def __init__(self, pt_ll, pt_ur):
self.ll = pt_ll
self.lr = Point(pt_ur.x, pt_ll.y)
self.ur = pt_ur
self.ul = Point(pt_ll.x, pt_ur.y)
def width(self):
"""Returns the width-float of the Rectangle."""
w = self.ur.x - self.ll.x
return w
Then I call it:
r = Rectangle(Point(0,0), Point(10,10))
print r.ur.x
print r.ll.x
print r.width
and get this output:
10.0
0.0
<bound method Rectangle.width of <__main__.Rectangle object at 0x000000000B5CBC50>>
print r.width
This returns the width method itself, this is what you see in the output.
You want to call that method so you need to instead do this:
print r.width()
This hints at an interesting thing about python, you can pass around functions just like you can with other variables.

Qt GUI Table / Spreadsheet type layout in Ruby

I am trying to design a GUI that will output data in a spreadsheet type of format, rows and columns.
The cells will be populated with data that will be fetched by another object at predefined intervals. Being able to change individual cell color would be ideal to highlight any cells that have changed.
After some research it seems like QtBindings gem for ruby is the most powerful GUI choice for this but I can't seem to find any documentation or examples that would help me with what I am trying to accomplish. Any advice in the form of code or examples would be more than helpful. Thank you.
Update:: after some research and brute force, I came up with this code:
class PositionModel < Qt::AbstractTableModel
slots 'timerhit()'
def initialize(risk)
super()
#timer = Qt::Timer.new(self)
connect(#timer, SIGNAL('timeout()'), self, SLOT('timerhit()'))
#timer.start(1000)
#risk = risk
#risk_a = #risk.to_a
#pp #risk_a
end
def timerhit()
emit dataChanged(createIndex(0,0), createIndex(0,0))
#emit dataChanged()
end
def rowCount(parent)
#risk_a.size
end
def columnCount(parent)
1
end
def data(index, role)
col = index.column
row = index.row
if role == Qt::DisplayRole
return Qt::Variant.new( #risk_a[row] )
else
return Qt::Variant.new()
end
end
end
app = Qt::Application.new(ARGV)
model = PositionModel.new(##risk)
table = Qt::TableView.new
table.model = model
table.setSortingEnabled(true)
table.show
It seems to be working well, and more importantly is a solid foundation for what I ultimately want to accomplish. However, I I tried to enable sorting by clicking on a column header, but it doesnt seem to be working. Does anyone know why?
Two words: Use QTableView or QTableWidget.
Populating Table Widget from Text File in Qt
How change row color with Null items?
Converting the c++ code to ruby qt should be trivial. Also the C++ Qt docs are awesome! Good luck.
Hope that helps.

Resources