Gtk.ListStore(*datatypes) string error - pygtk

self.ip_liststore = Gtk.ListStore(*datatypes)
where
datatypes = [str,str,str]
I have also tried
datatypes = ['gchararray','gchararray']
And the interpreter replies with
Traceback (most recent call last):
File "./gtktutorial.py", line 128, in <module>
main()
File "./gtktutorial.py", line 119, in main
[str,str,str,str,str,str,str])
File "./gtktutorial.py", line 37, in __init__
self.ip_liststore = Gtk.ListStore(*datatypes)
File "/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py", line 943, in __init__
self.set_column_types(column_types)
TypeError: Item 0: Must be gobject.GType, not str
What happens after the list is unpacked? Are the contents converted to strings? Is there something I don't know about unpacking?

I believe there is just a little confusion, and I remember I had a wrong time searching for it.
This is what I do :
self.searchCols = ["Object", "Index", "Date", "Program", "Person", "Mode"]
sequence = [str] * len(self.searchCols)
self.resultStore = gtk.ListStore( * sequence )
self.resView = gtk.TreeView(self.resultStore)
self.resView.cell = [None] * len(self.searchCols)
rvcolumn = [None] * len(self.searchCols)
for colnum, col in enumerate ( self.searchCols ) :
self.resView.cell[colnum] = gtk.CellRendererText()
rvcolumn[colnum] = gtk.TreeViewColumn(col, self.resView.cell[colnum])
rvcolumn[colnum].add_attribute(self.resView.cell[colnum], 'text', colnum)
self.resView.append_column(rvcolumn[colnum])

Related

TypeError: 'in <string>' requires string as left operand, not NoneType - - -

I'm getting an error with the following:
Traceback (most recent call last):
return cls._handle_exception(e)
File "/opt/odoo12/odoo/addons/website/models/ir_http.py", line 285, in _handle_exception
if exception.html in view.arch:
TypeError: 'in ' requires string as left operand, not NoneType - - -
This is my python file (report_xlsx module in odoo):
from odoo import models
class DailyTasksXLS(models.AbstractModel):
_name = 'report.hr_daily_task.report_daily_task_xls'
_inherit = 'report.report_xlsx.abstract'
def generate_xlsx_report(self, workbook, data, lines):
format2 = workbook.add_format({'font_size': 12, 'align': 'vcenter', })
for line in lines.work_ids:
sheet.write(l, 0, line.name, format2)
sheet.write(l, 1, line.description, format2)
sheet.write(l, 2, line.unit_amount, format2)
l = l+1
total_hours = total_hours + line.unit_amount
total_col = l
How to solve this?

send file to serial port in python

i am trying to send the file below '105.8k' to my energy meter.
i am using the xmodem example from pypi but i get the following error:
Traceback (most recent call last):
File "C:\Py\mainpy.py", line 68, in <module>
status = modem.send(f, retry=3)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\xmodem\__init__.py", line 270, in send
char = self.getc(1)
File "C:\py\mainpy.py", line 62, in getc
return ser.read(size) or None
AttributeError: 'str' object has no attribute 'read'
the code i use:
### send file to port###
ser = serialPortCombobox.get().split(" ")[0]
def getc(size, timeout=1):
return ser.read(size) or None
def putc(data, timeout=1):
return ser.write(data)
modem = XMODEM(getc, putc)
f = open('105.8k', 'rb')
status = modem.send(f, retry=3)
ser.close()
stream.close()
thank you for your help.

Conditioning pixelsnail on classes

