Beispiel #1
0
class Workspace(HBox):
    def __init__(self):
        HBox.__init__(self, False, 2)

        self.toolBox = VBox(False, 2)
        self.shapeCategoryCombo = DirCombo(join(data_path, 'shapes'))

        self.toolBox.pack_start(self.shapeCategoryCombo, False, False, 0)

        self.drawArea = DrawArea()

        root = self.drawArea.canvas.get_root_item()
        text = Text(text='Testing', x=200, y=200)
        rect = Rect(height=50,
                    width=100,
                    radius_x=10,
                    radius_y=10,
                    x=200,
                    y=500,
                    fill_color='gray')
        buttonText = Text(text='Button',
                          x=250,
                          y=525,
                          fill_color='dark-gray',
                          anchor=ANCHOR_CENTER)
        root.add_child(text, -1)
        root.add_child(rect, -1)
        root.add_child(buttonText, -1)

        self.pack_start(self.toolBox, False, False, 0)
        self.pack_start(self.drawArea, True, True, 0)
class command_dialog(Window):

    def __init__(self, icon):

        Window.__init__(self, WINDOW_TOPLEVEL)
        self.set_property("skip-taskbar-hint", True)
        self.set_property("destroy-with-parent", True)
        self.set_modal(True)
        self.set_position(WIN_POS_CENTER)

        self.vbox = VBox(False, 0)
        
        self.terminal = terminal()
        self.terminal.connect("child-exited",
                              lambda _: self.close_button.show())
        self.terminal.show()
        
        self.close_button = Button(stock=STOCK_CLOSE)
        self.close_button.connect("clicked", lambda _: self.destroy())

        self.vbox.pack_start(self.terminal, False, False, 0)
        self.vbox.pack_start(self.close_button, False, False, 0)
        self.vbox.show()

        self.add(self.vbox)

        self.set_icon(pixbuf_new_from_file(icon))

    def run(self, command):
        self.show()
        
        self.terminal.fork_command()
        self.terminal.feed_child("pacman --noconfirm -%s;exit\n" %command)
Beispiel #3
0
    def __init__(self):
        '''
        Constructor
        '''
        cellRendererText = CellRendererText()

        treeViewColumn = TreeViewColumn()
        treeViewColumn.pack_start(cellRendererText)

        treeView = TreeView()
        treeView.append_column(treeViewColumn)

        scrolledWindow = ScrolledWindow()
        scrolledWindow.add(treeView)

        btnAdd_Alternative = Button()
        btnDel_Alternative = Button()

        hButtonBox = HButtonBox()
        hButtonBox.pack_start(btnAdd_Alternative)
        hButtonBox.pack_start(btnDel_Alternative)

        vBox = VBox()
        vBox.pack_start(scrolledWindow)
        vBox.pack_start(hButtonBox)

        self.add(vBox)
Beispiel #4
0
class MenuWindow(Window, HasMenuDialog):
    def __init__(self, name='MenuVBoxWindow'):
        Window.__init__(self)
        self.set_name(name)
        self.vbox = VBox()
        self.add(self.vbox)
        self.menubar = SimpleMenuBar()
        self.vbox.pack_start(self.menubar, FALSE, FALSE, 0)
        self.vbox.show()
        self.show()
class MenuWindow(Window, HasMenuDialog):
    def __init__(self, name='MenuVBoxWindow'):
        Window.__init__(self)
        self.set_name(name)
        self.vbox = VBox()
        self.add(self.vbox)
        self.menubar = SimpleMenuBar()
        self.vbox.pack_start(self.menubar, False, False, 0)
        self.vbox.show()
        self.show()
Beispiel #6
0
class GeoResult(ScrolledWindow):
    def __init__(self):

        ScrolledWindow.__init__(self)

        self.set_policy(POLICY_NEVER, POLICY_ALWAYS)

        self.box = VBox()

        self.add_with_viewport(self.box)

    def add_cache(self, cache):

        self.box.pack_start(GtkCache(cache))

    '''
Beispiel #7
0
class GeoResult(ScrolledWindow):
    
    def __init__(self):
        
        ScrolledWindow.__init__(self)
        
        self.set_policy(POLICY_NEVER, POLICY_ALWAYS)
        
        self.box = VBox()
        
        self.add_with_viewport(self.box)
        
    
    def add_cache(self, cache):
        
        self.box.pack_start(GtkCache(cache))
        
    '''
