Ejemplo n.º 1
0
 def __init__(self, scrolling = 'hv', **kwds):
     width = 100
     height = 100
     frame = ((0, 0), (width,  height))
     ns_outer = NSScrollView.alloc().initWithFrame_(frame)
     ns_outer.setHasHorizontalScroller_('h' in scrolling)
     ns_outer.setHasVerticalScroller_('v' in scrolling)
     if 'h' in scrolling:
         cwidth = 2000
     else:
         cwidth = ns_outer.contentSize()[0]
     frame = ((0, 0), (cwidth,  height))
     ns_inner = PyGUI_NSTextView.alloc().initWithFrame_(frame)
     ns_inner.pygui_component = self
     ps = NSMutableParagraphStyle.alloc().init()
     ps.setDefaultTabInterval_(ps.tabStops()[0].location())
     ps.setTabStops_([])
     ns_inner.setDefaultParagraphStyle_(ps)
     ns_inner.setAllowsUndo_(True)
     ns_outer.setDocumentView_(ns_inner)
     if 'h' not in scrolling:
         ns_inner.setAutoresizingMask_(NSViewWidthSizable)
     if 'font' not in kwds:
         kwds['font'] = StdFonts.application_font
     GTextEditor.__init__(self, ns_outer,
         _ns_inner_view = ns_inner, **kwds)
Ejemplo n.º 2
0
 def __init__(self, scrolling='hv', **kwds):
     width = 100
     height = 100
     frame = ((0, 0), (width, height))
     ns_outer = NSScrollView.alloc().initWithFrame_(frame)
     ns_outer.setHasHorizontalScroller_('h' in scrolling)
     ns_outer.setHasVerticalScroller_('v' in scrolling)
     if 'h' in scrolling:
         cwidth = 2000
     else:
         cwidth = ns_outer.contentSize()[0]
     frame = ((0, 0), (cwidth, height))
     ns_inner = PyGUI_NSTextView.alloc().initWithFrame_(frame)
     ns_inner.pygui_component = self
     ps = NSMutableParagraphStyle.alloc().init()
     ps.setDefaultTabInterval_(ps.tabStops()[0].location())
     ps.setTabStops_([])
     ns_inner.setDefaultParagraphStyle_(ps)
     ns_inner.setAllowsUndo_(True)
     ns_outer.setDocumentView_(ns_inner)
     if 'h' not in scrolling:
         ns_inner.setAutoresizingMask_(NSViewWidthSizable)
     if 'font' not in kwds:
         kwds['font'] = StdFonts.application_font
     GTextEditor.__init__(self, ns_outer, _ns_inner_view=ns_inner, **kwds)
Ejemplo n.º 3
0
    def setupUI(self):
        self.statusbar = NSStatusBar.systemStatusBar()
        # Create the statusbar item
        self.statusitem = self.statusbar.statusItemWithLength_(NSVariableStatusItemLength)
        # Set initial image
        raw_data = base64.b64decode(''.join(GOAGENT_ICON_DATA.strip().splitlines()))
        self.image_data = NSData.dataWithBytes_length_(raw_data, len(raw_data))
        self.image = NSImage.alloc().initWithData_(self.image_data)
        self.statusitem.setImage_(self.image)
        # Let it highlight upon clicking
        self.statusitem.setHighlightMode_(1)
        # Set a tooltip
        self.statusitem.setToolTip_(GOAGENT_TITLE)

        # Build a very simple menu
        self.menu = NSMenu.alloc().init()
        # Show Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Show', 'show:', '')
        self.menu.addItem_(menuitem)
        # Hide Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Hide', 'hide2:', '')
        self.menu.addItem_(menuitem)
        # Rest Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Reload', 'reset:', '')
        self.menu.addItem_(menuitem)
        # Default event
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'exit:', '')
        self.menu.addItem_(menuitem)
        # Bind it to the status item
        self.statusitem.setMenu_(self.menu)

        # Console window
        frame = NSMakeRect(0,0,550,350)
        self.console_window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(frame, NSClosableWindowMask|NSTitledWindowMask, NSBackingStoreBuffered, False)
        self.console_window.setTitle_(GOAGENT_TITLE)
        self.console_window.setDelegate_(self)

        # Console view inside a scrollview
        self.scroll_view = NSScrollView.alloc().initWithFrame_(frame)
        self.scroll_view.setBorderType_(NSNoBorder)
        self.scroll_view.setHasVerticalScroller_(True)
        self.scroll_view.setHasHorizontalScroller_(False)
        self.scroll_view.setAutoresizingMask_(NSViewWidthSizable|NSViewHeightSizable)

        self.console_view = NSTextView.alloc().initWithFrame_(frame)
        self.console_view.setVerticallyResizable_(True)
        self.console_view.setHorizontallyResizable_(True)
        self.console_view.setAutoresizingMask_(NSViewWidthSizable)

        self.scroll_view.setDocumentView_(self.console_view)

        contentView = self.console_window.contentView()
        contentView.addSubview_(self.scroll_view)

        # Hide dock icon
        NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
 def __init__(self, **kwds):
     width, height = default_size
     ns_frame = NSMakeRect(0, 0, width, height)
     ns_inner_view = PyGUI_User_NSView.alloc().initWithFrame_(ns_frame)
     if self._ns_scrollable:
         ns_view = NSScrollView.alloc().initWithFrame_(ns_frame)
         ns_view.setDocumentView_(ns_inner_view)
         ns_view.setBackgroundColor_(ns_gray)
     else:
         ns_view = ns_inner_view
     ns_inner_view.pygui_component = self
     GDrawableContainer.__init__(self, _ns_view = ns_view, _ns_inner_view = ns_inner_view)
     self.set(**kwds)