I am trying to condition a pixelcnn model that I adapted, but there is needed some changes to condition the model on classes (series). I am working with time-series so in fact I would like to know how could I condition the model in some series as well. But the case, when I try to one hot encode my "Y"[batch,] labels that I am giving to it as an array of the same batch length that "X" [batch, sqrt(seq_len), sqrt(seq_len), channels]. To condition the model, I have the next code:
if args.class_conditional:
# raise NotImplementedError
num_labels = train_data.get_num_labels()
y_init = tf.placeholder(tf.int32, shape=(args.init_batch_size,))
h_init = tf.one_hot(y_init, num_labels)
y_sample = np.split(
np.mod(np.arange(args.batch_size), num_labels), args.nr_gpu)
h_sample = [tf.one_hot(tf.Variable(y_sample[i], trainable=False), num_labels)
for i in range(args.nr_gpu)]
ys = [tf.placeholder(tf.int32, shape=(args.batch_size,))
for i in range(args.nr_gpu)]
hs = [tf.one_hot(ys[i], num_labels) for i in range(args.nr_gpu)]
else:
h_init = None
h_sample = [None] * args.nr_gpu
hs = h_sample
The current output of "y_sample" that is where the shell is locating me the error:
[array([0. , 1. , 0.30521799, 1.30521799, 0.61043598,
1.61043598, 0.91565397, 0.22087195, 1.22087195, 0.52608994,
1.52608994, 0.83130793, 0.13652592, 1.13652592, 0.44174391,
1.44174391, 0.7469619 , 0.05217988, 1.05217988, 0.35739787,
1.35739787, 0.66261586, 1.66261586, 0.96783385, 0.27305184,
1.27305184, 0.57826983, 1.57826983, 0.88348781, 0.1887058 ,
1.1887058 , 0.49392379, 1.49392379, 0.79914178, 0.10435977,
1.10435977, 0.40957776, 1.40957776, 0.71479575, 0.02001373,
1.02001373, 0.32523172, 1.32523172, 0.63044971, 1.63044971,
0.9356677 , 0.24088569, 1.24088569, 0.54610368, 1.54610368])]
it is giving me an error in h_sample when it is going to do the one_hot
Traceback (most recent call last):
File "train.py", line 398, in <module>
main(FLAGS)
File "train.py", line 111, in main
for i in range(args.nr_gpu)]
File "train.py", line 111, in <listcomp>
for i in range(args.nr_gpu)]
File "/home/proto/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 2364, in one_hot
name)
File "/home/proto/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2831, in _one_hot
off_value=off_value, axis=axis, name=name)
File "/home/proto/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 609, in _apply_op_helper
param_name=input_name)
File "/home/proto/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint
", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: Value passed to parameter 'indices' has DataType float64 not in list of allowed values: uint8, int32, int64
I changed for i in range(args.nr_gpu)] hard-coded to 1 to see if it was the problem but it keeps giving me errors.

Pandas and timeseries

I have a dictionary of dataframes. I want to convert each dataframe in it to its respective timeseries. I am able to convert one nicely. But, if I do it within an iterator, it complains. Eg:
This works:
df = dfDict[4]
df['start_date'] = pd.to_datetime(df['start_date'])
df.set_index('start_date', inplace = True)
df.sort_index(inplace = True)
print df.head() works nicely.
But, this doesn't work:
tsDict = {}
for id, df in dfDict.iteritems():
df['start_date'] = pd.to_datetime(df['start_date'])
df.set_index('start_date', inplace = True)
df.sort_index(inplace = True)
tsDict[id] = df
It gives the following error message:
Traceback (most recent call last):
File "tsa.py", line 105, in <module>
main()
File "tsa.py", line 84, in main
df['start_date'] = pd.to_datetime(df['start_date'])
File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 1997, in __getitem__
return self._getitem_column(key)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 2004, in _getitem_column
return self._get_item_cache(key)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py", line 1350, in _get_item_cache
values = self._data.get(item)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/internals.py", line 3290, in get
loc = self.items.get_loc(item)
File "/usr/local/lib/python2.7/dist-packages/pandas/indexes/base.py", line 1947, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas/index.c:4154)
File "pandas/index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas/index.c:4018)
File "pandas/hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12368)
File "pandas/hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12322)
KeyError: 'start_date'
I am unable to see the subtle problem here...

AndroidViewClient serialno error

I'm testing various smartphones using AndroidViewClient.
To prevent connection errors, I used connection options(kwargs1, kwargs2) as follows.
from com.dtmilano.android.viewclient import *
from com.dtmilano.android.adb.adbclient import *
kwargs1 = {'ignoresecuredevice': True}
kwargs2 = {'startviewserver': False, 'autodump': False}
vc = ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2)
device, serialno = vc.device, vc.serialno
adb = AdbClient(serialno=serialno)
MODEL = adb.getProperty('ro.product.model')
print 'MODEL :', MODEL
So, connection errors disappeared.
But some phones with special serial number(such as 'LG-F160S-e0a852', 'EF47S01111100117300', ...) raised following serialno error.
Traceback (most recent call last):
File "D:\$Project\Eclipse\_Python\AutoTest\01_get_property4.py", line 43, in <module>
adb = AdbClient(serialno=serialno)
File "D:\$Project\Eclipse\AndroidViewClient-master\src\com\dtmilano\android\adb\adbclient.py", line 108, in __init__
self.__setTransport()
File "D:\$Project\Eclipse\AndroidViewClient-master\src\com\dtmilano\android\adb\adbclient.py", line 251, in __setTransport
raise RuntimeError("ERROR: couldn't find device that matches '%s'" % self.serialno)
RuntimeError: ERROR: couldn't find device that matches '8b1ac56e'
How can I get correct serialno or prevent this error?