class MenuWindowOrig(Window):
    def __init__(self, name='MenuVBoxWindow'):
        Window.__init__(self)
        self.set_name(name)
        self.vbox = VBox()
        self.add(self.vbox)
        self.menubar = SimpleMenuBar()
        self.vbox.pack_start(self.menubar, False, False, 0)
        self.vbox.show()
        self.show()

    def add_menu(self, commands, name, function, radio=False):
        if radio:
            new_menu = RadioMenu(commands, function)
        else:
            new_menu = SimpleMenu()
            for command in commands:
                new_menu.add(command, function)
        self.menubar.append(new_menu, name)
def main():
    print 'answer', input_entry_dialog("who what?", 'edit me')

    gtk_info_message("hi there missy")

    w = Window()
    w.resize(200, 200)
    w.connect( "delete-event", main_quit )
    vbox = VBox()
    w.add(vbox)
    ONE_DAY = timedelta(days=1)
    existing_list = [PersistentList(test_program_return_new_row())]
    model, tv, tv_vbox = \
        create_editable_type_defined_listview_and_model(
        ( ('date', date,),
          ('choose-me',
           (True, str, 'yo', 'hi', 'me', 'fun')
           ), # end choose-me tuple
          ('choose-me-only',
           (False, str, 'yo', 'hi', 'me', 'fun')
           ), # end choose-me-only tuple
          ('choose-me-num',
           (False, int, 1, 2, 3, 4)
           ), # end choose-num tuple
          ('description', str),
          ('count', int),
          ('file_path', {'type': file,
                         'file_type':FILE_CHOOSER_ACTION_SELECT_FOLDER} ),
          ('choose-me-date',
           (False, date,
            date.today() - ONE_DAY, date.today(), date.today() + ONE_DAY ) ),
          ('choose-me-obj',
           (False, (None, TestProgType(), TestProgType()),
            'None', 'obj 1', 'obj 2' ) ),
          ('choose-me-Decimal',
           (True, Decimal, '3.1', '3.4') ),
          ), # end type tuple
        test_program_return_new_row, existing_list, test_prog_list_changed,
        False
        ) # create_editable_type_defined_listview_and_model
    vbox.pack_start( tv_vbox )
    w.show_all()
    gtk_main()
Beispiel #10
0
class MenuWindowOrig(Window):
    def __init__(self, name='MenuVBoxWindow'):
        Window.__init__(self)
        self.set_name(name)
        self.vbox = VBox()
        self.add(self.vbox)
        self.menubar = SimpleMenuBar()
        self.vbox.pack_start(self.menubar, FALSE, FALSE, 0)
        self.vbox.show()
        self.show()

    def add_menu(self, commands, name, function, radio=False):
        if radio:
            new_menu = RadioMenu(commands, function)
        else:
            new_menu = SimpleMenu()
            for command in commands:
                new_menu.add(command, function)
        self.menubar.append(new_menu, name)
 def initXdbox(self):
     self.xdbox = Window()
     try:
         self.xdbox.set_title(str(self.node))
     except:
         pass
     vbox = VBox()
     self.xdbox.expr = MDSplusExprWidget()
     vbox.pack_start(self.xdbox.expr, True, True, 20)
     close = Button(stock=STOCK_CLOSE)
     close.connect("clicked", self.xdbox_close)
     redo = Button(stock=STOCK_REDO)
     redo.connect("clicked", self.xdbox_redo)
     cancel = Button(stock=STOCK_CANCEL)
     cancel.connect("clicked", self.xdbox_cancel)
     hbox = HBox()
     hbox.pack_start(close, False, False, 20)
     hbox.pack_start(redo, False, False, 20)
     hbox.pack_start(cancel, False, False, 20)
     vbox.pack_start(hbox, False, False, 20)
     self.xdbox.add(vbox)
     self.xdbox.expr.set_text(self.node_value())
 def initXdbox(self):
     self.xdbox=Window()
     try:
         self.xdbox.set_title(str(self.node))
     except:
         pass
     vbox=VBox()
     self.xdbox.expr=MDSplusExprWidget()
     vbox.pack_start(self.xdbox.expr,True,True,20)
     close=Button(stock=STOCK_CLOSE)
     close.connect("clicked",self.xdbox_close)
     redo=Button(stock=STOCK_REDO)
     redo.connect("clicked",self.xdbox_redo)
     cancel=Button(stock=STOCK_CANCEL)
     cancel.connect("clicked",self.xdbox_cancel)
     hbox=HBox()
     hbox.pack_start(close,False,False,20)
     hbox.pack_start(redo,False,False,20)
     hbox.pack_start(cancel,False,False,20)
     vbox.pack_start(hbox,False,False,20)
     self.xdbox.add(vbox)
     self.xdbox.expr.set_text(self.node_value())