Ejemplo n.º 5
0
 def __init__(self, **kwds):
     width, height = default_size
     ns_frame = NSMakeRect(0, 0, width, height)
     ns_tableview = PyNSTableView.alloc().initWithFrame_(ns_frame)
     ns_tableview.pygui_component = self
     ns_tableview.setColumnAutoresizingStyle_(0)
     ns_scrollview = NSScrollView.alloc().initWithFrame_(ns_frame)
     ns_scrollview.setDocumentView_(ns_tableview)
     ns_scrollview.setAutoresizingMask_(ns_table_autoresizing_mask)
     GTableView.__init__(self,
                         _ns_view=ns_scrollview,
                         _ns_inner_view=ns_tableview)
     self.set(**kwds)
     ns_tableview.setDataSource_(ns_tableview)
Ejemplo n.º 6
0
 def __init__(self, **kwds):
     width, height = default_size
     ns_frame = NSMakeRect(0, 0, width, height)
     ns_inner_view = PyGUI_User_NSView.alloc().initWithFrame_(ns_frame)
     if self._ns_scrollable:
         ns_view = NSScrollView.alloc().initWithFrame_(ns_frame)
         ns_view.setDocumentView_(ns_inner_view)
         ns_view.setBackgroundColor_(ns_gray)
     else:
         ns_view = ns_inner_view
     ns_inner_view.pygui_component = self
     GDrawableContainer.__init__(self,
                                 _ns_view=ns_view,
                                 _ns_inner_view=ns_inner_view)
     self.set(**kwds)
Ejemplo n.º 7
0
 def open_license(_):
     print(0)
     alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
         'License', None, None, None, 'GNU General Public License, version 3')
     alert.setAlertStyle_(0)
     textview = NSTextView.alloc().initWithFrame_(NSMakeRect(0, 0, 420, 180))
     textview.setEditable_(False)
     if getattr(sys, 'frozen', False):
         # noinspection PyUnresolvedReferences
         textview.setString_('\n' + open(sys._MEIPASS[:len(sys._MEIPASS) - 5] + 'Resources/LICENSE').read())
     else:
         textview.setString_('\n' + open('LICENSE').read())
     sv = NSScrollView.alloc().initWithFrame_(textview.frame())
     sv.setBorderType_(1)
     sv.setHasVerticalScroller_(True)
     sv.setAutoresizingMask_(2 | 16)
     sv.setDocumentView_(textview)
     alert.setAccessoryView_(sv)
     alert.runModal()
