def textarea_to_ctrltab(parent, attrs): attrs_ret = {} if not "width" in attrs: if "cols" in attrs: width = 7 * int(is_null(attrs["cols"], "80")) if width > 480: width = 480 attrs_ret["width"] = str(width) else: attrs_ret["width"] = "100%" else: attrs_ret["width"] = attrs["width"] if not "height" in attrs: if "rows" in attrs: attrs_ret["height"] = str(14 + 14 * int(is_null(attrs["rows"], "3"))) else: attrs_ret["height"] = "100%" else: attrs_ret["height"] = attrs["height"] if "src" in attrs: attrs_ret["src"] = attrs["src"] if "name" in attrs: attrs_ret["name"] = attrs["name"] return ("ctrl-textarea", attrs_ret)
def page(self, nr, sort=None, value=None): key = "FOLDER_" + bencode(self.folder) + "_TAB" tabvalue = None if tabvalue: tab = tabvalue else: tab = self._get_table(value)[nr * 256 : (nr + 1) * 256] cache.set(key + "::" + is_null(value, ""), tab, 300) self.var_count = len(tab) if sort != None: s = sort.split(",") ts = [] for pos in s: if pos != "": id = 0 znak = 0 if pos[0] == "-": id = self.col_names.index(pos[1:]) znak = -1 else: id = self.col_names.index(pos) znak = 1 ts.append((id, znak)) def _cmp(x, y): return str_cmp(x, y, ts) tab.sort(key=functools.cmp_to_key(_cmp)) return tab
def count(self, value): key = "FOLDER_" + bencode(self.folder) + "_COUNT" # countvalue = cache.get(key + '::' + is_null(value, '')) countvalue = None if countvalue: return countvalue else: countvalue = len(self._get_table(value)) cache.set(key + "::" + is_null(value, ""), countvalue, 300) return countvalue return len(self._get_table(value))
def input_to_ctrltab(parent, attrs): global SCHTYPE_MAP attrs_ret = {} ret = "text" upload = False if "type" in attrs: type = attrs["type"] else: type = "text" if "schtype" in attrs: schtype = attrs["schtype"] else: schtype = "text" if "class" in attrs: classname = attrs["class"] else: classname = "text" if schtype in SCHTYPE_MAP: ret = SCHTYPE_MAP[schtype] elif type == "text": if classname == "dateinput": ret = "datepicker" elif classname == "datetimeinput": ret = "datetimepicker" else: ret = "text" elif type == "button": ret = "button" elif type == "email": ret = "masktext" attrs_ret = {"src": "!EMAIL", "width": "250", "valuetype": "str"} if "value" in attrs: attrs_ret["value"] = attrs["value"] elif type == "hidden": ret = "text" attrs_ret = {"hidden": "1", "width": "0", "height": "0"} elif type == "password": ret = "password" elif type == "radio": ret = "radiobutton" if "checked" in attrs: attrs_ret["checked"] = "1" if "value" in attrs: attrs_ret["value"] = attrs["value"] attrs_ret["valuetype"] = "str" elif type == "checkbox": ret = "checkbox" if "checked" in attrs: attrs_ret["checked"] = "1" if "value" in attrs: attrs_ret["value"] = attrs["value"] attrs_ret["valuetype"] = "str" elif type == "file": ret = "filebrowsebutton" upload = True elif type == "submit": ret = "button" if "target" in attrs: target = attrs["target"] else: target = "_parent_refr" attrs_ret = { "defaultvalue": "1", "param": "post", "target": target, "id": "wx.ID_OK", } href = "." fields = None p = parent while p: if hasattr(p, "gethref"): href = p.gethref() fields = p.get_fields() if p.get_upload(): attrs_ret["valuetype"] = "upload" break p = p.parent if href == None: href = "" attrs_ret["href"] = href if fields: attrs_ret["fields"] = fields if "size" in attrs and type in ("text", "email"): width_text = 10 * int(is_null(attrs["size"], 20)) if width_text > 400: width_text = 8 * int(is_null(attrs["size"], 20)) if width_text > 480: width_text = 480 attrs_ret["width"] = str(width_text) if "maxlength" in attrs and type in ("text", ): attrs_ret["maxlength"] = str(is_null(attrs["maxlength"], "80")) elif "max_length" in attrs and type in ("text", ): attrs_ret["maxlength"] = str(is_null(attrs["max_length"], "80")) else: if "size" in attrs: attrs_ret["maxlength"] = str(int(is_null(attrs["size"], "80"))) if "value" in attrs and type in ("text", "hidden", "checkbox"): attrs_ret["value"] = is_null(attrs["value"], "") attrs_ret["valuetype"] = "str" if "value" in attrs and type in ("button", "submit"): attrs_ret["label"] = is_null(attrs["value"], "") if "title" in attrs and type in "checkbox": attrs_ret["label"] = is_null(attrs["title"], "") if "name" in attrs: p = parent while p: if p.form_obj: if upload: p.form_obj.set_upload(upload) break p = p.parent attrs_ret["name"] = attrs["name"] if ret == "text": if "date_" in attrs["name"]: ret = "datepicker" for attr in attrs: if not attr in attrs_ret and attr != "value": attrs_ret[attr] = attrs[attr] return ("ctrl-" + ret, attrs_ret)
def handle_ctrl(self, tag): value = None width = -1 height = -1 if "name" in self.attrs: name_reg = is_null(self.attrs["name"], "") parent = self.parent while parent: if hasattr(parent, "reg_field"): name_reg = parent.reg_field(self.attrs["name"]) break parent = parent.parent name = name_reg else: name = tag[4:] self.attrs["name"] = name parent = self.get_parent_window() if parent: gparent = parent.GetParent() tmp = name i = 1 while gparent.test_ctrl(tmp): tmp = name + "__" + str(i) i += 1 name = tmp for atrybut in _ATTRIBUTES: if atrybut in self.attrs: if self.attrs[atrybut] == None: self.kwargs[atrybut] = "" else: self.kwargs[atrybut] = self.attrs[atrybut] valuetype = "data" if "valuetype" in self.attrs: if self.attrs["valuetype"] == "ref": valuetype = "ref" if self.attrs["valuetype"] == "str": valuetype = "str" if "value" in self.attrs: if valuetype == "str": value = self.attrs["value"] value = unquote(value) else: try: value = eval(self.attrs["value"]) except: print("Value error:", self.attrs["value"]) value = None else: value = None if "strvalue" in self.attrs: value = self.attrs["strvalue"] self.kwargs["size"] = wx.Size( (self.width - self.padding[0]) - self.padding[1], (self.height - self.padding[2]) - self.padding[3], ) try: if tag.upper().startswith("CTRL-"): self.classObj = getattr(schctrl, tag[5:].upper()) # elif tag.upper().startswith('CTRL'): # self.classObj = getattr(schctrl, tag[4:].upper()) elif tag.startswith("_"): self.classObj = getattr(schctrl, tag[1:].upper()) else: self.classObj = getattr(schctrl, tag.upper()) except: return True if len(self.tdata) > 0: self.kwargs["tdata"] = self.tdata self.kwargs["param"] = dict(self.attrs) self.kwargs["param"]["table_lp"] = str(self.parser.table_lp) self.kwargs["param"]["tag"] = tag.lower() if self.data2 != None: self.kwargs["param"]["data"] = is_null(self.data2, "") else: self.kwargs["param"]["data"] = "".join(self.data) if self.list: l = self.list.get_list() self.kwargs["ldata"] = l obj = None if parent: gparent = parent.GetParent() obj = gparent.pop_ctrl(name) if obj: if parent.update_controls: if obj and hasattr(obj, "process_refr_data"): obj.process_refr_data(**self.kwargs) elif not (hasattr(obj, "is_ctrl_block") and obj.is_ctrl_block()): obj.SetValue(value) parent.append_ctrl(obj) else: obj = self.classObj(parent, **self.kwargs) if not obj: print("ERROR:", self.classObj) obj.set_unique_name(name) if value != None and (valuetype == "data" or valuetype == "str"): obj.SetValue(value) obj.after_create() parent.append_ctrl(obj) self.obj = obj