Beispiel #13
0
	def __init__ (self, title):
		Window.__init__(self)
		self.set_title(title)
		self.set_border_width(5)
		self.set_app_paintable(True)

		calendar = Calendar()
		testItem1 = SimpleItem('Hello')
		testItem2 = SimpleItem('This is Cool', '#b81919', '8f1b1b')

		toolBox = VBox(False, 5)
		toolBox.pack_start(testItem1, False, False, 0)
		toolBox.pack_start(testItem2, False, False, 0)

		mainBox = HBox(False, 5)
		mainBox.pack_start(toolBox, False, False, 0)
		mainBox.pack_start(calendar, False, False, 0)

		self.add(mainBox)
		self.maximize()

		self.connect('expose-event', self.expose, None)
		self.connect('destroy', main_quit)
Beispiel #14
0
    def __init__(self):
        Window.__init__(self)

        self.model = ListStore(str, str)

        self.aboutWindow = None
        self.helper = Helper(None)

        self.set_title('Gnome Custom Shortcuts')
        self.set_icon_from_file(join(data_path, 'icon.svg'))
        self.set_border_width(5)
        self.set_size_request(400, 400)

        list = TreeView()
        list.append_column(TreeViewColumn(''))
        list.append_column(TreeViewColumn('Command'))
        list.append_column(TreeViewColumn('Shortcut'))

        closeButton = Button(None, STOCK_CLOSE)
        aboutButton = Button(None, STOCK_ABOUT)

        buttonsBox = HButtonBox()
        buttonsBox.pack_start(aboutButton, False, False, 0)
        buttonsBox.pack_start(Label(''), True, True, 0)
        buttonsBox.pack_start(closeButton, False, False, 0)

        box = VBox(False, 5)
        box.pack_start(list, True, True, 0)
        box.pack_start(buttonsBox, False, False, 0)

        self.connect('destroy', main_quit, None)
        closeButton.connect('clicked', main_quit, None)
        aboutButton.connect('clicked', self.show_about, None)

        self.add(box)
        self.show_all()
    def __init__(self, objectives, new):
        Expander.__init__(self)

        self.connect("enter-notify-event", self.onEnterNotifyEvent)
        self.connect("leave-notify-event", self.onLeaveNotifyEvent)

        vBox = VBox()
        self.add(vBox)

        # Data model
        self.model = ListStore(str, float)

        # Title bar
        hBox = HBox()
        self.set_property("label-widget", hBox)

        self.title = Label()
        hBox.pack_start(self.title)

        # Alternatives
        treeView = TreeView(self.model)
        #		treeView.set_headers_visible(False)
        vBox.pack_start(treeView)

        listStore_objectives = ListStore(str)
        for name in objectives:
            listStore_objectives.append((name, ))

        def combo_changed(_, path, text, model):
            model[path][0] = text

        cellRenderer = CellRendererCombo()
        cellRenderer.connect("edited", combo_changed, self.model)
        cellRenderer.set_property("text-column", 0)
        cellRenderer.set_property("editable", True)
        cellRenderer.set_property("has-entry", True)
        cellRenderer.set_property("model", listStore_objectives)

        treeViewColumn = TreeViewColumn("Alternative", cellRenderer, text=0)
        #		treeViewColumn = TreeViewColumn(None,cellRenderer,text=0)
        treeView.append_column(treeViewColumn)

        def spin_changed(_, path, value, model):
            model[path][1] = float(value.replace(",", "."))

        cellRenderer = CellRendererSpin()
        cellRenderer.connect("edited", spin_changed, self.model)
        cellRenderer.set_property("adjustment",
                                  Adjustment(1, 0, 100, 1, 10, 0))
        cellRenderer.set_property("editable", True)
        cellRenderer.set_property("digits", 2)

        treeViewColumn = TreeViewColumn(None, cellRenderer, text=1)
        treeView.append_column(treeViewColumn)

        # Add/remove alternative button box
        #		hButtonBox = HButtonBox()
        #		vBox.pack_start(hButtonBox, False)

        # Add alternative
        button = Button("gtk-add")
        button.connect("clicked", self.on_btnAdd_Alternative_clicked)
        button.set_use_stock(True)
        #		hButtonBox.pack_start(button)
        vBox.pack_start(button, False)

        #		# Remove alternative
        #		button = Button("gtk-remove")
        #		button.connect("clicked",self.on_btnDel_Alternative_clicked)
        #		button.set_use_stock(True)
        #		hButtonBox.pack_start(button)

        # Expand the requeriment and add an alternative if it's new
        if new:
            self.set_expanded(True)
            self.model.append((None, 1.0))

        # Show requeriment
        self.show_all()

        # Delete requeriment button (default is hidden)
        self.imgRemove = Image()
        self.imgRemove.connect("button-press-event", self.onDelRequeriment)
        self.imgRemove.set_from_stock("gtk-cancel", ICON_SIZE_MENU)
        hBox.pack_start(self.imgRemove)
