def appStart(): try: global are, idu app = Application() idu = IronDiskUsage(app) global dispatcher dispatcher = Dispatcher.FromThread(Thread.CurrentThread) are.Set() app.Run() finally: IronPython.Hosting.PythonEngine.ConsoleCommandDispatcher = None
def _initialize(self, state): print('init') global main_window, logic_thread, application, _running print('coinitializing') pythoncom.CoInitialize() print('coinitialized') main_window = MainWindow() main_window.DataContext = ApplicationViewModel() logic_thread = LogicThread(main_window.DataContext) logic_thread.start() application = Application() main_window.Hide() print('ai opened') _running = True application.Run()
from System.Windows.Controls import (Button, Label, StackPanel) from System.Windows.Media.Effects import DropShadowBitmapEffect win = Window(Title="Welcome to IronPython", Width=450) win.SizeToContent = SizeToContent.Height stack = StackPanel() stack.Margin = Thickness(15) win.Content = stack button = Button(Content="Push Me", FontSize=24, BitmapEffect=DropShadowBitmapEffect()) def onClick(sender, event): msg = Label() msg.FontSize = 36 msg.Content = 'Welcome to IronPython!' stack.Children.Add(msg) button.Click += onClick stack.Children.Add(button) app = Application() app.Run(win)
def start(): global idu app = Application() idu = IronDiskUsage(app) app.Run()
def RunApp(rootElement): app = Application() app.Run(rootElement)
class Manager(object): """ Main control on the app init all components and launch the form handle the exit and saves some convenient settings """ def __init__(self): super(Manager, self).__init__() logger.info('iph starting in {}'.format(hostname)) self.app = None self.mode_dbg = False self.is_revit_host = 'Autodesk' in hostname self.modelview = None self.main_form = None self.settings_file = os.path.join(DIR_PATH, 'settings.json') self.settings = load_settings_from_file(self.settings_file) def init_components(self, target=None): """ init modelview and main form """ logger.debug('Loading Modelview...') self.modelview = ModelView(self) if self.mode_dbg: self.modelview.debug(self) logger.debug('Loading UI...') if self.modelview.ready: self.main_form = MainForm(self) self.modelview.init(target) else: ok_error('Sorry, modelview cannot start') def start_app(self): """ function called from __init__ display the window """ if self.main_form.ready and self.modelview.ready: if 'Autodesk' not in hostname: # ok in standalone, but makes Revit crash self.app = Application() self.app.DispatcherUnhandledException += self.on_run_exception self.app.Run(self.main_form) else: self.main_form.Show() # ShowDialog else: ok_error('Sorry, a component cannot start') def exit_app(self): """ "handle" the exit, TODO some cleanup... """ if self.mode_dbg: self.log_out() # self.Dispatcher.Invoke(lambda *_: self.win.Close()) if self.save_settings_and_quit(): # else cancel by user if not self.is_revit_host: logger.debug('app exit (standalone)') self.app.DispatcherUnhandledException -= self.on_run_exception Application.Current.Shutdown() # ok in standalone, but makes Revit crash else: logger.debug('app exit (revit context)') self.main_form.Close() # crash in standalone iph.SESSION = None def save_settings_and_quit(self): """ check if changes in settings and ask for save or cancel window pos is saved anyway """ _exit = True try: self.settings['window']['Left'] = self.main_form.Left self.settings['window']['Top'] = self.main_form.Top self.settings['window']['Width'] = self.main_form.Width self.settings['window']['Height'] = self.main_form.Height new_targets = [api.get_json() for api in self.modelview.treemanager.list_options] if not new_targets == self.settings['api_set']: action_user = ok_no_cancel('Save the targets changes ?') if action_user: self.settings['api_set'] = new_targets elif action_user is None: _exit = False if _exit: save_settings_to_file(self.settings, self.settings_file) except Exception as error: logger.error('save_settings failed :\n' + str(error)) finally: return _exit def log_out(self): """ logs the 100 last errors stacked in logger when app is closing """ logs = logger.errors[:100] if logs: import time ldate = time.strftime('%d %b %Y %X') with open(os.path.join(DIR_PATH, 'logs', 'session.log'), 'w') as fileout: fileout.write(ldate+'\n') for er in logs: fileout.write(str(er)+'\n') # # # EVENTS # # def on_run_exception(self, sender, event): """ catch runtime exception when running alone """ msg = str(event.Exception.Message) ok_error(msg) logger.error('Runtime exception :\n' + msg) event.Handled = True def __repr__(self): return 'Main App Manager (Debug: {})'.format(self.mode_dbg)
class ViewModel(NotifyPropertyChangedBase): def __init__(self): super(ViewModel, self).__init__() # must be string to two-way binding work correctly #self.define_notifiable_property("size") self.size = '10' self.fill_color = '#0066cc' self._red = 90 self._green = 55 self._blue = 200 class TestWindow(MetroWindow): def __init__(self): wpf.LoadComponent(self, 'MetroWindow.xaml') self._vm = ViewModel() self.DataPanel.DataContext = self._vm def __getattr__(self, name): # provides easy access to XAML elements (e.g. self.Button) return self.root.FindName(name) if __name__ == '__main__': app = Application() print "create window" wnd = TestWindow() print "run window" app.Run(wnd)
return self._size @size.setter def size(self, value): self._size = value print 'Size changed to %r' % self.size class TestWPF(object): def __init__(self): self._vm = ViewModel() self.root = XamlReader.Parse(XAML_str) self.DataPanel.DataContext = self._vm self.Button.Click += self.OnClick def OnClick(self, sender, event): # must be string to two-way binding work correctly self._vm.size = '10' def __getattr__(self, name): # provides easy access to XAML elements (e.g. self.Button) return self.root.FindName(name) if __name__ == '__main__': tw = TestWPF() app = Application() app.Run(tw.root)
self.listView.Items.Refresh() self.grid1.DataContext = self.data_worker.get_latest_element() def new_date_add(self, point): self.data_worker.data_update(point) self.bind_values() element = self.data_worker.get_latest_element() #date = datetime.datetime.strptime(element.date_start, "%Y-%m-%d %H:%M:%S.%f") self.CurrentTaskStart.Text = element.date_start self.CurrentTaskEnd.Text = element.date_end def MenuItem_Open_Click(self, sender, e): OpenDialogFile() def Edit_Click(self, id): task = self.data_worker.get_tracked_item_by_id(id) self.grid1.DataContext = task def Exit_Click(self, sender, e): app.Exit app.Shutdown() def MenuItem_Click(self, sender, e): pass if __name__ == '__main__': app = Application() window = MyWindow() app.Run(window)
def main(): hello = HelloWorld() app = Application() app.Run(hello.Root)