def __init__(self,value=None): super(MDSplusRoutineWidget,self).__init__(rows=4,columns=2,homogeneous=False) self.image=Entry() self.routine=Entry() self.args=list() self.argTable=Table(rows=8,columns=2,homogeneous=False) for i in range(8): self.args.append(Entry()) self.argTable.attach(Label("Arg %d: " % (i+1,)),0,1,i,i+1,0,0) self.argTable.attach(self.args[i],1,2,i,i+1,EXPAND|FILL,0) self.scrolledWindow=ScrolledWindow() self.scrolledWindow.add_with_viewport(self.argTable) self.scrolledWindow.set_policy(POLICY_NEVER,POLICY_ALWAYS) adj=self.scrolledWindow.get_vadjustment() adj.connect("changed",adj_changed) self.timeout=Entry() self.attach(Label("Library:"),0,1,0,1,0,0) self.attach(self.image,1,2,0,1,EXPAND|FILL,0) self.attach(Label("Routine:"),0,1,1,2,0,0) self.attach(self.routine,1,2,1,2,EXPAND|FILL,0) self.attach(self.scrolledWindow,0,2,2,3) self.attach(Label("Timeout:"),0,1,3,4,0,0) self.attach(self.timeout,1,2,3,4,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value
class password_dialog(Dialog): def __init__(self, parent, icon): Dialog.__init__(self, "GtkPacman Login", parent, DIALOG_MODAL | DIALOG_DESTROY_WITH_PARENT, (STOCK_OK, RESPONSE_ACCEPT, STOCK_CANCEL, RESPONSE_REJECT)) self.set_icon(pixbuf_new_from_file(icon)) self._setup_layout() def _setup_layout(self): self.password_entry = Entry() self.password_entry.set_visibility(False) self.password_entry.set_invisible_char('*') info_label = Label(' Enter root password ') self.hbox = HBox() self.vbox.pack_start(info_label) self.vbox.pack_start(self.password_entry) self.vbox.pack_start(self.hbox) self.show_all() def show_warning(self): image = Image() image.set_from_stock(STOCK_STOP, ICON_SIZE_BUTTON) warning_label = Label(' Invalid Password! ') self.hbox.pack_start(image, False, False, 10) self.hbox.pack_start(warning_label, False, False, 0) self.show_all()
class search_dialog(Dialog): def __init__(self, parent, icon): Dialog.__init__(self, _("Search for.."), parent, DIALOG_MODAL | DIALOG_DESTROY_WITH_PARENT, (STOCK_OK, RESPONSE_ACCEPT, STOCK_CANCEL, RESPONSE_REJECT)) self.set_icon(pixbuf_new_from_file(icon)) self._setup_layout() def _setup_layout(self): self.label = Label(_("Insert keywords:")) self.entry = Entry() self.entry.connect("activate", self._entry_response) self.vbox.pack_start(self.label, False, False, 0) self.vbox.pack_start(self.entry, False, False, 0) self.vbox.show_all() def _entry_response(self, widget, data=None): self.response(RESPONSE_ACCEPT)
def setupChannels(self): for child in self.table.get_children(): child.destroy() if self.incNidOffset > -1: columns = 6 else: columns = 5 self.table.resize(self.numChannels + 1, columns) self.table.attach(Label(""), 0, 1, 0, 1, 0, 0, 10, 0) self.table.attach(Label("On"), 1, 2, 0, 1, 0, 0, 10, 0) self.table.attach(Label("StartIdx"), 2, 3, 0, 1, EXPAND | FILL, 0, 10, 0) self.table.attach(Label("EndIdx"), 3, 4, 0, 1, EXPAND | FILL, 0, 10, 0) if self.incNidOffset > -1: self.table.attach(Label("Increment"), 4, 5, 0, 1, EXPAND | FILL, 0, 10, 0) self.table.attach(Label("Path"), columns - 1, columns, 0, 1, 0, 0, 10, 0) self.channels = list() for chan in range(self.numChannels): channel = dict() self.channels.append(channel) channel['number'] = Label("%d" % (chan + 1, )) self.table.attach(channel['number'], 0, 1, chan + 1, chan + 2, 0, 0, 10, 0) channel['on'] = CheckButton('') self.table.attach(channel['on'], 1, 2, chan + 1, chan + 2, 0, 0, 10, 0) channel['startIdx'] = Entry() self.table.attach(channel['startIdx'], 2, 3, chan + 1, chan + 2, EXPAND | FILL, 0, 10, 0) channel['endIdx'] = Entry() self.table.attach(channel['endIdx'], 3, 4, chan + 1, chan + 2, EXPAND | FILL, 0, 10, 0) if self.incNidOffset > -1: channel['inc'] = Entry() self.table.attach(channel['inc'], 4, 5, chan + 1, chan + 2, EXPAND | FILL, 0, 10, 0) channel['path'] = Label(' ') self.table.attach(channel['path'], columns - 1, columns, chan + 1, chan + 2, 0, 0, 10, 0) self.show_all() if not guibuilder: for chan in range(self.numChannels): chanNidOffset = self.node.nid + chan * self.nodesPerChannel channel = self.channels[chan] channel['dataNode'] = TreeNode( chanNidOffset + self.dataNidOffset, self.node.tree) channel['startIdxNode'] = TreeNode( chanNidOffset + self.startIdxNidOffset, self.node.tree) channel['endIdxNode'] = TreeNode( chanNidOffset + self.endIdxNidOffset, self.node.tree) if self.incNidOffset > -1: channel['incNode'] = TreeNode( chanNidOffset + self.incNidOffset, self.node.tree)
def __init__(self, item, name='ItemEntry'): HBox.__init__(self) self.set_name(name) self._key_, self._val_ = item self.label = Label(self._key_) self.entry = Entry() self.entry.set_text(self._val_) self.pack_start(self.label, 0, 0, 0) self.pack_end(self.entry, 0, 0, 0) map(lambda x: x.show(), [self.label, self.entry]) self.show()
class ItemEntry_orig(HBox): def __init__(self, item, name='ItemEntry'): HBox.__init__(self) self.set_name(name) self._key_, self._val_ = item self.label = Label(self._key_) self.entry = Entry() self.entry.set_text(self._val_) self.pack_start(self.label,0,0,0) self.pack_end(self.entry,0,0,0) map(lambda x: x.show(), [self.label, self.entry]) self.show()
def __init__(self, name, default=None): HBox.__init__(self) self.set_name(name) self.label = Label(name) self.entry = Entry() self.pack_start(self.label, TRUE, TRUE, 0) self.add(self.entry) self.label.show() self.entry.show() if default: self.set(default) self.show()
def __init__(self,value=None): super(MDSplusWindowWidget,self).__init__(rows=3,columns=2,homogeneous=False) self.startIdx=Entry() self.endIdx=Entry() self.timeAt0=Entry() self.attach(Label("StartIdx: "),0,1,0,1,0,0) self.attach(self.startIdx,1,2,0,1,EXPAND|FILL,0) self.attach(Label("EndIdx: "),0,1,1,2,0,0) self.attach(self.endIdx,1,2,1,2,EXPAND|FILL,0) self.attach(Label("TimeAt0:"),0,1,2,3,0,0) self.attach(self.timeAt0,1,2,2,3,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value
def __init__(self,value=None): super(MDSplusRangeWidget,self).__init__(rows=3,columns=2,homogeneous=False) self.begin=Entry() self.ending=Entry() self.delta=Entry() self.attach(Label("Begin: "),0,1,0,1,0,0) self.attach(self.begin,1,2,0,1,EXPAND|FILL,0) self.attach(Label("Ending: "),0,1,1,2,0,0) self.attach(self.ending,1,2,1,2,EXPAND|FILL,0) self.attach(Label("Delta:"),0,1,2,3,0,0) self.attach(self.delta,1,2,2,3,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value
def input_entry_dialog(msg, default_answer="", parent=None): dia = Dialog( msg, parent, gtk.DIALOG_MODAL |gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, RESPONSE_OK) ) dia.vbox.pack_start(Label(msg)) da_entry = Entry() da_entry.set_text(default_answer) dia.vbox.pack_end( da_entry ) dia.show_all() result = dia.run() datext = da_entry.get_text() dia.destroy() return datext if result == RESPONSE_OK else None
def __init__(self, item, name='ItemEntry'): if len(item) != 2: raise Error, 'ItemEntry needs item not %s' % item field, value = item HBox.__init__(self) self.set_name(name) self.label = Label(field) self.pack_start(self.label, FALSE, FALSE, 0) self.entry = Entry() self.set(str(value)) self.pack_end(self.entry, TRUE, TRUE, 0) self.label.show() self.entry.show() self.show()
class MDSplusSequentialWidget(Table): def __init__(self,value=None): super(MDSplusSequentialWidget,self).__init__(rows=4,columns=2,homogeneous=False) self.ident=Entry() self.phase=Entry() self.sequence=Entry() self.event=Entry() self.attach(Label("Server: "),0,1,0,1,0,0) self.attach(self.ident,1,2,0,1,EXPAND|FILL,0) self.attach(Label("Phase: "),0,1,1,2,0,0) self.attach(self.phase,1,2,1,2,EXPAND|FILL,0) self.attach(Label("Sequence:"),0,1,2,3,0,0) self.attach(self.sequence,1,2,2,3,EXPAND|FILL,0) self.attach(Label("Event: "),0,1,3,4,0,0) self.attach(self.event,1,2,3,4,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value def getValue(self): ans=Dispatch(dispatch_type=2) ans.ident=self.ident.get_text() try: ans.ident=Data.compile(ans.ident) except Exception,e: pass ans.phase=self.phase.get_text() try: ans.phase=Data.compile(ans.phase) except Exception,e: pass
def __init__(self, parent, icon): Dialog.__init__( self, _("Confirm makepkg as root"), parent, DIALOG_MODAL | DIALOG_DESTROY_WITH_PARENT, (STOCK_OK, RESPONSE_ACCEPT, STOCK_CANCEL, RESPONSE_REJECT), ) self.add_button(_("Run as root"), 1000) lab = Label( _( "Running makepkg as root is a bad idea.\nSelect an alternate user or confirm that you want to run it as root" ) ) uname_frame = Frame(_("Username:"******"Password")) self.uname_entry = Entry() uname_frame.add(self.uname_entry) self.vbox.pack_start(lab) self.vbox.pack_start(uname_frame) self.vbox.show_all()
class change_user_dialog(Dialog): def __init__(self, parent, icon): Dialog.__init__(self, _("Confirm makepkg as root"), parent, DIALOG_MODAL | DIALOG_DESTROY_WITH_PARENT, (STOCK_OK, RESPONSE_ACCEPT, STOCK_CANCEL, RESPONSE_REJECT)) self.add_button(_("Run as root"), 1000) lab = Label(_("Running makepkg as root is a bad idea.\nSelect an alternate user or confirm that you want to run it as root")) uname_frame = Frame(_("Username:"******"Password")) self.uname_entry = Entry() uname_frame.add(self.uname_entry) self.vbox.pack_start(lab) self.vbox.pack_start(uname_frame) self.vbox.show_all() def run(self): res = Dialog.run(self) if res == 1000: return "root" elif res == RESPONSE_ACCEPT: uname = self.uname_entry.get_text() return uname else: self.destroy() return "reject"
def __init__(self): from gtk import Window,WINDOW_TOPLEVEL,Button,Label,HBox,Entry,VBox,VSeparator self.window = Window(WINDOW_TOPLEVEL) self.window.set_title("Slideshow") self.window.connect("delete_event", self.delete_event) self.window.set_border_width(10) self.vbox = VBox(False, 0) self.window.add(self.vbox) self.hbox1 = HBox(False, 0) self.vbox.pack_start(self.hbox1, True, True, 1) self.hbox = HBox(False, 0) self.vbox.pack_start(self.hbox, False, False, 1) self.hbox2 = HBox(False, 0) self.vbox.pack_start(self.hbox2, True, True, 1) self.label = Label('Identifikační číslo:') self.hbox.pack_start(self.label, False, False, 1) self.label.show() self.editable = Entry() self.editable.connect('key_press_event', self.key_press_event) self.hbox.pack_start(self.editable, True, True, 1) self.editable.show() self.button = Button("Začít") self.button.connect("clicked", self.callback) self.button.set_receives_default(True) self.button.set_can_focus(True) self.hbox.pack_start(self.button, False, False, 1) self.button.show() self.hbox1.show() self.hbox.show() self.hbox2.show() self.vbox.show() self.window.show()
class _FieldEntry(HBox): def __init__(self, name, default=None): HBox.__init__(self) self.set_name(name) self.label = Label(name) self.entry = Entry() self.pack_start(self.label, True, True, 0) self.add(self.entry) self.label.show() self.entry.show() if default: self.set(default) self.show() def set(self, value): self.entry.set_text(value)
class _FieldEntry(HBox): def __init__(self, name, default=None): HBox.__init__(self) self.set_name(name) self.label = Label(name) self.entry = Entry() self.pack_start(self.label, TRUE, TRUE, 0) self.add(self.entry) self.label.show() self.entry.show() if default: self.set(default) self.show() def set(self, value): self.entry.set_text(value)
def __init__(self,value=None): super(MDSplusSequentialWidget,self).__init__(rows=4,columns=2,homogeneous=False) self.ident=Entry() self.phase=Entry() self.sequence=Entry() self.event=Entry() self.attach(Label("Server: "),0,1,0,1,0,0) self.attach(self.ident,1,2,0,1,EXPAND|FILL,0) self.attach(Label("Phase: "),0,1,1,2,0,0) self.attach(self.phase,1,2,1,2,EXPAND|FILL,0) self.attach(Label("Sequence:"),0,1,2,3,0,0) self.attach(self.sequence,1,2,2,3,EXPAND|FILL,0) self.attach(Label("Event: "),0,1,3,4,0,0) self.attach(self.event,1,2,3,4,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value
def __init__(self, value=None): super(MDSplusMethodWidget, self).__init__(rows=4, columns=2, homogeneous=False) self.device = Entry() self.method = Entry() self.args = list() self.argTable = Table(rows=8, columns=2, homogeneous=False) for i in range(8): self.args.append(Entry()) self.argTable.attach(Label("Arg %d: " % (i + 1, )), 0, 1, i, i + 1, 0, 0) self.argTable.attach(self.args[i], 1, 2, i, i + 1, EXPAND | FILL, 0) self.scrolledWindow = ScrolledWindow() self.scrolledWindow.add_with_viewport(self.argTable) self.scrolledWindow.set_policy(POLICY_NEVER, POLICY_ALWAYS) adj = self.scrolledWindow.get_vadjustment() adj.connect("changed", adj_changed) self.timeout = Entry() self.attach(Label("Device:"), 0, 1, 0, 1, 0, 0) self.attach(self.device, 1, 2, 0, 1, EXPAND | FILL, 0) self.attach(Label("Method:"), 0, 1, 1, 2, 0, 0) self.attach(self.method, 1, 2, 1, 2, EXPAND | FILL, 0) self.attach(self.scrolledWindow, 0, 2, 2, 3) self.attach(Label("Timeout:"), 0, 1, 3, 4, 0, 0) self.attach(self.timeout, 1, 2, 3, 4, EXPAND | FILL, 0) self.set_row_spacings(5) self.value = value
def __init__(self): Table.__init__(self, 1, 5) self.entry1 = Entry() self.entry2 = Entry() self.button = Button("Search") self.attach(self.entry1, 0, 1, 0, 1) self.attach(self.entry2, 1, 2, 0, 1) self.attach(self.button, 2, 3, 0, 1) self.entry1.set_width_chars(12) self.entry2.set_width_chars(12) self.entry1.set_text("59.666042") self.entry2.set_text("16.481794") self.button.connect('clicked', self.clicked)
def _setup_layout(self): self.label = Label(_("Insert keywords:")) self.entry = Entry() self.entry.connect("activate", self._entry_response) self.vbox.pack_start(self.label, False, False, 0) self.vbox.pack_start(self.entry, False, False, 0) self.vbox.show_all()
def on_add_button_clicked(self, *args): # Ask the user for a new trustor's name. md = MessageDialog(parent = self.top_window, type = MESSAGE_QUESTION, buttons = BUTTONS_OK_CANCEL, message_format = "What's the new trustor's name?") vbox = md.get_child() name_entry = Entry() vbox.pack_end(name_entry) vbox.show_all() r = md.run() new_trustor_name = name_entry.get_text() md.destroy() # destroys embedded widgets too # Save the new trustor. if r == RESPONSE_OK and new_trustor_name != '': self.current_name = new_trustor_name self.trust_module.add_trustor_by_name(new_trustor_name) transaction.get().commit() self.refresh_trustor_list()
def _setup_layout(self): self.password_entry = Entry() self.password_entry.set_visibility(False) self.password_entry.set_invisible_char('*') info_label = Label(' Enter root password ') self.hbox = HBox() self.vbox.pack_start(info_label) self.vbox.pack_start(self.password_entry) self.vbox.pack_start(self.hbox) self.show_all()
def __init__(self, name, default=None): HBox.__init__(self) self.set_name(name) self.label = Label(name) self.entry = Entry() self.pack_start(self.label, True, True, 0) self.add(self.entry) self.label.show() self.entry.show() if default: self.set(default) self.show()
class MDSplusRangeWidget(Table): def __init__(self,value=None): super(MDSplusRangeWidget,self).__init__(rows=3,columns=2,homogeneous=False) self.begin=Entry() self.ending=Entry() self.delta=Entry() self.attach(Label("Begin: "),0,1,0,1,0,0) self.attach(self.begin,1,2,0,1,EXPAND|FILL,0) self.attach(Label("Ending: "),0,1,1,2,0,0) self.attach(self.ending,1,2,1,2,EXPAND|FILL,0) self.attach(Label("Delta:"),0,1,2,3,0,0) self.attach(self.delta,1,2,2,3,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value def getValue(self): ans=Range() t=self.begin.get_text() if t == '': ans.begin=None else: try: ans.begin=Data.compile(self.begin.get_text()) except Exception,e: msg="Invalid begin specified.\n\n%s" % (e,) MDSplusErrorMsg('Invalid Begin',msg) raise t=self.ending.get_text() if t == '': ans.ending=None else: try: ans.ending=Data.compile(self.ending.get_text()) except Exception,e: msg="Invalid ending specified.\n\n%s" % (e,) MDSplusErrorMsg('Invalid Ending',msg) raise
class MDSplusWindowWidget(Table): def __init__(self,value=None): super(MDSplusWindowWidget,self).__init__(rows=3,columns=2,homogeneous=False) self.startIdx=Entry() self.endIdx=Entry() self.timeAt0=Entry() self.attach(Label("StartIdx: "),0,1,0,1,0,0) self.attach(self.startIdx,1,2,0,1,EXPAND|FILL,0) self.attach(Label("EndIdx: "),0,1,1,2,0,0) self.attach(self.endIdx,1,2,1,2,EXPAND|FILL,0) self.attach(Label("TimeAt0:"),0,1,2,3,0,0) self.attach(self.timeAt0,1,2,2,3,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value def getValue(self): ans=Window() t=self.startIdx.get_text() if t == '': ans.startIdx=None else: try: ans.startIdx=Data.compile(self.startIdx.get_text()) except Exception,e: msg="Invalid startIdx specified.\n\n%s" % (e,) MDSplusErrorMsg('Invalid StartIdx',msg) raise t=self.endIdx.get_text() if t == '': ans.endIdx=None else: try: ans.endIdx=Data.compile(self.endIdx.get_text()) except Exception,e: msg="Invalid endIdx specified.\n\n%s" % (e,) MDSplusErrorMsg('Invalid EndIdx',msg) raise
def __init__(self, item, name='ItemEntry'): if len(item) != 2: raise Error, 'ItemEntry needs item not %s' %item field, value = item HBox.__init__(self) self.set_name(name) self.label = Label(field) self.pack_start(self.label, FALSE, FALSE, 0) self.entry = Entry() self.set(str(value)) self.pack_end(self.entry, TRUE, TRUE, 0) self.label.show() self.entry.show() self.show()
def __init__(self, value=None): super(MDSplusSequentialWidget, self).__init__( rows=4, columns=2, homogeneous=False) self.ident = Entry() self.phase = Entry() self.sequence = Entry() self.event = Entry() self.attach(Label("Server: "), 0, 1, 0, 1, 0, 0) self.attach(self.ident, 1, 2, 0, 1, EXPAND | FILL, 0) self.attach(Label("Phase: "), 0, 1, 1, 2, 0, 0) self.attach(self.phase, 1, 2, 1, 2, EXPAND | FILL, 0) self.attach(Label("Sequence:"), 0, 1, 2, 3, 0, 0) self.attach(self.sequence, 1, 2, 2, 3, EXPAND | FILL, 0) self.attach(Label("Event: "), 0, 1, 3, 4, 0, 0) self.attach(self.event, 1, 2, 3, 4, EXPAND | FILL, 0) self.set_row_spacings(5) self.value = value
class ItemEntry(HBox): def __init__(self, item, name='ItemEntry'): if len(item) != 2: raise RuntimeError, 'ItemEntry needs item not %s' %item field, value = item HBox.__init__(self) self.set_name(name) self.label = Label(field) self.pack_start(self.label, False, False, 0) self.entry = Entry() self.set(str(value)) self.pack_end(self.entry, True, True, 0) self.label.show() self.entry.show() self.show() def get(self): return self.entry.get_text() def set(self, value): self.entry.set_text(value) def fieldname(self): return self.label.get_text()
class MDSplusMethodWidget(Table): def __init__(self,value=None): super(MDSplusMethodWidget,self).__init__(rows=4,columns=2,homogeneous=False) self.device=Entry() self.method=Entry() self.args=list() self.argTable=Table(rows=8,columns=2,homogeneous=False) for i in range(8): self.args.append(Entry()) self.argTable.attach(Label("Arg %d: " % (i+1,)),0,1,i,i+1,0,0) self.argTable.attach(self.args[i],1,2,i,i+1,EXPAND|FILL,0) self.scrolledWindow=ScrolledWindow() self.scrolledWindow.add_with_viewport(self.argTable) self.scrolledWindow.set_policy(POLICY_NEVER,POLICY_ALWAYS) adj=self.scrolledWindow.get_vadjustment() adj.connect("changed",adj_changed) self.timeout=Entry() self.attach(Label("Device:"),0,1,0,1,0,0) self.attach(self.device,1,2,0,1,EXPAND|FILL,0) self.attach(Label("Method:"),0,1,1,2,0,0) self.attach(self.method,1,2,1,2,EXPAND|FILL,0) self.attach(self.scrolledWindow,0,2,2,3) self.attach(Label("Timeout:"),0,1,3,4,0,0) self.attach(self.timeout,1,2,3,4,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value def getValue(self): ans=Method() ans.method=self.method.get_text() try: ans.method=Data.compile(ans.method) except Exception,e: pass try: ans.object=Data.compile(self.device.get_text()) except Exception,e: msg="Invalid device specified.\n\n%s" % (e,) MDSplusErrorMsg('Invalid Device',msg) raise
class MDSplusXdBox(props, MDSplusDtypeSelWidget, MDSplusWidget, Window): __gtype_name__ = "MDSplusXdBox" def inHBox(self, w): hb = HBox() hb.pack_start(w, False, False, 0) return hb def __init__(self, node=None, value=None): Window.__init__(self) MDSplusWidget.__init__(self) if node is not None: self.node = node else: self.value = value hbtop = HBox(homogeneous=False) self.on = CheckButton(label="On") self.parent_on = CheckButton(label="Parent") self.parent_on.set_sensitive(False) self.path = MDSplusPathWidget() if node is not None: self.path._node = self._node hbtags = HBox(homogeneous=False) self.tags = Entry() self.tags.set_width_chars(60) expression_menu = self.dtype_menu(tuple(), varname="dtype_expression", no_show=True) axis_menu = self.dtype_menu(("Range",), varname="dtype_axis", no_show=True) window_menu = self.dtype_menu(("Window",), varname="dtype_window", no_show=True) dispatch_menu = self.dtype_menu(("Dispatch",), varname="dtype_dispatch", no_show=True) action_menu = self.dtype_menu(("Action",), varname="dtype_action", no_show=True) task_menu = self.dtype_menu(("Method", "Routine"), varname="dtype_task", no_show=True) any_menu = self.dtype_menu( ("Range", "Window", "Dispatch", "Action", "Method", "Routine"), varname="dtype_any", no_show=True ) menus = ( self.dtype_expression, self.dtype_axis, self.dtype_dispatch, self.dtype_action, self.dtype_task, self.dtype_window, self.dtype_any, ) hbtop.pack_start(self.on, False, False, 10) hbtop.pack_start(self.parent_on, False, False, 10) hbtop.pack_start(self.path, False, False, 0) hbtags.pack_start(Label("Tags:"), False, False, 10) hbtags.pack_start(self.tags, False, False, 0) self.action = MDSplusActionWidget() self.windoww = MDSplusWindowWidget() self.sequential = MDSplusSequentialWidget() self.expression = MDSplusExpressionWidget() self.method = MDSplusMethodWidget() self.routine = MDSplusRoutineWidget() self.dispatch = MDSplusDispatchWidget() self.range = MDSplusRangeWidget() self.widgets = ( self.action, self.sequential, self.expression, self.method, self.routine, self.dispatch, self.range, self.windoww, ) self.ok = Button(stock=STOCK_OK) self.cancel = Button(stock=STOCK_CANCEL) self.redo = Button(stock=STOCK_REDO) self.ok.connect("clicked", self.do_ok) self.cancel.connect("clicked", self.do_cancel) self.redo.connect("clicked", self.do_redo) hb2 = HBox() hb2.add(self.ok) hb2.add(self.redo) hb2.add(self.cancel) vb = VBox(homogeneous=False) vb.set_border_width(10) vb.pack_start(hbtop, False, False, 0) vb.pack_start(hbtags, False, False, 0) vb.pack_start(expression_menu, False, False, 0) vb.pack_start(axis_menu, False, False, 0) vb.pack_start(window_menu, False, False, 0) vb.pack_start(dispatch_menu, False, False, 0) vb.pack_start(action_menu, False, False, 0) vb.pack_start(task_menu, False, False, 0) vb.pack_start(any_menu, False, False, 0) for w in self.widgets: w.set_no_show_all(True) vb.pack_start(w, False, False, 0) vb.pack_start(hb2, False, False, 20) self.add(vb) self.do_redo(self.redo) self.putOnApply = True self.nidOffset = -1 def set_dtype(self): if hasattr(self, "_node"): try: exec("self.dtype=self.dtype_%s" % (self.node.usage.lower(),)) except Exception: self.dtype = self.dtype_expression else: self.dtype = self.dtype_any self.dtype.set_no_show_all(False) def do_ok(self, button): try: value = self.value if not self.putOnApply: self.hide() elif hasattr(self, "_node"): try: self.node.record = value self.hide() except Exception: self.popupError(sys.exc_info()) else: self.value = value self.hide() except: pass def do_redo(self, button): if not hasattr(self, "_node"): self.value = _value self.set_dtype() else: self.path.reset() self.on.set_active(self.node.disabled == False) self.parent_on.set_active(self.node.parent_disabled == False) tags = self.node.tags if tags is None: self.tags.set_text("") else: taglist = "" for tag in tags: if taglist == "": taglist = tag else: taglist = taglist + "," + tag self.tags.set_text(taglist) self.set_dtype() try: self.value = self.record except: self.value = None self.reset() def do_cancel(self, button): self.hide()
class MDSplusSequentialWidget(Table): def __init__(self,value=None): super(MDSplusSequentialWidget,self).__init__(rows=4,columns=2,homogeneous=False) self.ident=Entry() self.phase=Entry() self.sequence=Entry() self.event=Entry() self.attach(Label("Server: "),0,1,0,1,0,0) self.attach(self.ident,1,2,0,1,EXPAND|FILL,0) self.attach(Label("Phase: "),0,1,1,2,0,0) self.attach(self.phase,1,2,1,2,EXPAND|FILL,0) self.attach(Label("Sequence:"),0,1,2,3,0,0) self.attach(self.sequence,1,2,2,3,EXPAND|FILL,0) self.attach(Label("Event: "),0,1,3,4,0,0) self.attach(self.event,1,2,3,4,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value def getValue(self): ans=Dispatch(dispatch_type=2) ans.ident=self.ident.get_text() try: ans.ident=Data.compile(ans.ident) except Exception: pass ans.phase=self.phase.get_text() try: ans.phase=Data.compile(ans.phase) except Exception: pass try: ans.when=Data.compile(self.sequence.get_text()) except Exception: msg="Invalid sequence specified.\n\n%s" % (sys.exc_info()[1],) MDSplusErrorMsg('Invalid Sequence',msg) raise ans.completion=self.event.get_text() if ans.completion == '': ans.completion=None else: try: ans.completion=Data.compile(ans.event) except Exception: pass return ans def setValue(self,d): self._value=d self.reset() def reset(self): if isinstance(self._value,Dispatch): self.ident.set_text(self._value.ident.decompile()) self.phase.set_text(self._value.phase.decompile()) self.sequence.set_text(self._value.when.decompile()) if self._value.completion is None: self.event.set_text('') else: self.event.set_text(self._value.completion.decompile()) else: self.ident.set_text('') self.phase.set_text('') self.sequence.set_text('') self.event.set_text('') value=property(getValue,setValue) def show(self): old=self.get_no_show_all() self.set_no_show_all(False) self.show_all() self.set_no_show_all(old)
class Base(object): def __init__(self): from gtk import Window,WINDOW_TOPLEVEL,Button,Label,HBox,Entry,VBox,VSeparator self.window = Window(WINDOW_TOPLEVEL) self.window.set_title("Slideshow") self.window.connect("delete_event", self.delete_event) self.window.set_border_width(10) self.vbox = VBox(False, 0) self.window.add(self.vbox) self.hbox1 = HBox(False, 0) self.vbox.pack_start(self.hbox1, True, True, 1) self.hbox = HBox(False, 0) self.vbox.pack_start(self.hbox, False, False, 1) self.hbox2 = HBox(False, 0) self.vbox.pack_start(self.hbox2, True, True, 1) self.label = Label('Identifikační číslo:') self.hbox.pack_start(self.label, False, False, 1) self.label.show() self.editable = Entry() self.editable.connect('key_press_event', self.key_press_event) self.hbox.pack_start(self.editable, True, True, 1) self.editable.show() self.button = Button("Začít") self.button.connect("clicked", self.callback) self.button.set_receives_default(True) self.button.set_can_focus(True) self.hbox.pack_start(self.button, False, False, 1) self.button.show() self.hbox1.show() self.hbox.show() self.hbox2.show() self.vbox.show() self.window.show() def delete_event(self, widget, event, data=None): gtk.main_quit() return False def key_press_event(self, widget, event): from gtk.gdk import keyval_from_name,keyval_name if event.keyval in (keyval_from_name('Return'),keyval_from_name('KP_Enter')): self.callback(widget) def _getFilePaths(self, fileTypes, recursive=True): import os import re from sys import argv pt = re.compile(r'.*([%(0)s][^%(0)s]*)'%{'0':os.path.extsep}) path = [a for m,a in ((pt.match(os.path.basename(a)),a) for a in argv[1:]) if m and m.group(1) in fileTypes] if not path: path = '/home/pi/img/*.jpg' if isinstance(path, str): ## Returns list containing paths of files in /path/ that are of a file type in /fileTypes/, ## if /recursive/ is False subdirectories are not checked. paths = [] if recursive: for root, folders, files in os.walk(path, followlinks=True): for file in files: for fileType in fileTypes: if file.endswith(fileType): paths.append(os.path.join(root, file)) else: for item in os.listdir(path): for fileType in fileTypes: if item.endswith(fileType): paths.append(os.path.join(root, item)) return paths elif iterable(path): return path else: return [] def _init_cb(self,trans): from threading import Thread if not iterable(trans): trans = trans, callbacks = [] for name,cb in trans: t = Thread(target=cb, name='%sThread'%name) t.daemon = True t.start() callbacks.append(cb.enqueue) def wrap(msg): for cb in callbacks: if not cb(msg): return False return True return wrap def callback(self, widget): from slideshow import SlideShow from trans import Message,GpioTransceiver,JsonTransceiver if not self.editable.get_text(): return False img_cbs = self._init_cb([('ImgGpioCallback',GpioTransceiver(24)),('ImgJsonCallback',JsonTransceiver('img.json'))]) kp_cbs = self._init_cb([('KpGpioCallback',GpioTransceiver(26,bcd=False)),('KpJsonCallback',JsonTransceiver('kp.json'))]) def ordfnc(path): from numpy.random import permutation gray = path[0] result = [] for p in permutation(path[1:]): result.append(p) result.append(gray) return result slide = SlideShow( path=self._getFilePaths(('.jpg', '.jpeg', '.png')), transition='None', fullscreen=True, delay=5, order=ordfnc, principal=self.editable.get_text(), img_callback = img_cbs, kp_callback = kp_cbs, ) self.editable.set_text('') slide() def __call__(self): gtk.main()
class GeoForm(Table): __gsignals__ = { 'search': (SIGNAL_ACTION, TYPE_NONE, (TYPE_FLOAT, TYPE_FLOAT)) } def __init__(self): Table.__init__(self, 1, 5) self.entry1 = Entry() self.entry2 = Entry() self.button = Button("Search") self.attach(self.entry1, 0, 1, 0, 1) self.attach(self.entry2, 1, 2, 0, 1) self.attach(self.button, 2, 3, 0, 1) self.entry1.set_width_chars(12) self.entry2.set_width_chars(12) self.entry1.set_text("59.666042") self.entry2.set_text("16.481794") self.button.connect('clicked', self.clicked) def get_lat_long(self): s1 = self.entry1.get_text() s2 = self.entry2.get_text() re1 = FMT1.match(s1) re2 = FMT1.match(s2) if re1 and re2: return float(re1.group(0)), float(re2.group(0)) re1 = FMT2.match(s1) re2 = FMT3.match(s2) if re1 and re2: c1 = re1.group(3), re1.group(1), re1.group(2) c2 = re2.group(3), re2.group(1), re2.group(2) return geo2dec(c1, c2) re1 = FMT4.match(s1) re2 = FMT5.match(s2) if re1 and re1: c1 = re1.group(1), re1.group(2), re1.group(3) c2 = re2.group(1), re2.group(2), re2.group(3) return geo2dec(c1, c2) raise SyntaxError() def clicked(self, event): try: self.emit('search', *self.get_lat_long()) except SyntaxError: pass
class MDSplusMethodWidget(Table): def __init__(self, value=None): super(MDSplusMethodWidget, self).__init__(rows=4, columns=2, homogeneous=False) self.device = Entry() self.method = Entry() self.args = list() self.argTable = Table(rows=8, columns=2, homogeneous=False) for i in range(8): self.args.append(Entry()) self.argTable.attach(Label("Arg %d: " % (i + 1, )), 0, 1, i, i + 1, 0, 0) self.argTable.attach(self.args[i], 1, 2, i, i + 1, EXPAND | FILL, 0) self.scrolledWindow = ScrolledWindow() self.scrolledWindow.add_with_viewport(self.argTable) self.scrolledWindow.set_policy(POLICY_NEVER, POLICY_ALWAYS) adj = self.scrolledWindow.get_vadjustment() adj.connect("changed", adj_changed) self.timeout = Entry() self.attach(Label("Device:"), 0, 1, 0, 1, 0, 0) self.attach(self.device, 1, 2, 0, 1, EXPAND | FILL, 0) self.attach(Label("Method:"), 0, 1, 1, 2, 0, 0) self.attach(self.method, 1, 2, 1, 2, EXPAND | FILL, 0) self.attach(self.scrolledWindow, 0, 2, 2, 3) self.attach(Label("Timeout:"), 0, 1, 3, 4, 0, 0) self.attach(self.timeout, 1, 2, 3, 4, EXPAND | FILL, 0) self.set_row_spacings(5) self.value = value def getValue(self): ans = Method() ans.method = self.method.get_text() try: ans.method = Data.compile(ans.method) except Exception: pass try: ans.object = Data.compile(self.device.get_text()) except Exception: msg = "Invalid device specified.\n\n%s" % (sys.exc_info()[1], ) MDSplusErrorMsg('Invalid Device', msg) raise if self.timeout.get_text() == '' or self.timeout.get_text() == '*': ans.timeout = None else: try: ans.timeout = Data.compile(self.timeout.get_text()) except Exception: msg = "Invalid timeout specified.\n\n%s" % ( sys.exc_info()[1], ) MDSplusErrorMsg('Invalid Timeout', msg) raise idx = len(self.args) - 1 found = False while idx >= 0: t = self.args[idx].get_text() if t == '': if found: ans.setArgumentAt(idx, None) else: try: a = Data.compile(t) except Exception: msg = "Invalid argument (%d) specified.\n\n%s" % ( idx + 1, sys.exc_info()[1], ) MDSplusErrorMsg('Invalid Argument', msg) raise ans.setArgumentAt(idx, a) found = True idx = idx - 1 return ans def setValue(self, d): self._value = d self.reset() def reset(self): if isinstance(self._value, Method): self.method.set_text(self._value.method.decompile()) self.device.set_text(self._value.object.decompile()) if self._value.timeout is None: self.timeout.set_text('') else: self.timeout.set_text(self._value.timeout.decompile()) idx = 0 for arg in self.args: if self._value.getArgumentAt(idx) is None: arg.set_text('') else: arg.set_text(self._value.getArgumentAt(idx).decompile()) idx = idx + 1 else: self.method.set_text('') self.device.set_text('') self.timeout.set_text('') for arg in self.args: arg.set_text('') value = property(getValue, setValue) def show(self): old = self.get_no_show_all() self.set_no_show_all(False) self.show_all() self.set_no_show_all(old)
class MDSplusWindowWidget(Table): def __init__(self, value=None): super(MDSplusWindowWidget, self).__init__( rows=3, columns=2, homogeneous=False) self.startIdx = Entry() self.endIdx = Entry() self.timeAt0 = Entry() self.attach(Label("StartIdx: "), 0, 1, 0, 1, 0, 0) self.attach(self.startIdx, 1, 2, 0, 1, EXPAND | FILL, 0) self.attach(Label("EndIdx: "), 0, 1, 1, 2, 0, 0) self.attach(self.endIdx, 1, 2, 1, 2, EXPAND | FILL, 0) self.attach(Label("TimeAt0:"), 0, 1, 2, 3, 0, 0) self.attach(self.timeAt0, 1, 2, 2, 3, EXPAND | FILL, 0) self.set_row_spacings(5) self.value = value def getValue(self): ans = Window() t = self.startIdx.get_text() if t == '': ans.startIdx = None else: try: ans.startIdx = Data.compile(self.startIdx.get_text()) except Exception: msg = "Invalid startIdx specified.\n\n%s" % (sys.exc_info(),) MDSplusErrorMsg('Invalid StartIdx', msg) raise t = self.endIdx.get_text() if t == '': ans.endIdx = None else: try: ans.endIdx = Data.compile(self.endIdx.get_text()) except Exception: msg = "Invalid endIdx specified.\n\n%s" % (sys.exc_info(),) MDSplusErrorMsg('Invalid EndIdx', msg) raise t = self.timeAt0.get_text() if t != '': try: ans.timeAt0 = Data.compile(self.timeAt0.get_text()) except Exception: msg = "Invalid timeAt0 specified.\n\n%s" % (sys.exc_info(),) MDSplusErrorMsg('Invalid TimeAt0', msg) raise return ans def setValue(self, d): self._value = d self.reset() def reset(self): if isinstance(self._value, Window): if self._value.startIdx is None: self.startIdx.set_text('') else: self.startIdx.set_text(self._value.startIdx.decompile()) if self._value.endIdx is None: self.endIdx.set_text('') else: self.endIdx.set_text(self._value.endIdx.decompile()) if self._value.timeAt0 is None: self.timeAt0.set_text('') else: self.timeAt0.set_text(self._value.timeAt0.decompile()) else: self.startIdx.set_text('') self.endIdx.set_text('') self.timeAt0.set_text('') value = property(getValue, setValue) def show(self): old = self.get_no_show_all() self.set_no_show_all(False) self.show_all() self.set_no_show_all(old)
class MDSplusXdBox(props,MDSplusDtypeSelWidget,MDSplusWidget,Window): __gtype_name__ = 'MDSplusXdBox' def inHBox(self,w): hb=HBox() hb.pack_start(w,False,False,0) return hb def __init__(self,node=None,value=None): Window.__init__(self) MDSplusWidget.__init__(self) if node is not None: self.node=node else: self.value=value hbtop=HBox(homogeneous=False) self.on=CheckButton(label="On") self.parent_on=CheckButton(label="Parent") self.parent_on.set_sensitive(False) self.path=MDSplusPathWidget() if node is not None: self.path._node=self._node hbtags=HBox(homogeneous=False) self.tags=Entry() self.tags.set_width_chars(60) expression_menu=self.dtype_menu(tuple(),varname='dtype_expression',no_show=True) axis_menu=self.dtype_menu(('Range',),varname='dtype_axis',no_show=True) window_menu=self.dtype_menu(('Window',),varname='dtype_window',no_show=True) dispatch_menu=self.dtype_menu(('Dispatch',),varname='dtype_dispatch',no_show=True) action_menu=self.dtype_menu(('Action',),varname='dtype_action',no_show=True) task_menu=self.dtype_menu(('Method','Routine'),varname='dtype_task',no_show=True) any_menu=self.dtype_menu(('Range','Window','Dispatch','Action','Method','Routine'),varname='dtype_any',no_show=True) menus=(self.dtype_expression,self.dtype_axis,self.dtype_dispatch,self.dtype_action,self.dtype_task,self.dtype_window,self.dtype_any) hbtop.pack_start(self.on,False,False,10) hbtop.pack_start(self.parent_on,False,False,10) hbtop.pack_start(self.path,False,False,0) hbtags.pack_start(Label("Tags:"),False,False,10) hbtags.pack_start(self.tags,False,False,0) self.action=MDSplusActionWidget() self.windoww=MDSplusWindowWidget() self.sequential=MDSplusSequentialWidget() self.expression=MDSplusExpressionWidget() self.method=MDSplusMethodWidget() self.routine=MDSplusRoutineWidget() self.dispatch=MDSplusDispatchWidget() self.range=MDSplusRangeWidget() self.widgets=(self.action,self.sequential,self.expression,self.method,self.routine,self.dispatch,self.range,self.windoww) self.ok=Button(stock=STOCK_OK) self.cancel=Button(stock=STOCK_CANCEL) self.redo=Button(stock=STOCK_REDO) self.ok.connect("clicked",self.do_ok) self.cancel.connect("clicked",self.do_cancel) self.redo.connect("clicked",self.do_redo) hb2=HBox() hb2.add(self.ok) hb2.add(self.redo) hb2.add(self.cancel) vb=VBox(homogeneous=False) vb.set_border_width(10) vb.pack_start(hbtop,False,False,0) vb.pack_start(hbtags,False,False,0) vb.pack_start(expression_menu,False,False,0) vb.pack_start(axis_menu,False,False,0) vb.pack_start(window_menu,False,False,0) vb.pack_start(dispatch_menu,False,False,0) vb.pack_start(action_menu,False,False,0) vb.pack_start(task_menu,False,False,0) vb.pack_start(any_menu,False,False,0) for w in self.widgets: w.set_no_show_all(True) vb.pack_start(w,False,False,0) vb.pack_start(hb2,False,False,20) self.add(vb) self.do_redo(self.redo) self.putOnApply = True self.nidOffset = -1 def set_dtype(self): if hasattr(self,'_node'): try: exec 'self.dtype=self.dtype_%s' % (self.node.usage.lower(),) except Exception,e: self.dtype=self.dtype_expression else:
def __init__(self, node=None, value=None): Window.__init__(self) MDSplusWidget.__init__(self) if node is not None: self.node = node else: self.value = value hbtop = HBox(homogeneous=False) self.on = CheckButton(label="On") self.parent_on = CheckButton(label="Parent") self.parent_on.set_sensitive(False) self.path = MDSplusPathWidget() if node is not None: self.path._node = self._node hbtags = HBox(homogeneous=False) self.tags = Entry() self.tags.set_width_chars(60) expression_menu = self.dtype_menu(tuple(), varname="dtype_expression", no_show=True) axis_menu = self.dtype_menu(("Range",), varname="dtype_axis", no_show=True) window_menu = self.dtype_menu(("Window",), varname="dtype_window", no_show=True) dispatch_menu = self.dtype_menu(("Dispatch",), varname="dtype_dispatch", no_show=True) action_menu = self.dtype_menu(("Action",), varname="dtype_action", no_show=True) task_menu = self.dtype_menu(("Method", "Routine"), varname="dtype_task", no_show=True) any_menu = self.dtype_menu( ("Range", "Window", "Dispatch", "Action", "Method", "Routine"), varname="dtype_any", no_show=True ) menus = ( self.dtype_expression, self.dtype_axis, self.dtype_dispatch, self.dtype_action, self.dtype_task, self.dtype_window, self.dtype_any, ) hbtop.pack_start(self.on, False, False, 10) hbtop.pack_start(self.parent_on, False, False, 10) hbtop.pack_start(self.path, False, False, 0) hbtags.pack_start(Label("Tags:"), False, False, 10) hbtags.pack_start(self.tags, False, False, 0) self.action = MDSplusActionWidget() self.windoww = MDSplusWindowWidget() self.sequential = MDSplusSequentialWidget() self.expression = MDSplusExpressionWidget() self.method = MDSplusMethodWidget() self.routine = MDSplusRoutineWidget() self.dispatch = MDSplusDispatchWidget() self.range = MDSplusRangeWidget() self.widgets = ( self.action, self.sequential, self.expression, self.method, self.routine, self.dispatch, self.range, self.windoww, ) self.ok = Button(stock=STOCK_OK) self.cancel = Button(stock=STOCK_CANCEL) self.redo = Button(stock=STOCK_REDO) self.ok.connect("clicked", self.do_ok) self.cancel.connect("clicked", self.do_cancel) self.redo.connect("clicked", self.do_redo) hb2 = HBox() hb2.add(self.ok) hb2.add(self.redo) hb2.add(self.cancel) vb = VBox(homogeneous=False) vb.set_border_width(10) vb.pack_start(hbtop, False, False, 0) vb.pack_start(hbtags, False, False, 0) vb.pack_start(expression_menu, False, False, 0) vb.pack_start(axis_menu, False, False, 0) vb.pack_start(window_menu, False, False, 0) vb.pack_start(dispatch_menu, False, False, 0) vb.pack_start(action_menu, False, False, 0) vb.pack_start(task_menu, False, False, 0) vb.pack_start(any_menu, False, False, 0) for w in self.widgets: w.set_no_show_all(True) vb.pack_start(w, False, False, 0) vb.pack_start(hb2, False, False, 20) self.add(vb) self.do_redo(self.redo) self.putOnApply = True self.nidOffset = -1
class MDSplusRangeWidget(Table): def __init__(self, value=None): super(MDSplusRangeWidget, self).__init__(rows=3, columns=2, homogeneous=False) self.begin = Entry() self.ending = Entry() self.delta = Entry() self.attach(Label("Begin: "), 0, 1, 0, 1, 0, 0) self.attach(self.begin, 1, 2, 0, 1, EXPAND | FILL, 0) self.attach(Label("Ending: "), 0, 1, 1, 2, 0, 0) self.attach(self.ending, 1, 2, 1, 2, EXPAND | FILL, 0) self.attach(Label("Delta:"), 0, 1, 2, 3, 0, 0) self.attach(self.delta, 1, 2, 2, 3, EXPAND | FILL, 0) self.set_row_spacings(5) self.value = value def getValue(self): ans = Range() t = self.begin.get_text() if t == '': ans.begin = None else: try: ans.begin = Data.compile(self.begin.get_text()) except Exception: msg = "Invalid begin specified.\n\n%s" % (sys.exc_info(), ) MDSplusErrorMsg('Invalid Begin', msg) raise t = self.ending.get_text() if t == '': ans.ending = None else: try: ans.ending = Data.compile(self.ending.get_text()) except Exception: msg = "Invalid ending specified.\n\n%s" % (sys.exc_info(), ) MDSplusErrorMsg('Invalid Ending', msg) raise t = self.delta.get_text() if t != '': try: ans.delta = Data.compile(self.delta.get_text()) except Exception: msg = "Invalid delta specified.\n\n%s" % (sys.exc_info(), ) MDSplusErrorMsg('Invalid Delta', msg) raise return ans def setValue(self, d): self._value = d self.reset() def reset(self): if isinstance(self._value, Range): if self._value.begin is None: self.begin.set_text('') else: self.begin.set_text(self._value.begin.decompile()) if self._value.ending is None: self.ending.set_text('') else: self.ending.set_text(self._value.ending.decompile()) if self._value.delta is None: self.delta.set_text('') else: self.delta.set_text(self._value.delta.decompile()) else: self.begin.set_text('') self.ending.set_text('') self.delta.set_text('') value = property(getValue, setValue) def show(self): old = self.get_no_show_all() self.set_no_show_all(False) self.show_all() self.set_no_show_all(old)
class MDSplusSequentialWidget(Table): def __init__(self, value=None): super(MDSplusSequentialWidget, self).__init__(rows=4, columns=2, homogeneous=False) self.ident = Entry() self.phase = Entry() self.sequence = Entry() self.event = Entry() self.attach(Label("Server: "), 0, 1, 0, 1, 0, 0) self.attach(self.ident, 1, 2, 0, 1, EXPAND | FILL, 0) self.attach(Label("Phase: "), 0, 1, 1, 2, 0, 0) self.attach(self.phase, 1, 2, 1, 2, EXPAND | FILL, 0) self.attach(Label("Sequence:"), 0, 1, 2, 3, 0, 0) self.attach(self.sequence, 1, 2, 2, 3, EXPAND | FILL, 0) self.attach(Label("Event: "), 0, 1, 3, 4, 0, 0) self.attach(self.event, 1, 2, 3, 4, EXPAND | FILL, 0) self.set_row_spacings(5) self.value = value def getValue(self): ans = Dispatch(dispatch_type=2) ans.ident = self.ident.get_text() try: ans.ident = Data.compile(ans.ident) except Exception: pass ans.phase = self.phase.get_text() try: ans.phase = Data.compile(ans.phase) except Exception: pass try: ans.when = Data.compile(self.sequence.get_text()) except Exception: msg = "Invalid sequence specified.\n\n%s" % (sys.exc_info(), ) MDSplusErrorMsg('Invalid Sequence', msg) raise ans.completion = self.event.get_text() if ans.completion == '': ans.completion = None else: try: ans.completion = Data.compile(ans.event) except Exception: pass return ans def setValue(self, d): self._value = d self.reset() def reset(self): if isinstance(self._value, Dispatch): self.ident.set_text(self._value.ident.decompile()) self.phase.set_text(self._value.phase.decompile()) self.sequence.set_text(self._value.when.decompile()) if self._value.completion is None: self.event.set_text('') else: self.event.set_text(self._value.completion.decompile()) else: self.ident.set_text('') self.phase.set_text('') self.sequence.set_text('') self.event.set_text('') value = property(getValue, setValue) def show(self): old = self.get_no_show_all() self.set_no_show_all(False) self.show_all() self.set_no_show_all(old)
def __init__(self,node=None,value=None): Window.__init__(self) MDSplusWidget.__init__(self) if node is not None: self.node=node else: self.value=value hbtop=HBox(homogeneous=False) self.on=CheckButton(label="On") self.parent_on=CheckButton(label="Parent") self.parent_on.set_sensitive(False) self.path=MDSplusPathWidget() if node is not None: self.path._node=self._node hbtags=HBox(homogeneous=False) self.tags=Entry() self.tags.set_width_chars(60) expression_menu=self.dtype_menu(tuple(),varname='dtype_expression',no_show=True) axis_menu=self.dtype_menu(('Range',),varname='dtype_axis',no_show=True) window_menu=self.dtype_menu(('Window',),varname='dtype_window',no_show=True) dispatch_menu=self.dtype_menu(('Dispatch',),varname='dtype_dispatch',no_show=True) action_menu=self.dtype_menu(('Action',),varname='dtype_action',no_show=True) task_menu=self.dtype_menu(('Method','Routine'),varname='dtype_task',no_show=True) any_menu=self.dtype_menu(('Range','Window','Dispatch','Action','Method','Routine'),varname='dtype_any',no_show=True) menus=(self.dtype_expression,self.dtype_axis,self.dtype_dispatch,self.dtype_action,self.dtype_task,self.dtype_window,self.dtype_any) hbtop.pack_start(self.on,False,False,10) hbtop.pack_start(self.parent_on,False,False,10) hbtop.pack_start(self.path,False,False,0) hbtags.pack_start(Label("Tags:"),False,False,10) hbtags.pack_start(self.tags,False,False,0) self.action=MDSplusActionWidget() self.windoww=MDSplusWindowWidget() self.sequential=MDSplusSequentialWidget() self.expression=MDSplusExpressionWidget() self.method=MDSplusMethodWidget() self.routine=MDSplusRoutineWidget() self.dispatch=MDSplusDispatchWidget() self.range=MDSplusRangeWidget() self.widgets=(self.action,self.sequential,self.expression,self.method,self.routine,self.dispatch,self.range,self.windoww) self.ok=Button(stock=STOCK_OK) self.cancel=Button(stock=STOCK_CANCEL) self.redo=Button(stock=STOCK_REDO) self.ok.connect("clicked",self.do_ok) self.cancel.connect("clicked",self.do_cancel) self.redo.connect("clicked",self.do_redo) hb2=HBox() hb2.add(self.ok) hb2.add(self.redo) hb2.add(self.cancel) vb=VBox(homogeneous=False) vb.set_border_width(10) vb.pack_start(hbtop,False,False,0) vb.pack_start(hbtags,False,False,0) vb.pack_start(expression_menu,False,False,0) vb.pack_start(axis_menu,False,False,0) vb.pack_start(window_menu,False,False,0) vb.pack_start(dispatch_menu,False,False,0) vb.pack_start(action_menu,False,False,0) vb.pack_start(task_menu,False,False,0) vb.pack_start(any_menu,False,False,0) for w in self.widgets: w.set_no_show_all(True) vb.pack_start(w,False,False,0) vb.pack_start(hb2,False,False,20) self.add(vb) self.do_redo(self.redo) self.putOnApply = True self.nidOffset = -1
class MDSplusXdBox(props,MDSplusDtypeSelWidget,MDSplusWidget,Window): __gtype_name__ = 'MDSplusXdBox' def inHBox(self,w): hb=HBox() hb.pack_start(w,False,False,0) return hb def __init__(self,node=None,value=None): Window.__init__(self) MDSplusWidget.__init__(self) if node is not None: self.node=node else: self.value=value hbtop=HBox(homogeneous=False) self.on=CheckButton(label="On") self.parent_on=CheckButton(label="Parent") self.parent_on.set_sensitive(False) self.path=MDSplusPathWidget() if node is not None: self.path._node=self._node hbtags=HBox(homogeneous=False) self.tags=Entry() self.tags.set_width_chars(60) expression_menu=self.dtype_menu(tuple(),varname='dtype_expression',no_show=True) axis_menu=self.dtype_menu(('Range',),varname='dtype_axis',no_show=True) window_menu=self.dtype_menu(('Window',),varname='dtype_window',no_show=True) dispatch_menu=self.dtype_menu(('Dispatch',),varname='dtype_dispatch',no_show=True) action_menu=self.dtype_menu(('Action',),varname='dtype_action',no_show=True) task_menu=self.dtype_menu(('Method','Routine'),varname='dtype_task',no_show=True) any_menu=self.dtype_menu(('Range','Window','Dispatch','Action','Method','Routine'),varname='dtype_any',no_show=True) menus=(self.dtype_expression,self.dtype_axis,self.dtype_dispatch,self.dtype_action,self.dtype_task,self.dtype_window,self.dtype_any) hbtop.pack_start(self.on,False,False,10) hbtop.pack_start(self.parent_on,False,False,10) hbtop.pack_start(self.path,False,False,0) hbtags.pack_start(Label("Tags:"),False,False,10) hbtags.pack_start(self.tags,False,False,0) self.action=MDSplusActionWidget() self.windoww=MDSplusWindowWidget() self.sequential=MDSplusSequentialWidget() self.expression=MDSplusExpressionWidget() self.method=MDSplusMethodWidget() self.routine=MDSplusRoutineWidget() self.dispatch=MDSplusDispatchWidget() self.range=MDSplusRangeWidget() self.widgets=(self.action,self.sequential,self.expression,self.method,self.routine,self.dispatch,self.range,self.windoww) self.ok=Button(stock=STOCK_OK) self.cancel=Button(stock=STOCK_CANCEL) self.redo=Button(stock=STOCK_REDO) self.ok.connect("clicked",self.do_ok) self.cancel.connect("clicked",self.do_cancel) self.redo.connect("clicked",self.do_redo) hb2=HBox() hb2.add(self.ok) hb2.add(self.redo) hb2.add(self.cancel) vb=VBox(homogeneous=False) vb.set_border_width(10) vb.pack_start(hbtop,False,False,0) vb.pack_start(hbtags,False,False,0) vb.pack_start(expression_menu,False,False,0) vb.pack_start(axis_menu,False,False,0) vb.pack_start(window_menu,False,False,0) vb.pack_start(dispatch_menu,False,False,0) vb.pack_start(action_menu,False,False,0) vb.pack_start(task_menu,False,False,0) vb.pack_start(any_menu,False,False,0) for w in self.widgets: w.set_no_show_all(True) vb.pack_start(w,False,False,0) vb.pack_start(hb2,False,False,20) self.add(vb) self.do_redo(self.redo) self.putOnApply = True self.nidOffset = -1 def set_dtype(self): if hasattr(self,'_node'): try: exec('self.dtype=self.dtype_%s' % (self.node.usage.lower(),)) except Exception: self.dtype=self.dtype_expression else: self.dtype=self.dtype_any self.dtype.set_no_show_all(False) def do_ok(self,button): try: value=self.value if not self.putOnApply: self.hide() elif hasattr(self,'_node'): try: self.node.record=value self.hide() except Exception: self.popupError(sys.exc_info()[1]) else: self.value=value self.hide() except: pass def do_redo(self,button): if not hasattr(self,'_node'): self.value=_value self.set_dtype() else: self.path.reset() self.on.set_active(self.node.disabled==False) self.parent_on.set_active(self.node.parent_disabled==False) tags = self.node.tags if tags is None: self.tags.set_text('') else: taglist='' for tag in tags: if taglist == '': taglist=tag else: taglist=taglist+','+tag self.tags.set_text(taglist) self.set_dtype() try: self.value=self.record except: self.value=None self.reset() def do_cancel(self,button): self.hide()
class MDSplusRoutineWidget(Table): def __init__(self,value=None): super(MDSplusRoutineWidget,self).__init__(rows=4,columns=2,homogeneous=False) self.image=Entry() self.routine=Entry() self.args=list() self.argTable=Table(rows=8,columns=2,homogeneous=False) for i in range(8): self.args.append(Entry()) self.argTable.attach(Label("Arg %d: " % (i+1,)),0,1,i,i+1,0,0) self.argTable.attach(self.args[i],1,2,i,i+1,EXPAND|FILL,0) self.scrolledWindow=ScrolledWindow() self.scrolledWindow.add_with_viewport(self.argTable) self.scrolledWindow.set_policy(POLICY_NEVER,POLICY_ALWAYS) adj=self.scrolledWindow.get_vadjustment() adj.connect("changed",adj_changed) self.timeout=Entry() self.attach(Label("Library:"),0,1,0,1,0,0) self.attach(self.image,1,2,0,1,EXPAND|FILL,0) self.attach(Label("Routine:"),0,1,1,2,0,0) self.attach(self.routine,1,2,1,2,EXPAND|FILL,0) self.attach(self.scrolledWindow,0,2,2,3) self.attach(Label("Timeout:"),0,1,3,4,0,0) self.attach(self.timeout,1,2,3,4,EXPAND|FILL,0) self.set_row_spacings(5) self.value=value def getValue(self): ans=Routine() ans.image=self.image.get_text() try: ans.image=Data.compile(ans.image) except Exception: pass ans.routine=self.routine.get_text() try: ans.routine=Data.compile(ans.routine) except Exception: pass if self.timeout.get_text() == '' or self.timeout.get_text() == '*': ans.timeout=None else: try: ans.timeout=Data.compile(self.timeout.get_text()) except Exception: msg="Invalid timeout specified.\n\n%s" % (sys.exc_info(),) MDSplusErrorMsg('Invalid Timeout',msg) raise idx=len(self.args)-1 found=False while idx >= 0: t = self.args[idx].get_text() if t == '': if found: ans.setArgumentAt(idx,None) else: try: a=Data.compile(t) except Exception: msg="Invalid argument specified.\n\n%s" % (sys.exc_info(),) MDSplusErrorMsg('Invalid Argument',msg) raise ans.setArgumentAt(idx,a) found=True idx=idx-1 return ans def setValue(self,d): self._value=d self.reset() def reset(self): if isinstance(self._value,Routine): self.image.set_text(self._value.image.decompile()) self.routine.set_text(self._value.routine.decompile()) if self._value.timeout is None or self._value.timeout.decompile() == '*': self.timeout.set_text('') else: self.timeout.set_text(self._value.timeout.decompile()) idx=0 for arg in self.args: if self._value.getArgumentAt(idx) is None: arg.set_text('') else: arg.set_text(self._value.getArgumentAt(idx).decompile()) idx=idx+1 else: self.image.set_text('') self.routine.set_text('') self.timeout.set_text('') for arg in self.args: arg.set_text('') value=property(getValue,setValue) def show(self): old=self.get_no_show_all() self.set_no_show_all(False) self.show_all() self.set_no_show_all(old)