Beispiel #16
0
 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 multipage_glade_editor(object):
    def __init__(self,
                 trans, transid, plugin, gui_parent, change_register_function,
                 book, display_mode=TRANSACTION_ALL_EDIT_FIRST_TIME,
                 transaction_edit_finished_function=null_function):
        self.trans = trans
        self.transid = transid
        self.plugin = plugin
        self.gui_parent = gui_parent
        self.change_register_function = change_register_function
        self.book = book
        self.display_mode = display_mode
        self.transaction_edit_finished_function = (
            null_function if display_mode not in HEADLESS_MODES
            else transaction_edit_finished_function )

        self.hide_parent = Window()
        self.hide_parent.hide()
        self.mainvbox = VBox()
        self.hide_parent.add(self.mainvbox)

        config = self.trans.get_configuration_and_provide_on_load_hook()
        config_module_name = self.plugin.config_module_name
        if not config_valid(config):
            # even in the case of a broken config, we should still
            # display all of the data we have available...
            self.mainvbox.pack_start(Label("no configuration"))
        elif not self.trans.can_safely_proceed_with_config_module(config):
            # should display all data that's available instead of just
            # this label
            #
            # and should give
            # user an overide option where they either pick an old config
            # for one time use or just blow out the memory of having used
            # a different config...
            #
            # should also print the checksum itself so they know
            # what they need...
            #
            # perhaps eventually we even put in place some archival support
            # for saving old glade and config files and then code into the
            # the transaction -- hey, code you need to be editable is
            # over here..
            #
            # now hopefully there is no marking of this transaction dirty
            # in this mode and the extra safegaurds we put into
            # MultipageGladeTransaction don't get activated
            self.mainvbox.pack_start(
                Label("out of date configuration. data is read only here for "
                      "the safety of your old information, last adler "
                      "CRC was %s" % self.trans.config_crc_cache ))
        else:
            # if the safety cache was relied on before we need to tell the
            # backend that the transaction is actually dirty,
            # and now that we know that we have a workable config,
            # there's a chance that we'll actually be able to avoid
            # relying on the cache this time
            if self.trans.get_safety_cache_was_used():
                self.change_register_function()

            self.page_label = Label("")
            (x_align, y_align) = self.page_label.get_alignment()
            self.page_label.set_alignment(0.0, y_align)
            self.mainvbox.pack_start(self.page_label, expand=False)

            # establish maincontainer, which is where the actual glade
            # pages are put by attach_current_page
            #
            # The order of placement here is important, we place this
            # after page_label has already been added to main
            # and we also need to do this prior to attach_current_page
            # being called, as it depends on self.maincontainer being
            # there
            #
            # when we're in headless mode the maincontainer can just be
            # the mainvbox itself
            #
            # but, outside headless mode we save screen real-estate and
            # place a scrolled window (which becomes the maincontainer)
            # inside the mainvbox and the glade by glade pages end up
            # in there instead (again, in attach_current_page)
            if display_mode in HEADLESS_MODES:
                self.maincontainer = self.mainvbox
            else:
                self.maincontainer = Viewport()
                sw = ScrolledWindow()
                sw.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
                sw.add( self.maincontainer)
                self.mainvbox.pack_start(sw)

            self.glade_pages = [
                self.__setup_page(glade_file, top_glade_element)
                for glade_file, top_glade_element in config.pages ]
            self.glade_pages_by_ident_index = dict(
                ( (key, self.glade_pages[i])
                  for i, key in enumerate(config.pages)
                  ) # end generator expression
                ) # end dict
            
            self.__setup_auto_widgets()

            self.current_page = 0
            self.attach_current_page()

            button_hbox = HBox()
            self.mainvbox.pack_end(button_hbox, expand=False)
            self.nav_buts = dict( (Button(), i)
                                  for i in range(2) )
            for but, i in self.nav_buts.iteritems():
                but.set_property('use-stock', True)
                but.set_label( STOCK_GO_BACK
                               if i == GLADE_BACK_NAV else STOCK_GO_FORWARD )
                button_hbox.pack_start(but, expand=False)
                but.connect("clicked", self.nav_but_clicked)

            config.gui_initialization_hook(
                self, self.trans, self.plugin, self.book)

        self.mainvbox.show_all()
        self.mainvbox.reparent(self.gui_parent)

    def page_is_current(self, page):
        # assumption is that config is fine and we're on a page
        assert( hasattr(self, 'glade_pages_by_ident_index') and
                True )
        return \
            self.glade_pages_by_ident_index[page] == self.current_widget_dict

    def __setup_page(self, glade_file, top_glade_element):
        widget_dict = {}
        
        # this should come from the config, seeing how we're setting up
        # our stuff manually
        event_handlers_dict = {}
        load_glade_file_get_widgets_and_connect_signals(
            glade_file, top_glade_element,
            widget_dict, event_handlers_dict )
        widget_dict[top_glade_element].hide()
        return widget_dict

    def __setup_auto_widgets(self):
        # go through each page
        for key, widget_dict in self.glade_pages_by_ident_index.iteritems():
            # go through each widget
            for widget_name, widget in widget_dict.iteritems():
                widget_key = (key, widget_name)

                # determine if the current widget is one that we can take
                # care of automatically saving, we do this with a linear
                # search through a table of eligible types,
                # where the first element of each entry is Widget class
                #
                # Once we have a match do one of the following
                #  * Change the widget from the existing stored stage
                #  * Establish new state from some default
                # The next two entries in the table
                # (change_widget_from_state, new_state_from_widget)
                # provide functions to do this
                #
                # Lastly, we establish event handlers for this widget using
                # the last element in the table
                for (cls,
                     change_widget_from_state, new_state_from_widget,
                     establish_event_handlers) in ( # start table

                    (Entry,
                     lambda w, wk: w.set_text(self.trans.get_widget_state(wk)),
                     lambda w: '',
                     lambda w: w.connect("changed", self.entry_changed),
                     ), # Entry

                    (Calendar,
                     self.__change_calendar_from_saved_version,
                     get_current_date_of_gtkcal,
                     lambda w: w.connect( "day_selected",
                                          self.calendar_changed ), 
                     ), # Calendar

                    (CheckButton,
                     lambda w, wk:
                         w.set_active(self.trans.get_widget_state(wk)),
                     get_state_of_checkbutton,
                     lambda w: w.connect("toggled", self.checkbutton_changed),
                     ), # CheckButton

                    ): # end of table and for declartion

                    # does the widget match the type in the current table entry?
                    if isinstance(widget, cls):

                        # use the three remaining functions in the table
                        # as appropriate
                        if self.trans.has_widget_state( widget_key ):
                            change_widget_from_state(widget, widget_key)
                        else:
                            self.trans.update_widget_state(
                                widget_key,
                                new_state_from_widget(widget) )
                        establish_event_handlers(widget)

    def __change_calendar_from_saved_version(self, widget, widget_key):
        set_current_date_of_gtkcal(widget, 
                                   self.trans.get_widget_state( widget_key ) )

    def attach_current_page(self):
        config = self.plugin.get_configuration(allow_reload=False)
        self.current_widget_dict = self.glade_pages[self.current_page] 
        self.current_window = self.current_widget_dict[
            config.pages[self.current_page][TOP_WIDGET] ]
        self.current_top_vbox = self.current_window.child
        self.current_top_vbox.reparent(
            self.maincontainer)
        self.page_label.set_text( "page %s of %s" %( self.current_page + 1,
                                                     len(config.pages) ) )
        self.update_auto_labels()

    def detach_current_page(self):
        # put the spawn back to wence it came
        self.current_top_vbox.reparent(
            self.current_window)

    def detach(self):
        if hasattr(self, 'current_page'):
            self.detach_current_page()
        self.mainvbox.reparent(self.hide_parent)

    def page_change_acceptable_by_input_valid(self):
        bad_fields = ', '.join( widget_name
            for widget_name, widget in self.current_widget_dict.iteritems()
            if not self.widget_valid(widget_name, widget)
            )
        if bad_fields == '':
            return True
        else:
            # this is kind of primiative, it would be better to
            # just highlight them by inserting red lights or something
            gtk_error_message("The following fields are invalid %s" %
                              bad_fields )
            return False
    
    def __current_page_ident(self):
        config = self.plugin.get_configuration(allow_reload=False)
        return config.pages[self.current_page]

    def __entry_widget_is_check_excempt(self, widget_name):
        config = self.plugin.get_configuration(allow_reload=False)
        return (self.__current_page_ident(), widget_name) in \
            config.non_decimal_check_labels

    def widget_valid(self, widget_name, widget):
        config = self.plugin.get_configuration(allow_reload=False)
        if isinstance(widget, Entry) and \
                not self.__entry_widget_is_check_excempt(widget_name):
            try:
                entry_to_decimal_convert(
                    widget.get_text(), widget_name,
                    self.__current_page_ident(),
                    config)
            except EntryTextToDecimalConversionFail:
                return False
        # this covers not only the else case on the first if, but the
        # the case with the above try, except passes without exception
        return True

    def nav_but_clicked(self, but, *args):
        config = self.plugin.get_configuration(allow_reload=False)
        
        old_page = self.current_page
        delta = -1 if self.nav_buts[but] == GLADE_BACK_NAV else 1
        new_page = old_page + delta
        # reject a change outside the acceptable range.. and hmm,
        # perhaps this event handler should never even run under those
        # conditions because we should really just grey the buttons
        if not (new_page < 0 or new_page == len(self.glade_pages)) and \
                self.page_change_acceptable_by_input_valid() and \
                config.page_change_acceptable(self.trans, old_page, new_page):

            # intentionally done before the page is actually attached,
            # that's what we mean by pre
            config.page_pre_change_config_hooks(self.trans, old_page, new_page)

            self.detach_current_page()
            self.current_page = new_page
            self.attach_current_page()
            
            # intentionally done after the page is actually attached,
            # that's what we mean by post
            config.page_post_change_config_hooks(self.trans, old_page, new_page)

    entry_changed = make_widget_changed_func(lambda w: w.get_text() )
    calendar_changed = make_widget_changed_func(get_current_date_of_gtkcal)
    checkbutton_changed = make_widget_changed_func(get_state_of_checkbutton)

    def update_auto_labels(self):
        config = self.plugin.get_configuration(allow_reload=False)
        # this function should never be called if the config hasn't been
        # checked out as okay
        assert( hasattr(config, 'auto_update_labels') )
        for page, label_name, label_source_func in config.auto_update_labels:
            if self.page_is_current(page):
                try:
                    label_text = str(label_source_func(
                            self.trans.widget_states, config))
                except EntryTextToDecimalConversionFail, e:
                    label_text = ''
                except WidgetFindError, no_find_e:
                    label_text = str(no_find_e)
                self.current_widget_dict[label_name].set_text(label_text)
