appkit

How to terminate all threads reading from Pipe (NSPipe) related to Process (NSTask)?

你。 提交于 2020-01-04 06:36:09
问题 I am writing a MacOS/Cocoa app that monitors a remote log file using a common recipe that launches a Process (formerly NSTask ) instance on a background thread and reads stdout of the process via a Pipe (formally a NSPipe ) as listed below: class LogTail { var process : Process? = nil func dolog() { // // Run ssh fred@foo.org /usr/bin/tail -f /var/log.system.log // on a background thread and monitor it's stdout. // let processQueue = DispatchQueue.global(qos: .background) processQueue.async {

How can I darken everything displayed in a single NSView?

时间秒杀一切 提交于 2020-01-04 02:33:09
问题 Background: My application has a main window which contains a few smaller NSView objects, each of which contains several different controls, labels, images, etc. One of these views (and everything it contains) is disabled in response to a given flag. When the flag is set, I automatically disable and grey-out all of the controls embedded within that NSView . Question: I would like to know how to darken the disabled NSView . The effect I am looking for would be something like drawing a 50%

NSView does not receive mouseUp: event when mouse button is released outside of view

a 夏天 提交于 2020-01-03 18:43:06
问题 I have a custom NSView subclass with (for example) the following methods: override func mouseDown(with event: NSEvent) { Swift.print("mouseDown") } override func mouseDragged(with event: NSEvent) { Swift.print("mouseDragged") } override func mouseUp(with event: NSEvent) { Swift.print("mouseUp") } As long as the mouse (button) is pressed, dragged and released all inside the view, this works fine. However, when the mouse is depressed inside the view, moved outside the view, and only then

NSView does not receive mouseUp: event when mouse button is released outside of view

一世执手 提交于 2020-01-03 18:43:01
问题 I have a custom NSView subclass with (for example) the following methods: override func mouseDown(with event: NSEvent) { Swift.print("mouseDown") } override func mouseDragged(with event: NSEvent) { Swift.print("mouseDragged") } override func mouseUp(with event: NSEvent) { Swift.print("mouseUp") } As long as the mouse (button) is pressed, dragged and released all inside the view, this works fine. However, when the mouse is depressed inside the view, moved outside the view, and only then

Separator item in NSPopupButton with bindings

天大地大妈咪最大 提交于 2020-01-03 07:21:28
问题 The contents of a NSPopupButton are bound to an NSArray of strings. How can we insert a separator item via bindings? The " - " strings (like in the olden/Classic days) doesn't work, i.e. shows up literally as a " - " menu item. Is there any out-of-the-box solution with standard Cocoa classes and bindings? This should be a trivial problem but I can't find any solution to the problem that doesn't involve silly hacks like subclassing NSMenu , NSPopupButton or other non-intuitive work arounds.

Subclassing NSScroller, how to get rid of the white square in the lower right corner?

旧时模样 提交于 2020-01-01 15:57:53
问题 I've created an iTunes like subclass of NSScroller, however if both the horizontal and vertical scrollers are visible in an NSScrollView or NSTableView I'm left with an ugly white square in the lower right corner. Anyone has a clue on where to add my custom drawing to fill that in with something prettier? 回答1: Ok, I think I have the solution(s). Either you tell the scrollview not to draw its background, in that case anything below it will fill the corner. Or, which is what I did, you override

Subclassing NSScroller, how to get rid of the white square in the lower right corner?

梦想的初衷 提交于 2020-01-01 15:57:04
问题 I've created an iTunes like subclass of NSScroller, however if both the horizontal and vertical scrollers are visible in an NSScrollView or NSTableView I'm left with an ugly white square in the lower right corner. Anyone has a clue on where to add my custom drawing to fill that in with something prettier? 回答1: Ok, I think I have the solution(s). Either you tell the scrollview not to draw its background, in that case anything below it will fill the corner. Or, which is what I did, you override

How do you get smooth high-rate playback from AVPlayer?

£可爱£侵袭症+ 提交于 2020-01-01 03:01:30
问题 AVPlayer has a property called rate that is meant to control the playback rate. 1.0 is normal speed while values like 2.0 or 5.0 should playback at 2x and 5x respectively. Whenever I set a playback rate value higher than 1.0 (say 10.0 ), the playback is very choppy and it looks like a large number of frames are getting dropped as the player can't keep up. However, the same values in QuickTime Player (with the same movie), produce smooth playback for rates of 2x, 5x, 10x, 30x and 60x (as

NSProgressIndicator in NSMenuItem not updating on second display

混江龙づ霸主 提交于 2019-12-31 02:29:09
问题 I've got a NSMenu attached to a NSStatusItem (a menu bar application). While downloading a file I want to display a NSProgressIndicator in an item of this menu. I've created a NSViewController subclass for this progress indicator with the following properties: @property NSUInteger current; // Bound to NSProgressIndicator value @property NSString *status; // Bound to a NSTextField value @property NSUInteger total; // Bound to NSProgressIndicator max value When needed I start the download of

UIKit's [NSString sizeWithFont:constrainedToSize:] in AppKit

霸气de小男生 提交于 2019-12-30 04:58:08
问题 Is there any equivalent method in AppKit (for Cocoa on Mac OS X) that does the same thing as UIKit's [NSString sizeWithFont:constrainedToSize:] ? If not, how could I go about getting the amount of space needed to render a particular string constrained to a width/height? Update: Below is a snippet of code I'm using that I expect would produce the results I'm after. NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSFont systemFontOfSize: [NSFont smallSystemFontSize]],