Ejemplo n.º 8
0
    def _setupContentView(self):
        # ------------------------------------------ #
        #                   Table View               #
        # ------------------------------------------ #
        rect = NSMakeRect(0, 0, self.WIDTH, self.HEIGHT)
        containerView = NSView.alloc().initWithFrame_(rect)

        # Startup btn
        height = 20
        margin = 20
        width = self.WIDTH - 2 * margin
        self.startupBtn = NSButton.buttonWithTitle_target_action_(
            "Run safetyapp on startup", self, "startupDidChanged:")
        self.startupBtn.setButtonType_(NSButtonTypeSwitch)
        self.startupBtn.setFrame_(
            NSMakeRect(margin, self.HEIGHT - 2 * height, width, height))
        self.startupBtn.setState_(self.data["startup"])
        containerView.addSubview_(self.startupBtn)

        # API Key settings
        titleLabel = NSTextField.labelWithString_("API Key")
        titleLabel.setTextColor_(NSColor.blackColor())
        rect = NSMakeRect(
            self.startupBtn.frame().origin.x,
            self.startupBtn.frame().origin.y -
            self.startupBtn.frame().size.height - height, width, height)
        titleLabel.setFrame_(rect)
        titleLabel.setFont_(NSFont.boldSystemFontOfSize_(14))
        containerView.addSubview_(titleLabel)

        # API Key Sub-label
        titleSubLabel = NSTextField.labelWithString_(
            "Lorem lpsum dolor sit amet")
        titleSubLabel.setTextColor_(NSColor.blackColor())
        rect = NSMakeRect(
            titleLabel.frame().origin.x,
            titleLabel.frame().origin.y - titleLabel.frame().size.height -
            height / 2, width, height)
        titleSubLabel.setFrame_(rect)
        titleSubLabel.setFont_(NSFont.systemFontOfSize_(14))
        containerView.addSubview_(titleSubLabel)

        # API Key text field
        self.apiTextField = NSTextField.textFieldWithString_("")
        rect = NSMakeRect(
            titleSubLabel.frame().origin.x,
            titleSubLabel.frame().origin.y -
            titleSubLabel.frame().size.height - height / 2, width,
            1.2 * height)
        self.apiTextField.setFrame_(rect)
        self.apiTextField.setFocusRingType_(NSFocusRingTypeNone)
        self.apiTextField.setTitleWithMnemonic_(self.data["api_key"])
        self.apiTextField.setEditable_(True)
        containerView.addSubview_(self.apiTextField)
        self.window().makeFirstResponder_(self.apiTextField)

        # Table title
        tableTitleLabel = NSTextField.labelWithString_("Directories")
        tableTitleLabel.setTextColor_(NSColor.blackColor())
        rect = NSMakeRect(
            self.apiTextField.frame().origin.x,
            self.apiTextField.frame().origin.y -
            self.apiTextField.frame().size.height - height, width, height)
        tableTitleLabel.setFrame_(rect)
        tableTitleLabel.setFont_(NSFont.boldSystemFontOfSize_(14))
        containerView.addSubview_(tableTitleLabel)

        # Table sub-title
        tableSubTitleLabel = NSTextField.labelWithString_(
            "Lorem lpsum dolor sit amet")
        tableSubTitleLabel.setTextColor_(NSColor.blackColor())
        rect = NSMakeRect(
            tableTitleLabel.frame().origin.x,
            tableTitleLabel.frame().origin.y -
            tableTitleLabel.frame().size.height - height / 2, width, height)
        tableSubTitleLabel.setFrame_(rect)
        tableSubTitleLabel.setFont_(NSFont.systemFontOfSize_(14))
        containerView.addSubview_(tableSubTitleLabel)

        # ------------------------------------------ #
        #               Toolbar button               #
        # ------------------------------------------ #
        rect = NSMakeRect(20, 20, 67, 21)
        segControl = NSSegmentedControl.alloc().initWithFrame_(rect)
        segControl.setSegmentCount_(2)
        segControl.setSegmentStyle_(NSSegmentStyleSmallSquare)
        segControl.setWidth_forSegment_(32, 0)
        segControl.setWidth_forSegment_(32, 1)
        segControl.setImage_forSegment_(
            NSImage.imageNamed_(NSImageNameAddTemplate), 0)
        segControl.setImage_forSegment_(
            NSImage.imageNamed_(NSImageNameRemoveTemplate), 1)
        segControl.setTarget_(self)
        segControl.setAction_("segControlDidClicked:")
        containerView.addSubview_(segControl)

        rect = NSMakeRect(86, 21,
                          self.WIDTH - 2 * margin - rect.size.width + 1, 21)
        toolbar = NSButton.alloc().initWithFrame_(rect)
        toolbar.setTitle_("")
        toolbar.setRefusesFirstResponder_(True)
        toolbar.setBezelStyle_(NSBezelStyleSmallSquare)
        containerView.addSubview_(toolbar)

        height = tableSubTitleLabel.frame().origin.y - segControl.frame(
        ).origin.y - margin - segControl.frame(
        ).size.height + 1 + tableSubTitleLabel.frame().size.height / 2
        rect = NSMakeRect(
            tableSubTitleLabel.frame().origin.x,
            tableSubTitleLabel.frame().origin.y -
            tableSubTitleLabel.frame().size.height / 2 - height, width, height)
        scrollView = NSScrollView.alloc().initWithFrame_(rect)
        scrollView.setBorderType_(NSBezelBorder)

        self.tableView = NSTableView.alloc().initWithFrame_(
            scrollView.bounds())
        self.tableView.setDataSource_(self)
        self.tableView.setDelegate_(self)
        self.tableView.setFocusRingType_(NSFocusRingTypeNone)

        # Path column
        pathCol = NSTableColumn.alloc().initWithIdentifier_(
            self.PATH_COL_IDENTIFIER)
        pathCol.setTitle_("Directory")  # <-- Table view directory column title
        pathCol.setWidth_(self.WIDTH * 0.8)
        textCell = NSTextFieldCell.alloc().init()
        textCell.setEditable_(True)
        textCell.setTarget_(self)
        pathCol.setDataCell_(textCell)

        # Enable column
        enableCol = NSTableColumn.alloc().initWithIdentifier_(
            self.ENALBE_COL_IDENTIFIER)
        enableCol.setTitle_("Enable?")  # <-- Enable column title
        enableCol.setWidth_(self.WIDTH * 0.2)
        cell = NSButtonCell.alloc().init()
        cell.setButtonType_(NSButtonTypeSwitch)
        cell.setTitle_("")
        cell.setTarget_(self)
        enableCol.setDataCell_(cell)

        self.tableView.addTableColumn_(pathCol)
        self.tableView.addTableColumn_(enableCol)

        scrollView.setDocumentView_(self.tableView)
        scrollView.setHasVerticalScroller_(True)
        containerView.addSubview_(scrollView)
        self.window().setContentView_(containerView)