def create_editable_type_defined_listview_and_model(
    field_list, new_row_func, parralell_list, change_register,
    readonly=False,
    insert_pre_hook=null_function, insert_post_hook=null_function,
    change_pre_hook=null_function, change_post_hook=null_function,
    del_pre_hook=null_function, del_post_hook=null_function):
    vbox = VBox()
    tv = TreeView()
    model = ListStore( * chain((display_fieldtype_transform(fieldtype)
                                for fieldname, fieldtype in field_list),
                               (store_fieldtype_transform(fieldtype)
                                for fieldname, fieldtype in field_list)
                               ) # chain
                         ) # ListStore
    # it is important to do this fill of the liststore
    # with the existing items first prior to adding event handlers
    # (row-changed, row-inserted, row-deleted) that
    # look for changes and keep the two lists in sync
    for list_row in parralell_list:
        model.append(
            tuple(transform_list_row_into_twice_repeated_row_for_model(
                    list_row, field_list) )
            ) # append
    if not readonly:
        model.connect("row-changed",
                      row_changed_handler,
                      parralell_list, change_register, field_list,
                      change_pre_hook, change_post_hook,
                      )
        model.connect("row-inserted",
                      row_inserted_handler,
                      parralell_list, change_register,
                      insert_pre_hook, insert_post_hook )
        model.connect("row-deleted",
                      row_deleted_handler, parralell_list, change_register,
                      del_pre_hook, del_post_hook)

    for i, (fieldname, fieldtype) in enumerate(field_list):
        def setup_edited_handler_for_renderer_to_original_model(cell_renderer):
            cell_renderer.connect(
                'edited',
                cell_edited_update_original_modelhandler, model, i,
                field_list[i][FIELD_TYPE])
            return cell_renderer

        if fieldtype == date:
            cell_renderer = \
                setup_edited_handler_for_renderer_to_original_model(
                CellRendererDate() )
        elif type(fieldtype) == tuple:
            cell_renderer = CellRendererCombo()
            cell_renderer.set_property("has-entry",
                                       fieldtype[COMBO_TYPE_HAS_ENTRY_FIELD])
            combo_liststore = ListStore(
                str, store_fieldtype_transform(fieldtype) )
            for combo_string, combo_value in \
                    combobox_list_strings_and_values_iteration(fieldtype):
                combo_liststore.append( (combo_string, combo_value) )
            cell_renderer.set_property("model", combo_liststore)
            cell_renderer.set_property("text-column", 0)
            if fieldtype[COMBO_TYPE_HAS_ENTRY_FIELD]:
                setup_edited_handler_for_renderer_to_original_model(
                    cell_renderer)
            else:
                lookup_dict = dict(
                    combobox_list_strings_and_values_iteration(fieldtype) )
                cell_renderer.connect(
                'edited',
                combo_cell_edited_update_original_modelhandler, model, i,
                lookup_dict)

        elif type(fieldtype) == dict and fieldtype['type'] == file:
            cell_renderer = CellRendererFile(
                fieldtype['file_type']  if 'file_type' in fieldtype
                else FILE_CHOOSER_ACTION_OPEN 
                )
            setup_edited_handler_for_renderer_to_original_model(cell_renderer)
        else:
            cell_renderer = \
                setup_edited_handler_for_renderer_to_original_model(
                CellRendererText() )
        if not readonly:
            cell_renderer.set_property("editable", True)
            cell_renderer.set_property("editable-set", True)
        tvc = TreeViewColumn(fieldname, cell_renderer, text=i)
        tv.append_column(tvc)
    vbox.pack_start(tv)
    tv.set_model(model)
    hbox = HBox()
    buttons = [ pack_in_stock_but_and_ret(start_stock_button(code), hbox)
                for code in (STOCK_ADD, STOCK_DELETE) ]
    if readonly: 
        for button in buttons:
            button.set_property("sensitive", False)
    else:
        buttons[0].connect(
            "clicked",
            editable_listview_add_button_clicked_handler,
            model, new_row_func, field_list  )
        buttons[1].connect(
            "clicked",
            editable_listview_del_button_clicked_handler,
            tv )
    vbox.pack_start(hbox, expand=False)
    return model, tv, vbox
