Post

Replies

Boosts

Views

Activity

Reply to NSPrintInfo design report
Claude, Makes sense what you posted, I was hoping there was a design tool to create the drawing code. So, does that mean thinks like Font, Font Size, colors, Graphics etc. are created in PrintView Class with code? And I guess the only way to see the report is to print it? Do you have any code of a PrintView class you could share? Thanks
Topic: UI Frameworks SubTopic: AppKit Tags:
May ’21
Reply to NSPrintInfo design report
The following is the correct answer. It was supplied by Claude31 as well as an offline template he sent me. The way I do it is to design the report as a view in code. Schematically, it will be: I create a PrintView and house all the drawing in the draw function class PrintView: NSView { override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. }} Then, to print, I call (from the handler of Print menu command for instance or from a print button in a view) let aSize = NSSize(width: printInfo.paperSize.width - 20, height: totalHeight) let printView = PrintView(frame: NSRect(origin: NSPoint(x: 1, y: 10), size: aSize)) // a full page, depending on orientation and call the printPanel         let printOp = NSPrintOperation(view: printView, printInfo: printInfo)
Topic: UI Frameworks SubTopic: AppKit Tags:
May ’21
Reply to How to call function in NSViewController?
Thanks for the reply! I tried it and I get the following: let printAction CustViewController.printCustomers(self) Instance member 'printCustomers' cannot be used on type 'CustViewController': did you mean to use a value of this type instead? The window controller I am referring to is the main window where as the view controller is from a separate/different window controller/view controller. My objective is to have a main printer control action which would control which printout would be generated when a CMD-P is pressed. One thing from another post mentioned I would need an instance just with contentViewController. Not sure how to code this as well?
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to How to call function in NSViewController?
You are right it compiled fine with the reference and creating and instance, but did throw an exception due to the IBAction used some CustViewController properties. So, using notification I was able to get it working. Also, why do you think the delegation may be the cleanest way? Thanks for the help.
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to How to see current window?
Maybe another way to accomplish what I want is...If when you change focus of a window an event is posted in the now focused window gets control. In other words can the focused window tell it just got the focus. Is there way to do this?
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to How to add headers programmatically to NSTableView
I got the answer to this from apple support. It seems the tableView must part of a scrollView for the headers to appear. So I removed any reference to the explicit creation of a table header view and I added the following code to get this working: let scrollView = NSScrollView() scrollView.documentView = tableViewForPrint stackView.addArrangedSubview(scrollView)
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to Drawing an NSImage using COCOA Drawing
Found the following code on gitHub extension NSImage {    /// Create a CIImage using the best representation available    ///    /// - Returns: Converted image, or nil    func asCIImage() -> CIImage? {       if let cgImage = self.asCGImage() {          return CIImage(cgImage: cgImage)       }       return nil    }    /// Create a CGImage using the best representation of the image available in the NSImage for the image size    ///    /// - Returns: Converted image, or nil    func asCGImage() -> CGImage? {       var rect = NSRect(origin: CGPoint(x: 0, y: 0), size: self.size)       return self.cgImage(forProposedRect: &rect, context: NSGraphicsContext.current, hints: nil)     } } extension CIImage {    /// Create a CGImage version of this image    ///    /// - Returns: Converted image, or nil    func asCGImage(context: CIContext? = nil) -> CGImage? {       let ctx = context ?? CIContext(options: nil)       return ctx.createCGImage(self, from: self.extent)    }    /// Create an NSImage version of this image    /// - Parameters:    ///   - pixelSize: The number of pixels in the result image. For a retina image (for example), pixelSize is double repSize    ///   - repSize: The number of points in the result image    /// - Returns: Converted image, or nil    #if os(macOS)    @available(macOS 10, *)    func asNSImage(pixelsSize: CGSize? = nil, repSize: CGSize? = nil) -> NSImage? {       let rep = NSCIImageRep(ciImage: self)       if let ps = pixelsSize {          rep.pixelsWide = Int(ps.width)          rep.pixelsHigh = Int(ps.height)       }       if let rs = repSize {          rep.size = rs       }       let updateImage = NSImage(size: rep.size)       updateImage.addRepresentation(rep)       return updateImage    }    #endif } extension CGImage {    /// Create a CIImage version of this image    ///    /// - Returns: Converted image, or nil    func asCIImage() -> CIImage {       return CIImage(cgImage: self)    }    /// Create an NSImage version of this image    ///    /// - Returns: Converted image, or nil    func asNSImage() -> NSImage? {       return NSImage(cgImage: self, size: .zero)    } } Added the following two lines to get what I needed  let cgimage: CGImage? = image.asCGImage() // Here comes the picture NSGraphicsContext.current?.cgContext.draw(cgimage!, in: dirtyRect)
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to How to get control from a combo box selection?
Thanks Claude, I used the @IBAction because I needed the contents of the comboBox and I had tried the delegate before and could not see a way to get contents of comboBox.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’21
Reply to Populate one column based on values of other column in a NSTableView
I know how I am going to proceed. I will build an array that I will update from the ComboAction and then use this array for the tableView as opposed to try to update the tableView cells directly.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’21
Reply to TableView not populating?
I found the problem, It was in the IB... there was not a connection from the column textField to the table view cell.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’21
Reply to Populate one column based on values of other column in a NSTableView
Thanks Claude.. I got it working like I want using what I suggested above. Very similar to what you had suggested.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’21
Reply to NSPrintInfo design report
Claude, Makes sense what you posted, I was hoping there was a design tool to create the drawing code. So, does that mean thinks like Font, Font Size, colors, Graphics etc. are created in PrintView Class with code? And I guess the only way to see the report is to print it? Do you have any code of a PrintView class you could share? Thanks
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to NSPrintInfo design report
The following is the correct answer. It was supplied by Claude31 as well as an offline template he sent me. The way I do it is to design the report as a view in code. Schematically, it will be: I create a PrintView and house all the drawing in the draw function class PrintView: NSView { override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. }} Then, to print, I call (from the handler of Print menu command for instance or from a print button in a view) let aSize = NSSize(width: printInfo.paperSize.width - 20, height: totalHeight) let printView = PrintView(frame: NSRect(origin: NSPoint(x: 1, y: 10), size: aSize)) // a full page, depending on orientation and call the printPanel         let printOp = NSPrintOperation(view: printView, printInfo: printInfo)
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to NSPrintInfo design report
Thanks Claude for sending me the additional examples. Very useful!
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to How to save an Image to NsData object and then retrieve.
Thanks, for your answer.. I have decided to save the image to a file.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Xcode 13.2 and Github - No Packages listed
I installed 13.2.1 but still don't see any packages in the GitHub source.
Replies
Boosts
Views
Activity
Dec ’21
Reply to General Question using swiftCharts?
Thanks I will give this a try!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to How to call function in NSViewController?
Thanks for the reply! I tried it and I get the following: let printAction CustViewController.printCustomers(self) Instance member 'printCustomers' cannot be used on type 'CustViewController': did you mean to use a value of this type instead? The window controller I am referring to is the main window where as the view controller is from a separate/different window controller/view controller. My objective is to have a main printer control action which would control which printout would be generated when a CMD-P is pressed. One thing from another post mentioned I would need an instance just with contentViewController. Not sure how to code this as well?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How to call function in NSViewController?
You are right it compiled fine with the reference and creating and instance, but did throw an exception due to the IBAction used some CustViewController properties. So, using notification I was able to get it working. Also, why do you think the delegation may be the cleanest way? Thanks for the help.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How to see current window?
Maybe another way to accomplish what I want is...If when you change focus of a window an event is posted in the now focused window gets control. In other words can the focused window tell it just got the focus. Is there way to do this?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How to add headers programmatically to NSTableView
I got the answer to this from apple support. It seems the tableView must part of a scrollView for the headers to appear. So I removed any reference to the explicit creation of a table header view and I added the following code to get this working: let scrollView = NSScrollView() scrollView.documentView = tableViewForPrint stackView.addArrangedSubview(scrollView)
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to Drawing an NSImage using COCOA Drawing
Found the following code on gitHub extension NSImage {    /// Create a CIImage using the best representation available    ///    /// - Returns: Converted image, or nil    func asCIImage() -> CIImage? {       if let cgImage = self.asCGImage() {          return CIImage(cgImage: cgImage)       }       return nil    }    /// Create a CGImage using the best representation of the image available in the NSImage for the image size    ///    /// - Returns: Converted image, or nil    func asCGImage() -> CGImage? {       var rect = NSRect(origin: CGPoint(x: 0, y: 0), size: self.size)       return self.cgImage(forProposedRect: &rect, context: NSGraphicsContext.current, hints: nil)     } } extension CIImage {    /// Create a CGImage version of this image    ///    /// - Returns: Converted image, or nil    func asCGImage(context: CIContext? = nil) -> CGImage? {       let ctx = context ?? CIContext(options: nil)       return ctx.createCGImage(self, from: self.extent)    }    /// Create an NSImage version of this image    /// - Parameters:    ///   - pixelSize: The number of pixels in the result image. For a retina image (for example), pixelSize is double repSize    ///   - repSize: The number of points in the result image    /// - Returns: Converted image, or nil    #if os(macOS)    @available(macOS 10, *)    func asNSImage(pixelsSize: CGSize? = nil, repSize: CGSize? = nil) -> NSImage? {       let rep = NSCIImageRep(ciImage: self)       if let ps = pixelsSize {          rep.pixelsWide = Int(ps.width)          rep.pixelsHigh = Int(ps.height)       }       if let rs = repSize {          rep.size = rs       }       let updateImage = NSImage(size: rep.size)       updateImage.addRepresentation(rep)       return updateImage    }    #endif } extension CGImage {    /// Create a CIImage version of this image    ///    /// - Returns: Converted image, or nil    func asCIImage() -> CIImage {       return CIImage(cgImage: self)    }    /// Create an NSImage version of this image    ///    /// - Returns: Converted image, or nil    func asNSImage() -> NSImage? {       return NSImage(cgImage: self, size: .zero)    } } Added the following two lines to get what I needed  let cgimage: CGImage? = image.asCGImage() // Here comes the picture NSGraphicsContext.current?.cgContext.draw(cgimage!, in: dirtyRect)
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22