Ejemplo n.º 9
0
    def setupUI(self):
        self.statusbar = NSStatusBar.systemStatusBar()
        # Create the statusbar item
        self.statusitem = self.statusbar.statusItemWithLength_(
            NSVariableStatusItemLength)
        # Set initial image
        raw_data = base64.b64decode(''.join(
            GOAGENT_ICON_DATA.strip().splitlines()))
        self.image_data = NSData.dataWithBytes_length_(raw_data, len(raw_data))
        self.image = NSImage.alloc().initWithData_(self.image_data)
        self.statusitem.setImage_(self.image)
        # Let it highlight upon clicking
        self.statusitem.setHighlightMode_(1)
        # Set a tooltip
        self.statusitem.setToolTip_(GOAGENT_TITLE)

        # Build a very simple menu
        self.menu = NSMenu.alloc().init()
        # Show Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Show', 'show:', '')
        self.menu.addItem_(menuitem)
        # Hide Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Hide', 'hide2:', '')
        self.menu.addItem_(menuitem)
        # Rest Menu Item
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Reload', 'reset:', '')
        self.menu.addItem_(menuitem)
        # Default event
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Quit', 'exit:', '')
        self.menu.addItem_(menuitem)
        # Bind it to the status item
        self.statusitem.setMenu_(self.menu)

        # Console window
        frame = NSMakeRect(0, 0, 550, 350)
        self.console_window = NSWindow.alloc(
        ).initWithContentRect_styleMask_backing_defer_(
            frame, NSClosableWindowMask | NSTitledWindowMask,
            NSBackingStoreBuffered, False)
        self.console_window.setTitle_(GOAGENT_TITLE)
        self.console_window.setDelegate_(self)

        # Console view inside a scrollview
        self.scroll_view = NSScrollView.alloc().initWithFrame_(frame)
        self.scroll_view.setBorderType_(NSNoBorder)
        self.scroll_view.setHasVerticalScroller_(True)
        self.scroll_view.setHasHorizontalScroller_(False)
        self.scroll_view.setAutoresizingMask_(NSViewWidthSizable
                                              | NSViewHeightSizable)

        self.console_view = NSTextView.alloc().initWithFrame_(frame)
        self.console_view.setVerticallyResizable_(True)
        self.console_view.setHorizontallyResizable_(True)
        self.console_view.setAutoresizingMask_(NSViewWidthSizable)

        self.scroll_view.setDocumentView_(self.console_view)

        contentView = self.console_window.contentView()
        contentView.addSubview_(self.scroll_view)

        # Hide dock icon
        NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)