class upgrade_dialog(Window):

    def __init__(self, to_upgrade, icon):

        Window.__init__(self, WINDOW_TOPLEVEL)
        self.set_property("skip-taskbar-hint", True)
        self.set_property("modal", True)
        self.set_property("destroy-with-parent", True)
        self.set_position(WIN_POS_CENTER)
        self.set_default_size (300, 300)

        self.set_icon(pixbuf_new_from_file(icon))
        self._setup_tree(to_upgrade)
        self._setup_layout()

    def _setup_layout(self):
        self.vbox = VBox(False, 0)
        self.vbox.show()

        self.terminal = terminal()
        self.terminal.connect("child-exited", lambda _: self.close_button.show())
        
        self.expander = expander_new_with_mnemonic(_("_Terminal"))
        self.expander.set_expanded(False)
        self.expander.add(self.terminal)
        self.expander.show_all()
        
        self.close_button = Button(stock=STOCK_CLOSE)
        self.close_button.connect("clicked", lambda _: self.destroy())

        scr = ScrolledWindow()
        scr.set_policy ("automatic", "automatic")
        scr.add (self.tree)
        scr.show()

        vpaned = VPaned()
        vpaned.add1(scr)
        vpaned.add2(self.expander)
        vpaned.set_position (260)
        vpaned.show()

        self.vbox.pack_start(vpaned, True, True, 0)
        self.vbox.pack_start(self.close_button, False, False, 0)

        self.add(self.vbox)
        return

    def _setup_tree(self, pacs):
        self.model = ListStore(str, str, str)

        for pac in pacs:
            self.model.append(["yellow", pac.name, pac.version])
            continue

        self.tree = TreeView()
        self.tree.show()

        self.tree.insert_column_with_attributes(-1, "", CellRendererPixbuf(),
                                                stock_id = 0)
        self.tree.insert_column_with_attributes(-1, "Package",
                                                CellRendererText(), text = 1)
        self.tree.insert_column_with_attributes(-1, "Version",
                                                CellRendererText(), text = 2)

        self.tree.set_model(self.model)
        return
    
    def run(self):
        self.show()
        self.terminal.do_upgrade()
class do_dialog(Window):

    def __init__(self, queues, icon):

        Window.__init__(self, WINDOW_TOPLEVEL)
        self.set_property("skip-taskbar-hint", True)
        self.set_property("destroy-with-parent", True)
        self.set_modal(True)
        self.connect("delete-event", self._stop_closing)
        self.set_position(WIN_POS_CENTER)

        self.set_icon(pixbuf_new_from_file(icon))
        self._setup_trees(queues)
        self._setup_layout()

        self.queues = queues

    def _setup_trees(self, queues):

        self._setup_install_tree(queues["add"])
        self._setup_remove_tree(queues["remove"])

    def _setup_install_tree(self, add_queue):

        self.inst_model = ListStore(str, str, str)

        for pac in add_queue:
            if pac.isold:
                image = "yellow"
            elif pac.installed:
                image = "green"
            else:
                image = "red"

            self.inst_model.append([image, pac.name, pac.version])
            continue

        self.inst_tree = TreeView()

        self.inst_tree.insert_column_with_attributes(-1, "",
                                                     CellRendererPixbuf(),
                                                     stock_id = 0)
        self.inst_tree.insert_column_with_attributes(-1, _("Package"),
                                                     CellRendererText(),
                                                     text = 1)
        self.inst_tree.insert_column_with_attributes(-1, _("Version"),
                                                     CellRendererText(),
                                                     text = 2)
        self.inst_tree.set_model(self.inst_model)

    def _setup_remove_tree(self, remove_queue):

        self.rem_model = ListStore(str, str, str)

        for pac in remove_queue:
            if pac.isold:
                image = "yellow"
            elif pac.installed:
                image = "green"
            else:
                image = "red"

            self.rem_model.append([image, pac.name, pac.inst_ver])
            continue

        self.rem_tree = TreeView()

        self.rem_tree.insert_column_with_attributes(-1, "",
                                                    CellRendererPixbuf(),
                                                    stock_id = 0)
        self.rem_tree.insert_column_with_attributes(-1, _("Package"),
                                                    CellRendererText(),
                                                    text = 1)
        self.rem_tree.insert_column_with_attributes(-1, _("Installed Version"),
                                                    CellRendererText(),
                                                    text = 2)

        self.rem_tree.set_model(self.rem_model)

    def _set_size (self, widget, event, data=None):
        if self.expander.get_expanded():
            self.size = self.get_size()
            self.expander.add(self.terminal)
            self.terminal.show()
        else:
            self.expander.remove(self.terminal)
            self.resize(self.size[0], self.size[1])
            self.show_all()

    def _setup_layout(self):

        self.hpaned = HPaned()
        self.hpaned.add1(self.inst_tree)
        self.hpaned.add2(self.rem_tree)
        self.hpaned.show_all()

        self.close_button = Button(stock=STOCK_CLOSE)
        self.close_button.connect("clicked", lambda _: self.destroy())

        self.terminal = terminal()
        self.terminal.connect("child-exited", lambda _: self.close_button.show())

        self.expander = Expander(_("Terminal"))
        self.expander.connect("notify::expanded", self._set_size)
        self.expander.show()

        self.vbox = VBox(False, 0)
        self.vbox.show()
        
        self.vbox.pack_start(self.hpaned, False, False, 0)
        self.vbox.pack_start(self.expander, False, False, 0)
        self.vbox.pack_start(self.close_button, False, False, 0)

        
        self.add(self.vbox)

    def run(self):

        self.show()
        self.terminal.do(self.queues)
        return

    def _stop_closing(self, widget, event):
        self.stop_emission("delete-event")
        return True
 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
Beispiel #22
0
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()